简体   繁体   English

Python concatenate_videoclips,奇怪的音频和视频故障

[英]Python concatenate_videoclips, strange audio and video glitches

I concatenated video clips with:我将视频剪辑与:

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)

and get very weird glitches and I don't know what I did wrong.并且出现非常奇怪的故障,我不知道我做错了什么。 Any help is appreciated!任何帮助表示赞赏!

Here are the videos: https://www.dropbox.com/sh/hbd4cwooy9xjf19/AACLcv4Rqtmj7YmGzbpmCTtsa?dl=0以下是视频: https://www.dropbox.com/sh/hbd4cwooy9xjf19/AACLcv4Rqtmj7YmGzbpmCTtsa?dl=0

using python 3.8.10使用 python 3.8.10

I too faced the same isue.我也面临同样的问题。 Concatenating .mp4 files directly causes glitches due to encoding issues.由于编码问题,连接.mp4文件直接导致故障。

The best way to avoid gltiches while concatenating is to convert the .mp4 videos to .ts vidoes, concat the .ts videos and convert the final .ts video to .mp4为了避免gltiches的最好方法,同时串接是将转换.mp4影片.ts vidoes,CONCAT的.ts视频并转换成最终.ts视频.mp4

Using MoviePy to do all this process can be time consuming, hence, we can use ffmpeg directly to do all of it.使用 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.

I have faced similar issue.我遇到过类似的问题。 what i did is concatenate the audios and videos separately and combine them later.我所做的是分别连接音频和视频,然后再将它们组合起来。

video_clip = concatenate_videoclips(clips,method='compose')
audioConc = concatenate_audioclips(audio_clips)
video_clip=video_clip.set_audio(audioConc)
video_clip.write_videofile("video-output.mp4",fps=24)

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

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