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

fftools/ffprobe: add only_first_vframe option to show first video frame info #519

Open
wants to merge 2 commits into
base: jellyfin
Choose a base branch
from

Conversation

gnattu
Copy link
Member

@gnattu gnattu commented Dec 22, 2024

Currently, ffprobe can only read frames at a specific interval, and users have no options to select only video frames without explicitly selecting a stream. This option instructs show_frames to pick the first video frame and prints its information. This will be useful for extracting tricky metadata, such as the HDR10plus ST2094 metadata.

One potential edge case is that the video file contains multiple video streams and this will only show info for one of the stream. But our prober does not really handle this case anyway.

Another potential edge case is that the video contains embedded images and such image becomes the first frame, but I have failed to generate such files. Maybe the image itself has to be the stream 0?

Now all video streams will be printed if possible, the only question would be performance if there are a lot of streams in a single file, but that should be an extremely rare case.

The output would look like this which is easier for us to detect HDR10+ videos and some potentially problematic files:

JSON output of ffprobe
{
  "frames": [
      {
          "media_type": "video",
          "stream_index": 0,
          "key_frame": 1,
          "pts": 6144,
          "pts_time": "0.400000",
          "best_effort_timestamp": 6144,
          "best_effort_timestamp_time": "0.400000",
          "duration": 256,
          "duration_time": "0.016667",
          "pkt_pos": "17082",
          "pkt_size": "196722",
          "width": 3840,
          "height": 2160,
          "crop_top": 0,
          "crop_bottom": 0,
          "crop_left": 0,
          "crop_right": 0,
          "pix_fmt": "yuv420p10le",
          "sample_aspect_ratio": "1:1",
          "pict_type": "I",
          "interlaced_frame": 0,
          "top_field_first": 0,
          "repeat_pict": 0,
          "color_range": "tv",
          "color_space": "bt2020nc",
          "color_primaries": "bt2020",
          "color_transfer": "smpte2084",
          "chroma_location": "topleft",
          "side_data_list": [
              {
                  "side_data_type": "Mastering display metadata",
                  "red_x": "34000/50000",
                  "red_y": "16000/50000",
                  "green_x": "13250/50000",
                  "green_y": "34500/50000",
                  "blue_x": "7500/50000",
                  "blue_y": "3000/50000",
                  "white_point_x": "15635/50000",
                  "white_point_y": "16450/50000",
                  "min_luminance": "1/10000",
                  "max_luminance": "10000000/10000"
              },
              {
                  "side_data_type": "Content light level metadata",
                  "max_content": 1000,
                  "max_average": 400
              },
              {
                  "side_data_type": "HDR Dynamic Metadata SMPTE2094-40 (HDR10+)",
                  "application version": 1,
                  "num_windows": 1,
                  "targeted_system_display_maximum_luminance": "300/1",
                  "maxscl": "3956/100000",
                  "maxscl": "2063/100000",
                  "maxscl": "2047/100000",
                  "average_maxrgb": "93/100000",
                  "num_distribution_maxrgb_percentiles": 9,
                  "distribution_maxrgb_percentage": 1,
                  "distribution_maxrgb_percentile": "0/100000",
                  "distribution_maxrgb_percentage": 5,
                  "distribution_maxrgb_percentile": "2094/100000",
                  "distribution_maxrgb_percentage": 10,
                  "distribution_maxrgb_percentile": "96/100000",
                  "distribution_maxrgb_percentage": 25,
                  "distribution_maxrgb_percentile": "3/100000",
                  "distribution_maxrgb_percentage": 50,
                  "distribution_maxrgb_percentile": "4/100000",
                  "distribution_maxrgb_percentage": 75,
                  "distribution_maxrgb_percentile": "5/100000",
                  "distribution_maxrgb_percentage": 90,
                  "distribution_maxrgb_percentile": "88/100000",
                  "distribution_maxrgb_percentage": 95,
                  "distribution_maxrgb_percentile": "720/100000",
                  "distribution_maxrgb_percentage": 99,
                  "distribution_maxrgb_percentile": "2888/100000",
                  "fraction_bright_pixels": "0/1000",
                  "knee_point_x": "0/4095",
                  "knee_point_y": "0/4095",
                  "num_bezier_curve_anchors": 9,
                  "bezier_curve_anchors": "102/1023",
                  "bezier_curve_anchors": "205/1023",
                  "bezier_curve_anchors": "307/1023",
                  "bezier_curve_anchors": "410/1023",
                  "bezier_curve_anchors": "512/1023",
                  "bezier_curve_anchors": "614/1023",
                  "bezier_curve_anchors": "717/1023",
                  "bezier_curve_anchors": "819/1023",
                  "bezier_curve_anchors": "922/1023"
              }
          ]
      }
  ],
  "streams": [
      {
          "index": 0,
          "codec_name": "hevc",
          "codec_long_name": "H.265 / HEVC (High Efficiency Video Coding)",
          "profile": "Main 10",
          "codec_type": "video",
          "codec_tag_string": "hvc1",
          "codec_tag": "0x31637668",
          "width": 3840,
          "height": 2160,
          "coded_width": 3840,
          "coded_height": 2160,
          "closed_captions": 0,
          "film_grain": 0,
          "has_b_frames": 2,
          "sample_aspect_ratio": "1:1",
          "display_aspect_ratio": "16:9",
          "pix_fmt": "yuv420p10le",
          "level": 153,
          "color_range": "tv",
          "color_space": "bt2020nc",
          "color_transfer": "smpte2084",
          "color_primaries": "bt2020",
          "chroma_location": "topleft",
          "refs": 1,
          "id": "0x1",
          "r_frame_rate": "60/1",
          "avg_frame_rate": "60/1",
          "time_base": "1/15360",
          "start_pts": 6144,
          "start_time": "0.400000",
          "duration_ts": 913408,
          "duration": "59.466667",
          "bit_rate": "70248435",
          "nb_frames": "3568",
          "nb_read_frames": "1",
          "extradata_size": 184,
          "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,
              "non_diegetic": 0,
              "captions": 0,
              "descriptions": 0,
              "metadata": 0,
              "dependent": 0,
              "still_image": 0
          },
          "tags": {
              "language": "und",
              "handler_name": "VideoHandler",
              "vendor_id": "[0][0][0][0]"
          }
      },
      {
          "index": 1,
          "codec_name": "aac",
          "codec_long_name": "AAC (Advanced Audio Coding)",
          "profile": "LC",
          "codec_type": "audio",
          "codec_tag_string": "mp4a",
          "codec_tag": "0x6134706d",
          "sample_fmt": "fltp",
          "sample_rate": "48000",
          "channels": 2,
          "channel_layout": "stereo",
          "bits_per_sample": 0,
          "initial_padding": 0,
          "id": "0x2",
          "r_frame_rate": "0/0",
          "avg_frame_rate": "0/0",
          "time_base": "1/48000",
          "start_pts": 0,
          "start_time": "0.000000",
          "duration_ts": 2872320,
          "duration": "59.840000",
          "bit_rate": "320118",
          "nb_frames": "2808",
          "extradata_size": 2,
          "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,
              "non_diegetic": 0,
              "captions": 0,
              "descriptions": 0,
              "metadata": 0,
              "dependent": 0,
              "still_image": 0
          },
          "tags": {
              "language": "und",
              "handler_name": "SoundHandler",
              "vendor_id": "[0][0][0][0]"
          }
      }
  ],
  "format": {
      "filename": "/Volumes/ex/HDR Samles/HDR10Plus_test.mp4",
      "nb_streams": 2,
      "nb_programs": 0,
      "nb_stream_groups": 0,
      "format_name": "mov,mp4,m4a,3gp,3g2,mj2",
      "format_long_name": "QuickTime / MOV",
      "start_time": "0.000000",
      "duration": "59.866667",
      "size": "524677055",
      "bit_rate": "70112746",
      "probe_score": 100,
      "tags": {
          "major_brand": "isom",
          "minor_version": "512",
          "compatible_brands": "isomiso2mp41",
          "encoder": "Lavf61.1.100"
      }
  }
}

Changes

Issues

@gnattu gnattu requested a review from a team December 22, 2024 07:12
@gnattu gnattu changed the title fftools/ffprobe: add only_first_vframe option for to show first video frame info fftools/ffprobe: add only_first_vframe option to show first video frame info Dec 22, 2024
Currently, ffprobe can only read frames at a specific interval,
and users have no options to select only video frames without
explicitly selecting a stream. This option instructs show_frames
to pick the first video frame and prints its information.
This will be useful for extracting tricky metadata, such as the
HDR10plus ST2094 metadata.
@gnattu gnattu force-pushed the ffprobe-first-vframe branch from ab09afe to 31d75a3 Compare December 22, 2024 07:14
@gnattu
Copy link
Member Author

gnattu commented Dec 22, 2024

Handling multiple video streams within the same file has a significant challenge after playing with the implementation a bit. The first frame of alternative streams may arrive after the first stream by a huge amount of data, requiring a substantial amount of the frame reading, which severely impacts probe performance. If there are numerous alternative streams, the IO read to probe the file could even reach GBs before printing the output.

Copy link
Contributor

@Shadowghost Shadowghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having multiple video streams should be a really rare edge case so this should be fine. If it happens like once or twice per library, I think reading some rather big amount of data should still be fine.

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

Successfully merging this pull request may close these issues.

2 participants