please rewrite this bash script in perl, keeping the same functionality (reading…
- User
please rewrite this bash script in perl, keeping the same functionality (reading arguments passed to the script), and also calling the same executables like the original (ffmpeg, rm, av1an)
#!/bin/bash set -euo pipefail
DIR="(readlink -f -- "DIR/../video.sh" Initialize variables with default values
quality="" preset="" resize="" noise="" input_file="" Loop through the command-line arguments
while [[ # -gt 0 ]]; do case 1 in -q | --quality) quality="2" shift 2 ;; -r | --resize) resize="2" shift 2 ;; *) input_file="$1" shift ;; esac done
if [[ ! -f "input_file" fi Check for required arguments
if [[ -z preset ]] || [[ -z 0 -q|--quality -p|--preset [-n|--noise ] [-r|--resize ] " exit 1 fi
file_path=input_file") file_name=file_path")
chunk_method="ffms2"
output_name="{quality}.p{preset}, cq=chunk_method"
if [ -n "{noise}" else noise=10 fi
if [ -n "{resize}p" fi Supposedtly to work without L-SMASH: av1an -i "input" -y --resume --verbose --split-method av-scenechange -m hybrid -c mkvmerge -e rav1e --force -v " --tiles 8 -s 4 --quantizer 80 --no-scene-detection" --photon-noise 7 --chroma-noise --pix-format yuv420p10le -w 8 -o "output.mkv" --disable-kf --enable-fwd-kf=0 We're disabling keyframes cause Av1an already did scene detection, so we wont have to.. And it speeds things up. --kf-max-dist=9999 Maximum keyframe interval, we're setting it at the highest possible value since av1an's scene detection keyframe interval is already 240 by default --enable-chroma-deltaq=1 --enable-qm=1 --quant-b-adapt=1 Parameters that give you free efficiency boost, ignore it. --ffmpeg "-vf 'scale=-1:720'"
--concat mkvmerge --chunk-method ffms2
--workers 4 --set-thread-affinity=2 \ #does not seem to work on OSX, remember to also set --threads of the --video params to the same value as thread affinity --photon-noise=10 \ # for grain synthesis --chunk-method lsmash --sc-method fast --sc-downscale-height 320 \ulimit -n 2048
threads=2
av1an --verbose -i "([[ -n "resize" ]] && echo " -vf 'scale=-1:{resize}'")" --split-method av-scenechange --chunk-method threads" --photon-noise="threads --end-usage=q --cq-level=preset --tile-columns=0 --tile-rows=0 --tune-content=psy --tune=ssim --lag-in-frames=64 --enable-keyframe-filtering=1 --disable-kf --kf-max-dist=9999 --enable-qm=1 --deltaq-mode=0 --aq-mode=0 --quant-b-adapt=1 --enable-fwd-kf=0 --arnr-strength=4 --sb-size=dynamic --enable-dnl-denoising=0 " -o "${output_name}.audioless.mkv" put the audio back and convert to mp4
ffmpeg -loglevel warning -hide_banner -i "file_path" -c copy -map 0:v -map 1:a -metadata comment="{output_name}.mp4"
rm -rf "${output_name}.audioless.mkv"
echo -e "\n\n" exa -al --color=always --no-permissions --no-user --time-style=long-iso "{output_name}.mp4"
echo "" echo "video-compare "{output_name}.mp4""
echo -e "\n✅ FINISHED"
Assistant
Here is the Perl script that replicates the same functionality as the given Bash script:
#!/usr/bin/env perl use strict; use warnings; use File::Basename qw(dirname filename); use Path::Tiny; use List::MoreUtils qw(first); use Time::Piece; use open ':std', ':encoding(UTF-8)'; my ($DIR, $script) = file($0); my $video_sh = path($DIR)->parent->parent->child('video.sh'); die "ERROR: Could not find video.sh\n" unless -e $video_sh; my $quality; my $preset; my $resize; my $noise; my $input_file; while ( my $arg = shift // last ) { if ($arg eq '-q' || $arg eq '--quality') { $quality = shift; } elsif ($arg eq '-p' || $arg eq '--preset') { $preset = shift; } elsif ($arg eq '-r' || $arg eq '--resize') { $resize = shift; } elsif ($arg eq '-n' || $arg eq '--noise') { $noise = shift; } elsif ($arg =~ m{.+}) { $input_file = $arg; } } die "ERROR: File '$input_file' not found\n" unless -e $input_file; if (!defined($quality) || !defined($preset) || !defined($input_file)) { print "Usage: $0 -q|--quality -p|--preset [-n|--noise ] [-r|--resize ] \n"; exit 1; } my $file_path = readlink_f($input_file); my $file_name = get_filename($file_path); my $chunk_method = 'ffms2'; my $output_name = "$file_name.reencode.av1an.aom.rf$quality.p$preset"; my $metadata_comment = "reencoded with av1an(aom), 10-bit, cpu-used=$preset, cq=$quality, chunk-method=$chunk_method"; if ($noise) { $output_name .= ".noise$noise"; } if ($resize) { $output_name .= ".${resize}p"; } my $av1an_params = q{ -i "input" -y --resume --verbose --split-method av-scenechange -m hybrid -c mkvmerge -e rav1e --force -v " --tiles 8 -s 4 --quantizer 80 --no-scene-detection" --photon-noise 7 --chroma-noise --pix-format yuv420p10le -w 8 }; my $ffmpeg_video_params = ""; $ffmpeg_video_params .= q{ -vf 'scale=-1:720' } if defined $resize; my $concat_params = q{ mkvmerge --chunk-method $chunk_method --workers 4 --set-thread-affinity=2 }; my $av1an_extra_params = q{ --disable-kf --enable-fwd-kf=0 --kf-max-dist=9999 --enable-chroma-deltaq=1 --enable-qm=1 --quant-b-adapt=1 }; my $av1an_audio_params = q{ -an }; my $ffmpeg_audio_params = q{ -an }; my $extra_split = 300; my $ignore_frame_mismatch = 1; my $output_name_without_ext = $output_name; $output_name_without_ext =~ s/\.[^.]+$//; my $ulimit = `ulimit -n`; chomp $ulimit; my $threads = 2; print "ULIMIT: $ulimit\n"; print "THREADS: $threads\n"; print "Execut
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.