concatenating audio for merge with video
Hi all, I'm the one who asked how to put my own audio stream on a video. The commands ffmpeg -i in.avi -an -vcodec copy -y nosound.avi ffmpeg -i nosound.avi -vcodec copy -i audio.wav -y out.avi -newaudio worked like a charm except for the case where the video is longer than the audio. I'd like to start with audio1.wav and go to audio2.wav and maybe even audio3.wav if the video runs longer. Is there a way to tell FFMPEG to use multiple audio files in order like that? Or is there an easy way to merge the audio files in sequence? Thanks for any help you can give. Adam N. Rosenberg mailto:adam at the-adam.com http://www.the-adam.com
Are you a linux user? In linux there is sox. It is i most linux distroes (small tool easy to install or build if you don't have it) sox --combin concatenate file0.wav file1.wav file2.wav file3.wav file4.wav result.ogg; Here I am concatenating wav files to an ogg but you could as well concatenate ogg to a mp3 or what ever. /Mikkel
Hi Mikkel, Good news, I have /usr/bin/sox version 12.18.1 that doesn't seem happy with this. Maybe I have an ancient version. [1]$ sox --combin concatenate audio_01.wav audio_02.wav foo.mp3 sox: invalid option -- - sox: -c must be given a number [2]$ sox --help sox: invalid option -- - sox: Version 12.18.1 Usage: [ gopts ] [ fopts ] ifile [ fopts ] ofile [ effect [ effopts ] ] gopts: -e -h -p -q -S -V fopts: -r rate -c channels -s/-u/-U/-A/-a/-i/-g/-f -b/-w/-l/-d -v volume -x effect: avg band bandpass bandreject chorus compand copy dcshift deemph earwax echo echos fade filter flanger highp highpass lowp lowpass mask mcompand noiseprof noisered pan phaser pick pitch polyphase rate repeat resample reverb reverse silence speed stat stretch swap synth trim vibro vol effopts: depends on effect Supported file formats: aiff al alsa au auto avr cdr cvs dat vms gsm hcom la lu maud nul ossdsp prc raw sb sf sl smp sndt sph 8svx sw txw ub ul uw voc vorbis vox wav wve ================================================================ On Tue, 29 Sep 2009, mikkel meinike wrote:
Are you a linux user? In linux there is sox. It is i most linux distroes (small tool easy to install or build if you don't have it)
sox --combin concatenate file0.wav file1.wav file2.wav file3.wav file4.wav result.ogg;
Here I am concatenating wav files to an ogg but you could as well concatenate ogg to a mp3 or what ever.
/Mikkel _______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
-- Adam N. Rosenberg mailto:adam at the-adam.com http://www.the-adam.com
On 09/29/2009 12:55 PM, Adam N. Rosenberg wrote:
Hi Mikkel,
Good news, I have /usr/bin/sox version 12.18.1 that doesn't seem happy with this. Maybe I have an ancient version.
[1]$ sox --combin concatenate audio_01.wav audio_02.wav foo.mp3 sox: invalid option -- - sox: -c must be given a number
[2]$ sox --help sox: invalid option -- - sox: Version 12.18.1
Usage: [ gopts ] [ fopts ] ifile [ fopts ] ofile [ effect [ effopts ] ]
gopts: -e -h -p -q -S -V
fopts: -r rate -c channels -s/-u/-U/-A/-a/-i/-g/-f -b/-w/-l/-d -v volume -x
effect: avg band bandpass bandreject chorus compand copy dcshift deemph earwax echo echos fade filter flanger highp highpass lowp lowpass mask mcompand noiseprof noisered pan phaser pick pitch polyphase rate repeat resample reverb reverse silence speed stat stretch swap synth trim vibro vol
effopts: depends on effect
Supported file formats: aiff al alsa au auto avr cdr cvs dat vms gsm hcom la lu maud nul ossdsp prc raw sb sf sl smp sndt sph 8svx sw txw ub ul uw voc vorbis vox wav wve
================================================================
On Tue, 29 Sep 2009, mikkel meinike wrote:
Are you a linux user? In linux there is sox. It is i most linux distroes (small tool easy to install or build if you don't have it)
sox --combin concatenate file0.wav file1.wav file2.wav file3.wav file4.wav result.ogg;
Here I am concatenating wav files to an ogg but you could as well concatenate ogg to a mp3 or what ever.
/Mikkel _______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
On FC11: $ sox --version sox: SoX v14.2.0 $ sox --help sox: SoX v14.2.0 Usage summary: [gopts] [[fopts] infile]... [fopts] outfile [effect [effopts]]... SPECIAL FILENAMES (infile, outfile): - Pipe/redirect input/output (stdin/stdout); use with -t -d, --default-device Use the default audio device (where available) -n, --null Use the `null' file handler; e.g. with synth effect -p, --sox-pipe Alias for `-t sox -' SPECIAL FILENAMES (infile only): "|program [options] ..." Pipe input from external program (where supported) http://server/file Use the given URL as input file (where supported) GLOBAL OPTIONS (gopts) (can be specified at any point before the first effect): --buffer BYTES Set the size of all processing buffers (default 8192) --combine concatenate Concatenate multiple input files (default for sox, rec) --combine sequence Sequence multiple input files (default for play) --effects-file FILENAME File containing effects and options -h, --help Display version number and usage information --help-effect NAME Show usage of effect NAME, or NAME=all for all --help-format NAME Show info on format NAME, or NAME=all for all --input-buffer BYTES Override the input buffer size (default: as --buffer) --interactive Prompt to overwrite output file -m, --combine mix Mix multiple input files (instead of concatenating) -M, --combine merge Merge multiple input files (instead of concatenating) --plot gnuplot|octave Generate script to plot response of filter effect -q, --no-show-progress Run in quiet mode; opposite of -S --replay-gain track|album|off Default: off (sox, rec), track (play) -R Use default random numbers (same on each run of SoX) -S, --show-progress Display progress while processing audio data --version Display version number of SoX and exit -V[LEVEL] Increment or set verbosity level (default 2); levels: 1: failure messages 2: warnings 3: details of processing 4-6: increasing levels of debug messages FORMAT OPTIONS (fopts): Input file format options need only be supplied for files that are headerless. Output files will have the same format as the input file where possible and not overriden by any of various means including providing output format options. -v|--volume FACTOR Input file volume adjustment factor (real number) -t|--type FILETYPE File type of audio -s/-u/-f/-U/-A/-i/-a/-g Encoding type=signed-integer/unsigned-integer/floating- point/mu-law/a-law/ima-adpcm/ms-adpcm/gsm-full-rate -e|--encoding ENCODING Set encoding (ENCODING in above list) -b|--bits BITS Encoded sample size in bits -1/-2/-3/-4/-8 Encoded sample size in bytes -N|--reverse-nibbles Encoded nibble-order -X|--reverse-bits Encoded bit-order --endian little|big|swap Encoded byte-order; swap means opposite to default -L/-B/-x Short options for the above -c|--channels CHANNELS Number of channels of audio data; e.g. 2 = stereo -r|--rate RATE Sample rate of audio -C|--compression FACTOR Compression factor for output format --add-comment TEXT Append output file comment --comment TEXT Specify comment text for the output file --comment-file FILENAME File containing comment text for the output file AUDIO FILE FORMATS: 8svx aif aifc aiff aiffc al amb au avr caf cdda cdr cvs cvsd dat dvms f4 f8 fap flac fssd gsm hcom htk ima ircam la lpc lpc10 lu mat mat4 mat5 maud nist ogg paf prc pvf raw s1 s2 s3 s4 sb sd2 sds sf sl smp snd sndfile sndr sndt sou sox sph sw txw u1 u2 u3 u4 ub ul uw vms voc vorbis vox w64 wav wavpcm wv wve xa xi PLAYLIST FORMATS: m3u pls AUDIO DEVICE DRIVERS: alsa ao oss ossdsp EFFECTS: allpass band bandpass bandreject bass bend chorus compand contrast dcshift deemph delay dither earwax echo echos equalizer fade filter flanger gain highpass ladspa loudness lowpass mcompand mixer noiseprof noisered norm oops pad phaser pitch rate remix repeat reverb reverse riaa silence spectrogram speed splice stat stretch swap synth tempo treble tremolo trim vol EFFECT OPTIONS (effopts): effect dependent; see --help-effect
Hi Mikkel, I found this script #!/bin/sh sox $1 -r 44100 -c 2 -s -w /tmp/$$-1.raw sox $2 -r 44100 -c 2 -s -w /tmp/$$-2.raw cat /tmp/$$-1.raw /tmp/$$-2.raw > /tmp/$$.raw sox -r 44100 -c 2 -s -w /tmp/$$.raw $3 rm /tmp/$$*.raw on this http://www.boutell.com/scripts/catwav.html web page. That seems to work. It creates a new WAV file that not only gets past MPLAYER (which "cat 001.wav 002.wav > 003.wav" does), but also is clean enough that ffmpeg -i in.avi -an -vcodec copy -y nosound.avi ffmpeg -i nosound.avi -vcodec copy -i 003.wav -y out.avi -newaudio continues to play music, which the "cat" solution did not do. Thanks for pointing me at SOX even if my version is so old it doesn't work the way the newer ones do. (And my YUM mirror is down.) On Tue, 29 Sep 2009, Adam N. Rosenberg wrote:
Hi Mikkel,
Good news, I have /usr/bin/sox version 12.18.1 that doesn't seem happy with this. Maybe I have an ancient version.
[1]$ sox --combin concatenate audio_01.wav audio_02.wav foo.mp3 sox: invalid option -- - sox: -c must be given a number
[2]$ sox --help sox: invalid option -- - sox: Version 12.18.1
Usage: [ gopts ] [ fopts ] ifile [ fopts ] ofile [ effect [ effopts ] ]
gopts: -e -h -p -q -S -V
fopts: -r rate -c channels -s/-u/-U/-A/-a/-i/-g/-f -b/-w/-l/-d -v volume -x
effect: avg band bandpass bandreject chorus compand copy dcshift deemph earwax echo echos fade filter flanger highp highpass lowp lowpass mask mcompand noiseprof noisered pan phaser pick pitch polyphase rate repeat resample reverb reverse silence speed stat stretch swap synth trim vibro vol
effopts: depends on effect
Supported file formats: aiff al alsa au auto avr cdr cvs dat vms gsm hcom la lu maud nul ossdsp prc raw sb sf sl smp sndt sph 8svx sw txw ub ul uw voc vorbis vox wav wve
================================================================
On Tue, 29 Sep 2009, mikkel meinike wrote:
Are you a linux user? In linux there is sox. It is i most linux distroes (small tool easy to install or build if you don't have it)
sox --combin concatenate file0.wav file1.wav file2.wav file3.wav file4.wav result.ogg;
Here I am concatenating wav files to an ogg but you could as well concatenate ogg to a mp3 or what ever.
/Mikkel _______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
Hi everybody, I don't know if anybody else wants this, but I wrote the following shell script for inserting one or more WAV files into an AVI video file using FFMPEG and SOX on my Linux machine. Your mileage may vary. ================================================================ # User asking for help? if test "$1" = "/help" -o "$1" = "--help" then echo echo "Adds sound to a video that has lousy or no sound." echo "Usage: $0 <input.avi> <output.avi> <input.wav>" echo " Multiple WAV sound files are allowed and they" echo " will be added to the video file in sequence." echo exit 1 fi # Must have three arguments. if test $# -lt 3 then echo echo "You must have three arguments." echo $0 /help exit 9 fi # Input video file has to exist. export IN_AVI=${1/.avi/}.avi if test -f $IN_AVI then echo "Input AVI file $IN_AVI found." else echo "Cannot find input file $IN_AVI." fi # Done with first argument. */ shift # Output video file has not to exist. export OUT_AVI=${1/.avi/}.avi if test -f $OUT_AVI then echo "Output AVI file $OUT_AVI already exist." while true do echo -n "Do you want to delete $OUT_AVI? " read ANSWER if test "$ANSWER" = "yes" then rm $OUT_AVI if test -f $OUT_AVI then echo "I can't seem to get rid of $OUT_AVI." echo "Command script $0 halted." exit 1 fi echo "Old output file $OUT_AVI removed." break elif test "$ANSWER" = "no" then echo "Command script $0 halted." exit 1 else echo 'Answer "yes" or "no" please.' fi done fi # Done with second argument. shift # Get rid of temp files. if test -f temp-000.raw then echo "Removing temp-000.raw file." rm temp-000.raw fi if test -f temp-001.raw then echo "Removing temp-001.raw file." rm temp-001.raw fi # Build sound file. export SOUND=sound.wav for f in $* do if test -f $f then sox $f -r 44100 -c 2 -s -w temp-001.raw cat temp-001.raw >> temp-000.raw else echo "Cannot find sound file $f." exit 1 fi done sox -r 44100 -c 2 -s -w temp-000.raw $SOUND ffmpeg -i $IN_AVI -an -vcodec copy -y nosound.avi ffmpeg -i nosound.avi -vcodec copy -i $SOUND -y $OUT_AVI -newaudio # Get rid of temp files. if test -f temp-000.raw then echo "Removing temp-000.raw file." rm temp-000.raw fi if test -f temp-001.raw then echo "Removing temp-001.raw file." rm temp-001.raw fi if test -f nosound.avi then if test "$DEBUG" = "ON" then echo "Keeping nosound.avi file." else echo "Removing nosound.avi file." rm nosound.avi fi fi ================================================================ On Tue, 29 Sep 2009, Adam N. Rosenberg wrote:
Hi Mikkel,
I found this script
#!/bin/sh sox $1 -r 44100 -c 2 -s -w /tmp/$$-1.raw sox $2 -r 44100 -c 2 -s -w /tmp/$$-2.raw cat /tmp/$$-1.raw /tmp/$$-2.raw > /tmp/$$.raw sox -r 44100 -c 2 -s -w /tmp/$$.raw $3 rm /tmp/$$*.raw
on this http://www.boutell.com/scripts/catwav.html web page. That seems to work. It creates a new WAV file that not only gets past MPLAYER (which "cat 001.wav 002.wav > 003.wav" does), but also is clean enough that
ffmpeg -i in.avi -an -vcodec copy -y nosound.avi ffmpeg -i nosound.avi -vcodec copy -i 003.wav -y out.avi -newaudio
continues to play music, which the "cat" solution did not do.
Thanks for pointing me at SOX even if my version is so old it doesn't work the way the newer ones do. (And my YUM mirror is down.)
On Tue, 29 Sep 2009, Adam N. Rosenberg wrote:
Hi Mikkel,
Good news, I have /usr/bin/sox version 12.18.1 that doesn't seem happy with this. Maybe I have an ancient version.
[1]$ sox --combin concatenate audio_01.wav audio_02.wav foo.mp3 sox: invalid option -- - sox: -c must be given a number
[2]$ sox --help sox: invalid option -- - sox: Version 12.18.1
Usage: [ gopts ] [ fopts ] ifile [ fopts ] ofile [ effect [ effopts ] ]
gopts: -e -h -p -q -S -V
fopts: -r rate -c channels -s/-u/-U/-A/-a/-i/-g/-f -b/-w/-l/-d -v volume -x
effect: avg band bandpass bandreject chorus compand copy dcshift deemph earwax echo echos fade filter flanger highp highpass lowp lowpass mask mcompand noiseprof noisered pan phaser pick pitch polyphase rate repeat resample reverb reverse silence speed stat stretch swap synth trim vibro vol
effopts: depends on effect
Supported file formats: aiff al alsa au auto avr cdr cvs dat vms gsm hcom la lu maud nul ossdsp prc raw sb sf sl smp sndt sph 8svx sw txw ub ul uw voc vorbis vox wav wve
================================================================
On Tue, 29 Sep 2009, mikkel meinike wrote:
Are you a linux user? In linux there is sox. It is i most linux distroes (small tool easy to install or build if you don't have it)
sox --combin concatenate file0.wav file1.wav file2.wav file3.wav file4.wav result.ogg;
Here I am concatenating wav files to an ogg but you could as well concatenate ogg to a mp3 or what ever.
/Mikkel _______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
_______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
-- Adam N. Rosenberg mailto:adam at the-adam.com http://www.the-adam.com
You are a wild boy :-) making a script right away (I am like that to scripting is so nice). Thanks for it. Yes now I remember the raw method. I tried that to start with and then that didn't work for me I don't remember why but then I did a sox --help and found the concatenate method and then there was noting more to worry about. So it is sox a version thing I think. Mine is SoX v14.2.0 like JD above /Mikkel
Hi Mikkel, There are a few good reasons for creating and posting scripts. I'm glad you agree that it's a good thing to do. First, having advice like "just add --fwizzle=7,0,X" doesn't tell me context or meaning. I don't know how this person was using it, or even which utility he was running sometimes. Second, you have a working example of *something*. You can try it and see if it works on your stuff to do the same thing. Then you can figure out what changes you need for your own application. Third, if you're a really nice person, then you can tell me, as script guy, what changes you made and why. You can even tell me mistakes I made that will lose files I care about under some conditions *before* I make the mistake and cuss at my computer. Or maybe you'll tell me a better way to do something. Fourth, we learn shell techniques ("tricks") from each other. I learned about testing for a file's existance ("if -f $filename") and editing shell variables ("${filename/.avi/}.avi") from other people's examples. Unlike other lists I've tried, I see concrete examples and command lines used in advice to other people, including to me. I'm grateful I found this list even if I don't use FFMPEG much except for the application I already have. Then, again, I just might use it more now that I have a good group. On Wed, 30 Sep 2009, mikkel meinike wrote:
You are a wild boy :-) making a script right away (I am like that to scripting is so nice). Thanks for it. Yes now I remember the raw method. I tried that to start with and then that didn't work for me don't remember why but then I did a sox --help and found the concatenate method and then there was noting more to worry about. So it is sox a version thing I think. Mine is SoX v14.2.0 like JD above
/Mikkel _______________________________________________ ffmpeg-user mailing list ffmpeg-user at mplayerhq.hu https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-user
-- Adam N. Rosenberg mailto:adam at the-adam.com http://www.the-adam.com
--- On Wed, 9/30/09, Adam N. Rosenberg <adam at the-adam.com> wrote:
From: Adam N. Rosenberg <adam at the-adam.com> Subject: Re: [FFmpeg-user] concatenating audio for merge with video To: "FFmpeg user questions and RTFMs" <ffmpeg-user at mplayerhq.hu> Date: Wednesday, September 30, 2009, 7:11 AM
Hi Mikkel,
There are a few good reasons for creating and posting scripts. I'm glad you agree that it's a good thing to do.
I agree. The examples that prevail in this list are very helpful. Sox AFAIK, defaults to concatenation. So regardless of version the following should work. $ sox input1.wav input2.wav input3.wav output.wav If the file types / headers don't match, you might need to help it out by preconverting like that script does, or just specifying the details on each to sox. -c 2 -r 48000 yada yada yada... And some conversion apps are picky about the input, so you might need to be more specific about the output format. -s -w -c 2 -r 48000 output.wav. $ sox -c 2 -r 44100 inputCD.wav -c 2 -r 48000 inputDVD.wav -s -w -c 2 -r 48000 output.wav There are some pretty big differences between sox versions. -M for multiple channels, useful for making / editing surround tracks (6 channels). And effect avg being renamed to mixer. And probably some future upgrades that could break / change how you use it. I tend not to do conversions of formats in sox(wav to mp3). It just seems to me that lame directly would be better, or mp2enc, or whatever destination specific thing you need. Not that ffmpeg couldn't/shouldn't do most of this for you. But sometimes ffmpeg gets it wrong. Although it gets better most days. - James
participants (4)
-
adam@the-adam.com -
jd1008@gmail.com -
mimeini@gmail.com -
wwwshadow7@yahoo.com