Add silent track to WebM video - audio

FFMPEG documentation says this can be achieved by doing something similar to the following:
ffmpeg -f lavfi -i anullsrc=channel_layout=stereo:sample_rate=44100 -i $media -shortest -c:v copy -c:a aac $output
However when i try this with a WebM video I get the following error:
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Error initializing output stream 0:1
I there a workaround for this? Thanks.

AAC is not a compatible codec for WebM. You can simply drop -c:a aac and FFmpeg will select the default audio codec for the output format. Opus (libopus) and Vorbis (libvorbis) are acceptable audio codecs for WebM.

Related

Merging MP3 with MP4 using FFMPEG. Unexpected silent at the end

I'm using ffmpeg -i video.mp4 -i audio.mp3 -c:a aac -shortest output.mp4 to join a part of an mp3 file to a video while converting to AAC, but the last 3 centiseconds of the audio are silent. Is there a way to fix this?
Log: https://jpst.it/2aIIh - This one had 10 ms of silence at the end.

convert m4a to WAV file (containing signed 16-bit PCM samples) in ffmpeg

I have a MP4a file which I am looking to convert to WAV file, containing signed 16-bit PCM samples. I have ffmpeg at my disposal, and looking at previous SOF posts, I have tried:
ffmpeg -y -i input.mp4 -acodec pcm_s16le -f s16le -ac 1 -ar 16000 output.pcm
but, the program I use complains that this converted file has data in unknown format. I was wondering if anyone had any pointers on how to go from m4a to wav with pcm samples.
ffmpeg -i input.mp4 output.wav
This command will output WAV file containing signed 16-bit PCM samples. Your command is outputting raw PCM, not WAV.
You can add -c:a pcm_s16le output option if you prefer, but that's the default encoder for WAV so it can be omitted.

ffmpeg to make mp4 container with opus audio

I have audio in opus format and need to make mp4 container
ffmpeg -i input.opus -c:a opus -strict experimental output.mp4
Throws Could not find tag for codec opus in stream
What is wrong here?

FFMPEG Audio streaming over RTP

I have a encoded Audio File(.aac file). I want to stream this file over RTP using FFMPEG without any transcoding. I am using following command :
ffmpeg -i input_file.aac -re -vn -acodec copy -strict experimental -f rtp rtp://225.0.0.1:1234
But above command gives below error:
AAC with no global headers is currently not supported
Can anyone point out any corrections ?
Thanks for the help.
The warning means it wants global headers to be set on your audio stream, like this:
ffmpeg -re -i input_file.aac -c:a copy -flags:a +global_headers -f rtp rtp://225.0.0.1:1234

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?
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?
I'm doing the same as the OP, but with an m4v container. I'm using the MacPorts "nonfree" variant of ffmpeg so that I can use libfaac, which gives better audio quality than the built-in AAC encoder and also had the same issue as #dkam. The command line I ended using is like this:
ffmpeg -i input.m4v -map 0:v -c:v copy -map 0:a -c:a:0 copy -map 0:a -c:a:1 libfaac output.m4v
(The videos are for playback on an iPad, which doesn't seem to be able to handle ac3.)
This command will take a video with 1 audio stream, and downmix to stereo and convert the audio stream and add it as a 2nd audio stream. It will be in AAC 384k.
ffmpeg -i INPUT.mkv -strict -2 -map 0 -c copy -map 0:a:0 -c:a:1 aac -b:a 384k -ac 2 OUTPUT.mkv
Explanation of the command
ffmpeg -i INPUT.mkv The application and input file
-strict -2 Enable downmixing support
-map 0 Tell ffmpeg read all Video, Audio, and Subtitle streams for the following arguments
-c copy Copy everything
-map 0:a:0 Tell ffmpeg to read the first audio stream for the following arguments
-c:a:1 aac Output the audio to a 2nd audio channel (0 = first channel) in aac format. Important! You must change the output channel to a higher number if there are multiple audio streams to prevent overwriting them.
-b:a 384k 384k bitrate (I don't know what's good for aac stereo but this is really high since it's for 5.1 aac)
-ac 2 Downmix to stereo
OUTPUT.mkv Output file
More examples
A video with two audio streams. Creating a third audio stream by encoding the first.
ffmpeg -i INPUT.mkv -strict -2 -map 0 -c copy -map 0:a:0 -c:a:2 aac -b:a 384k -ac 2 OUTPUT.mkv
Again a video with two audio streams, but you want to encode the second one
ffmpeg -i INPUT.mkv -strict -2 -map 0 -c copy -map 0:a:1 -c:a:2 aac -b:a 384k -ac 2 OUTPUT.mkv

Resources