Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Infinoid opened this issue Mar 31, 2020 · 2 comments
Open

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

Infinoid opened this issue Mar 31, 2020 · 2 comments

Comments

@Infinoid
Copy link

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.

@MrinalJain17
Copy link
Owner

Hi @Infinoid

Right now, it'll be difficult for me to test (and possibly fix) the issue. So, I would recommend using .mp4 for now. Let me know if even then you face a similar problem.

I'll update here as soon as I get time to look into this.

Also, is there any particular reason why you're converting videos to .mkv?

@Infinoid
Copy link
Author

Infinoid commented Apr 6, 2020

The input files I received are in .mkv format and I was hoping to read from them as-is.

FWIW, it looks like scikit-video works around this by running ffprobe -count_frames.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants