Skip to content

mkv video files do not have "nb_frames" field in video header #18

Open
@Infinoid

Description

@Infinoid

I tried reading a .mkv file and it crashed.

    video = mydia.Videos().read(video_path)
  File ".../python3.6/site-packages/mydia/mydia.py", line 234, in read
    video_tensor = np.vstack(map(self._read_video, paths_iterator))
  File "<__array_function__ internals>", line 6, in vstack
  File ".../python3.6/site-packages/numpy/core/shape_base.py", line 280, in vstack
    arrs = atleast_2d(*tup)
  File ".../python3.6/site-packages/mydia/mydia.py", line 286, in _read_video
    fps, total_frames = self._probe(path)
  File ".../python3.6/site-packages/mydia/mydia.py", line 365, in _probe
    total_frames = int(video_stream["nb_frames"])
KeyError: 'nb_frames'

To reproduce:

  1. Locate a video file which works
  2. Convert it to .mkv as follows: ffmpeg -i working.mp4 -vc copy test.mkv
  3. Try to read mkv file

I printed the video_stream data in _probe(), here was the result:

{'index': 0, 'codec_name': 'h264', 'codec_long_name': 'H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10', 'profile': 'High', 'codec_type': 'video', 'codec_time_base': '1/50', 'codec_tag_string': '[0][0][0][0]', 'codec_tag': '0x0000', 'width': 700, 'height': 500, 'coded_width': 700, 'coded_height': 500, 'has_b_frames': 2, 'sample_aspect_ratio': '0:1', 'display_aspect_ratio': '0:1', 'pix_fmt': 'yuv420p', 'level': 30, 'chroma_location': 'left', 'field_order': 'progressive', 'refs': 1, 'is_avc': 'true', 'nal_length_size': '4', 'r_frame_rate': '25/1', 'avg_frame_rate': '25/1', 'time_base': '1/1000', 'start_pts': 0, 'start_time': '0.000000', 'bits_per_raw_sample': '8', 'disposition': {'default': 1, 'dub': 0, 'original': 0, 'comment': 0, 'lyrics': 0, 'karaoke': 0, 'forced': 0, 'hearing_impaired': 0, 'visual_impaired': 0, 'clean_effects': 0, 'attached_pic': 0, 'timed_thumbnails': 0}, 'tags': {'HANDLER_NAME': 'VideoHandler', 'ENCODER': 'Lavc57.107.100 libx264', 'DURATION': '00:00:05.120000000'}}

Do .mp4 files work reliably? If so, converting input to .mp4 should work as a workaround.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions