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"'
Related
I am trying to setup my linux desktop to be able to view and listent to the device connected to my capture card. I wrote this 2 liner script to be able to do that however my sound is out of tone and a bit distorted, how could I clean it up?
arecord --buffer-time=1 -f cd - | aplay --buffer-time=1 -c 5 -r 48000 -f S16_LE - 2> /dev/null &
ffplay -f video4linux2 -framerate 30 -video_size 1920x1080 -input_format mjpeg /dev/video1 2> /dev/null &
I also tried to do that with ffmpeg piped to ffplay and the sound is crystal clear however there is 2-3 seconds delay on the video and sound, is there a way to fix this?
ffmpeg -framerate 30 -video_size 1920x1080 -thread_queue_size 1024 -input_format mjpeg -i /dev/video1 -f pulse -i 'Analog Input - USB Video' -r 30 -threads 4 -vcodec libx264 -crf 0 -preset ultrafast -vsync 1 -async 1 -f matroska - |ffplay -
Could you try just using ffplay for your second approach?
ffplay -framerate 30 -video_size 1920x1080 \
-thread_queue_size 1024 -input_format mjpeg -i /dev/video1 \
-f pulse -i 'Analog Input - USB Video'`
I could be off-base as I'm only familiar with ffmpeg and don't personally use ffplay, but they share a lot of things (e.g., backend libraries and command line parsing) so I'm hedging this would work.
Also, what do you mean by "there is 2-3 seconds delay on the video and sound"? Are they 2-3 seconds behind what you are physically seeing and hearing? Or are they out of sync by that many seconds?
[addendum]
Not sure if OP is still checking this post, but there is a solution to combine two inputs for ffplay by using an input filtergraph with movie and amovie filters. The following worked in Windows (despite unacceptably large latency):
ffplay -f lavfi -i \
movie=filename=video="Logitech HD Webcam C310":format_name=dshow:format_opts=rtbufsize=702000k[out0]; \
amovie=filename=audio="Microphone (HD Webcam C310)":format_name=dshow[out1]
Note that this is only for the illustration purpose as dshow device can output multiple streams (though the latency is still too bad for real-time use).
The same should be possible in Linux:
ffplay -f lavfi -i \
movie=filename=/dev/video1:format_name=video4linux2:format_opts='framerate=30:video_size=1920x1080:thread_queue_size=1024:input_format=mjpeg'[out0]; \
amovie=filename='Analog Input - USB Video':format_name=pulse[out1]
(Disclaimer: Untested and it may be missing escaping)
The latency may be better in Linux (and with a higher spec'ed PC than mine) so it might be worth a try.
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 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.
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'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).