Answer the question
In order to leave comments, you need to log in
How to merge multiple videos with ffmpeg without quality loss?
I want to make a video from pictures, then glue a few more video recordings with it.
Code for creating slideshow:
# для каждой картинки создаем видео
# длительность всего слайдшоу равна dur
dur = 12
for num, pic in enumerate(os.listdir(path)):
os.system('ffmpeg -loop 1 -i %s -r %s -vf scale=%s:%s -t %s -y %s.ts' % (path+pic, fps, w,h, dur/len(os.listdir(path)), num))
# соединяем временные файлы со слайдами в один
slides = [i for i in os.listdir('.')]
command = 'ffmpeg -i concat:"' + '|'.join(slides) + '" -vf scale={}:{} -framerate {} -y '.format(w,h,fps) + 'slideshow.mp4'
os.system(command)
videos = ['vids/begin.mp4', 'slideshow.mp4', 'vids.mp4']
command = 'ffmpeg -i concat:"' + '|'.join(videos) + '" -vf scale={}:{} -framerate {} -y '.format(w,h,fps) + 'result.mp4'
os.system(command)
Answer the question
In order to leave comments, you need to log in
One good way would be to use unfinalized media containers for intermediate files, as you do with .ts
. They can be glued together without losing the quality of the final file. And wrap the final result in mp4
. If you already have files *.mp4
with the correct codec to merge, then convert them to ts
:
ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb OUTPUT.ts
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question