简体   繁体   中英

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.

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)

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)

encode the first video sequence input at .2 and export at 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
 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
 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM