viper25

ffmpeg Commands

Aug 1st, 2014 (edited)
716
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 6.32 KB | None | 0 0
  1. MOVED TO https://gist.github.com/viper25/286b27a41993eb9dfc5761bf2baa770f
  2. https://ffmpeg.lav.io/
  3. https://alfg.dev/ffmpeg-commander/
  4.  
  5. 🔴 IMPORTANT
  6. 🔵 COMMANDS
  7. ⚪️ Minor Commands
  8. Remuxing is a lossless process that simply takes the video and audio streams from one container and puts them into a new container.
  9. "-c:v copy" to just re-mux the video instead of also re-encoding it.
  10.  
  11. https://video.stackexchange.com/questions/15468/non-monotonous-dts-on-concat-ffmpeg
  12.  
  13. 🔴 CONCATENATE or JOIN
  14. ls *.mp4 | sort -n | while read a; do echo "file '$a'"; done> list && ffmpeg -y -safe 0 -f concat -i list -c copy -c:a aac o.mp4
  15. Sort by asc timestamp:
  16. ls -lrt *.mp4 | while read a; do echo "file '$a'"; done> list && ffmpeg -y -safe 0 -f concat -i list -c copy -c:a aac OUT.mp4  
  17.  
  18. Create as dir /b > mylist.txt will create:
  19. file 'D:\temp\phone\20160911_192835.mp4'
  20. file 'D:\temp\phone\20160911_193516.mp4'
  21.  
  22. ⚪️  Concatenate files
  23.     ffmpeg -f concat -safe 0 -i mylist.txt -c copy out.mp4
  24. ⚪️  Remove audio
  25.     ffmpeg -f concat -safe 0 -i D:\junk\car_video\raw\mylist.txt -an -c copy D:\junk\car_video\raw\out.mov
  26.  
  27. (use this if warnings appear)
  28. ffmpeg -f concat -safe 0 -i D:\junk\car_video\raw\mylist.txt -c copy output.mp4
  29.  
  30.  
  31. 🔴 Trim a video (ss = start time and t = duration)
  32. Note: Provide -ss BEFORE -i and -t else you'll get blank video first few sec.
  33. ffmpeg -ss 00:00:00 -i input.mp4 -t 00:00:10 -codec copy out.mp4
  34. The ss you can specify as 00:01:02 or 62
  35.  
  36. 🔵 Getting audio/video file information (❗️ add -hide_banner to remove annoying banner)
  37. ffmpeg -i video.mp4 -hide_banner
  38.  
  39. 🔵 Converting video files to different formats (if player doesn't play one)
  40. This just changes the container. ffmpeg automatically selects the appropriate codec for that container
  41.     ffmpeg -i video.mp4 out.avi
  42.     ffmpeg -i video.flv out.mpeg
  43.     ffmpeg -formats
  44. To change codec explicitly:
  45.     ffmpeg -i video.mp4 -vcodec libx264 out.avi
  46.  
  47. 🔵 Converting video files to audio files
  48.     ffmpeg -i input.mp4 -vn -ab 320 output.mp3
  49.    
  50. 🔵 Change resolution of video files
  51.     ffmpeg -i input.mp4 -filter:v scale=1280:720 -c:a copy output.mp4
  52.  
  53. 🔵 Extract MP3 from video file
  54.     ffmpeg -i input.mp4 -q:a 0 -map a output.mp3
  55.  
  56. 🔵 Encode only Audio (c:a), leave Video stream as it is (copy)
  57.     ffmpeg -i "Z:\video1.avi" -c:v copy -c:a libfdk_aac "Z:\video1-Out.avi"
  58.  
  59. 🔵 Encode Audio Track to MP3 (output file larger)
  60.     ffmpeg -i "Z:\video1.avi" -c:v copy -c:a libmp3lame -b:a 192k "Z:\video1-Audio-only.mp3"
  61.  
  62. 🔵 To loop over a set of files, in the command prompt:
  63. for %A in ("*.mp4") do call "E:\APPS\ffmpeg\bin\ffmpeg.exe" -i "%A" -c:v copy -c:a libmp3lame -b:a 192k "newfiles\%~nA.mp4"
  64.  
  65. Or create a bat file  and enter the following contents. (in a bat file, use %%, when run from command line use %). Make the newfiles directory beforehand
  66.     for %A in ("*.mp4") do call "C:\Users\user1\Downloads\ffmpeg-20150702-git-03b2b40-win64-static\bin\ffmpeg.exe" -i "%A" -c:v copy -c:a libmp3lame -b:a 192k "newfiles\%%~nA.mp3"
  67. pause
  68.     ⚪️ Loop over and convert flac to mp3. Input = "%%A". Output = %%~nA.mp3
  69.      for %%A in ("*.flac") do call "ffmpeg.exe" -i "%%A" -ab 320k -map_metadata 0 -id3v2_version 3 "newfiles\%%~nA.mp3"
  70. ============================
  71. Sometime you can't concatenate because of differing ** See https://stackoverflow.com/questions/31691943/ffmpeg-concat-produces-dts-out-of-order-errors/56002050#56002050
  72. So loop through all and change like:
  73.  
  74. call "E:\APPS\ffmpeg\bin\ffmpeg.exe" -i "out.mp4" -video_track_timescale 60000 "newfiles\out.mp4"
  75.  
  76. THEN concatenate
  77. ============================
  78.  
  79. 🔵 Encode Video and Audio streams
  80.     ffmpeg -i "Z:\video1.avi" -c:v libx264 -c:a libmp3lame -b:a 320k "Z:\video1-Out.avi"
  81.  
  82. ⚪️ Change just the audio codec to mp3
  83.     ffmpeg -i input.avi -acodec mp3 -vcodec copy out.avi
  84. ⚪️ Or change just the video codec
  85.     ffmpeg -i input.avi -vcodec h264 out.avi
  86. ⚪️ Encode only Video to H.264 and leave Audio alone
  87.     ffmpeg -i "Z:\video1.avi" -c:v libx264 -c:a copy "Z:\video1-out.avi"
  88.  
  89. 🔵 Remove one audio stream from a file
  90. See how many streams exist
  91.     ffmpeg -i file.mp4
  92. Output:
  93.     Stream #0.0: Video: mpeg4, yuv420p, 720x304 [PAR 1:1 DAR 45:19], 23.98 tbr, 23.98 tbn, 23.98 tbc
  94.     Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 384 kb/s
  95.     Stream #0.2: Audio: ac3, 48000 Hz, 5.1, s16, 384 kb/s
  96. Copy video stream and say, 2nd audio to new file
  97.     ffmpeg -i file.mp4 -map 0:0 -map 0:2 -acodec copy -vcodec copy new_file.mp4
  98.  
  99. 🔵 Compressing video files
  100.     ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 output.mp4
  101.    
  102. REDUCE File size (Video bitrate from 3607 kb/s --> 1300k)
  103.     ffmpeg.exe -i "T:\Ghostbusters (2016).mkv"
  104.  
  105.   Metadata:
  106.     encoder         : libebml v1.3.3 + libmatroska v1.4.4
  107.     creation_time   : 2016-09-30 06:02:49
  108.   Duration: 02:13:44.98, start: 0.000000, bitrate: 3607 kb/s
  109.    
  110.     ffmpeg.exe -i "T:\Ghostbusters (2016).mkv" -b 1300k out.mp4
  111.  
  112. 🔵 Speed up or Slow a video: Set setpts=0.5 & -r 60 (original 30 fps to 60fps)
  113. For 2X speed set to 1/2 or 0.5, for 3x, set to 1/3 or 0.3
  114. ffmpeg -i 20170810_191555A.mov -r 60 -filter:v "setpts=0.5*PTS" output.mkv
  115. https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video
  116.  
  117. https://www.ostechnix.com/20-ffmpeg-commands-beginners/
  118.  
  119. 🔵 Rotate video
  120. ffmpeg -i in.mov -vf "transpose=2" out.mov
  121.  
  122. 0 = 90 Counter CLockwise and Vertical Flip (default)
  123. 1 = 90 Clockwise
  124. 2 = 90 Counter Clockwise
  125. 3 = 90 Clockwise and Vertical Flip
  126.  
  127. 🔵 Cut middle parts of video
  128. Say you have 6 segments ABCDEF each 5 seconds long and you want A (0-5 seconds), C (10-15 seconds) and E (20-25 seconds) you'd do this:
  129. ffmpeg -i input.mp4 -t 5 a.tvshow -ss 10 -t 5 c.tvshow -ss 20 -t 5 e.tvshow
  130. or
  131. ffmpeg -i input.mp4 -t 0:00:05 a.tvshow -ss 0:00:10 -t 0:00:05 c.tvshow -ss 0:00:20 -t 0:00:05 e.tvshow
  132. Then join
  133. https://superuser.com/questions/681885/how-can-i-remove-multiple-segments-from-a-video-using-ffmpeg
  134.  
  135. 🔵 Join an audio stream to a video stream (to the shortest stream)
  136. ffmpeg -i out.mp4 -itsoffset 00:01:03 -i audio.wav  -c:v copy -c:a aac -strict experimental -map 0:v:0 -map 1:a:0 -async 1 -shortest out1.mp4
  137.  
  138. 🔵 Split into 900 sec (15 min) files
  139. ffmpeg -i input.mp3 -c copy -map 0 -segment_time 900 -f segment "input-%03d.mp3"
  140.  
  141. 🔵 Convert videos to WhatsApp format
  142. ffmpeg -i Rube.mp4 -vcodec libx264 -acodec aac output.mp4
Add Comment
Please, Sign In to add comment