Mix Audio tracks with offset in SOX - audio

From ASP.Net, I am using FFMPEG to convert flv files on a Flash Media Server to wavs that I need to mix into a single MP3 file. I originally attempted this entirely with FFMPEG but eventually gave up on the mixing step because I don't believe it it possible to combine audio only tracks into a single result file. I would love to be wrong.
I am now using FFMPEG to access the FLV files and extract the audio track to wav so that SOX can mix them. The problem is that I must offset one of the audio tracks by a few seconds so that they are synchronized. Each file is one half of a conversation between a student and a teacher. For example teacher.wav might need to begin 3.3 seconds after student.wav. I can only figure out how to mix the files with SOX where both tracks begin at the same time.
My best attempt at this point is:
ffmpeg -y -i rtmp://server/appName/instance/student.flv -ac 1 student.wav
ffmpeg -y -i rtmp://server/appName/instance/teacher.flv -ac 1 teacher.wav
sox -m student.wav teacher.wav combined.mp3 splice 3.3
These tools (FFMEG/SoX) were chosen based on my best research, but are not required. Any working solution would allow an ASP.Net service to input the two FMS flvs and create a combined MP3 using open-source or free tools.
EDIT:
I was able to offset the files using the delay switch in SOX.
sox -M student.wav teacher.wav combined.mp3 delay 2.8
I'm leaving the question open in case someone has a better approach than the combined FFMPEG/SOX solution.

For what it's worth, this should be possible with a combination of -itsoffset and the amix filter, but a bug with -itsoffset prevents it. If it worked, the command would look something like this:
ffmpeg -i student.flv -itsoffset 3.3 -i teacher.flv -vn -filter_complex amix out.mp3

mixing can be pretty simple: how to mix two audio channels?

well i suggest you should use flash.
it may sounds weird, correct me if im wrong but with Flash's new multimedia abilities you can mix a couple tracks.
im not sure, but i'm just trying to help you,
theese 2 link can help you for your aim (specially second link i guess);
http://3d2f.com/programs/25-187-swf-to-mp3-converter-download.shtml
http://blog.debit.nl/2009/02/mp3-to-swf-converter-in-actionscript-3/

Related

ffmpeg : is there a simple way to edit the video resolution, but keep all audio and subtitles

I would like to lower video resolution - usually from .mkv files - but to keep all possible audio tracks (might be only one, might be several) and subtitles (might be none, might be several) from the original one. I also would like to keep as many encoding parameters as I can from the original video file (especially those I do not understand).
I am still new to ffmpeg : at first the idea seemed simple, but after many attempts, it seems it is more complex than that. Do I have to use the -filter_complex option ? It seems to be an overkill (or overcomplex) for what I thought to be an easy conversion, but I might be wrong.
I tried to combine -vf scale=-1:720 with -c copy -map 0, which gave me an error that I now understand, but I am stuck with the next step.
Any lead on to achieve that ? Could it be done with ffmpeg only or would I need a script ?
Your try should've worked. For example,
ffmpeg -i input.mp4 -vf scale=-1:720 -map 0 -c:a copy -c:s copy output.mp4
grabs all the streams from the input, passes all video streams through the scale filter, and copies all audio and subtitle streams.
What was the error?
keep as many encoding parameters
This it cannot do. When you reencode, it's on you to pick the parameters to best match those possibly used for the input.

adding silent audio to channels 3-8 in ffmpeg

This has been discussed before, but my question is a bit different.
Lets say have a video file with 1+2 as stereo.
Now I want to add 3-8 with silent audio - most likely using the anullsrc.
I need to map that generator to only affect channel 3-8.
Anyone has a solution for that?
No need for a source filter. Just need pan.
ffmpeg -i input -af "pan=8C|c0=c0|c1=c1" -c:v copy out
The first two output channels have their maps set to the two input channels. Since the other 6 are omitted, they will be mute.

Normalize audio, then reduce the volume in ffmpeg

I have a question relating to ffmpeg. First here is the scenario, I am working on a project where I need to have some audio with a presenter talking and then potentially some background music. I also have the requirement to normalize the audio. I would like to do this without presenting a bunch of options to the user.
For normalization I use something similar to this post:
How to normalize audio with ffmpeg.
In short, I get a volume adjustment which I then apply to ffmpeg like this:
ffmpeg -i <input> -af "volume=xxxdB" <output>
So far so good. Now let's consider the backing track, it doesn't want to be the same volume as the presenters voice, this would be really distracting, so I want to lower that by some percentage. I can also do this with ffmpeg, I could do it like this (example would set volume to 50%):
ffmpeg -i <input> -af "volume=0.5" <output>
Using these two commands back to back, I can get the desired result.
My question has two parts:
Is there a way to do this in one step?
Is there any benefit to doing it in one step?
Thanks for any help!
After testing some more, I actually think the answer was pretty straight forward, I just needed to do this.
ffmpeg -i <input> -af "volume=xxxdB,volume=0.5" <output>
Took me a while to realize it, I had to try with a view samples before I felt confident.

Ffmpeg, avconv and sameq

