Bernhard Döbler
Bernhard Döbler

Reputation: 2116

ffmpeg Will stream be copied if same codec is requested?

I loop over some files and convert them with ffmpeg. I provide -vcodec h264. When the input video already is encoded with that codec: will the video stream be copied? How to make sure it's not reencoded in that case? Is it what -sameq was used previously?

Upvotes: 2

Views: 2107

Answers (1)

Arnaud Leyder
Arnaud Leyder

Reputation: 7002

You need to use -c:v copy if you want the raw H.264 stream to be passed on without re-encoding:

ffmpeg -i myh264file.mp4 -c:v copy -c:a copy myh264output.mp4

-c:a copy will also copy the audio

-c copy will copy both audio and video as in:

ffmpeg -i myh264file.mp4 -c copy myh264output.mp4

Detecting H.264 streams is not straight forward. You will need to code this.

For the -sameq settings please refer to this statement.

I would recommend upgrading to a recent version of ffmpeg if it is not already done as -vcodec is not used anymore, now it is -c:v.

The documentation on ffmpeg could help you.

Upvotes: 3

Related Questions