Advertisement
ggeecckkoo

ffmpeg intro

Aug 22nd, 2017
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. Always make sure that you have the latest version installed
  2. ffmpeg.zeranoe.com
  3.  
  4. STANDARD VIDEO ENCODE
  5. ffmpeg -i input.file -ss 00:00:10.000 -to 00:00:20.000 -c:v libvpx -crf 4 -vf scale=640:-1 output.file
  6.  
  7. Merging audio
  8. video.file -i audio.file -c:v copy/libvpx -c:a copy/libvorbis -strict experimental output.file
  9. Extracting/converting audio
  10. input.file output.file
  11. Extracting and/or converting into multiple different formats
  12. input.file output.file1 output.file2 output.file3 etc
  13. Using image instead of video
  14. -loop 1 -i image.file -i audio.file output.file
  15.  
  16. OVERLAY
  17. One overlay:
  18. -filter_complex "[0:v][1:v] overlay=x:y:enable='between(t,0,20)'"
  19. [0:v] refers to the first video stream (or the first input file) [1:v] refers to the second video stream (or the second input file) that is used as the overlay.
  20. overlay=x:y means that the overlay will be placed y pixels down and x pixels to the right from the top left corner that is 0:0.
  21. enable='between(t,0,20)' means that the overlay will be placed between 0 and 20 seconds, remove to make the overlay present from start to finish
  22. Multiple overlays:
  23. -filter_complex -"[0:v][1:v] overlay=x:y:enable='between(t,0,20)' [tmp]; [tmp][2:v] overlay=x:y:enable='between(t,0,20)' [tmp]; [tmp][3:v] overlay=x:y:enable='between(t,0,20)'"
  24. [tmp] is a temporary output file that you then need to specify as the source (instead of [0:v]) or else ffmpeg will ignore the subsequent commands leading to only one overlay present in output file
  25.  
  26. HARDCODE SUBTITLES INTO VIDEO
  27. Image based:
  28. input.file -filter_complex "[0:v][0:s(:#)]overlay[v]" -map "[v]" -map 0:a output.file
  29. change # according to which subtitle you want. 0 is first subtitle stream, 1 is the second. etc.
  30. Ass sub external:
  31. input.file -vf subtitles=sub.file output.file
  32. Ass sub internal:
  33. input.file -vf subtitles=input.file output.file (add :si=1 for second stream)
  34. Can only hardcode .ass subtitles
  35. Converting to ass
  36. sub.srt sub.ass
  37. Change subtitle color and font
  38. input.file subtitles=sub.srt:force_style='FontName=DejaVu Serif,PrimaryColour=&HAA00FF00' output.file
  39. Extracting subtitle from video
  40. input.file -an -vn -c:s:0 subfile sub.subfile
  41. remember to hardcode video before changing resolution
  42.  
  43. MERGE VIDEO
  44. Vertically merge:
  45. -i input1.file (top) -i input2.file (bottom) -filter_complex vstack output.file
  46. Horizontally merge:
  47. -i input1.file (left) -i input2.file (right) -filter_complex hstack output.file
  48. note:when stacking vertically/horizontally quality of video might degrade
  49. Splice video:
  50. -i input1.file -i input2.file -filter_complex "[0:v:0] [1:v:0] concat=n=2:v=1 [v]" -map "[v]" output.file
  51. Splice video with audio:
  52. -i input1.file -i input2.file "[0:v:0] [0:a:0] [1:v:0] [1:a:0] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" output.file
  53. Splice multiple videos
  54. -f concat -i textfile.file -fflags +genpts output.file
  55. note: textfile should have multiple lines looking like this:
  56. file 1.mp4
  57. file 2.mp4
  58. file 3.mp4
  59. file 4.mp4
  60. (mp4 can be changed to other video formats)
  61.  
  62. FILTERS
  63. -ss (start of video)
  64. -to (end of video)
  65. -c:v (video codec)
  66. -c:a (audio codec)
  67. -b:v [enter number followed by K (Kilobit) or M (Megabit)] (video bitrate)
  68. -b:a [cannot be set lower than 50k] (audio bitrate)
  69. -vf scale=height:width [-1 on either side to scale resolution to corresponding height/width] (change resolution)
  70. -auto-alt-ref [0/1] (disables/enables alternate reference frames)
  71.  
  72. OPTIONAL
  73. -y (automatically replace duplicate file)
  74. -threads # (number of threads used)
  75. -metadata title="title" (embedding title to video)
  76. -an (disable audio)
  77. -sn (disable subtitles)
  78. -vn (disable video)
  79. -r (framerate (not recommended))
  80. -aq 5 [higher is better] (constant audio quality)
  81. -crf [4-63 lower is better (0 for lossless)] (constant video quality)
  82. -bufsize (for more accurate average bitrate)
  83. -minrate (sets minimum video bitrate (useless))
  84. -maxrate (sets maximum video bitrate, used in conjunction with -bufsize)
  85. -acodec [can be used instead of -c:a] (audio codec)
  86. -vcodec [can be used instead of -c:v] (video codec)
  87. -movflags +faststart (will make the video play before completely dl'd by browser (only for browser viewing))
  88. -stream_loop -1 (loops video)
  89. -loop 1 (loops image (not gif))
  90.  
  91. OTHER FILTERS
  92. -strict experimental
  93. -filter_complex
  94. -vf=video filter
  95. -af=audio filter
  96.  
  97. AUDIO CODECS
  98. libvorbis (.ogg, low quality)
  99. libfaac (.aac)
  100. libmp3lame (.mp3)
  101. libopus (.ogg, high quality, does not support quality based commands)
  102.  
  103. VIDEO CODECS
  104. libvpx
  105. libx264
  106.  
  107. COMMANDS
  108. -formats (lists all supported formats)
  109. -codecs (lists all supported codecs)
  110. -filters (lists all supported filters)
  111. -help (lists commands)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement