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
#!/usr/bin/perl use strict; use warnings; use File::Basename;
my DIR/../video.pl"; Initialize variables with default values
my preset; my noise; my $input_file;
Loop through the command-line arguments
while (@ARGV) { my arg eq '-q' || arg eq '--quality') { quality = shift @ARGV; } elsif (arg eq '--preset') { preset = shift @ARGV; } elsif (arg eq '-r' || arg eq '--resize') { resize = shift @ARGV; } elsif (arg eq '--noise') { noise = shift @ARGV; } else { input_file = $arg; } }
if (!-f input\_file) { print STDERR "FILE NOT FOUND: input_file\n"; }
Check for required arguments
if (!defined(preset) || !defined(input\_file)) { print STDERR "Usage: 0 -q|--quality -p|--preset [-n|--noise ] [-r|--resize ] <input_file>\n"; exit 1; }
my (file_name) = fileparse($input_file, qr/.[^.]*/);
my $chunk_method = "ffms2";
my file_name.reencode.av1an.aom.rfpreset"; my preset, cq=chunk_method";
if (defined(noise)) { output_name .= ".noisenoise"; } else { noise = 10; }
if (defined(resize)) { output_name .= ".${resize}p"; }
my $threads = 2;
my file_path" --encoder aom --workers 4 --resume --extra-split 300 --ignore-frame-mismatch --audio-params " -an " --ffmpeg " -an ); {resize}'" if (defined(av1an_cmd .= qq( --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");
system($av1an_cmd);
my output_name.audioless.mkv" -i "metadata_comment" "ffmpeg_cmd);
system("rm", "-rf", "$output_name.audioless.mkv");
print "\n\n"; system("exa", "-al", "--color=always", "--no-permissions", "--no-user", "--time-style
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.