This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

vidcompress: add new script

+96 -3
+3 -3
flake.lock
··· 2 2 "nodes": { 3 3 "nixpkgs": { 4 4 "locked": { 5 - "lastModified": 1771369470, 6 - "narHash": "sha256-0NBlEBKkN3lufyvFegY4TYv5mCNHbi5OmBDrzihbBMQ=", 5 + "lastModified": 1781074563, 6 + "narHash": "sha256-md8WlXOlfnIeHeOScMTTHFyf2d6iaTwPl2apR5EQ3P4=", 7 7 "owner": "NixOS", 8 8 "repo": "nixpkgs", 9 - "rev": "0182a361324364ae3f436a63005877674cf45efb", 9 + "rev": "9ae611a455b90cf061d8f332b977e387bda8e1ca", 10 10 "type": "github" 11 11 }, 12 12 "original": {
+3
flake.nix
··· 31 31 scr = final.callPackage ./nix/scr.nix { }; 32 32 thm = final.callPackage ./nix/thm.nix { }; 33 33 vid2gif = final.callPackage ./nix/vid2gif.nix { }; 34 + vidcompress = final.callPackage ./nix/vidcompress.nix { }; 34 35 yemou-scripts = final.symlinkJoin { 35 36 name = "yemou-scripts"; 36 37 paths = [ ··· 39 40 scr 40 41 thm 41 42 vid2gif 43 + vidcompress 42 44 ]; 43 45 }; 44 46 }; ··· 50 52 scr = pkgs.scr; 51 53 thm = pkgs.thm; 52 54 vid2gif = pkgs.vid2gif; 55 + vidcompress = pkgs.vidcompress; 53 56 yemou-scripts = pkgs.yemou-scripts; 54 57 }); 55 58 };
+26
nix/vidcompress.nix
··· 1 + { 2 + writeScriptBin, 3 + bash, 4 + coreutils, 5 + ffmpeg, 6 + ... 7 + }: 8 + 9 + writeScriptBin "vidcompress" ( 10 + builtins.replaceStrings 11 + [ 12 + "#!/bin/sh" 13 + "ffmpeg " 14 + "ffprobe " 15 + "printf " 16 + "rm " 17 + ] 18 + [ 19 + "#!${bash}/bin/sh" 20 + "${ffmpeg}/bin/ffmpeg " 21 + "${ffmpeg}/bin/ffprobe " 22 + "${coreutils}/bin/printf " 23 + "${coreutils}/bin/rm " 24 + ] 25 + (builtins.readFile ../scritps/vidcompress) 26 + )
+64
scritps/vidcompress
··· 1 + #!/bin/sh 2 + usage() { 3 + printf '%b\n' "${0##*/} -i <input_file> [OPTIONS]" \ 4 + "\noptions:" \ 5 + "\t-c CODEC - video codec to use (default: libx264)" \ 6 + "\t-h - display this message" \ 7 + "\t-o FILE - output file (default: out.ext)" \ 8 + "\t-p PRESET - ffmpeg encoding preset to use (default: veryslow)" \ 9 + "\t-t FILE_SIZE - file size to target in MiB (default: 50)" 10 + } 11 + 12 + while [ "$*" ] 13 + do 14 + case $1 in 15 + - ) shift; continue ;; 16 + -- ) shift; break ;; 17 + -* ) flag=${1#-}; shift ;; 18 + * ) shift; continue ;; 19 + esac 20 + 21 + while [ "$flag" ] 22 + do 23 + arg=${flag%"${flag#?}"} 24 + 25 + case $arg in 26 + c ) VIDCOMP_CODEC=$1; shift ;; 27 + h ) usage; exit 0 ;; 28 + i ) VIDCOMP_INPUT_FILE=$1; shift ;; 29 + o ) VIDCOMP_OUTPUT_FILE=$1; shift ;; 30 + t ) VIDCOMP_TARGET_SIZE=$1; shift ;; 31 + * ) printf '%s\n' "${0##*/}: -$arg: invalid argument" 1>&2 32 + usage 1>&2; exit 1 ;; 33 + esac 34 + 35 + flag=${flag#?} 36 + done 37 + done 38 + 39 + [ -z "$VIDCOMP_INPUT_FILE" ] && { 40 + printf '%s\n' "${0##*/}: missing input video" 1>&2 41 + usage 1>&2; exit 1 42 + } 43 + 44 + ext="${VIDCOMP_INPUT_FILE##.*}" 45 + : "${VIDCOMP_OUTPUT_FILE:=out.${ext}}" 46 + 47 + : "${VIDCOMP_CODEC:=libx264}" 48 + : "${VIDCOMP_TARGET_SIZE:=50}" 49 + : "${VIDCOMP_PRESET:=veryslow}" 50 + 51 + a_bitrate="$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 \ 52 + "${VIDCOMP_INPUT_FILE}")" 53 + secs="$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${VIDCOMP_INPUT_FILE}")" 54 + bitrate="$(fend floor \("${VIDCOMP_TARGET_SIZE} * 8388.608 / ${secs}" - \("${a_bitrate}" / 1000\)\))" 55 + 56 + ffmpeg -hide_banner -loglevel warning \ 57 + -i "${VIDCOMP_INPUT_FILE}" -c:v "${VIDCOMP_CODEC}" -b:v "${bitrate}k" -preset "${VIDCOMP_PRESET}" -pass 1 \ 58 + -an -f null -y /dev/null && \ 59 + ffmpeg -hide_banner -loglevel warning \ 60 + -i "${VIDCOMP_INPUT_FILE}" -c:v "${VIDCOMP_CODEC}" -b:v "${bitrate}k" -preset "${VIDCOMP_PRESET}" -pass 2 \ 61 + -c:a copy "${VIDCOMP_OUTPUT_FILE}" 62 + 63 + rm ffmpeg2pass*.log 64 + rm ffmpeg2pass*.log.mbtree