Use sox to combine audios - ffmpeg

I have three 3gp file,and I use sox to combine them
sox --combine sequence C:\1.3gp C:\2.3gp C:\3.3gp C:\newaudio.3gp
but It's show that "FAIL formats:no handler for file extension 3gp"
Its means that I have to install some extension?
I'm trying to do it with sox,Can anybody give me any suggestions ?
Or It's possible do it with ffmpeg ?

3gp is a multimedia container and not supported by sox.
You can extract the audio with ffmpeg and further process it with sox although ffmpeg can also do a lot of audio processing.
Here's one way to convert the data to wav, concatenate and convert back to 3gp:
ffmpeg -i 1.3gp 1.wav
ffmpeg -i 2.3gp 2.wav
ffmpeg -i 3.3gp 3.wav
Concatenate, maybe other things with sox (sequence is default so no need to specify):
sox 1.wav 2.wav 3.wav long.wav
Convert back to 3gp:
ffmpeg -i long.wav newaudio.3gp

Related

How to use filtered audio in complex filter in FFMPEG?

I'm using the highpass audio filter then trying to use showfreqs on the resulting audio stream but it's not working. The showfreqs filter uses the original audio stream instead of the filtered one.
Command:
ffmpeg -i audio.mp3 -filter_complex highpass,showfreqs,format=yuv420p highpass.mp4
I tried naming the highpass output but it didn't make any difference:
ffmpeg -i audio.mp3 -filter_complex highpass[hi],[hi]showfreqs,format=yuv420p highpass.mp4
How do I structure my command so showfreqs uses the output from highpass?
UPDATE
I'm using FFMPEG 4.1.4 installed on Mac via Homebrew.
Source audio: https://dsc.cloud/weavermedia/audio.mp3
Commands and resulting files:
Run highpass on audio.mp3:
ffmpeg -i audio.mp3 -filter_complex highpass highpass.mp3
result: https://dsc.cloud/weavermedia/highpass.mp3 CORRECT
Run showfreqs on audio.mp3:
ffmpeg -i audio.mp3 -filter_complex showfreqs,format=yuv420p showfreqs.mp4
result: https://dsc.cloud/weavermedia/showfreqs.mp4 CORRECT
Run showfreqs on highpass.mp3:
ffmpeg -i highpass.mp3 -filter_complex showfreqs,format=yuv420p showfreqs.mp4
result: https://dsc.cloud/weavermedia/highpass-showfreqs.mp4 CORRECT
Run highpass and showfreqs in series on audio.mp3:
ffmpeg -i audio.mp3 -filter_complex highpass,showfreqs,format=yuv420p highpass.mp4
result: https://dsc.cloud/weavermedia/highpass.mp4 INCORRECT
I tried several different source audio files and always get the same results.
I tried on 2 different Macs, albeit both with FFMPEG 4.1.4 installed via Homebrew.
I tried with different highpass settings and get same results (the default highpass settings are enough to hear the difference anyway).
UPDATE 2
Looking at the resulting videos side by side in QuickTime I see that showfreqs does actually appear to be using the audio stream from highpass but the final video contains the original unfiltered audio.
So my problem is actually how to get the resulting video to use the filtered audio stream instead of the original.
showfreqs converts its audio input to a video output, so ffmpeg will fallback on the original audio for audio output. In order to avoid this, split the highpass result and pass one copy to showfreqs while leaving the other for audio output.
ffmpeg -i audio.mp3 -filter_complex highpass,asplit=2[sf][aud];[sf]showfreqs,format=yuv420p;[aud]anull highpass.mp4

Concat multiple video and audio files with ffmpeg

