Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MOVED TO https://gist.github.com/viper25/286b27a41993eb9dfc5761bf2baa770f
- https://ffmpeg.lav.io/
- https://alfg.dev/ffmpeg-commander/
- 🔴 IMPORTANT
- 🔵 COMMANDS
- ⚪️ Minor Commands
- Remuxing is a lossless process that simply takes the video and audio streams from one container and puts them into a new container.
- "-c:v copy" to just re-mux the video instead of also re-encoding it.
- https://video.stackexchange.com/questions/15468/non-monotonous-dts-on-concat-ffmpeg
- 🔴 CONCATENATE or JOIN
- 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
- Sort by asc timestamp:
- 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
- Create as dir /b > mylist.txt will create:
- file 'D:\temp\phone\20160911_192835.mp4'
- file 'D:\temp\phone\20160911_193516.mp4'
- ⚪️ Concatenate files
- ffmpeg -f concat -safe 0 -i mylist.txt -c copy out.mp4
- ⚪️ Remove audio
- ffmpeg -f concat -safe 0 -i D:\junk\car_video\raw\mylist.txt -an -c copy D:\junk\car_video\raw\out.mov
- (use this if warnings appear)
- ffmpeg -f concat -safe 0 -i D:\junk\car_video\raw\mylist.txt -c copy output.mp4
- 🔴 Trim a video (ss = start time and t = duration)
- Note: Provide -ss BEFORE -i and -t else you'll get blank video first few sec.
- ffmpeg -ss 00:00:00 -i input.mp4 -t 00:00:10 -codec copy out.mp4
- The ss you can specify as 00:01:02 or 62
- 🔵 Getting audio/video file information (❗️ add -hide_banner to remove annoying banner)
- ffmpeg -i video.mp4 -hide_banner
- 🔵 Converting video files to different formats (if player doesn't play one)
- This just changes the container. ffmpeg automatically selects the appropriate codec for that container
- ffmpeg -i video.mp4 out.avi
- ffmpeg -i video.flv out.mpeg
- ffmpeg -formats
- To change codec explicitly:
- ffmpeg -i video.mp4 -vcodec libx264 out.avi
- 🔵 Converting video files to audio files
- ffmpeg -i input.mp4 -vn -ab 320 output.mp3
- 🔵 Change resolution of video files
- ffmpeg -i input.mp4 -filter:v scale=1280:720 -c:a copy output.mp4
- 🔵 Extract MP3 from video file
- ffmpeg -i input.mp4 -q:a 0 -map a output.mp3
- 🔵 Encode only Audio (c:a), leave Video stream as it is (copy)
- ffmpeg -i "Z:\video1.avi" -c:v copy -c:a libfdk_aac "Z:\video1-Out.avi"
- 🔵 Encode Audio Track to MP3 (output file larger)
- ffmpeg -i "Z:\video1.avi" -c:v copy -c:a libmp3lame -b:a 192k "Z:\video1-Audio-only.mp3"
- 🔵 To loop over a set of files, in the command prompt:
- 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"
- 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
- 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"
- pause
- ⚪️ Loop over and convert flac to mp3. Input = "%%A". Output = %%~nA.mp3
- for %%A in ("*.flac") do call "ffmpeg.exe" -i "%%A" -ab 320k -map_metadata 0 -id3v2_version 3 "newfiles\%%~nA.mp3"
- ============================
- Sometime you can't concatenate because of differing ** See https://stackoverflow.com/questions/31691943/ffmpeg-concat-produces-dts-out-of-order-errors/56002050#56002050
- So loop through all and change like:
- call "E:\APPS\ffmpeg\bin\ffmpeg.exe" -i "out.mp4" -video_track_timescale 60000 "newfiles\out.mp4"
- THEN concatenate
- ============================
- 🔵 Encode Video and Audio streams
- ffmpeg -i "Z:\video1.avi" -c:v libx264 -c:a libmp3lame -b:a 320k "Z:\video1-Out.avi"
- ⚪️ Change just the audio codec to mp3
- ffmpeg -i input.avi -acodec mp3 -vcodec copy out.avi
- ⚪️ Or change just the video codec
- ffmpeg -i input.avi -vcodec h264 out.avi
- ⚪️ Encode only Video to H.264 and leave Audio alone
- ffmpeg -i "Z:\video1.avi" -c:v libx264 -c:a copy "Z:\video1-out.avi"
- 🔵 Remove one audio stream from a file
- See how many streams exist
- ffmpeg -i file.mp4
- Output:
- Stream #0.0: Video: mpeg4, yuv420p, 720x304 [PAR 1:1 DAR 45:19], 23.98 tbr, 23.98 tbn, 23.98 tbc
- Stream #0.1: Audio: ac3, 48000 Hz, 5.1, s16, 384 kb/s
- Stream #0.2: Audio: ac3, 48000 Hz, 5.1, s16, 384 kb/s
- Copy video stream and say, 2nd audio to new file
- ffmpeg -i file.mp4 -map 0:0 -map 0:2 -acodec copy -vcodec copy new_file.mp4
- 🔵 Compressing video files
- ffmpeg -i input.mp4 -vf scale=1280:-1 -c:v libx264 -preset veryslow -crf 24 output.mp4
- REDUCE File size (Video bitrate from 3607 kb/s --> 1300k)
- ffmpeg.exe -i "T:\Ghostbusters (2016).mkv"
- Metadata:
- encoder : libebml v1.3.3 + libmatroska v1.4.4
- creation_time : 2016-09-30 06:02:49
- Duration: 02:13:44.98, start: 0.000000, bitrate: 3607 kb/s
- ffmpeg.exe -i "T:\Ghostbusters (2016).mkv" -b 1300k out.mp4
- 🔵 Speed up or Slow a video: Set setpts=0.5 & -r 60 (original 30 fps to 60fps)
- For 2X speed set to 1/2 or 0.5, for 3x, set to 1/3 or 0.3
- ffmpeg -i 20170810_191555A.mov -r 60 -filter:v "setpts=0.5*PTS" output.mkv
- https://trac.ffmpeg.org/wiki/How%20to%20speed%20up%20/%20slow%20down%20a%20video
- https://www.ostechnix.com/20-ffmpeg-commands-beginners/
- 🔵 Rotate video
- ffmpeg -i in.mov -vf "transpose=2" out.mov
- 0 = 90 Counter CLockwise and Vertical Flip (default)
- 1 = 90 Clockwise
- 2 = 90 Counter Clockwise
- 3 = 90 Clockwise and Vertical Flip
- 🔵 Cut middle parts of video
- 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:
- ffmpeg -i input.mp4 -t 5 a.tvshow -ss 10 -t 5 c.tvshow -ss 20 -t 5 e.tvshow
- or
- 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
- Then join
- https://superuser.com/questions/681885/how-can-i-remove-multiple-segments-from-a-video-using-ffmpeg
- 🔵 Join an audio stream to a video stream (to the shortest stream)
- 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
- 🔵 Split into 900 sec (15 min) files
- ffmpeg -i input.mp3 -c copy -map 0 -segment_time 900 -f segment "input-%03d.mp3"
- 🔵 Convert videos to WhatsApp format
- ffmpeg -i Rube.mp4 -vcodec libx264 -acodec aac output.mp4
Add Comment
Please, Sign In to add comment