Answers.Body: <p>In ffmpeg, <code>copy</code> mode for <code>-codec / -c</code> always needs to be expressly set.</p>
  
  <p>So for</p>
  
  <pre><code>ffmpeg -i in -c copy out
  </code></pre>
  
  <p>ffmpeg will perform automatic <a href="https://ffmpeg.org/ffmpeg.html#Stream-selection" rel="nofollow noreferrer">stream selection</a> and copy all those streams.</p>
  
  <p>For</p>
  
  <pre><code>ffmpeg -i in -c:a copy out
  </code></pre>
  
  <p>ffmpeg will perform automatic stream selection and copy audio stream. Video stream will be transcoded.</p>
  
  <p>I suggest you read the above link on stream selection fully. It covers stream handling.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-17T13:06:03.120Z
Answers.Text: 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
Answers.UserDisplayName: kite
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-17T13:38:28.247Z
Answers.Text: 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.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-17T13:45:35.960Z
Answers.Text: 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?
Answers.UserDisplayName: kite
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-17T15:31:21.840Z
Answers.Text: 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.
Answers.UserDisplayName: Gyan
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-17T18:59:15.707Z
Answers.Text: https://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.
Answers.UserDisplayName: kite
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-17T20:10:18.273Z
Answers.Text: ffmpeg -i %d.png -c:v libx264 -crf 0 -pix_fmt yuv420p -c:v copy output.mkv ; can you explain what is going to happen to the video in this relationship with -c:v copy there? Is it going to negate the -c:v libx264 part and simply store the png in the mkv without re-encode or does the "-c:v libx264 -crf 0 -pix_fmt yuv420p" apply to the image and then it stores itself still as this downgraded png in the mkv?
Answers.UserDisplayName: kite
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-17T20:53:07.363Z
Answers.Text: @kite `-bsf:v h264_mp4toannexb` is a bitstream filter, which is the rare exception to what Gyan was saying (technically not an exception, but for the sake of using the word 'filter').
Answers.UserDisplayName: hmedia1
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-17T20:55:10.437Z
Answers.Text: @kite try it and see.  You can only specify one encoder per input file
Answers.UserDisplayName: hmedia1
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-18T16:27:11.023Z
Answers.Text: ffmpeg -i %d.png -c:v libx264 -crf 0 -pix_fmt yuv420p -c:v copy output.mkv; says for the output the data is in png. So the c:v copy is preventing it from changing from png. Removing the -c:v copy says it converts from png to h.264 as written. "Input data: png, rgb48be(pc), Output data: png (MPNG/0x473E504D), rgb48be(pc)" Are what the info's of the inputs and outputs say for top command with -c:v used. I don't know what MPNG/0x etc.... means and my question is unchanged from before. Also I don't get if png are classified video codecs or how a h.264 codec applies to them without converting it.
Answers.UserDisplayName: kite
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-17T10:54:55.250Z
Answers.LastActivityDate: 2018-12-17T10:54:55.250Z
Answers.UserDisplayName: Gyan
Answers.Body: <blockquote>
    <p>Does the audio codec just automatically get a kinda pseudo -c copy command applied and translated over to new video file?</p>
  </blockquote>
  
  <p>No, use <code>-c:v</code> for your video codec, and then <code>-c:a copy</code> to instruct the stream copy of the audio stream.</p>
  
  <p>For example:</p>
  
  <p><code>ffmpeg -i "inputfile" -vf "filter" -c:v libx264 -crf 18 -c:a copy "output.mp4"</code></p>
  
  <p><strong>Another note about ffmpeg defaults:</strong> </p>
  
  <p>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 <code>-f mp4</code> 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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-17T13:15:16.423Z
Answers.Text: 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.
Answers.UserDisplayName: kite
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-17T11:00:42.667Z
Answers.LastActivityDate: 2018-12-17T11:00:42.667Z
Answers.UserDisplayName: hmedia1
Body: <p>Say I have a video file with contained audio file. So a container with audio and video codecs.</p>
  
  <p>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?</p>
  
  <p>Does the audio codec just automatically get a kinda pseudo -c copy command applied and translated over to new video file?</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
Tags: <ffmpeg>
Title: Do video re-encoding operations affect the container's audio file?
UserDisplayName: kite
ThreadText: # Do video re-encoding operations affect the container's audio file?
  
  (Asked by: username_0 on 2018-12-17)
  
  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.
  
  **Tags:** ffmpeg
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-12-17. Score: 2 | Accepted answer
  
  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](https://ffmpeg.org/ffmpeg.html#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.
  
  > **Comments:**
  > **username_0**: 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  
  > **username_1**: 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.  
  > **username_0**: 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?  
  > **username_1**: 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.  
  > **username_0**: https://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.  
  > **username_0**: ffmpeg -i %d.png -c:v libx264 -crf 0 -pix_fmt yuv420p -c:v copy output.mkv ; can you explain what is going to happen to the video in this relationship with -c:v copy there? Is it going to negate the -c:v libx264 part and simply store the png in the mkv without re-encode or does the "-c:v libx264 -crf 0 -pix_fmt yuv420p" apply to the image and then it stores itself still as this downgraded png in the mkv?  
  > **username_2**: @username_0 `-bsf:v h264_mp4toannexb` is a bitstream filter, which is the rare exception to what username_1 was saying (technically not an exception, but for the sake of using the word 'filter').  
  > **username_2**: @username_0 try it and see.  You can only specify one encoder per input file  
  > **username_0**: ffmpeg -i %d.png -c:v libx264 -crf 0 -pix_fmt yuv420p -c:v copy output.mkv; says for the output the data is in png. So the c:v copy is preventing it from changing from png. Removing the -c:v copy says it converts from png to h.264 as written. "Input data: png, rgb48be(pc), Output data: png (MPNG/0x473E504D), rgb48be(pc)" Are what the info's of the inputs and outputs say for top command with -c:v used. I don't know what MPNG/0x etc.... means and my question is unchanged from before. Also I don't get if png are classified video codecs or how a h.264 codec applies to them without converting it.  
  
  ---
  
  ### Answer by username_2 on 2018-12-17. Score: 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.
  
  > **Comments:**
  > **username_0**: 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.  
  
  ---
  
  