Не может искать кадр 0 в opencv?

Для некоторого видео я не могу искать кадр <11 с cap.set(cv2.CAP_PROP_POS_FRAMES, x), Любой x <11 приведет к поиску 11-го кадра. любой x<=0 приведет к поиску 10-го кадра. Почему это происходит? Как я могу это исправить?

def check_frame_seek(fname, frames, x, msec=False, seek=True):
    cap = cv2.VideoCapture(fname)
    _info = "start frame: {:d}; seek to {}".format(
        int(cap.get(cv2.CAP_PROP_POS_FRAMES)),
        x
    )
    if seek:
        if msec:
            _ret = cap.set(cv2.CAP_PROP_POS_MSEC, x)
            _info +="ms;"
        else:
            _ret = cap.set(cv2.CAP_PROP_POS_FRAMES, x)
            _info +="frame;"
        _info += "support seek?({});".format(_ret)
    _ret, framenow = cap.read()

    if _ret:
        for _i, _frame in enumerate(frames):
            if not _frame is None:
                if (np.all(framenow == _frame)):
                    _info +="loaded=={}.".format(_i)
    else:
        _info += "cannot read."
    cap.release()
    print(_info)


def load_all_frames(fname):
    cap = cv2.VideoCapture(fname)
    frames = []
    _ret, _frame = cap.read()
    while (_ret):
        print(
            "frame: {:d}".format(
                int(cap.get(cv2.CAP_PROP_POS_FRAMES))
            )
        )
        frames.append(_frame)
        _ret, _frame = cap.read()
    print(
        "total frame number: {}; cap.get = {}".format(
            len(frames),
            cap.get(cv2.CAP_PROP_FRAME_COUNT)
        )
    )
    return frames

def main():
    fname = "video"
    frames  = load_all_frames(fname)

    check_frame_seek(fname, frames, 0)
    check_frame_seek(fname, frames, -1)
    check_frame_seek(fname, frames, 49)
    check_frame_seek(fname, frames, 50)
    check_frame_seek(fname, frames, 51)
    check_frame_seek(fname, frames, 1)
    check_frame_seek(fname, frames, 10)
    check_frame_seek(fname, frames, 11)
    check_frame_seek(fname, frames, 12)
    check_frame_seek(fname, frames, 30)

Выход положен:

total frame number: 50; cap.get = 49.0

[h264 @ 0x55aabd321540] Missing reference picture
[h264 @ 0x55aabd321540] decode_slice_header error
[h264 @ 0x55aabd350120] Missing reference picture
[h264 @ 0x55aabd3505e0] Missing reference picture
[h264 @ 0x55aabd350aa0] reference picture missing during reorder
[h264 @ 0x55aabd350aa0] reference picture missing during reorder
[h264 @ 0x55aabd350aa0] reference picture missing during reorder
[h264 @ 0x55aabd350aa0] Missing reference picture
[h264 @ 0x55aabd350aa0] Missing reference picture
[h264 @ 0x55aabd350aa0] Missing reference picture
[h264 @ 0x55aabd321540] Missing reference picture
[h264 @ 0x55aabd350120] mmco: unref short failure
[h264 @ 0x55aabd350aa0] reference picture missing during reorder
[h264 @ 0x55aabd350aa0] Missing reference picture
start frame: 0; seek to 0frame;support seek?(True);loaded==10.
start frame: 0; seek to -1frame;support seek?(True);loaded==10.
start frame: 0; seek to 49frame;support seek?(True);loaded==49.
start frame: 0; seek to 50frame;support seek?(True);loaded==49.
start frame: 0; seek to 51frame;support seek?(True);loaded==49.
start frame: 0; seek to 1frame;support seek?(True);loaded==11.
start frame: 0; seek to 10frame;support seek?(True);loaded==11.
start frame: 0; seek to 11frame;support seek?(True);loaded==11.
start frame: 0; seek to 12frame;support seek?(True);loaded==12.
start frame: 0; seek to 30frame;support seek?(True);loaded==30.

Результат ffprobe проблемных видео:

Stream #0:0[0x100]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 1920x1080 [SAR 16:15 DAR 256:135], 50 fps, 50 tbr, 90k tbn, 100 tbc

Ffmpeg:

ffmpeg version 3.3.3 
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --disable-ffserver --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libtheora --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc --enable-libzimg
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100

0 ответов

Другие вопросы по тегам