【问题标题】:Python concatenate_videoclips, strange audio and video glitchesPython concatenate_videoclips,奇怪的音频和视频故障
【发布时间】:2021-09-28 20:22:32
【问题描述】:

我将视频剪辑与:

clip1=VideoFileClip('cutclip35.mp4')
clip2=VideoFileClip('cutclip165.mp4')
clip3=VideoFileClip('cutclip24.mp4')
final_clip = concatenate_videoclips([clip1,clip2,clip3],method='compose')
final_clip.write_videofile("my_concatenation.mp4",fps=20)

并得到非常奇怪的故障,我不知道我做错了什么。任何帮助表示赞赏!

这里是视频:https://www.dropbox.com/sh/hbd4cwooy9xjf19/AACLcv4Rqtmj7YmGzbpmCTtsa?dl=0

使用 python 3.8.10

【问题讨论】:

    标签: python concatenation moviepy


    【解决方案1】:

    我也面临同样的问题。由于编码问题,连接.mp4 文件会直接导致故障。

    在连接时避免出现故障的最佳方法是将.mp4 视频转换为.ts 视频,连接.ts 视频并将最终的.ts 视频转换为.mp4

    使用 MoviePy 完成所有这些过程可能会很耗时,因此,我们可以直接使用 ffmpeg 来完成所有这些。

    def ConcatVideos(input_video_path_list:List[str], output_video_path:str, temporary_process_folder:str):    
        concat_file_list:List[str] = []
        for idx, input_video_path in enumerate(input_video_path_list, start=1):
    
            # convering individual file to .ts #
            temp_file_ts = f'{temporary_process_folder}/concat_{idx}.ts'
            os.system(f'''ffmpeg -y -loglevel error -i {input_video_path} -c copy -bsf:v h264_mp4toannexb -f mpegts {temp_file_ts} ''')
            concat_file_list.append(temp_file_ts)
    
        # concatenating .ts files and saving as .mp4 file #
        # ffmpeg will take care of encoding .ts to .mp4 #
        concat_string = '|'.join(concat_file_list)
        os.system(f'''ffmpeg -y -loglevel error -i \
            "concat:{concat_string}" -c copy {output_video_path}''')
        
        return output_video_path
    
    final_video_path = ConcatVideos(['input1.mp4','input2.mp4'], 'final_video.mp4', 'Temp')
    # make sure '/Temp` folder exists or create it before-hand.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      • 2023-02-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多