冻结帧和demux错误

时间:2015-11-19 20:44:48

标签: python video ffmpeg

我尝试使用子进程通过python脚本使用ffmpeg加入一些视频片段。

以下是代码的一部分:

def join_videos(videos):
    # videos is a list of tuples with (file_name, start_point, duration)
    path = os.path.dirname(__file__)

    # create a new video file containg only the desired bit, it will be named output_N.mov
    for out_n, (file_name, start, duration) in enumerate(videos, 1):
        video_path = path + "/VIDEOS/" + file_name
        ## essentialy ffmpeg -i %PATH_TO_VIDEO -ss %STARTING_POINT -c copy -t %DURATION output_%NUMBER.mov
        command = ["ffmpeg", "-i",video_path,"-ss", str(start),"-c","copy","-t",str(duration),"output_%i.mov"%out_n]
        subprocess.Popen(command, stderr=subprocess.PIPE, stdout=subprocess.PIPE)

    # get the list of files with this pattern
    files = glob.glob("output_*.mov")
    # add them to a text file
    with open("to_merge_tmp.txt", 'w') as f:
        for file_name in files:
            f.write("file '{path}/{file_name}'\n".format(**locals()))
    # use 'ffmpeg' to concatenate
    command = "ffmpeg -f concat -i to_merge_tmp.txt -c copy final.mov"
    subprocess.Popen(command.split(" "), stderr=subprocess.PIPE, stdout=subprocess.PIPE)

我使用文件名列表和所需的起点和持续时间发布新视频。

例如:

videos = [('video1.mov', 15.5, 10), # video1, starting at 15.5 seconds, duration of 10 seconds
          ('video2.mov', 10.7, 5), 
          ('video3.mov', 0, 20)]
join_videos(videos)

这将生成一个 final.mov 文件,其中各个部分连接在一起(一个接一个)

程序运行正常。没有错误或任何东西。

但是当我尝试播放它时,我会有一些帧停留太久(冻结),音频播放正常。

我制作了第二个脚本,使用python bindings for VLC

以编程方式播放

在这里:

import vlc

instance = vlc.Instance()
media = instance.media_new("final.mov")
player = instance.media_player_new()
player.set_media(media)
player.play()

while player.is_playing():
     pass

instance.vlm_release()
player.release()
instance.release()

有了这个,我在播放文件时会收到一些警告。

例如,发生这种情况并且视频没有播放(解复用错误)

[0x7f4e64009528] mp4 demux error: MP4 plugin discarded (no moov,foov,moof box)  
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f4e64025be0] moov atom not found
[0x7f4e64009528] avformat demux error: Could not open /medi /.../final.mov: Unknown error 1052488119

这种情况发生了,视频会播放,但屏幕也会结束。

Fontconfig warning: FcPattern object size does not accept value "0"
Fontconfig warning: FcPattern object size does not accept value "0"
Fontconfig warning: FcPattern object size does not accept value "0"
Fontconfig warning: FcPattern object size does not accept value "0"
Non-reference picture received and no reference available
[h264 @ 0x7fe76c0e5280] decode_slice_header error
[h264 @ 0x7fe76c0e5280] concealing 1080 DC, 1080 AC, 1080 MV errors
Non-reference picture received and no reference available
[h264 @ 0x7fe76c0e5820] decode_slice_header error
[h264 @ 0x7fe76c0e5820] concealing 1080 DC, 1080 AC, 1080 MV errors
[0x7fe740001248] main vout display error: Failed to resize display

或者这个,它会中途停止播放并使程序崩溃。

Fontconfig warning: FcPattern object size does not accept value "0"
Fontconfig warning: FcPattern object size does not accept value "0"
Fontconfig warning: FcPattern object size does not accept value "0"
Fontconfig warning: FcPattern object size does not accept value "0"
Non-reference picture received and no reference available
[h264 @ 0x7f5c3c0c0000] decode_slice_header error
[h264 @ 0x7f5c3c0c0000] concealing 1080 DC, 1080 AC, 1080 MV errors
Non-reference picture received and no reference available
[h264 @ 0x7f5c3c0c0440] decode_slice_header error
[h264 @ 0x7f5c3c0c0440] concealing 1080 DC, 1080 AC, 1080 MV errors
[h264 @ 0x7f5c3c0c0440] Reinit context to 1280x720, pix_fmt: 12
Non-reference picture received and no reference available
[h264 @ 0x7f5c3c0c09e0] decode_slice_header error
Non-reference picture received and no reference available
[h264 @ 0x7f5c3c0befa0] decode_slice_header error

我不知道最近发生了什么,我很确定ffmpeg是如何加入文件的。

修改

当我找到here时,如果录像机在创建文件时崩溃,则会发生moov atom not found错误。但我发现很难理解为什么会发生这种情况,并且在创建这些文件时不会显示任何错误。

0 个答案:

没有答案