I am using ffmpeg to calculate the volume of my audio file, but I find that ffmpeg returns different values for different containers (like mp3 v.s. ogg)
Here is an example. I am using an ogg file from Wikimedia Commons, and converting it to mp3, then analyze the volume of both files. For ogg file, I get -3.0 dB for mean volume, but for mp3 file, I get -3.4 dB. When I use other files, I also get different max volume and histogram.
[user#localhost tmp]$ wget https://upload.wikimedia.org/wikipedia/commons/b/b9/Audio_Frequency_tone%2C_Middle_C%2C_C4%2C_261.63hz.ogg -O a.ogg 2> /dev/null
[user#localhost tmp]$ ffmpeg -i a.ogg a.mp3 2> /dev/null
[user#localhost tmp]$ ffmpeg -i a.ogg -af volumedetect tmp.ogg 2>&1 | grep volumedetect
[Parsed_volumedetect_0 # 0x555f69f3f4a0] n_samples: 88768
[Parsed_volumedetect_0 # 0x555f69f3f4a0] mean_volume: -3.0 dB
[Parsed_volumedetect_0 # 0x555f69f3f4a0] max_volume: 0.0 dB
[Parsed_volumedetect_0 # 0x555f69f3f4a0] histogram_0db: 27541
[user#localhost tmp]$ ffmpeg -i a.mp3 -af volumedetect tmp.mp3 2>&1 | grep volumedetect
[Parsed_volumedetect_0 # 0x55fd62be4740] n_samples: 88768
[Parsed_volumedetect_0 # 0x55fd62be4740] mean_volume: -3.4 dB
[Parsed_volumedetect_0 # 0x55fd62be4740] max_volume: -0.0 dB
[Parsed_volumedetect_0 # 0x55fd62be4740] histogram_0db: 21340
[user#localhost tmp]$
Why is this bug happening? Which one should I believe?
You're transcoding the audio. So, the output isn't identical to the input. You should get the same result if you transcode to a lossless format like WAV or FLAC.
Related
I have the following script on linux:
arecord -t raw -f S16_LE -r 44100 -c 1 | split -d -b 882000 --filter='flac - -f --endian little --sign signed --channels 1 --bps 2 --sample-rate 44100 -s -o "${FILE}.flac"'
this script records audio at 44100 fs, 1 channel, then flac files with 882000 bytes, ie 10 seconds of audio at 44100 sample rate are created and saved. The audios are 2 mb, is there any way I can do this but save it in wav or ogg format?
Flac files, not having loss, take up a lot of memory space, I want to reduce that with another format
You can use lame instead flac:
arecord -t raw -f S16_LE -r 44100 -c 1 | split -d -b 882000 --filter='lame -r -s 44.1 - "${FILE}.mp3"'
Does any one know how to merge multiple raw audio file into single wav file. I am using Sox but any other tools also fine.
I am trying below commands, but i know something wrong here
sox -r 16000 -b 16 -c 1 -e signed-integer file1.raw file2.raw out.wav
I am missing something ?
You need to specify all input file parameters per file (as RAW obviously does not have a header). Your initial guess was same as mine: that -r 16000 -b 16 -c 1 -e signed-integer applies to both file1.raw and file2.raw. It doesn't.
Here's how it should be done:
sox -r 16000 -b 16 -c 1 -e signed-integer file1.raw -r 16000 -b 16 -c 1 -e signed-integer file2.raw out.wav
You might want to add option -m for merge.
I'm saving an fm station to an mp3 file using rtl_fm and sox.
rtl_fm to capture the signal and sox to transcode it to mp3.
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 | sox -traw -r8k -es -b16 -c1 -V1 - -tmp3 - | sox -tmp3 - some_file.mp3
Then I'm trying to play that file in a second terminal, as the mp3 is being written using:
play -t mp3 some_file.mp3
The problem is that it only plays up until the time the mp3 had at the time the play command was invoked.
How do I get it to play the appended mp3 over time, while it's being written?
EDIT:
Running on Raspberry Pi 3 (Raspian Jessie), NooElec R820T SDR
There are a couple of things here. I don't think sox supports "tailing" a file, but I know mplayer does. However, in order to have better control over the pipeline, using gstreamer might be the way to go, as it has a parallel event stream built into its effects pipeline.
If you want to stick with sox, I would first get rid of the redundant second invocation of sox, e.g.:
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 |
sox -ts16 -r8k -c1 -V1 - some_file.mp3
And in order to play the stream while transcoding it, you could multiplex it with tee, e.g.:
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 |
tee >(sox -ts16 -r8k -c1 -V1 - some_file.mp3) |
play -ts16 -r8k -c1 -
Or if you want them to be separate processes:
# Save stream to a file
rtl_fm -M wbfm -f 88.1M -d 0 -s 22050k -l 310 > some_file.s16
# Encode stream
sox -ts16 -r8k -c1 -V1 some_file.s16 some_file.mp3
# Start playing the file at 10 seconds in
tail -c+$((8000 * 10)) -f some_file.s16 |
play -ts16 -r8k -c1 -
I execute the command in Ubuntu to cut a video:
/usr/bin/ffmpeg -i video.mp4 -an -ss 00:00:1 -t 00:00:08 -async 1
In Windows 10 its work, but not work in Ubuntu.
I receive in Ubuntu the warning:
Trailing options were found on the commandline.
and receive the error:
At least one output file must be specified
What do I do?
do:
ffmpeg -i video.mp4 -ss 00:00:01 -t 00:00:08 -async 1 cut.mp4
just add output file name, in this situation - cut.mp4
I'm using this command to record audio in Linux Fedora 23
/usr/bin/arecord -d 11400 -D hw:1,0 -f S32_LE -c2 -r48000 -t wav | lame -b 192 - longrec.mp3 >> output.txt 2>&1 & echo $!
Basically I want an mp3 record of 3 hours and 10 minutes (11400 seconds) from the input soundcard. Everything works fine when started, but it always stops after 1h33m12s. File output.txt shows nothing of any interest:
LAME 3.99.5 64bits (http://lame.sf.net)
Using polyphase lowpass filter, transition band: 18774 Hz - 19355 Hz
Encoding <stdin> to longrec.mp3
Encoding as 48 kHz j-stereo MPEG-1 Layer III (8x) 192 kbps qval=3
Any clue of what the problem is?
[SOLVED] instead of using arecord I have switched to ffmpeg, command:
ffmpeg -f pulse -i alsa_input.usb-Focusrite_Scarlett_Solo_USB-00.analog-stereo -t 11400 -c:a libmp3lame -b:a 192k longrec.mp3
Has the same effect as arecord one and it also doesn't block sound-card resource (I can run multiple ffmpeg record instance from the same source, while with arecord I can do only one).