Earlier I wrote so:
ffmpeg -i input.mp4 -sameq output.mp3
...and thus receive audio from video file. Ffmpeg just taken out or converted audio to mp3 with an appropriate quality. All thanks to key: -sameq [use same quantizer as source]
Now in Ubuntu instead of ffmpeg we have libav and there (in man for avcomv) I see no -sameq key. Well, here is a question: what I have to do now?..
What I have to do now to get converted audio file with the same quality as in original?
PS. -sameq : Use same quantizer as source (implies VBR).
$ man ffmpeg | col -b > ./man_ffmpeg
this man_ffmpeg is there: http://pastebin.com/qYxz1M1E
FFMPEG(1)
NAME
ffmpeg - ffmpeg video converter
SYNOPSIS
ffmpeg [[infile options][-i infile]]... {[outfile options] outfile}...
...
...
...
-sameq
Use same quantizer as source (implies VBR).
...
...
...
SEE ALSO
avplay(1), avprobe(1), avserver(1) and the Libav HTML documentation
AUTHORS
The Libav developers
2014-02-06
FFMPEG(1)
You are correct, -sameq option has been deprecated and then removed from avconv, there were many reasons for it. Not the least of it being that there are different quantizers and it makes little sense talking about same quantizer parameters when reencoding between different codecs.
Majority of people, when reencoding are looking for quality, not quantizers. So they should use -qscale n where n is between 1 and 31 representing quality from best to worst.
In a way if you have gotten used to -sameq option, you have fallen victim to a tool that should have been there at best for testing purposes. It doesn't produce anything reasonable, and can be kinned to trying to put "same metadata" into the container that doesn't support it, or doing "copy stream" into an archaic file format (leading to things like AVI with vorbis audio, that can't even be played). You can hack something together that does all these things, but it has no place in a video encoding tool.
I suggest that if you are going to be doing much stress testing of different containers and codecs, then you install ffmpeg which has more tools allowing the creation of frankensteins. If you are reencoding for the purposes of actually keeping the files that you produce or distributing them, than you can create another question explaining your situation, and what is your desired outcome.
In short "How can i create reencoding process with exactly the same quantizer?" Can only be answered with "No".

Transcoding audio and video

What is the best way to transcode audio and video to show on the web?
I need to do it programmatically. I'd like to do something like YouTube or Google Video where users can upload whatever format they want, and I encode it to flv, mp3, and/or mp4. I could do it on our server, but I would rather use an EC2 instance or even a web service. We have a Windows 2008 server.
I strongly recommend ffmpeg. On Windows, I have found this site to host good binaries.
kind of depends on how much you want to spend. if this is a brand new (and mostly unfunded) idea, then go the ffmpeg route, but as you scale and look to iprove the quality, consider one of the more professional encoding tools that can be automated (Rhozet, Inlet, Digital Rapids are 3 options).
ffmpeg can do it, its a command-line tool that uses the libavcodec. Can handle conversion of most video formats. Its license is LPGL, if that suits your needs. You can utilize it as a separate process programmatically, or if you're feeling hardcore, you can use the libavcodec library yourself to encode directly.
When you want to transcode to Flv (which is probably the best for the web) then I use this line:
ffmpeg -hq -y -i $directory/$file -r 20 -s 300x200 -deinterlace -ar 22050 $directory/$file.flv 1>/dev/null 2>/dev/null
It works very well, under linux of course :-).
If you are looking for GPL'ed stuff:
For audio mucking about, try sox. Very powerful! It does a lot! It's included in most linux distributions.
There is also the famous LAME for mp3 [audio] encoding.
For video, mencoder is impressive! It's part of the mplayer package. It will handle conversions from most video formats. Far more than I ever dreamed existed. (For documentation, see Chapter 9. Basic usage of MEncoder and Chapter 10. Encoding with MEncoder.)
It's somewhat more limited about what it can create. But it does support mpeg4, mpeg2, dvd-mpeg, flv, and many others. (While I haven't tried flv myself, google shows other folks are using it.)
I have done things like jpeg + sound -> mpeg4 movie:
nice +20 $MENCODER mf://${JPEGFILE} -mf w=720:h=480:fps=1/${SOUNDLENGTH}:type=jpeg -audiofile ${SOUNDFILE} -ovc lavc -oac lavc -lavcopts vcodec=mpeg4 -ofps 30000/1001 -o ${MENU_MPG}
Or transcode arbitrarily formated video to dvd-compatible mpeg:
nice +20 $MENCODER -edl ${EDL} -ovc lavc -oac lavc -lavcopts vcodec=mpeg2video:vrc_buf_size=1835:vrc_maxrate=9800:vbitrate=${VBITRATE}:keyint=18:acodec=ac3:abitrate=192:aspect=4/3:trell:mbd=2:dia=4:cmp=3:precmp=3:ildctcmp=3:subcmp=3:mbcmp=3:cbp:mv0:dc=10 -of mpeg -mpegopts format=dvd -vf scale=720:480,harddup -srate 48000 -af lavcresample=48000 -ofps 30000/1001 -o ./${INFILE}.reformatted ${FILEPATH}
-edl/-edlout [Edit Decision Lists] are used to snip out just the video sections I want.
${VBITRATE} is normally 5000 for DVD-mpeg-video. But if you flub it a bit you can squeeze more video onto a dvd. Assuming you can tolerate the artifacts.
scale=720:480,harddup -- Little issue with the scale being wrong for my dvdplayer, and harddup to resolve a sound-video desync issue on my "el cheapo" player.
(To playback on a widescreen player that wouldn't handle 4x3 video, I've used atrocities like "aspect=16/9", "-vf scale=560:480,expand=720:480,harddup". But in general you don't want to waste bits encoding black-bars.)
This is not the most efficient set of options to mencoder by far! It can be time consuming to run. But I had other goals in mind...
Do be aware that certain parts of ffmpeg are under GPL. I believe the libpostproc module is and if I recall correctly this is used in transcoding. Make sure this license is compatible with what you're doing.
I would take a look at Main Concept's Reference SDK:
http://www.mainconcept.com/site/developer-products-6/pc-based-sdks-20974/reference-sdk-21221/information-21243.html
It is built for transcoding and, since it is a licensed SDK it doesn't have any of the legal issues surrounding ffmpeg/libavcodec.
Rhozet Carbon Coder can handle a wide range of formats plus you can use plugins to alter the video (eg add a watermark)

Resources