Advertisement
Guest User

ffmpeg enhancement suite 2024-02-13 2

a guest
Feb 13th, 2024
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 4.43 KB | Source Code | 0 0
  1. # ffmpeg concat 20230804013241 # 20231118122511: added: -metadata:s:v rotate="" # 20231128170123: $3 for additional parameters such as -an.
  2. ffco() { ffmpeg -f concat -safe 0 $3 -i "$1" -metadata:s:v rotate="" -c copy "$2"; }
  3. # ffco-instant from last ffmpeg file 20230914000245 # 20231118122459: added: -metadata:s:v rotate=""
  4. ffco-instant() {
  5.     fflist; # 20231209120458: now that fflist autodetects if the text file was already modified, it can be run automatically.
  6.     ffmpeg -f concat -safe 0 $2 -i "$(fflastfile)" -metadata:s:v rotate="" -c copy "$1";
  7. }
  8. # ffmute - mute audio 20231123001501
  9. ffmute() { ffmpeg -i "$1" -c:v copy -an "$2"; }
  10. # fferror - verify integrity 20231123021438 #changed to fferror-core 20240211102245
  11. fferror-core() { ffmpeg -v error -i "$1" -f null  - ;}
  12. fferror() { for filename in "$@"; do echo "Checking $filename for errors."; fferror-core "$filename"; done; }
  13. # ffmpeg filelist generator 20231020044358
  14. fflist() {
  15.     selected_file="$1"
  16.     # auto-select last file if no argument provided
  17.     if [ "$1" == "" ]; then selected_file="$(fflastfile)";fi
  18.     echo "Creating concatinated video from: $selected_file"
  19.    
  20.     # sort file names and filter out blank lines
  21.     sort "$selected_file" |grep -v "^$" >> $selected_file.sorted
  22.     mv "${selected_file}.sorted" "$selected_file"
  23.    
  24.     if [[ $(head -n 1 $selected_file) == "file '"* ]]; then return 1; fi # return if file already modified
  25.     sed -i -r "s/([^#]+)/file '\1'/g" "$selected_file"; # make file list digestable for ffmpeg concat, exclude comments with "#"
  26. }
  27. # return last text file for concatenation
  28. fflastfile() { ls -t -1 ~/Documents/massdmp/ffmpeg* |head -n 1; }
  29.  
  30. # mediainfo table 20231130012905 (Filter out useless audio "frame rate" first)
  31. mediainfotable() { mediainfo "$@" |grep -v "Frame rate.*SPF" |grep -P "(name|Width|Height|Frame rate  )" |tr '\n' ' ' |sed -r 's/FPS/FPS\n/g' |sed -r "s/(  )+//g"; }
  32. # redact geotag from video for privacy 20231203215921
  33. gpsnull() { sed -i -r "s/\+[0-9][0-9]\.[0-9][0-9][0-9][0-9]\+[0-9][0-9][0-9]\.[0-9][0-9][0-9][0-9]\//+00.0000+000.0000\//g" "$@"; }
  34. gpsnull_exif() { exiftool -gps:all="" "$@"; } # for pictures 20231218172111
  35.  
  36. # only list time stamp and file name
  37. lstimestamp() { ls -l --full-time "$@" | sed -r "s/\*//g" |sed -r "s/\.000000000//g" |sed -r "s/^.* (2[0-9][0-9][0-9]-)/\1/g"; }
  38.  
  39.  
  40.  
  41. # mediainfo get videos by resolution 20240121043425
  42.  
  43. lsvideoheight_core() {
  44.     # $1 = height
  45.     # $2 = current file name
  46.     mediainfo_result=$(mediainfo "$2" |egrep "(Complete name|Height.*: $1)");
  47.     if [ $(echo "$mediainfo_result" | wc -l) -eq 2 ]; # check for two lines to exclude file names that contain "720" or "480" or another video height.
  48.         then mediainfo_height=$(echo "$mediainfo_result" | tail -n 1 );
  49.     fi
  50.     if ( [[ $mediainfo_height == *"$1"*  ]] ); # if video height matches
  51.         then { echo "$mediainfo_result" | head -n 1 | grep "$2" |sed -r "s/^.*: //g"; }; fi # remove everything except the file path
  52. }
  53.  
  54.  
  55. lsvideoheight() {
  56.     # Iterate though multiple files.
  57.     # 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.
  58.    
  59.     argument_count=0; # for loop skips over first argument with video height
  60.     if [[ "$2" == "" ]]; then # no file specified = list all in current directory
  61.         for current_filename in "" *; # blank dummy string so files start at second argument; not using "${@:2}" for sh compatibility
  62.             do { if (test $argument_count -ge 1 ); then lsvideoheight_core "$1" "$current_filename"; fi;
  63.             argument_count=$(( argument_count + 1 ));
  64.         }
  65.         done   
  66.     else # list specified file names
  67.         for current_filename in "$@";
  68.                 do { if (test $argument_count -ge 1 ); then lsvideoheight_core "$1" "$current_filename"; fi;
  69.                 argument_count=$(( argument_count + 1 ));
  70.             }
  71.         done
  72.     fi
  73. }
  74.  
  75. ls4320p() { lsvideoheight "2 160" "$@"; } # 8K
  76. ls2160p() { lsvideoheight "2 160" "$@"; } # 4K
  77. ls1440p() { lsvideoheight "1 440" "$@"; } # QHD / WQHD
  78. ls1080p() { lsvideoheight "1 080" "$@"; } # Full HD
  79. ls720p() { lsvideoheight "720" "$@"; } # HD
  80. ls480p() { lsvideoheight "480" "$@"; } # HQ ("high quality") / SD ("standard definition")
  81.  
  82.     # aliases
  83. alias ls8K=ls4320p;
  84. alias ls4K=ls2160p;
  85. alias lsUHD=ls2160p;
  86. alias lsQHD=ls1440p;
  87. alias lsFHD=ls1080p;
  88. alias lsHD=ls720p;
  89.     # no alias for 480p because the abbreviations "HQ" and "SD" have ambiguous meanings such as "SD card".
  90.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement