[英]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.