diff --git a/issue-report.sh b/issue-report.sh index b94967c..ce2f368 100644 --- a/issue-report.sh +++ b/issue-report.sh @@ -7,7 +7,7 @@ ffmpeg_version=ffmpeg # shellcheck source=/.github/workflows/mock/VERSION source "/etc/VERSION" -# shellcheck source=/patch_config.sh +# shellcheck source=/utils/patch_config.sh source "/var/packages/VideoStation/patch_config.sh" || echo "No patch_config.sh" dsm_version="$productversion $buildnumber-$smallfixnumber" vs_path=/var/packages/VideoStation diff --git a/motd.txt b/motd.txt index 37c7552..889ee64 100644 --- a/motd.txt +++ b/motd.txt @@ -1,4 +1,6 @@ A new version of the wrapper was deployed (v2.6) fixing an issue with offline transcoding. You can find the changelog here: https://github.com/AlexPresso/VideoStation-FFMPEG-Patcher/releases/tag/2.6 +/!\ PLEASE FOLLOW THE UPDATE PROCEDURE IN THE CHANGELOG TO UPDATE /!\ + As always, please let me know of any issue you could have. diff --git a/patcher.sh b/patcher.sh index 536266b..f87c73e 100755 --- a/patcher.sh +++ b/patcher.sh @@ -20,7 +20,6 @@ wrappers=( vs_base_path=/var/packages/VideoStation vs_path="$vs_base_path/target" libsynovte_path="$vs_path/lib/libsynovte.so" -vs_scripts=("preuninst") cp_base_path=/var/packages/CodecPack cp_path="$cp_base_path/target" cp_bin_path="$cp_path/bin" @@ -197,21 +196,6 @@ patch() { exit 1 fi - for filename in "${vs_scripts[@]}"; do - if [[ -f "$vs_base_path/scripts/$filename" ]]; then - info "Saving current $filename script as $filename.orig" - mv -n "$vs_base_path/scripts/$filename" "$vs_base_path/scripts/$filename.orig" - - download "$filename.sh" "$repo_base_url/$branch/scripts/$filename.sh" "$vs_base_path/scripts/$filename" - - info "Injecting script variables..." - repo_full_url="$repo_base_url/$branch" - sed -i -e "s|@repo_full_url@|$repo_full_url|" "$vs_base_path/scripts/$filename" - - chmod 755 "$vs_base_path/scripts/$filename" - fi - done - for filename in "${wrappers[@]}"; do if [[ -f "$vs_path/bin/$filename" ]]; then info "Saving current $filename as $filename.orig" @@ -221,6 +205,8 @@ patch() { chown root:VideoStation "$vs_path/bin/$filename" chmod 750 "$vs_path/bin/$filename" chmod u+s "$vs_path/bin/$filename" + + sed -i -e "s/@package_name@/VideoStation/" "$vs_path/bin/$filename" fi done @@ -233,24 +219,61 @@ patch() { info "Patching CodecPack's $filename" mv -n "$cp_bin_path/$filename" "$cp_bin_path/$filename.orig" - ln -s -f "$vs_path/bin/$target" "$cp_bin_path/$filename" + download "$filename.sh" "$repo_base_url/$branch/wrappers/$target.sh" "$cp_bin_path/$filename" + chmod 750 "$cp_bin_path/$filename" + chmod u+s "$cp_bin_path/$filename" + + sed -i -e "s/@package_name@/CodecPack/" "$cp_bin_path/$filename" fi done + + if [[ -d "$cp_path/lib/gstreamer" ]]; then + gst_lib_path="$cp_path/lib/gstreamer/patch" + gst_plugin_path="$cp_path/lib/gstreamer/gstreamer-1.0/patch" + + info "Downloading CodecPack's gstreamer plugins..." + + mkdir "$gst_plugin_path" + for plugin in "${gstreamer_plugins[@]}"; do + download "Gstreamer plugin: $plugin" "$repo_base_url/$branch/plugins/$plugin.so" "$gst_plugin_path/$plugin.so" + done + + mkdir "$gst_lib_path" + mkdir -p "$gst_lib_path/dri" + mkdir -p "$gst_lib_path/x264-10bit" + mkdir -p "$gst_lib_path/x265-10bit" + + for lib in "${gstreamer_libs[@]}"; do + download "Gstreamer library: $lib" "$repo_base_url/$branch/libs/$lib" "$gst_lib_path/$lib" + done + fi + + mkdir "$cp_base_path/patch" + download "CodecPack's patch_config.sh" "$repo_base_url/$branch/utils/patch_config.sh" "$cp_base_path/patch/patch_config.sh" + download "CodecPack's patch_utils.sh" "$repo_base_url/$branch/utils/patch_utils.sh" "$cp_base_path/patch/patch_utils.sh" + + info "Setting CodecPack's ffmpeg version to: ffmpeg$ffmpegversion" + sed -i -e "s/@ffmpeg_version@/ffmpeg$ffmpegversion/" "$cp_base_path/patch/patch_config.sh" fi if [[ -f "$vs_path/bin/gst-launch-1.0" ]]; then + gst_lib_path="$vs_path/lib/gstreamer/patch" + gst_plugin_path="$vs_path/lib/gstreamer/gstreamer-1.0/patch" + info "Downloading gstreamer plugins..." + mkdir "$gst_plugin_path" for plugin in "${gstreamer_plugins[@]}"; do - download "Gstreamer plugin: $plugin" "$repo_base_url/$branch/plugins/$plugin.so" "$vs_path/lib/gstreamer/gstreamer-1.0/$plugin.so" + download "Gstreamer plugin: $plugin" "$repo_base_url/$branch/plugins/$plugin.so" "$gst_plugin_path/$plugin.so" done - mkdir -p "$vs_path/lib/gstreamer/dri" - mkdir -p "$vs_path/lib/gstreamer/x264-10bit" - mkdir -p "$vs_path/lib/gstreamer/x265-10bit" + mkdir "$gst_lib_path" + mkdir -p "$gst_lib_path/dri" + mkdir -p "$gst_lib_path/x264-10bit" + mkdir -p "$gst_lib_path/x265-10bit" for lib in "${gstreamer_libs[@]}"; do - download "Gstreamer library: $lib" "$repo_base_url/$branch/libs/$lib" "$vs_path/lib/gstreamer/$lib" + download "Gstreamer library: $lib" "$repo_base_url/$branch/libs/$lib" "$gst_lib_path/$lib" done info "Saving current GSTOmx configuration..." @@ -260,10 +283,12 @@ patch() { cp -n "$cp_path/etc/gstomx.conf" "$vs_path/etc/gstomx.conf" fi - download "patch_config.sh" "$repo_base_url/$branch/patch_config.sh" "$vs_base_path/patch_config.sh" + mkdir "$vs_base_path/patch" + download "VideoStation's patch_config.sh" "$repo_base_url/$branch/utils/patch_config.sh" "$vs_base_path/patch/patch_config.sh" + download "VideoStation's patch_utils.sh" "$repo_base_url/$branch/utils/patch_utils.sh" "$vs_base_path/patch/patch_utils.sh" info "Setting ffmpeg version to: ffmpeg$ffmpegversion" - sed -i -e "s/@ffmpeg_version@/ffmpeg$ffmpegversion/" "$vs_base_path/patch_config.sh" + sed -i -e "s/@ffmpeg_version@/ffmpeg$ffmpegversion/" "$vs_base_path/patch/patch_config.sh" info "Saving current libsynovte.so as libsynovte.so.orig" cp -n "$libsynovte_path" "$libsynovte_path.orig" @@ -293,32 +318,33 @@ unpatch() { mv -T -f "$filename" "${filename::-5}" done - find "$vs_base_path/scripts" -type f -name "*.orig" | while read -r filename; do - info "Restoring VideoStation's $filename script" - mv -T -f "$filename" "${filename::-5}" - done - if [[ -d $cp_bin_path ]]; then for file in "${cp_to_patch[@]}"; do filename="${file%%:*}" + target="${file##*:}" + + rm -f "$cp_bin_path/$target" if [[ -f "$cp_bin_path/$filename.orig" ]]; then info "Restoring CodecPack's $filename" mv -T -f "$cp_bin_path/$filename.orig" "$cp_bin_path/$filename" fi done + + if [[ -d "$cp_path/lib/gstreamer" ]]; then + info "Removing CodecPack gstreamer's patched libraries and plugins" + rm -rf "$cp_path/lib/gstreamer/patch" + rm -rf "$cp_path/lib/gstreamer/gstreamer-1.0/patch" + fi + + info "Remove CodecPack's patch directory" + rm -rf "$cp_base_path/patch" fi if [[ -f "$vs_path/bin/gst-launch-1.0" ]]; then - for plugin in "${gstreamer_plugins[@]}"; do - info "Removing gstreamer's $plugin plugin" - rm -f "$vs_path/lib/gstreamer/gstreamer-1.0/$plugin.so" - done - - for lib in "${gstreamer_libs[@]}"; do - info "Removing gstreamer's $lib library" - rm -f "$vs_path/lib/gstreamer/$lib" - done + info "Removing VideoStation gstreamer's patched libraries and plugins" + rm -rf "$vs_path/lib/gstreamer/patch" + rm -rf "$vs_path/lib/gstreamer/gstreamer-1.0/patch" if [[ -f "$vs_path/etc/gstomx.conf.orig" ]]; then info "Restoring GSTOmx configuration..." @@ -328,8 +354,8 @@ unpatch() { fi fi - info "Remove patch config." - rm -f "$vs_base_path/patch_config.sh" + info "Remove VideoStation's patch directory." + rm -rf "$vs_base_path/patch" restart_packages clean diff --git a/scripts/preuninst.sh b/scripts/preuninst.sh deleted file mode 100644 index 8ca07f2..0000000 --- a/scripts/preuninst.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -repo_full_url=@repo_full_url@ -curl "$repo_full_url/patcher.sh" | bash -s -- -a unpatch - -exit 0 diff --git a/patch_config.sh b/utils/patch_config.sh similarity index 100% rename from patch_config.sh rename to utils/patch_config.sh diff --git a/utils/patch_utils.sh b/utils/patch_utils.sh new file mode 100644 index 0000000..6245528 --- /dev/null +++ b/utils/patch_utils.sh @@ -0,0 +1,87 @@ +#!/bin/bash + +stderrfile=/dev/null +child="" +pid=$$ + +log() { + local now + now=$(date '+%Y-%m-%d %H:%M:%S') + echo "[$now] [$1] $2" >> "$stderrfile" +} + +newline() { + echo "" >> "$stderrfile" +} + +info() { + log "INFO" "$1" +} + +kill_child() { + if [[ "$child" != "" ]]; then + kill "$child" > /dev/null 2> /dev/null || : + fi +} + +endprocess() { + info "========================================[end $0 $pid]" + newline + + if [[ $errcode -eq 1 ]]; then + cp "$stderrfile" "$stderrfile.prev" + fi + + kill_child + rm -f "$stderrfile" + + exit "$errcode" +} + +handle_error() { + log "ERROR" "An error occurred" + newline + errcode=1 + kill_child +} + +fix_args() { + while [[ $# -gt 0 ]]; do + case "$1" in + -acodec) + shift + if [[ "$1" = "libfaac" ]]; then + args+=("-acodec" "aac") + else + args+=("-acodec" "libfdk_aac") + fi + ;; + + -vf) + shift + arg="$1" + + if [[ "$arg" =~ "scale_vaapi" ]]; then + scale_w=$(echo "$arg" | sed -n 's/.*w=\([0-9]\+\):h=\([0-9]\+\).*/\1/p') + scale_h=$(echo "$arg" | sed -n 's/.*w=\([0-9]\+\):h=\([0-9]\+\).*/\2/p') + + if (( scale_w && scale_h )); then + arg="scale_vaapi=w=$scale_w:h=$scale_h:format=nv12,hwupload,setsar=sar=1" + else + arg="scale_vaapi=format=nv12,hwupload,setsar=sar=1" + fi + fi + + args+=("-vf" "$arg") + ;; + + -r) + shift + ;; + + *) args+=("$1") ;; + esac + + shift + done +} diff --git a/wrappers/ffmpeg.sh b/wrappers/ffmpeg.sh index 6a298c4..ae4d459 100644 --- a/wrappers/ffmpeg.sh +++ b/wrappers/ffmpeg.sh @@ -1,5 +1,14 @@ #!/bin/bash +# shellcheck source=/utils/patch_config.sh +source "/var/packages/VideoStation/patch/patch_config.sh" 2> /dev/null || +source "/var/packages/CodecPack/patch/patch_config.sh" 2> /dev/null + +# shellcheck source=/utils/patch_utils.sh +source "/var/packages/VideoStation/patch/patch_utils.sh" 2> /dev/null || +source "/var/packages/CodecPack/patch/patch_utils.sh" 2> /dev/null || +{ echo "Cannot load patch_utils.sh" >> "ffmpeg-0.stderr.prev" && echo "Cannot load patch_utils.sh" && exit 1; } + ######################### # VARS ######################### @@ -9,93 +18,8 @@ pid=$$ child="" stderrfile="/tmp/ffmpeg-$pid.stderr" errcode=0 - -# shellcheck source=/patch_config.sh -source "/var/packages/VideoStation/patch_config.sh" - -######################### -# UTILS -######################### - -log() { - local now - now=$(date '+%Y-%m-%d %H:%M:%S') - echo "[$now] [$1] $2" >> $stderrfile -} -newline() { - echo "" >> $stderrfile -} -info() { - log "INFO" "$1" -} - -handle_error() { - log "ERROR" "An error occurred" - newline - errcode=1 - kill_child -} - -kill_child() { - if [[ "$child" != "" ]]; then - kill "$child" - fi -} - -endprocess() { - info "========================================[end ffmpeg $pid]" - newline - - if [[ $errcode -eq 1 ]]; then - cp "$stderrfile" "$stderrfile.prev" - fi - - kill_child - rm -f "$stderrfile" - - exit $errcode -} - -fix_args() { - while [[ $# -gt 0 ]]; do - case "$1" in - -acodec) - shift - if [[ "$1" = "libfaac" ]]; then - args+=("-acodec" "aac") - else - args+=("-acodec" "libfdk_aac") - fi - ;; - - -vf) - shift - arg="$1" - - if [[ "$arg" =~ "scale_vaapi" ]]; then - scale_w=$(echo "$arg" | sed -n 's/.*w=\([0-9]\+\):h=\([0-9]\+\).*/\1/p') - scale_h=$(echo "$arg" | sed -n 's/.*w=\([0-9]\+\):h=\([0-9]\+\).*/\2/p') - - if (( scale_w && scale_h )); then - arg="scale_vaapi=w=$scale_w:h=$scale_h:format=nv12,hwupload,setsar=sar=1" - else - arg="scale_vaapi=format=nv12,hwupload,setsar=sar=1" - fi - fi - - args+=("-vf" "$arg") - ;; - - -r) - shift - ;; - - *) args+=("$1") ;; - esac - - shift - done -} +path=$(realpath "$0") +args=() ######################### # ENTRYPOINT @@ -109,12 +33,12 @@ rm -f /tmp/ffmpeg*.stderr.prev fix_args "$@" newline -info "========================================[start ffmpeg $pid]" +info "========================================[start $0 $pid]" info "DEFAULT ARGS: $*" info "UPDATED ARGS: ${args[*]}" -info "Trying with VideoStation's ffmpeg with fixed args..." -/var/packages/VideoStation/target/bin/ffmpeg.orig "${args[@]}" <&0 2>> $stderrfile & +info "Trying fixed args with $path.orig ..." +"${path}.orig" "${args[@]}" <&0 2>> $stderrfile & child=$! wait "$child" @@ -123,8 +47,8 @@ if [[ $errcode -eq 0 ]]; then fi errcode=0 -info "Trying with VideoStation's ffmpeg with default args..." -/var/packages/VideoStation/target/bin/ffmpeg.orig "$@" <&0 2>> $stderrfile & +info "Trying default args with $path.orig ..." +"${path}.orig" "$@" <&0 2>> $stderrfile & child=$! wait "$child" @@ -133,7 +57,7 @@ if [[ $errcode -eq 0 ]]; then fi errcode=0 -info "Trying with SC's ffmpeg and fixed args..." +info "Trying with SC's $ffmpeg_version and fixed args..." "/var/packages/${ffmpeg_version}/target/bin/ffmpeg" "${args[@]}" <&0 2>> $stderrfile & child=$! wait "$child" diff --git a/wrappers/gst-inspect-1.0.sh b/wrappers/gst-inspect-1.0.sh index 1e3918a..feab82c 100644 --- a/wrappers/gst-inspect-1.0.sh +++ b/wrappers/gst-inspect-1.0.sh @@ -2,6 +2,11 @@ export GST_DEBUG=1 #1: ERROR (Log fatal errors only). +# shellcheck source=/utils/patch_utils.sh +source "/var/packages/VideoStation/patch/patch_utils.sh" 2> /dev/null || +source "/var/packages/CodecPack/patch/patch_utils.sh" 2> /dev/null || +{ echo "Cannot load patch_utils.sh" >> "gstinspect-0.stderr.prev" && echo "Cannot load patch_utils.sh" && exit 1; } + ######################### # VARS ######################### @@ -9,48 +14,9 @@ export GST_DEBUG=1 #1: ERROR (Log fatal errors only). pid=$$ child="" stderrfile="/tmp/gstinspect-$pid.stderr" +path=$(realpath "$0") errcode=0 -######################### -# UTILS -######################### - -log() { - local now - now=$(date '+%Y-%m-%d %H:%M:%S') - echo "[$now] [$1] $2" >> $stderrfile -} -newline() { - echo "" >> $stderrfile -} -info() { - log "INFO" "$1" -} - -handle_error() { - log "ERROR" "An error occurred" - newline - errcode=1 - endprocess -} - -endprocess() { - info "========================================[end gst $pid]" - newline - - if [[ $errcode -eq 1 ]]; then - cp "$stderrfile" "$stderrfile.prev" - fi - - rm "$stderrfile" - - if [[ "$child" != "" ]]; then - kill "$child" - fi - - exit $errcode -} - ######################### # ENTRYPOINT ######################### @@ -64,7 +30,7 @@ newline info "========================================[start gst-inspect $pid]" info "GST_ARGS: $*" -/var/packages/VideoStation/target/bin/gst-inspect-1.0.orig "$@" 2>> $stderrfile & +"$path.orig" "$@" 2>> $stderrfile & child=$! wait "$child" diff --git a/wrappers/gst-launch-1.0.sh b/wrappers/gst-launch-1.0.sh index 6da75e7..20fc97d 100644 --- a/wrappers/gst-launch-1.0.sh +++ b/wrappers/gst-launch-1.0.sh @@ -1,6 +1,12 @@ #!/bin/bash export GST_DEBUG=1 #1: ERROR (Log fatal errors only). +export LD_LIBRARY_PATH=/var/packages/@package_name@/target/lib/gstreamer/patch + +# shellcheck source=/utils/patch_utils.sh +source "/var/packages/VideoStation/patch/patch_utils.sh" 2> /dev/null || +source "/var/packages/CodecPack/patch/patch_utils.sh" 2> /dev/null || +{ echo "Cannot load patch_utils.sh" >> "gstlaunch-0.stderr.prev" && echo "Cannot load patch_utils.sh" && exit 1; } ######################### # VARS @@ -9,48 +15,9 @@ export GST_DEBUG=1 #1: ERROR (Log fatal errors only). pid=$$ child="" stderrfile="/tmp/gstlaunch-$pid.stderr" +path=$(realpath "$0") errcode=0 -######################### -# UTILS -######################### - -log() { - local now - now=$(date '+%Y-%m-%d %H:%M:%S') - echo "[$now] [$1] $2" >> $stderrfile -} -newline() { - echo "" >> $stderrfile -} -info() { - log "INFO" "$1" -} - -handle_error() { - log "ERROR" "An error occurred" - newline - errcode=1 - endprocess -} - -endprocess() { - info "========================================[end gst $pid]" - newline - - if [[ $errcode -eq 1 ]]; then - cp "$stderrfile" "$stderrfile.prev" - fi - - rm "$stderrfile" - - if [[ "$child" != "" ]]; then - kill "$child" - fi - - exit $errcode -} - ######################### # ENTRYPOINT ######################### @@ -61,10 +28,10 @@ trap handle_error ERR rm -f /tmp/gstlaunch*.stderr.prev newline -info "========================================[start gst-launch $pid]" +info "========================================[start $0 $pid]" info "GST_ARGS: $*" -/var/packages/VideoStation/target/bin/gst-launch-1.0.orig "$@" 2>> $stderrfile & +"$path.orig" "$@" 2>> $stderrfile & child=$! wait "$child"