Advertisement
Guest User

ffmpeg enhancement suite 2024-02-13

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