Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ffmpeg to duplicate an audio stream and encode this new stream

I have some video files that I need to re-encode due to compatibility issues. They are currently mkv files with h.264 video and ac3-a52 audio. I want to keep the h.264 video, convert the container to m4v and create two audio tracks, one with the original ac3-a52 and one copied from that but in aac stereo.

I assume there has to be some sort of audio stream mapping command but I don't know how to map and re-encode at the same time. What command should I enter into ffmpeg to achieve this?

Also, what is the difference between ac3 and ac3-a52? Will an apple TV still be able to pass through ac3-a52 or does that have to be converted to ac3?

like image 424
Sam Avatar asked Feb 05 '14 01:02

Sam


People also ask

How do I copy audio from FFmpeg?

-map 0 tells ffmpeg to all streams from input 0 (the first input) in the output file. -c:a copy -c:s copy will copy over any audio and subtitle streams present.

What does FFmpeg copy do?

Video codec, copy. This tells FFmpeg to copy the compressed video stream into the new file without re-encoding. Audio codec, copy. This tells FFmpeg to copy the compressed audio stream into the new file without re-encoding.

What is FFmpeg CRF?

The Constant Rate Factor or CRF is an option available in the libx264 encoder to set our desired output quality. It enables us to specify a target value that maps to a specific quality by adjusting the bitrates automatically based on the input video.

What is FFmpeg transcoding?

ffmpeg. FFmpeg is a software, which uses all formats for media you may need – H. 264, H. 265, Apple ProRes, Avid DNxHD etc, even also used for images like PNG and others – support all type of platform you're on. It is a command-line tool, it is quicker than some other tools which are available for transcoding.


1 Answers

this works for me:

ffmpeg -y -i Source.mkv -map 0:v -c:v copy -map 0:a -c:a copy -map 0:a -strict -2 -c:a aac out.mkv
  • -y – A global option to overwrite the output file if it already exists.
  • -map 0:v – Designate the video stream(s) from the first input as a source for the output file.
  • -c:v copy – Stream copy the video. This just muxes the input to the output. No re-encoding occurs.
  • -map 0:a – Designate the audio stream(s) from the first input as a source for the output file.
  • -c:a copy – Stream copy the audio. This just muxes the input to the output. No re-encoding occurs.
  • -strict -2 -c:a aac – Use the native FFmpeg AAC audio encoder. -strict -2 is required as a way that you acknowledge that the encoder is designated as experimental. It is not a great encoder, but it is not too bad at higher bitrates.

According to wikipedia, there is no difference between AC3 and ATSC A/52: the 1st one is the name of the codec, the 2nd is the name of the standard specifying the AC3 codec. Maybe someone have more knowledge about it?

like image 179
AJ29 Avatar answered Nov 02 '22 06:11

AJ29