Advertisement
j3628800

FFmpeg notes

May 10th, 2024 (edited)
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.14 KB | Software | 0 0
  1. Some options and filters I used in FFmpeg.
  2.  
  3. EDIT: Hah that's a nice and memorable URL, "Software development kit, java edition, (version) 8.8.9"
  4.  
  5. I downloaded a pre-compiled binary from www.gyan.dev (thanks!) because I didn't know how to compile it manually back then...
  6.  
  7. Version:
  8. ffmpeg version 6.0-essentials_build-www.gyan.dev Copyright (c) 2000-2023 the FFmpeg developers
  9. built with gcc 12.2.0 (Rev10, Built by MSYS2 project)
  10.  
  11. Sources:
  12. ffmpeg.org/ffmpeg-filters.html
  13. trac.ffmpeg.org
  14. video.stackexchange.com
  15. superuser.com
  16. (Possibly other StackExchange sites)
  17.  
  18. ==General==
  19.  
  20. %i% is path to your input file
  21. %i1%, %i2%, ... are used when multiple input files are needed
  22. %o% is path to your output file
  23.  
  24. -r sets framerate/tbr, usually same with fps
  25. -framerate sets framerate/fps, usually same with tbr.
  26. Nevertheless, one must set both manually, otherwise the result asrom-izu.
  27. -f [format]
  28. -t [duration]s
  29. -to [stop time]s
  30. -ss [start time]s (with -seek_timestamp)
  31. -timestamp ["now"|time]
  32. -r:v [rate]Hz
  33. -fpsmax [rate]Hz
  34. -s size [width]x[height]
  35.  
  36. ==Recording==
  37. Procedure:
  38. 1. Turn off power save mode
  39. 2. Toggle resolution to 1024x768
  40. 3. Record
  41. 4. Crop with -vf crop=w=1024:h=768:x=0:y=0 for further processing
  42.  
  43. Uses Screen Capturer Recorder, open source project from GitHub.
  44.  
  45. chdir C:\Program Files (x86)\Screen Capturer Recorder\configuration_setup_utility\vendor\ffmpeg\bin
  46. ffmpeg -f dshow -i video="screen-capture-recorder" -r 30 -filter:v crop=800:600:0:0 -y D:/_o.mp4
  47. -f dshow -i audio="virtual-audio-capturer" D:/_o.wav
  48. -f dshow -i audio="Mic (Conexant SmartAudio HD)" D:/_o.wav
  49. -f dshow -i video="screen-capture-recorder" -r 30 -framerate 30 -maxrate 30 -bufsize 1000000 -vcodec libx264 -preset:v ultrafast D:/_putout.mp4
  50.  
  51. ffmpeg -hide_banner -f dshow -i audio="Mic (Conexant SmartAudio HD)" -y D:/_output.wav
  52. ffmpeg -hide_banner -f dshow -i audio="virtual-audio-capturer" -y D:/_output.wav
  53.  
  54.  
  55. ==Basic==
  56.  
  57. '''Aas'''
  58. ffmpeg -i lbla.src lbla.ass
  59. ffmpeg -i video.mp4 -vf ass=filename=lbla.ass video-with-subtitles.mp4
  60.  
  61. '''Combine images'''
  62. -framerate 25 -i pic%3d.png -c copy -y D:/vid0.mp4
  63. NOTE: pic%3d.png expands to pic001.png, pic002.png, etc
  64.  
  65. '''Combine video and audio'''
  66. -i D:/video.mp4 -i D:/audio.mp3 -c:v copy -map 0:v -map 1:a -y D:/video-with-sound.mp4
  67.  
  68. '''Concat'''
  69. 1. Generate concat.txt
  70. Windows: (for %i in (*.wav) do @echo file '%i') > concat.txt
  71. Batch file: (for %%i in (*.wav) do @echo file '%%i') > concat.txt
  72. 2. -f concat -i D:/input.txt -codec copy %o%
  73.  
  74. '''Cut without reencoding'''
  75. -ss 1:02 -to 1:50 -i %i% -map 0 -c copy %o%
  76.  
  77. '''Crop'''
  78. -i %i% -vf crop=w=1280:h=720:x=0:y=0 %o%
  79.  
  80. '''Edgedetect'''
  81. -i d:/motion-2.mp4 -vf edgedetect=low=0.2:high=0.3 d:/motion-3.mp4
  82. NOTE: (high - low): closer means more details, farther means less
  83.  
  84. '''Fade'''
  85. -i %i% -vf fade=type=in:st=4:d=0.5 -af afade=in:st=0:d=5 %o%
  86.  
  87. '''Fade into another video'''
  88. -i %i1% -i %i2% -lavfi xfade=transition=fade:duration=1:offset=5.5 %o%
  89. NOTE: duration is length of effect, offset is (length_of_video1 - duration/2), use n=300*15, which is frames
  90.  
  91. '''First frame as png'''
  92. -i %i% -c:v copy -frames:v 1 first-frame.png
  93. -f image2 -start_number 100 -i img%d.jpg video-from-jpgs.mp4
  94.  
  95. '''Framerate'''
  96. -vf fps=25 %o1%
  97.  
  98. '''Last frame'''
  99. ffmpeg -sseof -2 -i %o2% -update 1 -q:v 1 last-frame.png
  100. NOTE: read last 2 seconds, and take 1 frame
  101.  
  102. '''Looping'''
  103. -loop 1 -t 5 -i %i% %o%
  104. -i %i% -f lavfi -i anullsrc -vcodec copy -af apad -t 10 %o%
  105. -stream_loop 10 -i %i% -c copy D:/%o%
  106.  
  107. '''Pitch'''
  108. -i %i% -af asetrate=44100*8/9,atempo=9/8 %temp%
  109. -i %temp% -ar 44100 %o%
  110. NOTE: This changes the sample rate so we must reset it...
  111.  
  112. '''Resize'''
  113. -s 1280x720
  114. -i %i%.png -update -frames:v 1 -s 1366x706 %o%
  115.  
  116. '''Rotate without reencoding'''
  117. -i %i% -metadata:s:v rotate=90 -map 0 -c copy %o%
  118.  
  119. '''Rotate'''
  120. -vf rotate=PI/6+2*PI*t/10
  121.  
  122. '''Scaling'''
  123. -i %o% -vf scale=w=500:h=500:flags=neighbor %o%
  124.  
  125. '''Speed up/Slow down'''
  126. -vf "setpts=2*PTS" %o%
  127. NOTE: may cause strange desync problems
  128.  
  129. '''Subtitles'''
  130. -i %i% -vf ass=filename=subtitles.ass %o%
  131. NOTE: This will not work unless in %usr% directory!!!
  132.  
  133. '''Zoom'''
  134. -i %i% -vf zoompan=z='min(zoom+0.005,2.0)':x=600:y=10:d=125 -t 5.0s %o%
  135.  
  136. ==Video advanced==
  137.  
  138. Valid constants and expressions in expr:
  139. random(1) min(x, y) sin(x) floor(expr)
  140. lt(x, y) lte(x, y) hypot(x, y) gauss(x)
  141. squish(x) 1/(1 + exp(4*x))
  142. if(x, y, z) return y if x isn't 0, else return z
  143. if(x, y) return y if x isn't 0, else return 0
  144. while(x, expr) loop and take expr if x isn't 0, and return expr when end
  145. print(x)
  146. T time X pixel at x Y pixel at y W video width H video height
  147. PI 3.14159...
  148.  
  149. '''Blend'''
  150. -filter_complex blend=all_expr='if(eq(mod(X,2),mod(Y,2)),A,B)' D:/%o%
  151.  
  152. '''FFT filter'''
  153. -vf fftfilt=dc_Y=128:weight_Y='squish(1-(Y+X)/100)' D:/details-high-pass.mp4
  154.  
  155. '''Brightness, contrast, and the like'''
  156. -vf "curves=all='0/0 0.5/1 1/1'" D:/_brighten.mp4
  157. -vf eq=contrast=10:gamma_r=0.2:gamma_b=0.2 D:/_green.mp4
  158. -vf eq=brightness=0.06:saturation=2 D:/_brighten.mp4
  159. (other choices include colorize and hue)
  160.  
  161. '''geq, rapidly morphing spectacle'''
  162. -vf geq=lum='...':cb='...':cr='...' %o%
  163. (cb=cr=127: black&white)
  164. -vf geq=a='...':r='...':g='...':b='...' %o%
  165. (either YUV or RGB)
  166. -f lavfi color,geq='st(3,pow(X-(W/2),2)+pow(Y-(H/2),2));if(lte(ld(3),80*80),255,0)':128:128
  167. -i %i% -vf geq=lum='125':cb='100*sin(X/50)-100*tan(X/50)' -t 1 %o%
  168. -lavfi nullsrc=s=256x256,geq=random(1)/hypot(X-cos(N*0.07)*W/2-W/2\,Y-sin(N*0.09)*H/2-H/2)^2*1000000*sin(N*0.02):128:128
  169. -i %i% -vf geq=lum='gauss(400)':cb='100+100*sin(PI/10*T*X)':cr='0' -t 5 %o%
  170. -i %i% -vf geq=lum='random(1)*20*T':cb='min(T*50,X)' -t 5 %o%
  171.  
  172. -f lavfi -t 5 -i allyuv -vf crop=w=1280:h=720 %p%
  173. -i %i% -vf geq=lum=127:cb='127':cr='127' -t 2 -y %o%
  174. -i %i% -vf geq=lum='127+T/2*mod(1/2/T*sqrt(pow(X-640,2)+pow(Y-360,2)),255)' %o%
  175. -i %i% -vf geq=lum='128+T*32*sin(squish(T)*X)+(64-32*T)*random(1)' %o%
  176.  
  177. '''Generate video'''
  178. -f lavfi -t 10 -i color=black:s=1280x720 %o%
  179.  
  180. '''Motion Interpolation'''
  181. -vf minterpolate=fps=30:me=esa (exhaustive search)
  182. NOTE: Also with scene change detection method and 20 modes of interpolate. Very processing-intensive
  183.  
  184. -vf tmix=frames=8:weights="1 1 1 1 1 1 1 1"
  185. -vf tmix=frames=3:weights="-1 3 -1" - with temporal convolution (weird color-inverse-flash)
  186.  
  187. '''Play video side by side'''
  188. ffplay -v warning -f rawvideo -s 800x400 -i /dev/zero -vf 'movie=video1.mkv,scale=400x400 [mv2] ; movie=video2.mkv,scale=400x400 [mv1]; [in][mv1] overlay=0:0 [tmp]; [tmp][mv2] overlay=400:0'
  189. ffmpeg -v warning -i video1.mkv -i video2.mkv -filter_complex '[0:v]scale=400:400,pad=800:400 [0:q]; [1:v]scale=400:400[1:q]; [0:q][1:q]overlay=400:0' -f nut -c:v rawvideo -c:a copy - | mplayer -noconsolecontrols -cache-min 1 -cache 1024000 -
  190. ffplay -f lavfi "movie=org[a];movie=enc[b];[a][b]blend=all_mode=difference"
  191.  
  192. ==Audio==
  193.  
  194. '''aevalsrc'''
  195. ffmpeg -i d:/anb.wav -lavfi aevalsrc="sin(440*2*PI*t):s=44100:d=1s" d:/sine-440.wav
  196. NOTE: Remember to specify d, or it will generate forever!
  197.  
  198. '''Compress or expand dynamic range: Noise-gate, 1:2 compression'''
  199. -lavfi compand=(louding time):(quieting time):(line x)/(line y)
  200. -lavfi "compand=attacks=0.3:decays=0.8:points=-36/-900|-35/-35|0/0|20/20" D:/0.wav
  201. -lavfi compand=.1|.1:.2|.2:-900/-900|-50.1/-900|-50/-50:.01:0:-90:.1
  202. -lavfi compand=.1|.1:.1|.1:-45.1/-45.1|-45/-900|0/-900:.01:45:-90:.1 D:/high_noise_gate.wav
  203.  
  204. '''Bass'''
  205. -af bass=(freq):(gain):(width or steepness):(mix):(normalize)
  206. -af bass=frequency=100:gain=-50 %o%
  207.  
  208. '''Bandreject'''
  209. -af bandreject=f=200:width_type=h:width=200 %o%
  210.  
  211. '''Dynaudnorm'''
  212. dynaudnorm=f=500:g=5:p=0.5
  213. f - frame length
  214. g - gaussian size (number of frames taken into consideration each step)
  215. p - peak loudness
  216. m - maximum gain
  217.  
  218. '''Equalizer'''
  219. -af equalizer=f=1000:t=q:w=1:g=2,equalizer=f=100:t=q:w=2:g=-5 %o%
  220. -af equalizer=f=1000:width_type=h:width=600:g=-30 %o%
  221.  
  222. '''Flanger'''
  223. -af flanger=delay=29:depth=5:regen=60 %o%
  224.  
  225. '''Fade'''
  226. -i %i% -af afade=t=in:d=2s %o%
  227. -i %i%.wav -af afade=t=out:st=40:d=2s %o%
  228. NOTE: st (start time) must be specified for fade out otherwise it will fade out at the beginning and most of the track will be silence
  229.  
  230. '''Magic'''
  231. -af "asplit[a],aphasemeter=video=0,ametadata=select:key=lavfi.aphasemeter.phase:value=-0.005:function=less,pan=1c|c0=c0,aresample=async=1:first_pts=0,[a]amix"
  232.  
  233. '''Mix'''
  234. -i %i1% -i %i2% -filter_complex amix=inputs=2:normalize=0 %o%
  235.  
  236. '''Sample rate'''
  237. -i %i% -af aresample=44100 %o%
  238.  
  239. '''Spectrogram'''
  240. -i D:/vowel.wav -lavfi showspectrumpic D:/vowel.png
  241.  
  242. '''Split to mono'''
  243. -lavfi "[0:a]channelsplit=channel_layout=stereo:channels=FR[right]" -map "[right]" front-right.wav
  244.  
  245. '''Silence remove'''
  246. -af silenceremove=start_periods=1:start_threshold=-35dB %o%
  247. -af silenceremove=start_periods=1:start_duration=5:start_threshold=0.02 %o%
  248.  
  249. '''Sound generation'''
  250. -f lavfi -i "sine=duration=3:f=220"
  251. aevalsrc="sine(220*2*PI*t):sample_rate=44100":duration=1
  252. anoisesrc=sample_rate=44100:amplitude=0.5:duration=4:color=brown
  253.  
  254. '''Normalization'''
  255. -af speechnorm=compression=5:raise=0.0001:l=1 %o%
  256. -af dynaudionorm=f=500:g=31:maxgain=10.0 %o%
  257.  
  258. '''Chorus'''
  259. -af "chorus=0.5:0.9:50|60|40:0.4|0.32|0.3:0.25|0.4|0.3:2|2.3|1.3" %o%
  260.  
Tags: notes ffmpeg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement