2

I'm currently using this FFmpeg command to create an MP4 video from WMV video, to be a component of a mosaic file from multiple MP4's; duration of this video is about 30 seconds:

ffmpeg -i TFootpFA.wmv -vf "crop=1092:788, eq=1.2:.03:gamma_g=.8:gamma_b=.7, scale=1020x706" -b:v 3M TFootpFA.mp4

I want to adjust to take audio from two other video files (which both have either mono or left/right stereo audio), and use their audio as the audio for the final MP4 file as follows; calling these files audioL.mp4 and audioR.mp4):

  • I would like to create that MP4 with stereo audio.
  • The audio from audioL.mp4 will be the left channel.
  • The audio from audioR.mp4 will be the right channel.
  • Each channel should have its audio combined/downmixed into one channel if that audio is stereo.

The duration of all three files is the same (within a few frames), but I want the target duration to be strictly that of the main WMV file I'm already using, TFootpFA.wmv.

What parameters can I use to achieve this?


EDIT: After originally posting this question, I found this other Super User question that seems to be asking the same thing, and that arrives at this command “Trying to encode multiple audio files and map them to specific channels with FFmpeg”:

 ffmpeg -i video.mov -i audio1.wav -i audio2.wav -filter_complex
 "[1:a][2:a]amerge=inputs=2,pan=stereo|c0<c0+c1|c1<c2+c3,apad[aout]"
-map 0:v -map "[aout]" -shortest output.mp3

While this command has its output as an MP3 file rather than a video file, is it possible to use these settings for the FFmpeg command I already have?


EDIT: FWIW, I discovered that the command line I was originally using takes stereo audio in the source WMV file, and produces mono audio in the resulting MP4 file. I tried various filters to make the resulting MP4 file retain the stereo audio of the original WMV file, but nothing I tried worked. How would I accomplish this?


EDIT: I tried the method Gyan has posted in his answer:

ffmpeg -i TFootpFA.wmv -i audioL.mp4 -i audioR.mp4 -filter_complex "[0]crop=1092:788, eq=1.2:.03:gamma_g=.8:gamma_b=.7, scale=1020x706[v];[1]aformat=channel_layouts=mono[l];[2]aformat=channel_layouts=mono[r];[l][r]amerge=2,apad[a]" -map "[v]" -map "[a]" -b:v 3M -shortest TFootpFA.mp4

Unfortunately, the result was FFmpeg got stuck on frame=1 endlessly, while its “time” setting racked up over 3 hours in a matter of minutes of execution, until I terminated it. The final file was nonfunctional, although it did indeed report a length of over 3 hours.

As it happens, getting stuck on frame=1 is the same as what happened to me before when I tried to use a WMV file in a -filter_complex operation, as described in a question I asked over a year ago here on the Video Stack Exchange.

At that time, I settled on a workaround where I converted the WMV files to MP4 files before using them to create a “video mosaic” with -filter_complex. That is, in fact, what my original command line for this question was an example of.

After this current failure with a WMV file, I tried Gyan's method with an MP4 file instead.

Now, I mentioned earlier here that all my files have the same duration; short clips that are around 30 seconds. Gyan’s command with an MP4 file did avoid getting stuck on frame=1, but after its time got to about 30 seconds, instead of completing, it got stuck on frame=900 and then quickly racked up its own lengthy time value (stating over an hour before I terminated it). The resulting file played for about 30 seconds, and then got stuck again. This is as far as I got with this.

In the meantime, I searched around for alternative strategies. I didn’t find anything that actually worked for me, but I tried something I devised based on clues I picked up on the way.

I fell back on the lengthier approach of extracting the audio from my two audio-source video files (both of which turned out to be mono audio, I found out) into MP3 files, and then combining these MP3 files’ audio data into a stereo MP3 file with this command:

ffmpeg -i audioL.mp3 -i audioR.mp3 -filter_complex "join=map=0.0-FL|1.0-FR" TwoSound.mp3

It ran okay until it got to about 21 seconds out of 30 seconds, and then FFmpeg crashed.

However, the resulting file was at least a functional stereo MP3 file of 21 seconds duration of something that worked.

I then decided to go back and re-create TFootpFA.wmv with this new file as its audio track, using Windows Live Movie Maker, where I had created the WMV file in the first place.

As the sound itself was just sound effects of a very generalized nature, I applied the new 21-second audio file to the video to be produced, and then added 9 seconds of a second iteration of the audio file, to make the full 30 seconds the video needed. This worked fine, and I now had my file TFootpFA.wmv already incorporating my desired stereo audio (or a satisfactory approximation thereof), and went to carry out my original command line to obtain TFootpFA.mp4 with the desired stereo audio.

But that's where I hit my latest snag: With my original command, the resulting MP4 had the audio reduced to mono! Apparently my conversion-to-MP4 method has always had that result; I just never checked into that before.

So then I went and tried various FFmpeg filters to try and insure that the resulting MP4 file retained the stereo nature of the WMV source, but nothing has worked: the MP4 file always comes out mono.

So I end with the question:

Does anyone know how I can induce FFmpeg to have the finished MP4 file retain the stereo audio of the WMV source?

  • Cleaned up this question. The reality is while I believe I condensed it, I still see this question as a valid question that asks too much of the community to support. At the end of the day, one question morphed into new question and then even newer info based on an answer that still did not solve the issue. Phew! The way I am reading this is simply: “How to merge audio from two WMV video files into a third MP4 file and still retain the WMV audio as well?” I edited only as much as I feel I can do. Bu encourage the original poster to review and condense further. Good question but too long. – JakeGould Mar 7 '19 at 3:24
2

Use

ffmpeg -i TFootpFA.wmv -i audioL.mp4 -i audioR.mp4 -filter_complex "[0]crop=1092:788, eq=1.2:.03:gamma_g=.8:gamma_b=.7, scale=1020x706[v];[1]aformat=channel_layouts=mono[l];[2]aformat=channel_layouts=mono[r];[l][r]amerge=2,apad[a]" -map "[v]" -map "[a]" -b:v 3M -shortest TFootpFA.mp4

(As your audio inputs may be mono, the linked answer isn't reliable since it assumes stereo inputs)

|improve this answer|||||
1

So I finally discovered it has to do with audio quality (bitrate/sample rate). I was creating WMV files with relatively "low grade" audio (in stereo, nevertheless), and apparently ffmpeg automatically decided it would be best to reduce the audio to mono in the output file. With higher-quality audio in the source WMV, ffmpeg retained the stereo format in the output video after all.

|improve this answer|||||

Not the answer you're looking for? Browse other questions tagged or ask your own question.