Copy Video and Audio Streams via FFmpeg

Extracting or transferring video and audio streams without re-encoding is one of FFmpeg’s most powerful features. This process, known as stream copying, allows you to change file containers, trim media, or isolate tracks instantly because it bypasses the time-consuming and lossy compression phase. By using the -c copy flag, FFmpeg acts as a demuxer and muxer rather than an encoder, preserving the exact original quality of your media while completing the operation in a matter of seconds.

The Basic Stream Copy Command

To copy both the video and audio tracks from an input file into a new container without altering the underlying data, use the following syntax:

ffmpeg -i input.mp4 -c copy output.mkv

Command Breakdown

Copying Specific Streams

If your file contains multiple tracks and you only want to preserve specific elements without re-encoding, you can target the video or audio streams individually using stream specifiers.

Copy Video Only (Discard Audio)

To strip the audio track and copy only the pristine video stream, combine the video copy flag with the -an (audio none) block:

ffmpeg -i input.mp4 -c:v copy -an output_video_only.mp4

Copy Audio Only (Discard Video)

To extract the raw audio track from a video file without re-encoding it, use the video block flag -vn (video none):

ffmpeg -i input.mp4 -vn -c:a copy output_audio.mp3

Note: Ensure the output file extension matches the actual codec of the audio stream (e.g., use .m4a for AAC audio or .mp3 for MP3 audio) to avoid container compatibility issues.

Trimming Media Without Re-Encoding

Stream copying is highly efficient for cutting or trimming videos instantly. You can slice a segment out of a larger file by defining a start time (-ss) and a duration (-t) or an end time (-to).

ffmpeg -ss 00:01:30 -i input.mp4 -to 00:02:45 -c copy cut_output.mp4

Placing the -ss flag before the -i flag enables “input seeking.” This tells FFmpeg to jump directly to the specified timestamp quickly, making the stream copy process remarkably fast.