Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge two videos?

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?

like image 431
Alexander Avatar asked May 01 '16 14:05

Alexander


1 Answers

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, wav ...

like image 68
Ajay Tom George Avatar answered Sep 23 '22 17:09

Ajay Tom George