How to merge two videos using ffmpeg Android

Viewed 950

I have two videos which I want to merge. Both have same resolution. The second video does not have any audio

ffmpeg -i test.mp4 -i picture.mp4 -filter_complex "[0:v] [0:a] [1:v] [1:a] concat=n=1:v=2:a=1 [v] [a]" -map "[vv]" -map "[aa]" mergedVideo.mp4

this is the command that I am using but I am getting the following error Stream specifier ':a' in filtergraph description [0:v] [0:a] [1:v] [1:a] concat=n=2:v=2:a=1 [v] [a] matches no streams.

I am not very familiar with ffmpeg commands but I guess I am giving some wrong -filter complex values

2 Answers

You are trying "concat video filter" method of ffmpeg. I would suggest trying "concat demuxer". Create a file named inputlist.txt (or anything you like) with the following content:

file 'test.mp4'
file 'picture.mp4'

and then run ffmpeg as follows:

ffmpeg -f concat -safe 0 -i inputlist.txt -c copy mergedVideo.mp4

Missing audio

  • picture.mp4 does not have audio.
  • You cannot concatenate an input with audio with an input that does not have audio.
  • Solution is to add silent/dummy/filler audio with the anullsrc filter. Or add an audio file.

Example

ffmpeg -i test.mp4 -i picture.mp4 -t 0.1 -f lavfi -i anullsrc -filter_complex "[0:v] [0:a] [1:v] [2:a] concat=n=2:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" mergedVideo.mp4

Other problems

  • In your first command you were telling the concat filter that you have 1 set of segments (n=1) instead of 2 (n=2). See the concat filter documentation.
  • You were telling the concat filter that you have 2 video outputs (v=2) instead of 1 (v=1). See the concat filter documentation.
  • Your -map labels were referring to non-existent labels. See FFmpeg Wiki: Map.
  • There may be additional issues to resolve, but you did not include the complete log.
Related