How to merge two videos?

Alexander picture Alexander · May 1, 2016 · Viewed 11.6k times · Source

I use https://github.com/Zulko/moviepy library for merge two videos with python. It merged successfully but sound of videos is not exists in merged.mp4.

The python code :

clip1 = VideoFileClip("2.mp4",audio=True)
clip2 = VideoFileClip("1.mp4",audio=True)
final_clip = concatenate_videoclips([clip1,clip2],method="compose")
final_clip.write_videofile("merged.mp4")

I also tried with ffmpeg

ffmpeg -i 'concat:1.mp4|2.mp4' -codec copy merged.mp4

ffmpeg couldn't merge videos. It create merged.mp4 which has only 1.mp4

How can I merge two videos with python or another way?

Answer

Ajay Tom George picture Ajay Tom George · Dec 13, 2019

ffmpeg offcial

Instructions Create a file mylist.txt with all the files you want to have concatenated in the following form (lines starting with a # are ignored):

file 'path/to/file1.wav'
file 'path/to/file2.wav'
file 'path/to/file3.wav'

Note that these can be either relative or absolute paths. Then you can stream copy or re-encode your files:

ffmpeg -f concat -safe 0 -i mylist.txt -c copy mergedfile.mp4

The -safe 0 above is not required if the paths are relative.

It works for all kinds of video formats mp4, wiv ...