Advertisement
Guest User

ffmpeg video resolution filter 2024-03-18

a guest
Mar 18th, 2024
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.14 KB | Source Code | 0 0
  1. lsvideoheight_core() {
  2.     # $1 = height
  3.     # $2 = current file name
  4.     mediainfo_result=$(mediainfo "$2" |egrep "(Complete name|Height.*: $1)");
  5.     mediainfo_height=$(echo "$mediainfo_result" | tail -n 1 );
  6.     if ( [[ $mediainfo_height == "Height"*": $1 pixels"  ]] ); # if video height matches; no quotation marks to remove excessive spaces
  7.         then { echo "$mediainfo_result" | head -n 1 | grep "$2" |sed -r "s/^.*: //g"; }; fi # remove everything except the file path
  8. }
  9.  
  10.  
  11. lsvideoheight() {
  12.     # Iterate though multiple files.
  13.     # Two separate loops because arguments containing file names with spaces can not be passed through a variable containing either all files in the current directory or all specified files, because they would be stringified into one argument.
  14.    
  15.     argument_count=0; # for loop skips over first argument with video height
  16.     if [ ! "$2" ]; then # no file specified = list all in current directory
  17.         for current_item in "" *; # blank dummy string so files start at second argument; not using "${@:2}" for sh compatibility
  18.             do { if [ $argument_count -ge 1 ] && [ -f "$current_item" ]; then lsvideoheight_core "$1" "$current_item"; fi; # files only, exclude directories
  19.             argument_count=$(( argument_count + 1 ));
  20.         }
  21.         done   
  22.     else # specified file names and directories
  23.         for current_item in "$@";
  24.                 do {
  25.                 if (test $argument_count -ge 1 ); then
  26.                     # directory handler: if current item is a directory
  27.                     if [ -d "$current_item" ]; then
  28.                         for subfile in "$current_item"/*; do lsvideoheight_core "$1" "$subfile"; done
  29.                     else lsvideoheight_core "$1" "$current_item";
  30.                     fi;
  31.                 fi;
  32.                 argument_count=$(( argument_count + 1 ));
  33.             }
  34.         done
  35.     fi
  36. }
  37.  
  38. ls4320p() { lsvideoheight "2 160" "$@"; } # 8K
  39. ls2160p() { lsvideoheight "2 160" "$@"; } # 4K
  40. ls1440p() { lsvideoheight "1 440" "$@"; } # QHD / WQHD
  41. ls1080p() { lsvideoheight "1 080" "$@"; } # Full HD
  42. ls720p() { lsvideoheight "720" "$@"; } # HD
  43. ls480p() { lsvideoheight "480" "$@"; } # HQ ("high quality") / SD ("standard definition")
  44.  
  45.     # aliases
  46. alias ls8K=ls4320p;
  47. alias ls4K=ls2160p;
  48. alias lsUHD=ls2160p;
  49. alias lsQHD=ls1440p;
  50. alias lsFHD=ls1080p;
  51. alias lsHD=ls720p;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement