Skip to content

Commit d4e0e4d

Browse files
authored
Fix issue report and Fix AAC (#89)
* Update issue-report.sh * Fix vsync * Better look and feel * Fix -acodec * Fix vaapi pixel format * Fix scale_vaapi * Update motd
1 parent 84446f3 commit d4e0e4d

File tree

5 files changed

+116
-49
lines changed

5 files changed

+116
-49
lines changed

issue-report.sh

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
# VARS
55
###############################
66

7+
ffmpeg_version=ffmpeg
78
# shellcheck source=/.github/workflows/mock/VERSION
89
source "/etc/VERSION"
10+
# shellcheck source=/patch_config.sh
11+
source "/var/packages/VideoStation/patch_config.sh" || echo "No patch_config.sh"
912
dsm_version="$productversion $buildnumber-$smallfixnumber"
1013
vs_path=/var/packages/VideoStation
1114
cp_path=/var/packages/CodecPack
@@ -29,44 +32,52 @@ root_check
2932

3033
echo "
3134
================ ISSUE REPORT TOOL ================
35+
https://github.com/AlexPresso/VideoStation-FFMPEG-Patcher
3236
3337
System Details.....................................
3438
DSM Version: $dsm_version
3539
Arch details: $(uname -a)
3640
3741
Package Details....................................
3842
VideoStation version: $(synopkg version VideoStation || echo "Not installed")
39-
FFMPEG version: $(synopkg version ffmpeg || echo "Not installed")
43+
FFMPEG version ($ffmpeg_version): $(synopkg version "${ffmpeg_version}" || echo "Not installed")
4044
CodecPack version: $(synopkg version CodecPack || echo "Not installed")
4145
4246
Patch Details......................................
4347
Is patched ? $([ -f "$vs_path/target/lib/libsynovte.so.orig" ] && echo "yes" || echo "no")
4448
Has gstreamer ? $([ -f "$vs_path/target/bin/gst-launch-1.0" ] && echo "yes" || echo "no")
49+
50+
FFMPEG VAAPI.......................................
51+
$("/var/packages/${ffmpeg_version}/target/bin/vainfo" || echo "No VAAPI Support")
52+
53+
CodecPack Details..................................
54+
Has AAC ? $([ -f "$cp_path/target/pack/HAS_AAC" ] && echo "yes" || echo "no")
55+
Has HEVC ? $([ -f "$cp_path/target/pack/HAS_HEVC" ] && echo "yes" || echo "no")
4556
"
4657

47-
echo " CodecPack target/bin content:"
58+
echo "CodecPack target/bin content......................."
4859
ls -l "$cp_path/target/bin"
4960
echo ""
50-
echo " CodecPack target/pack/bin content:"
61+
echo "CodecPack target/pack/bin content.................."
5162
ls -l "$cp_path/target/pack/bin"
5263
echo ""
53-
echo " CodecPack status:"
64+
echo "CodecPack status..................................."
5465
cat "$cp_path/var/codec_requirements.json" || echo "file not exists"
5566

5667
echo ""
5768

5869
echo ""
59-
echo "GSTInspect last stderr logs........................."
70+
echo "GSTInspect last stderr logs........................"
6071
tail -22 /tmp/gstinspect*.stderr
6172
echo ""
62-
echo "GSTInspect last stderr.prev logs........................."
63-
tail -22 /tmp/gstinspect*.stderr.prev
73+
echo "GSTInspect stderr.prev logs........................"
74+
cat /tmp/gstinspect*.stderr.prev
6475
echo ""
6576
echo "GSTLaunch last stderr logs........................."
6677
tail -22 /tmp/gstlaunch*.stderr
6778
echo ""
68-
echo "GSTLaunch last stderr.prev logs........................."
69-
tail -22 /tmp/gstlaunch*.stderr.prev
79+
echo "GSTLaunch stderr.prev logs........................."
80+
cat /tmp/gstlaunch*.stderr.prev
7081

7182
echo ""
7283
echo "FFMPEG head logs..................................."
@@ -76,8 +87,6 @@ echo "FFMPEG last stderr logs............................"
7687
tail -22 /tmp/ffmpeg*.stderr
7788

7889
echo ""
79-
echo "FFMPEG prev head logs..................................."
80-
head /tmp/ffmpeg*.stderr.prev
90+
echo "FFMPEG prev logs..................................."
91+
cat /tmp/ffmpeg*.stderr.prev
8192
echo ""
82-
echo "FFMPEG prev tail logs..................................."
83-
tail -22 /tmp/ffmpeg*.stderr.prev

motd.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
The patcher now supports every scenario including gstreamer (credits to @nap-liu).
2-
3-
A new version of the wrapper was deployed (v2.1).
4-
You can find the changelog here: https://github.com/AlexPresso/VideoStation-FFMPEG-Patcher/releases/tag/2.1
1+
A new version of the wrapper was deployed (v2.2) fixing some issues with HEVC and AAC transcoding.
2+
You can find the changelog here: https://github.com/AlexPresso/VideoStation-FFMPEG-Patcher/releases/tag/2.2
53

64
As always, please let me know of any issue you could have.

patch_config.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# shellcheck disable=SC2034
4+
ffmpeg_version=@ffmpeg_version@

patcher.sh

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -89,31 +89,32 @@ gstreamer_libs=(
8989
###############################
9090

9191
log() {
92-
echo "[$(date '+%Y-%m-%d %H:%M:%S')] [$1] $2"
92+
printf "\e[0;37m[%s] \e[0m[%s] %b" "$(date '+%Y-%m-%d %H:%M:%S')" "$1" "$2$3"
9393
}
9494
info() {
95-
log "INFO" "$1"
95+
log "INFO" "\e[0m" "$1\n"
9696
}
9797
error() {
98-
log "ERROR" "$1"
98+
log "ERROR" "\e[0;31m" "$1\n"
9999
}
100-
101-
root_check() {
102-
if [[ "$EUID" -ne 0 ]]; then
103-
error "This tool needs root access (please run 'sudo -i' before proceeding)."
104-
exit 1
105-
fi
100+
success() {
101+
log "SUCCESS" "\e[0;32m" "$1\n"
106102
}
107103

108104
welcome_motd() {
109105
info "ffmpeg-patcher v$version"
110106

111-
download "$repo_base_url/$branch/motd.txt" /tmp/tmp.wget
107+
download "motd" "$repo_base_url/$branch/motd.txt" /tmp/tmp.wget
108+
log "Message of the day" "\033[1;33m" "\n\n$(cat /tmp/tmp.wget)\n\n"
109+
110+
sleep 3
111+
}
112112

113-
log "Message of the day"
114-
echo ""
115-
cat /tmp/tmp.wget
116-
echo ""
113+
root_check() {
114+
if [[ "$EUID" -ne 0 ]]; then
115+
error "This tool needs root access (please run 'sudo -i' before proceeding)."
116+
exit 1
117+
fi
117118
}
118119

119120
check_dependencies() {
@@ -164,16 +165,20 @@ clean() {
164165
}
165166

166167
download() {
167-
wget -q -O - "$1" > /tmp/temp.wget
168+
log "INFO" "\e[0m" "Downloading $1... "
169+
170+
wget -q -O - "$2" > /tmp/temp.wget
168171
downloadStatus=$?
169172

170173
if [[ $downloadStatus == 0 ]]; then
171-
mv -f /tmp/temp.wget "$2"
174+
mv -f /tmp/temp.wget "$3"
175+
printf "\e[0;32mDone\n"
172176
else
173-
error "An error occurred while downloading $1. Rolling back changes..."
177+
printf "\e[0;31mError\n"
178+
error "An error occurred while downloading $2. Rolling back changes..."
174179
unpatch
175180

176-
error "An error occurred while downloading $1, every changes were rolled back."
181+
error "An error occurred while downloading $2, every changes were rolled back."
177182
error "Please check your internet connection / GithubStatus. If you think this is an error, please file an issue to the repository."
178183
exit 1
179184
fi
@@ -198,8 +203,7 @@ patch() {
198203
info "Saving current $filename script as $filename.orig"
199204
mv -n "$vs_base_path/scripts/$filename" "$vs_base_path/scripts/$filename.orig"
200205

201-
info "Downloading $filename script..."
202-
download "$repo_base_url/$branch/scripts/$filename.sh" "$vs_base_path/scripts/$filename"
206+
download "$filename.sh" "$repo_base_url/$branch/scripts/$filename.sh" "$vs_base_path/scripts/$filename"
203207

204208
info "Injecting script variables..."
205209
repo_full_url="$repo_base_url/$branch"
@@ -214,8 +218,7 @@ patch() {
214218
info "Saving current $filename as $filename.orig"
215219
mv -n "$vs_path/bin/$filename" "$vs_path/bin/$filename.orig"
216220

217-
info "Downloading and installing $filename's wrapper..."
218-
download "$repo_base_url/$branch/wrappers/$filename.sh" "$vs_path/bin/$filename"
221+
download "$filename.sh" "$repo_base_url/$branch/wrappers/$filename.sh" "$vs_path/bin/$filename"
219222
chown root:VideoStation "$vs_path/bin/$filename"
220223
chmod 750 "$vs_path/bin/$filename"
221224
chmod u+s "$vs_path/bin/$filename"
@@ -240,17 +243,15 @@ patch() {
240243
info "Downloading gstreamer plugins..."
241244

242245
for plugin in "${gstreamer_plugins[@]}"; do
243-
info "Downloading $plugin to gstreamer directory..."
244-
download "$repo_base_url/$branch/plugins/$plugin.so" "$vs_path/lib/gstreamer/gstreamer-1.0/$plugin.so"
246+
download "Gstreamer plugin: $plugin" "$repo_base_url/$branch/plugins/$plugin.so" "$vs_path/lib/gstreamer/gstreamer-1.0/$plugin.so"
245247
done
246248

247249
mkdir -p "$vs_path/lib/gstreamer/dri"
248250
mkdir -p "$vs_path/lib/gstreamer/x264-10bit"
249251
mkdir -p "$vs_path/lib/gstreamer/x265-10bit"
250252

251253
for lib in "${gstreamer_libs[@]}"; do
252-
info "Downloading $lib to gstreamer directory..."
253-
download "$repo_base_url/$branch/libs/$lib" "$vs_path/lib/gstreamer/$lib"
254+
download "Gstreamer library: $lib" "$repo_base_url/$branch/libs/$lib" "$vs_path/lib/gstreamer/$lib"
254255
done
255256

256257
info "Saving current GSTOmx configuration..."
@@ -260,8 +261,10 @@ patch() {
260261
cp -n "$cp_path/etc/gstomx.conf" "$vs_path/etc/gstomx.conf"
261262
fi
262263

264+
download "patch_config.sh" "$repo_base_url/$branch/patch_config.sh" "$vs_base_path/patch_config.sh"
265+
263266
info "Setting ffmpeg version to: ffmpeg$ffmpegversion"
264-
sed -i -e "s/@ffmpeg_version@/ffmpeg$ffmpegversion/" "$vs_path/bin/ffmpeg"
267+
sed -i -e "s/@ffmpeg_version@/ffmpeg$ffmpegversion/" "$vs_base_path/patch_config.sh"
265268

266269
info "Saving current libsynovte.so as libsynovte.so.orig"
267270
cp -n "$libsynovte_path" "$libsynovte_path.orig"
@@ -273,8 +276,7 @@ patch() {
273276
restart_packages
274277
clean
275278

276-
echo ""
277-
info "Done patching, you can now enjoy your movies ;) (please add a star to the repo if it worked for you)"
279+
success "Done patching, you can now enjoy your movies ;) (please add a star to the repo if it worked for you)"
278280
}
279281

280282
unpatch() {
@@ -327,11 +329,13 @@ unpatch() {
327329
fi
328330
fi
329331

332+
info "Remove patch config."
333+
rm -f "$vs_base_path/patch_config.sh"
334+
330335
restart_packages
331336
clean
332337

333-
echo ""
334-
info "unpatch complete"
338+
success "Unpatch complete"
335339
}
336340

337341
################################

wrappers/ffmpeg.sh

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,15 @@
44
# VARS
55
#########################
66

7+
ffmpeg_version=ffmpeg
78
pid=$$
89
child=""
910
stderrfile="/tmp/ffmpeg-$pid.stderr"
1011
errcode=0
1112

13+
# shellcheck source=/patch_config.sh
14+
source "/var/packages/VideoStation/patch_config.sh"
15+
1216
#########################
1317
# UTILS
1418
#########################
@@ -49,6 +53,51 @@ endprocess() {
4953
exit $errcode
5054
}
5155

56+
fix_args() {
57+
while [[ $# -gt 0 ]]; do
58+
case "$1" in
59+
-acodec)
60+
shift
61+
if [[ "$1" = "libfaac" ]]; then
62+
args+=("-acodec" "aac")
63+
else
64+
args+=("-acodec" "libfdk_aac")
65+
fi
66+
;;
67+
68+
-vf)
69+
shift
70+
arg="$1"
71+
72+
if [[ "$arg" =~ "scale_vaapi" ]]; then
73+
scale_w=$(echo "$arg" | sed -e 's/.*=w=//g' | sed -e 's/:h=.*//g')
74+
# shellcheck disable=SC2001
75+
scale_h=$(echo "$arg" | sed -e 's/.*:h=//g')
76+
if [[ "$scale_w" != "" && "$scale_h" != "" ]]; then
77+
arg="scale_vaapi=w=$scale_w:h=$scale_h:format=nv12,hwupload,setsar=sar=1"
78+
else
79+
arg="scale_vaapi=format=nv12,hwupload,setsar=sar=1"
80+
fi
81+
fi
82+
83+
args+=("-vf" "$arg")
84+
;;
85+
86+
-r)
87+
shift
88+
;;
89+
90+
-pix_fmt)
91+
shift
92+
;;
93+
94+
*) args+=("$1") ;;
95+
esac
96+
97+
shift
98+
done
99+
}
100+
52101
#########################
53102
# ENTRYPOINT
54103
#########################
@@ -58,11 +107,14 @@ trap handle_error ERR
58107

59108
rm -f /tmp/ffmpeg*.stderr.prev
60109

110+
fix_args "$@"
111+
61112
newline
62113
info "========================================[start ffmpeg $pid]"
63114
info "DEFAULT ARGS: $*"
115+
info "UPDATED ARGS: ${args[*]}"
64116

65-
/var/packages/@ffmpeg_version@/target/bin/ffmpeg "$@" <&0 2>> $stderrfile &
117+
"/var/packages/${ffmpeg_version}/target/bin/ffmpeg" "${args[@]}" <&0 2>> $stderrfile &
66118

67119
child=$!
68120
wait "$child"

0 commit comments

Comments
 (0)