Not outputting Opus raw audio - audio

I'm currently writing a small script that coverts an MP4 to Opus audio on the fly and sends it to Discord in golang. Initially my script would pass an MP4 as it was downloading to ffmpeg through stdin and then pass stdout to an Opus encoder, then to Discord (exactly like this). After learning I could build ffmpeg with Opus, I'd like to cut out the opus encoder I previous had and pass ffmpeg's output directly to Discord.
Previous, my ffmpeg command looked like this (with using the second opus encoder)
ffmpeg -i - -f s16le -ar 48000 -ac 2 pipe:1
Now, without the encoder and letting ffmpeg do all the work, this is what I've come up with so far.
ffmpeg -i - -f s16le -ar 48000 -ac 2 -acodec libopus -b:a 192k -vbr on -compression_level 10 pipe:1
With this command however the audio doesn't get accepted by Discord's server, meaning I'm suspecting opus audio isn't coming out the other end. No errors outputted. Have I done something wrong with ffmpeg that could of caused this?

Try
ffmpeg -i - -sample_fmt s16 -ar 48000 -ac 2 -acodec libopus -b:a 192k -vbr on -compression_level 10 -f opus pipe:1
You can't use -f s16le as that specifies an uncompressed output format (of a specific sample type), whereas you need a compressed data stream of a certain codec. Instead, you can use sample_fmt and -f opus

Related

Detect silence(s) in audio channel from video stream

We need to detect the 'silence'(s) in the audio channel of a video stream. We have been able to receive a UDP video stream and extract audio from it using the command:
ffmpeg -y -i udp://127.0.0.1:23000 -ab 3000k -ar 44100 -ac 1 test.wav
The audio file was saved only to verify whether audio has been extracted correctly or not.
To detect 'silence'(s) in the audio, we are using the silencedetect filter. We referred to some examples and it seems to work for audio files:
ffmpeg -i audio/file/path -af silencedetect=noise=-50dB:d=0.25 -f null -
We are unable to detect silence(s) in the audio from a video stream. This is the command we came up with:
ffmpeg -y -i udp://127.0.0.1:23000 -ab 3000k -ar 44100 -ac 1 -af silencedetect=noise=-50dB:d=0.25 -f null -
What is it that we are doing wrong? Any help would be appreciated.
Thanks!

How to convert AC3 audio to Wav audio?

I would like to convert a AC3 audio file (ATSC A/52 aka AC-3 aka Dolby Digital stream 6 channels) to Wave audio file (16khz mono/1 channel).
While searching on the internet, a lot of people just used ffmpeg -i file.ac3 file.wav however, i'm not sure if that even works.
I keep getting
[ac3 # 0x55ac1a0b0660] exponent -1 is out-of-rangets/s speed= 125x
[ac3 # 0x55ac1a0b0660] error decoding the audio block
[ac3 # 0x55ac1a0b0660] frame sync error
Error while decoding stream #0:0: Invalid data found when processing input
etc
while I do the same command.
How do I convert ac3 to wav (16khz mono)?
*Note:
I also tried ffmpeg -i file.ac3 -codec:a:1 ac3 -codec copy -b:a 384 file.wav -ac 1 -ar 16000. But this doesn't output an actual wav file.
ffmpeg -i file.ac3 -vcodec copy -acodec pcm_s16le -ar 16000 -ab 128k -ac 1 file.wav should do it!
Also you can convert Eac3 to wav in high quality mode.
The wav file will be 48KHz 24Bit 6 Channels.
ffmpeg -i "input.eac3" -acodec pcm_s24le -ar 48000 -ac 6 "output.wav"
If you want to export in 8 channels, just write 8 instead of 6.

How do I convert wav into an mxf file with timecode?

I'm looking for a way to convert wav(16bit, 48kHz, LPCM) into an mxf file with timecode.
Since ffmpeg supports mxf, I'm trying, but I don't know the command.
ffmpeg -i ./input.wav [hh:mm:ss.ff, name1] [hh:mm:ss.ff, name2]... ./output.mxf
I'm expecting the above command, but does anyone know?
MXF is a pain
The default MXF muxer requires video.
The -timecode option with MXF requires video.
The mxf_opatom muxer allows just audio, but only mono with 48000 MHz sample rate, so each channel will need to be in its own MXF file.
Workaround 1: Pipe
ffmpeg -i input.wav -ar 48000 -c:a pcm_s16le -timecode 01:02:03:04 -f nut - | ffmpeg -i - -c:a pcm_s16le -f mxf_opatom output.mxf
I'm assuming your audio is mono (you didn't say what it is). If your input is multichannel then output each channel into its own file.
Use 01:02:03:04 for non-drop timecode, and 01:02:03.04 or 01:02:03;04 for drop.
Workaround 2: Dummy/blank video
Just ignore the video.
Non-drop timecode:
ffmpeg -f lavfi -i color=r=25 -i input.wav -timecode 01:02:03:04 -c:a copy -shortest output.mxf
Drop timecode:
ffmpeg -f lavfi -i color=r=30000/1001 -i input.wav -timecode 01:02:03.04 -c:a copy -shortest output.mxf

How to extract audio in 8khz using ffmpeg

I am using ffmpeg to extract the audio from a video. Below code downlaods the audio from a video file. I'm not sure how efficient this program is but I do know that it downloaods it in 48KHZ.
How do I use this program to extract audio from a video in 8Khz because the file is getting too big.
ffmpeg -i video_link -vn output.wav
Use -ar option to change frequency rate
ffmpeg -i video_link -vn -ar 8000 output.wav
If you want to try different formats of audio check the available formats in ffmpeg using ffmpeg -formats and available codecs using ffmpeg -codecs
Here's an example to extract to mp3 file
ffmpeg -i video_link -vn -ar 8000 -f mp3 output.mp3
Edit: as #llogan pointed out, -f option is not needed, ffmpeg automatically mux mp3 file.
ffmpeg -i video_link -vn -ar 8000 output.mp3

Discard channels when recording from audio interface with FFmpeg

I'm calling ffmpeg from a program I'm writing in order to record audio from an audio interface. The audio interface has six channels and what I'd like to do is only record from the first two audio channels, discarding the rest. I can't work out how to do this or if it is even possible from the documentation.
The command I'm using is as follows:
ffmpeg -f alsa -acodec pcm_s32le -ac 6 -ar 44100 -i hw:CARD=K6,DEV=0 output.wav
Is this something that is possible? If so, how?
Use
ffmpeg -f alsa -acodec pcm_s32le -ac 6 -ar 44100 -i hw:CARD=K6,DEV=0
-af "pan=2c|c0=c0|c1=c1" output.wav
The first argument to the pan filter is the number of output channels. Then come the individual channel mixes. Here it is first out channel is first in channel, and a similar assignment for the second.

Resources