0

Say I have a video file with contained audio file. So a container with audio and video codecs.

If I'm applying an operation in ffmpeg that will re-encode the video, such as applying filters or changing the container (assume it supports the audio codec) or video codec or whatever, does this also re-encode or affect the audio of the output file in any way?

Does the audio codec just automatically get a kinda pseudo -c copy command applied and translated over to new video file?

I'm trying to understand whether I need to specify a -c copy for the audio every-time I do an operation to the video part. Whether for the purpose of speeding up the operation or for avoiding quality-loss.

Like when setting an audio input and a video input and combining you need to specify a -c copy to get it to simply combine them. But I'm just a bit confused if you need to worry about it once the audio codec is already safely in the container and I'm applying operations to this video afterthefact.

2 Answers 2

2

In ffmpeg, copy mode for -codec / -c always needs to be expressly set.

So for

ffmpeg -i in -c copy out

ffmpeg will perform automatic stream selection and copy all those streams.

For

ffmpeg -i in -c:a copy out

ffmpeg will perform automatic stream selection and copy audio stream. Video stream will be transcoded.

I suggest you read the above link on stream selection fully. It covers stream handling.

9
  • Will I always get an error message and/or corrupted video when I specify -c copy or -c:v or -c:a when encoding of the specific type does infact need to happen? I'm just curious with -c copy if there might be instances, that I haven't tested, where it might drop the copy for say...the video stream if in my command its assumed I need to re-encode the video. Or will -c copy always tell me or make the video unplayable if there is any contradiction in the command that makes either the video or audio have to re-encode? Will ffmpeg ever make assumptions if there is contradiction without letting mekno
    – kite
    Commented Dec 17, 2018 at 13:06
  • Encoding only needs to happen if you're filtering the stream or if the input codec is not supported in the output. Else if you set copy, ffmpeg will copy the stream over.
    – Gyan
    Commented Dec 17, 2018 at 13:38
  • When you say filtering the stream does that refer to filters specifically? Or is there something else to that. Cause if I do -i input.mkv -c copy output.avi. it won't work. So isn't that an example where avi supports the .wav audio codec within the mkv and the h.264 8 bit format of the video codec? Is it the fitlering the stream part that plays into that then? I thought re-encoding always needed to happen when I'm changing containers, except in certain exceptions like mkv to mp4. re-encoding and encoding are referring to the same general thing right?
    – kite
    Commented Dec 17, 2018 at 13:45
  • Filtering happens with -vf / -af / -filter_complex / -lavfi . -i input.mkv -c copy output.avi is an example of remuxing / rewrapping. If all streams are supported, this won't fail. Share log if it does.
    – Gyan
    Commented Dec 17, 2018 at 15:31
  • imgur.com/a/esIJRIb ; I tried it on a few input videos and same error code. adding -bsf:v h264_mp4toannexb like it said in the error code fixed it though. Which I suppose functions as some kind of decoder as far as I can read into it. So I think I'm good, learned alot here.
    – kite
    Commented Dec 17, 2018 at 18:59
1

Does the audio codec just automatically get a kinda pseudo -c copy command applied and translated over to new video file?

No, use -c:v for your video codec, and then -c:a copy to instruct the stream copy of the audio stream.

For example:

ffmpeg -i "inputfile" -vf "filter" -c:v libx264 -crf 18 -c:a copy "output.mp4"

Another note about ffmpeg defaults:

Not all things need to be explicit, only experience and reading the documentation gives you the best feel for this. Notice that we had to explicitly specify the audio stream copy, yet in my example above, I haven't explicitly set -f mp4 container. This is because the file extension of the output file (mp4) selects the default container for that file extension, which is something one may or may not want.

1
  • I'm not familiar with what -f mp4 or -f anything does in ffmpeg. The full command as you had written I'm familiar with, but not any extra variation on it with -f. What should I google to find more on that? And when would there be an instance of the extension of the output not being the container I want to use for my video? I always assumed the output extension existed to specify the container of my video and audio codecs and no other reason.
    – kite
    Commented Dec 17, 2018 at 13:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.