Skip to content
TheChatArchiveThe Chat Archive
Upstagesolar-10.7b-instruct-v1.0· UpstageHugging Face Arena Human Preference 55K

please rewrite this bash script in perl, keeping the same functionality (reading…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmixtral-8x7b-instruct-v0.1’s answer.
  1. 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="(dirname−−"(dirname -- "(readlink -f -- "0")")"source"0")")" source "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"shift2;;−p∣−−preset)preset="2" shift 2 ;; -p | --preset) preset="2" shift 2 ;; -r | --resize) resize="2"shift2;;−n∣−−noise)noise="2" shift 2 ;; -n | --noise) noise="2" shift 2 ;; *) input_file="$1" shift ;; esac done

    if [[ ! -f "inputfile"]];thenecho"FILENOTFOUND:input_file" ]]; then echo "FILE NOT FOUND: input_file" fi Check for required arguments

    if [[ -z quality]]∣∣[[−zquality ]] || [[ -z preset ]] || [[ -z inputfile]];thenecho"Usage:input_file ]]; then echo "Usage: 0 -q|--quality -p|--preset [-n|--noise ] [-r|--resize ] " exit 1 fi

    file_path=(readlink−f"(readlink -f "input_file") file_name=(get−filename"(get-filename "file_path")

    chunk_method="ffms2"

    output_name="filename.reencode.av1an.aom.rf{file_name}.reencode.av1an.aom.rf{quality}.ppreset"metadatacomment="reencodedwithav1an(aom),10−bit,cpu−used={preset}" metadata_comment="reencoded with av1an(aom), 10-bit, cpu-used={preset}, cq=quality,chunk−method={quality}, chunk-method=chunk_method"

    if [ -n "noise"];thenoutputname+=".noisenoise" ]; then output_name+=".noise{noise}" else noise=10 fi

    if [ -n "resize"];thenoutputname+=".resize" ]; then output_name+=".{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 "filepath"−−encoderaom−−workers4−−resume−−extra−split300−−ignore−frame−mismatch−−audio−params"−an"−−ffmpeg"−anfile_path" --encoder aom --workers 4 --resume --extra-split 300 --ignore-frame-mismatch --audio-params " -an " --ffmpeg " -an ([[ -n "resize" ]] && echo " -vf 'scale=-1:{resize}'")" --split-method av-scenechange --chunk-method chunkmethod−−concatmkvmerge−−set−thread−affinity="chunk_method --concat mkvmerge --set-thread-affinity="threads" --photon-noise="noise"−−video−params"−−bit−depth=10−−threads=noise" --video-params " --bit-depth=10 --threads=threads --end-usage=q --cq-level=quality−−cpu−used=quality --cpu-used=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 "outputname.audioless.mkv"−i"{output_name}.audioless.mkv" -i "file_path" -c copy -map 0:v -map 1:a -metadata comment="metadatacomment""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 "inputfile""input_file" "{output_name}.mp4"

    echo "" echo "video-compare "inputfile""input_file" "{output_name}.mp4""

    echo -e "\n✅ FINISHED"

  2. Upstage 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
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.