voxel51/eta

VideoStreamInfo: Incorrect total frame count fallback

Closed this issue · 3 comments

When stream_info does not contain nb_frames, duration_ts is used for total_frame_count instead.

duration_ts is the video duration in the media's time base and does not seem to be an accurate frame count.

return int(self.stream_info["duration_ts"])

Reference: https://video.stackexchange.com/questions/27546/difference-between-duration-ts-and-duration-in-ffprobe-output

The example stream_info below gives a value of 28602000 frames. The video is 317.8 seconds long. So that is just nonsense.

    "streams": [
        {
            "index": 0,
            "codec_name": "h264",
            "codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
            "profile": "Main",
            "codec_type": "video",
            "codec_time_base": "1/60",
            "codec_tag_string": "avc1",
            "codec_tag": "0x31637661",
            "width": 640,
            "height": 480,
            "coded_width": 640,
            "coded_height": 480,
            "has_b_frames": 1,
            "sample_aspect_ratio": "1:1",
            "display_aspect_ratio": "4:3",
            "pix_fmt": "yuv420p",
            "level": 30,
            "color_range": "tv",
            "color_space": "bt470bg",
            "chroma_location": "left",
            "field_order": "progressive",
            "refs": 1,
            "is_avc": "true",
            "nal_length_size": "4",
            "r_frame_rate": "30/1",
            "avg_frame_rate": "30/1",
            "time_base": "1/90000",
            "start_pts": 0,
            "start_time": "0.000000",
            "duration_ts": 28602000,
            "duration": "317.800000",
            "bit_rate": "14530",
            "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": {
                "creation_time": "2018-03-13T10:38:46.000000Z",
                "language": "und",
                "handler_name": "VideoHandler"
            }
        }
    ]

@benjaminpkane thanks for digging into this! I fixed it here #243.

Regarding the post above, duration_ts x time_base = duration. So I added that as a fallback for computing duration if the duration field is not available.

Right. I just didn't know if something like duration * frame_rate was reliable.

Not ideal but I tested on some videos and it gives the correct number of frames