FFmpeg is a powerful command-line tool for video and audio processing. I find myself reusing these commands frequently.
Extract LPCM Audio Track
Extracts an audio track from a fully muxed input file.
ffmpeg -i stream_file.m2ts -map 0:a:0 audio.wav
-ispecifies the input file-map 0:a:0selects the first audio stream- Output format determined by file extension
Extract a Video Track
Extracts a video track from a muxed input file without re-encoding.
ffmpeg -i stream_file.m2ts -c copy -an vid_only.mp4
-c copycopies the stream without re-encoding-anremoves audio streams
Convert Video Format
Convert between video formats while maintaining quality.
ffmpeg -i input.mov -c:v libx264 -crf 23 -c:a aac output.mp4
-c:v libx264uses H.264 video codec-crf 23sets quality (lower = better, 18-28 is typical)-c:a aacuses AAC audio codec
Resize Video
Resize video to specific dimensions.
ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4
-vf scale=1280:720sets width and height- Use
-1for auto:scale=1280:-1maintains aspect ratio
Extract Frames as Images
Extract video frames as individual images.
ffmpeg -i input.mp4 -vf fps=1 frame_%04d.png
fps=1extracts 1 frame per second%04dcreates numbered sequence (0001, 0002, etc.)
Combine Audio and Video
Merge separate audio and video files.
ffmpeg -i video.mp4 -i audio.wav -c:v copy -c:a aac output.mp4
- First
-iis video source - Second
-iis audio source -c:v copykeeps original video encoding
Learn More
Full documentation available at ffmpeg.org.