I have an array of audio and video clips, where each audio clip has a 1:1 correlation with it's video clip. The encoding of each video and each audio clip are the same. How can I concat all of the audio clips, and all the video clips, then merge them together to output a video. As of now I only figured out how to merge 1 audio clip with 1 video clip:
$ ffmpeg -i video_1.webm -i audio_1.wav -acodec copy -vcodec copy output.mkv
Update
I just came across mkvmerge would this possibly be a better option?
If all the files are encoded with the same codecs then it's easy to do. First merge the audio and video files as you have already done so each pair of files is contained in one mkv. Then you can concatenate them with the concat demuxer like this:
ffmpeg -f concat -i <(printf "file '%s'\n" ./file1.mkv ./file2.mkv ./file3.mkv) -c copy merged.mkv
or:
ffmpeg -f concat -i <(printf "file '%s'\n" ./*.mkv) -c copy merged.mkv
You could also list one file per line in a text file called mergelist.txt (or whatever you want to call it), i.e.:
file './file1.mkv'
file './file2.mkv'
file './file3.mkv'
Then use that as the input, a la:
ffmpeg -f concat -i mergelist.txt -c copy merged.mkv
This is by far the easiest and fastest way to do what you want since it won't re-encode the files, just line them up one after another.
You can find your answer here in this old question:
Concatenate two mp4 files using ffmpeg
This answer is not restricted to MP4. But it will depend on the file format you wanna concatenate!
Once you have your new VIDEO file and AUDIO file, to merge them together:
ffmpeg -i AUDIO -i VIDEO -acodec copy -vcodec copy OUTPUT

How to pass options to ffmpeg from SoX?

I'm trying to combine and encode some files from wav to m4a. I installed both ffmpeg and sox from source to make sure nothing was disabled. When I do the conversion with ffmpeg
ffmpeg -i input.wav -acodec aac -strict experimental output.m4a
it works fine. When I use SoX
sox input.wav output.m4a
I get the error
[NULL # 0x251b4e0] Codec is experimental but experimental codecs are not enabled, see -strict -2
sox FAIL ffmpeg: ffmpeg could not open CODEC
sox FAIL formats: can't open output file `output.m4a':
I need to way to get SoX to tell ffmpeg that its ok to use the experimental codecs.
Also I already tried using this guide http://ffmpeg.org/trac/ffmpeg/wiki/UbuntuCompilationGuide to install the fdk-acc encoder, but it didn't work. The experimental one works fine so I'd rather just use that.
I don't think sox supports m4a formats. you can do sox --help to see the audio file formats supported.

Add multiple audio files to video at specific points using FFMPEG

I am trying to create a video out of a sequence of images and various audio files using FFmpeg. While it is no problem to create a video containing the sequence of images with the following command:
ffmpeg -f image2 -i image%d.jpg video.mpg
I haven't found a way yet to add audio files at specific points to the generated video.
Is it possible to do something like:
ffmpeg -f image2 -i image%d.jpg -i audio1.mp3 AT 10s -i audio2.mp3 AT 15s video.mpg
Any help is much appreciated!
EDIT:
The solution in my case was to use sox as suggested by blahdiblah in the answer below. You first have to create an empty audio file as a starting point like that:
sox -n -r 44100 -c 2 silence.wav trim 0.0 20.0
This generates a 20 sec empty WAV file. After that you can mix the empty file with other audio files.
sox -m silence.wav "|sox sound1.mp3 -p pad 0" "|sox sound2.mp3 -p pad 2" out.wav
The final audio file has a duration of 20 seconds and plays sound1.mp3 right at the beginning and sound2.mp3 after 2 seconds.
To combine the sequence of images with the audio file we can use FFmpeg.
ffmpeg -i video_%05d.png -i out.wav -r 25 out.mp4
See this question on adding a single audio input with some offset. The -itsoffset bug mentioned there is still open, but see users' comments for some cases in which it does work.
If it works in your case, that would be ideal:
ffmpeg -i in%d.jpg -itsoffset 10 -i audio1.mp3 -itsoffset 15 -i audio2.mp3 out.mpg
If not, you should be able to combine all the audio files with sox, overlaying or inserting silence to produce the correct offsets and then use that as input to FFmpeg. Not as convenient, but guaranteed to work.
One approach I can think of is to create your audio file for the whole duration of the video first and then mux the audio with the video file

Convert streaming MPEG-4 raw data to H.264

I've got a Sony network camera (SNC-RZ25N) that I am trying desperately to get data from in some meaningful format. The documentation says it sends MPEG-4 raw data, but is not more specific than than. I can capture a segment of the stream using curl ( http://techhead.biz/media/tsv.m4v ) and it will play using VLC and ffplay (though it plays too fast in ffplay).
After a day and a half of tinkering, I just discovered that I cannot use ffmpeg to convert this stream directly. For one, the only way ffmpeg accepts piped data as input (that I'm aware of) is in the 'yuv4mpegpipe' format.
I tried piping to ffmpeg using 'm4v' as the specified format, but it seems to want to read the entire stream before it begins processing.
Anyone know how I can do this? Using commandline tools? Open source libraries in ANY programming language? Simpler solutions are preferred, but any working solution would be great.
It appears mplayer can play your m4v file over HTTP, and at least with your sample file this works:
mkfifo /tmp/fifo
mplayer -benchmark -vo yuv4mpeg:file=/tmp/fifo http://techhead.biz/media/tsv.m4v
ffmpeg -f yuv4mpegpipe -i /tmp/fifo -vcodec libx264 -vpre libx264-hq /tmp/foo.mp4
(-benchmark tells mplayer to ignore frame duration, might or might not be needed)
Alternatively, with just mencoder:
mencoder -o /tmp/foo.avi -of avi -ovc x264 -x264encopts bitrate=250 http://techhead.biz/media/tsv.m4v
Finally, if you don't actually need H.264, you could just put the existing MPEG-ES data in whatever container format you need; MP4Box might be able to do this, and ffmpeg and mencoder can if they support the output format.

Resources