fluent-ffmpeg / node-fluent-ffmpeg

A fluent API to FFMPEG (http://www.ffmpeg.org)
MIT License
7.82k stars 874 forks source link

Error concatenating files: 1 with audio + video, 1 with only video #517

Open ariestav opened 8 years ago

ariestav commented 8 years ago

Hi There,

I'm trying to concatenate two files with fluent-ffmpeg. The first file, referenced by anchor, has both audio and video, while the second file, reference by tablex5, only has video. When I try to concatenate them, I get the following error:

ffmpeg exited with code 1: Cannot find a matching stream for unlabeled input pad 3 on filter Parsed_concat_0

However, if I set it so that tablex5 comes first, and then anchor comes second, I get a successful merge, but the files are not concatenated, I can hear the audio from anchor, but the video track is replaced completely by anchor. Here is my code that generates the error above:

ffmpeg_cmd.input(path.resolve(anchor))
      .mergeAdd(path.resolve(tablex5))
      .videoCodec('libx264')
      .outputOption('-pix_fmt yuv420p')
      .addOption('-ac 2');

ffmpeg_cmd.mergeToFile(final_mix);

Here is the resultant ffmpeg command from that code:

ffmpeg -i B:\mixing\dc-news-anchor.avi -i B:\mixing\dc-tablex5.avi -y -filter_complex concat=n=2:v=1:a=1 -vcodec libx264 -pix_fmt yuv420p -ac 2 dc-final-mix.avi

Here is the code that successfully gives me a new output, but as I mentioned the result is incorrect. That is there is no concatenation, just that tablex5 video appears over the anchor audio. I see no video from the anchor file.

ffmpeg_cmd.input(path.resolve(tablex5))
      .mergeAdd(path.resolve(anchor))
      .videoCodec('libx264')
      .outputOption('-pix_fmt yuv420p')
      .addOption('-ac 2');

ffmpeg_cmd.mergeToFile(final_mix);

Here is the resultant command from the above code

ffmpeg -i B:\mixing\dc-tablex5.avi -i B:\mixing\dc-news-anchor.avi -y -filter_complex concat=n=2:v=1:a=0 -vcodec libx264 -pix_fmt yuv420p -ac 2 dc-final-mix.avi

I suspect the error is due to the fact that one file has an audio track and another doesn't. How can I fix using fluent-ffmpeg code?

Thank you.

njoyard commented 8 years ago

I suspect you'd have to generate null audio for the second track. You may be able to do this using a complex filtergraph. Head to the ffmpeg docs to learn how to do that, and come back here when you have a working command line if you want help translating it into fluent-ffmpeg calls !

ariestav commented 8 years ago

Thanks for your suggestion. I took a look at the docs for formulating an appropriate filtergraph but I simply cannot wrap my head around it. Is there a good book you can recommend on it? Or just a tutorial that really explains it in some kind of visual way. I searched for one, but had no luck.

njoyard commented 8 years ago

Have a look at the second example for anullsrc here, seems close to what you want to achieve !

ariestav commented 8 years ago

Thank you for that reference! I very much appreciate it. I will try it and post back the results.

matiasbenedetto commented 8 years ago

I have the exactly the same problem. Have you found a solution? Regards

ariestav commented 8 years ago

No not yet. Have not had the time. Although the resources that @njoyard pointed to seem relevant.

mansiJspaceo commented 4 years ago

@ariestav @matiasbenedetto if you found any solution please share command of it. also facing same issue

oleg131 commented 4 years ago

@mansiJspaceo I've used save instead mergeToFile to avoid fluent-ffmpeg adding the -filter_complex part and it worked. The command looked right too

ding10k commented 2 years ago

I have same issue now . Is there best way to concat two videos without considering whether those videos has audio or not ?

EyalSinay commented 2 years ago

add this: .complexFilter('anullsrc=channel_layout=5.1:sample_rate=48000')