简体   繁体   English

如何使用avconv和python将两个不同帧速率的不同图像序列组合到视频中?

[英]How to combine two differnt Image Sequences at different Frame Rates Into A Video with avconv & python?

I have a two sets of images that I have no problem combining separately with avconv (with different rates using -r) One set at -r .20 (extending one image to five seconds of video ) and the other set at a regular framerate to assemble a video at regular speed. 我有两组图像,分别与avconv组合使用时没有问题(使用-r使用不同的速率),一组设置为-r .20(将一幅图像扩展到五秒钟的视频),另一组设置为常规帧速率为定期整理视频。

When I try to combine these seperate avi files with avconv or avimerge the resulting video only has the frame rate of the first video (-r .20) 当我尝试将这些单独的avi文件与avconv或avimerge合并时,所得视频仅具有第一个视频的帧速率(-r .20)

Is there a way to combine these two and both sequences be in the frame rates they were exported at? 有没有一种方法可以将这两个序列组合在一起,并且两个序列都以它们导出时的帧速率为准?

Here is the sloppy code I put together here: 这是我在这里放在一起的草率代码:

try:

p = subprocess.Popen(["avconv" , "-y" ,  "-r" , ".20" , "-i" , "head%03d.jpg" , "-i" , audio , head_video_filename],  universal_newlines=True, stdout=subprocess.PIPE)      
    out, err = p.communicate()
    retcode = p.wait()
except IOError:
    pass
else:
    print "] ENCODING OF HEADER.AVI FINISHED:" + str(retcode)

try:
    p = subprocess.Popen(["avconv" , "-y"  , "-i" , "tail%03d.jpg" , "-r" , "25" , tail_video_filename],  universal_newlines=True, stdout=subprocess.PIPE)      
    out, err = p.communicate()
    retcode = p.wait()
except IOError:
    pass
else:
    print "] ENCODING OF TAIL.AVI FINISHED:" + str(retcode)
try:

    group_of_videos = "concat:"+head_video_filename+"|"+tail_video_filename
    p = subprocess.Popen(["avconv" , "-i" , group_of_videos , "-c" , "copy" , full_video_filename] ,  universal_newlines=True, stdout=subprocess.PIPE)      
    out, err = p.communicate()
    retcode = p.wait()
except IOError:
    pass
else:
    print "] ENCODING OF FULL_VIDEO.AVI FINISHED:" + str(retcode)


return
#

I figured it out more or less. 我大概知道了。 These are the steps I took although longer, it more or less gives me two videos from separate sources as images and frame rates, the chance to encode them together and add a separate music track for an ending video. 这些是我采取的步骤,虽然时间更长,但它或多或少为我提供了来自不同来源的两个视频,分别为图像和帧频,可以将它们编码在一起并为结束视频添加单独的音乐曲目。 It works really well but still needs a tweaking on the frame rates (30, 29.X etc to get just right) 它确实运作良好,但仍然需要调整帧速率(30、29.X等以使其正确)

encode the first video sequence input at .2 and export at 30FPS 编码以.2输入的第一个视频序列并以30FPS导出
try:
    p = subprocess.Popen(["mencoder"  , "-forceidx" , "-ovc" , "copy" , "-o" , combined_video_filename , first_video_filename , second_video_filename] ,  universal_newlines=True, stdout=subprocess.PIPE)      
    out, err = p.communicate()
    retcode = p.wait()
except IOError:
    "* FAILED TO MAKE COMBINED VIDEO"
    pass
else:
    print "] ENCODING OF COMBINED VIDEO FINISHED:" + str(retcode)
encode the second video sequence input at 29.7FPS and export at 30FPS 以29.7FPS编码输入的第二个视频序列,并以30FPS导出
 try: p = subprocess.Popen(["avconv" , "-stats" , "0" , "-y" , "-i" , "second%03d.jpg" , "-crf" , "1" , "-b" , "65536k" , "-s" , "1280x720" , "-r" , "30" , second_video_filename], universal_newlines=True, stdout=subprocess.PIPE) out, err = p.communicate() retcode = p.wait() except IOError: pass else: print "] ENCODING OF SECOND VIDEO FINISHED: " + str(retcode) 
combine the avi's 结合AVI
 try: p = subprocess.Popen(["mencoder" , "-forceidx" , "-ovc" , "copy" , "-o" , combined_video_filename , first_video_filename , second_video_filename] , universal_newlines=True, stdout=subprocess.PIPE) out, err = p.communicate() retcode = p.wait() except IOError: "* FAILED TO MAKE COMBINED VIDEO" pass else: print "] ENCODING OF COMBINED VIDEO FINISHED:" + str(retcode) 
# add audio mix track #添加音频混音轨道
 try: p = subprocess.Popen(["avconv" , "-stats" , "0" , "-y" , "-i" , combined_video_filename , "-i" , combined_audio , "-c" , "copy" , "-crf" , "1" , "-b" , "65536k" ,"-shortest" , final_video_filename] , universal_newlines=True, stdout=subprocess.PIPE) out, err = p.communicate() retcode = p.wait() except IOError: "* FAILED TO MAKE FINAL VIDEO" pass else: print "] ENCODING OF FINAL VIDEO FINISHED: " + str(retcode) 

ham fisted, but hopefully this helps someone one day XOXOXOX 火腿拳头,但希望这有一天可以帮助某人

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以不同的帧速率同时运行 python 中的两个程序? - How do you run two programs in python simultaneously at different frame rates? Avconv命令组合图像和音频文件(以创建视频) - Avconv command to combine image and audio file (to create a video) 如何在python中对图像序列(具有不同的扩展名)进行排序 - How to sort image sequences (with different extensions) in python 如何在 python 中组合(合并)两个数据表框架 - How to combine (merge) two datatable Frame in python 如何合并两个字典序列中的数据 - How to combine data from two sequences of dictionaries 如何组合两个标记化的 bert 序列 - How to combine two tokenized bert sequences 如何在Python中合并两个不同维度的arrays? - How to combine two arrays of different dimension in Python? 通过Python使用avconv获取视频持续时间 - Get Video-Duration with avconv via Python 在 python 中,如何让两个文件迭代器以不同的速率迭代行? - In python how to have two file iterators iterating over lines at different rates? 如何在Tensorflow中以不同的学习率训练两个密集层? - How to train two dense layers at different learning rates in Tensorflow?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM