FFMPEG Command Examples (Useful FFMPEG Commands)
Some of these are taken from here and here and here.
Good beginner guide: here
Nice set of examples: here
Good beginner guide: here
Nice set of examples: here
FFMPEG Audio Manipulation commands: https://trac.ffmpeg.org/wiki/AudioChannelManipulation
- Shorten a file. Start at 0, and encode 180 seconds. Copy ALL streams, not just the first or "best" of each type, which is the FFMPEG default:
ffmpeg -i input.mpg -ss 00:00:00 -t 180 -map 0 -codec copy output.mpg - Convert MP4 frames to Annex B:
ffmpeg -i input.mov -codec:v copy -codec:a copy -bsf:v h264_mp4toannexb -f mp4 -y output.mp4
Get information about a media file: ffmpeg -i video.avi
Extract (demux) the audio track from a video file: ffmpeg -i video.mts -acodec copy -vn audio.ac3
Extract (demux) the video track from a video file: ffmpeg -i video.mts -vcodec copy -an -f h264 ffNT.h264
Merge an audio and a video track (mux): ffmpeg -i video.h264 -i audio.ac3 -vcodec copy -acodec copy videoaudio.ts
Resize an original Full-HD (16:9) video file from a camcorder down to DVD resolution (and MPEG) for further processing, e.g. burning on DVD (e.g. with DVDStyler), but keep the source aspect ratio of 16:9: ffmpeg -i video.ts -s 720x405 -aspect "1.7777" -vb 8000k video.mpg
Resize a video to a certain width, retaining the aspect ratio (width = 640px, in this example; the "-strict -2" may be necessary on Linux because of licence issues): ffmpeg -i video.mp4 [-strict -2] -vf "scale=640:-1" video-resize640.mp4
Use FFMPEG to scan a file for errors: ffmpeg -i video.mpg -t 10 -benchmark -loglevel error -f mpeg -y NUL > t.t 2>&1 ffmpeg -i video.mpg -t 10 -benchmark -loglevel error -f mpeg -y NUL ffmpeg -i video.mpg -t 10 -benchmark -loglevel error -f mpeg -y NUL 2>&1 | find /c "error" ffmpeg -v error -i pid-dhxmedia.ca-aid-MOVE0200000045140141-movie.mpg -f null -y NUL
Extract all 8 audio channels from a file into 8 separate mono tracks: ffmpeg -i file.mxf -map 0:1 1.wav -map 0:2 2.wav -map 0:3 3.wav -map 0:4 4.wav -map 0:5 5.wav -map 0:6 6.wav -map 0:7 7.wav -map 0:8 8.wav
Pro Res encode, 1 source video track, 36 source audio tracks. Take first 6 audio tracks, map to 5.1 and convert to stereo. Source fps is 25, convert to 24. Source is 1080p, resize to 720p: ffmpeg -i pro_res.mov -map 0:0 -filter_complex "[0:1:a][0:2:a][0:3:a][0:4:a][0:5:a][0:6:a]amerge=inputs=6[aout]" -map "[aout]" -ac 2 -acodec ac3 -vcodec h264 -s 1280x720 -r 24 output.mp4
Same as above but libx264, H.264 profile main and level 4.0, with 720p, AAC codec, web optimized with moov atom at start, start at 2:25 in, video bitrate 3.5 Mbs, audio bitrate 192kbps, deinterlace with yadif filter: ffmpeg -i movie.mov -map 0:0 -filter_complex "[0:1:a][0:2:a][0:3:a][0:4:a][0:5:a][0:6:a]amerge=inputs=6[aout]" -map "[aout]" -ac 2 -acodec libvo_aacenc -c:v libx264 -s 1280x720 -pix_fmt yuv420p -profile:v main -level:v 4.0 -movflags faststart -ss 00:02:25 -vb 3500k -ab 192k -vf yadif output.mp4
Extract 8 mono audio tracks into 8 separate mono wave files: ffmpeg -i file_8_audio_channels.mxf -map_channel 0.1.0 chan1.wav -map_channel 0.2.0 chan2.wav -map_channel 0.3.0 chan3.wav -map_channel 0.4.0 chan4.wav -map_channel 0.5.0 chan5.wav -map_channel 0.5.0 chan6.wav -map_channel 0.7.0 chan7.wav -map_channel 0.8.0 chan8.wav
Convert from MP4 container to MPGTS, and convert to Annex B NALU in the process: ffmpeg -i zOriginal_CCM00212.mp4 -bsf:v h264_mp4toannexb -acodec copy -vcodec copy zOriginal_CCM00212.ts
Set timestamps to zero: ffmpeg -i input.mp4 -reset_timestamps 1 output.mp4 ffmpeg -i input.mp4 -vf "setpts=PTS-STARTPTS" -af "asetpts=PTS-STARTPTS" output.mp4
Raw YUV Streams: To create a raw yuv stream from an existing video: ffmpeg -i test.mp4 -c:v rawvideo -pix_fmt yuv420p test.yuv To play the yuv stream with ffplay: ffplay -f rawvideo -pix_fmt yuv420p -s 1280x720 -i test.yuv
5.1 + stereo audio source. First 6 tracks are the mono 5.1. Encode video and only the stereo source: ffmpeg -i file.mov -map_channel 0.6.0 -ac 2 -acodec ac3 -c:v libx264 -pix_fmt yuv420p -profile:v main -level:v 4.0 -movflags faststart -vb 4000k -s 1920x1080 out.mp4
Rotate video, only touching the metadata ffmpeg -i input.mp4 -metadata:s:v rotate=-90 -vcodec copy -acodec copy output.mp4
Still image with audio:
ffmpeg -loop 1 -y -i image8.jpg -i sound11.amr -shortest -acodec copy -vcodec mjpeg result.avi or ffmpeg -loop 1 -i image.jpg -i audio.wav -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p -shortest out.mp4
Put frame numbers on each frame: ffmpeg -i input -vf "drawtext=fontfile=Arial.ttf: text='%{frame_num}': start_number=1: x=(w-tw)/2: y=h-(2*lh): fontcolor=black: fontsize=52: box=1: boxcolor=white: boxborderw=5" -c:a copy output
Fragmented MP4 from MP4 ffmpeg -i <h264-file> -c:v copy -f mp4 -movflags frag_keyframe+empty_moov -y output.mp4
Filtering Audio ffmpeg -i low.mp3 -af "volume=1.33" high.mp3 Video ffmpeg -y -i b.mp4 -vf rotate=angle=-25*PI/180:fillcolor=brown b25.mp4 ffmpeg -i grainy.mov -vf nlmeans=s=1:p=3 -codec libx265 -preset medium -vb 1800k out_h265_1.8Mb.mov
Quite a nice post! And I've found another useful guide on how to use ffmpeg to convert MKV to MP4 easily, check it out if needed!
ReplyDelete