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.mkvCommand Breakdown
-i input.mp4: Specifies the path to your source file.-c copy: Instructs FFmpeg to use the “stream copy” mode for all streams (video, audio, subtitles, etc.). This tells the program to skip the decoding and encoding processes entirely.output.mkv: The desired name and format of your output file.
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.mp4Copy 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.mp3Note: Ensure the output file extension matches the actual codec of the audio stream (e.g., use
.m4afor AAC audio or.mp3for 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.mp4Placing 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.