Advertisement
Guest User

ffmpeg t00lz revision 20240509

a guest
May 9th, 2024
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.18 KB | Source Code | 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 "Making file list processable for FFMPEG: $selected_file";
  20.    
  21.     # sort file names and filter out blank lines
  22.     if [[ $(sort "$selected_file" |md5sum ) != $(cat "$selected_file" |md5sum ) ]]; then # sort if not already sorted
  23.         sort "$selected_file" |grep -v "^$" >> "${selected_file}.sorted"
  24.         mv "${selected_file}.sorted" "$selected_file"
  25.         echo "File sorted: $selected_file"
  26.     else    echo "This file is already sorted: $selected_file"
  27.     fi
  28.    
  29.     if [[ $(head -n 1 "$selected_file") == "file '"* ]]; then
  30.         echo "This file was already made processable for FFMPEG: $selected_file";
  31.         return 1;
  32.     fi # return if file already modified
  33.     sed -i -r "s/([^#]+)/file '\1'/g" "$selected_file"; # make file list digestable for ffmpeg concat, exclude comments with "#"
  34. }
  35. # return last text file for concatenation
  36. fflastfile() { ls -t -1 ~/Documents/massdmp/ffmpeg* |head -n 1; }
  37.  
  38.  
  39.  
  40. # audioreset - instantly restart laggy audio driver - 20231123230335
  41. audioreset() { systemctl --user restart pulseaudio; }
  42.  
  43. HDDspin() {
  44.     while : ; do (sudo dd if=/dev/$@ of=/dev/null iflag=direct ibs=4096 count=1; sleep 29); done
  45. } # 20220828230011
  46.  
  47.  
  48. # mediainfo get videos by resolution 20240121043425
  49.  
  50. lsvideoheight_core() {
  51.     # $1 = height
  52.     # $2 = current file name
  53.     mediainfo_result=$(mediainfo "$2" |egrep "(Complete name|Height.*: $1)");
  54.     mediainfo_height=$(echo "$mediainfo_result" | tail -n 1 );
  55.     if ( [[ $mediainfo_height == "Height"*": $1 pixels"  ]] ); # if video height matches; no quotation marks to remove excessive spaces
  56.         then { echo "$mediainfo_result" | head -n 1 | grep "$2" |sed -r "s/^.*: //g"; }; fi # remove everything except the file path
  57. }
  58.  
  59.  
  60. lsvideoheight() {
  61.     # Iterate though multiple files.
  62.     # 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.
  63.    
  64.     argument_count=0; # for loop skips over first argument with video height
  65.     if [ ! "$2" ]; then # no file specified = list all in current directory
  66.         for current_item in "" *; # blank dummy string so files start at second argument; not using "${@:2}" for sh compatibility
  67.             do { if [ $argument_count -ge 1 ] && [ -f "$current_item" ]; then lsvideoheight_core "$1" "$current_item"; fi; # files only, exclude directories
  68.             argument_count=$(( argument_count + 1 ));
  69.         }
  70.         done   
  71.     else # specified file names and directories
  72.         for current_item in "$@";
  73.                 do {
  74.                 if (test $argument_count -ge 1 ); then
  75.                     # directory handler: if current item is a directory
  76.                     if [ -d "$current_item" ]; then
  77.                         for subfile in "$current_item"/*; do lsvideoheight_core "$1" "$subfile"; done
  78.                     else lsvideoheight_core "$1" "$current_item";
  79.                     fi;
  80.                 fi;
  81.                 argument_count=$(( argument_count + 1 ));
  82.             }
  83.         done
  84.     fi
  85. }
  86.  
  87. ls4320p() { lsvideoheight "4 320" "$@"; } # 8K
  88. ls2160p() { lsvideoheight "2 160" "$@"; } # 4K
  89. ls1440p() { lsvideoheight "1 440" "$@"; } # QHD / WQHD
  90. ls1080p() { lsvideoheight "1 080" "$@"; } # Full HD
  91. ls720p() { lsvideoheight "720" "$@"; } # HD
  92. ls480p() { lsvideoheight "480" "$@"; } # HQ ("high quality") / SD ("standard definition")
  93.  
  94.     # aliases
  95. alias ls8K=ls4320p;
  96. alias ls4K=ls2160p;
  97. alias lsUHD=ls2160p;
  98. alias lsQHD=ls1440p;
  99. alias lsFHD=ls1080p;
  100. alias lsHD=ls720p;
  101.     # no alias for 480p because the abbreviations "HQ" and "SD" have ambiguous meanings such as "SD card".
  102.    
  103. # import 20240201192822
  104. window_title() { printf "\033]0;$*\007"; } # 20220809154814  to prevent opening "iotop" window in task switcher.
  105.  
  106. # 20240226104528
  107. flush_N() {
  108.     echo "[incoming]" >>~/Documents/N-Mint.2023-04-11.txt
  109.     cat ~/Documents/N-Mint-incoming.20230911101930.txt  >>~/Documents/N-Mint.2023-04-11.txt
  110.     truncate ~/Documents/N-Mint-incoming.20230911101930.txt  --size=0
  111. }
  112.  
  113. remove_invalid_char() { rename "s/[^A-Za-z0-9- \.]/_/g" "$@"; } # 20240302015720
  114.  
  115. # totalsize 20240307234812
  116. totalsize() { du -sh -c "$@" |tail -n 1; }
  117.  
  118. # getfps 20240309145929 - ffprobe only accepts one file.
  119. getfps() { ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate "$1"; }
  120.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement