mans
mans

Reputation: 18218

getting frame no and time stamp from a video using ffprobe

I am able to get frame time stamp for a video using ffprobe using the following code:

ffprobe inputVideo.avi -hide_banner -show_entries frame=frame_no,best_effort_timestamp_time -of json

it generate data similar to this:

{
    "frames": [
        {
            "best_effort_timestamp_time": "1509110230.335000"
        },
        {
            "best_effort_timestamp_time": "1509110230.764000"
        },
        {
            "best_effort_timestamp_time": "1509110230.621000"
        },
        {
            "best_effort_timestamp_time": "1509110230.764000"
        },
        {
            "best_effort_timestamp_time": "1509110230.906000"
        },

The result is not complete, but it shows that data is in json format and also it starts from frame one and goes to the end of video.

How can I change it so:

  1. I can specify the duration of video (start and end or start and duration, for example start 5 sec from start and get data for 10 minute)
  2. How to make the output has the frame number to, ( so I know that when that the first time stamp belong to which frame ).

Edit 1

After using this code:

ffprobe inputVideo.avi -hide_banner -show_entries frame=coded_picture_number,best_effort_timestamp_time -of json

I am getting this result:

    {
        "best_effort_timestamp_time": "1509110236.763000",
        "coded_picture_number": 47
    },
    {
        "best_effort_timestamp_time": "1509110236.906000",
        "coded_picture_number": 46
    },
    {
        "best_effort_timestamp_time": "1509110237.049000",
        "coded_picture_number": 48
    },
    {
        "best_effort_timestamp_time": "1509110237.192000",
        "coded_picture_number": 45
    },
    {
        "best_effort_timestamp_time": "1509110237.335000",
        "coded_picture_number": 51
    },
    {
        "best_effort_timestamp_time": "1509110237.478000",
        "coded_picture_number": 50
    },

in the result, the frame no doesn't seems correct.

Upvotes: 2

Views: 7009

Answers (1)

Gyan
Gyan

Reputation: 93319

Use

ffprobe inputVideo.avi -hide_banner
 -show_entries frame=coded_picture_number,best_effort_timestamp_time -read_intervals 5%+10
 -of json

-read_intervals 5%+10 starts at 5 seconds and continues for further 10 seconds. -read_intervals 5%10 ends at 10 seconds. Seeking, however, is not accurate.

coded_picture_number will tell you the encoding order. If there are no B-frames, this is the same as frame no. With B-frames, you're better off keeping count yourself. Although you can add pict_type in entries and sync using the last I-frame entry.

Upvotes: 4

Related Questions