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

command: add video-frame-info/{gop,smpte,estimated-smpte}-timecode #14898

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions DOCS/interface-changes/video-frame-info-timecode.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add `video-frame-info/gop-timecode`, `video-frame-info/smpte-timecode` and `video-frame-info/estimated-smpte-timecode`
9 changes: 9 additions & 0 deletions DOCS/man/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2733,6 +2733,15 @@ Property list
``video-frame-info/repeat``
Whether the frame must be delayed when decoding.

``video-frame-info/gop-timecode``
String with the GOP timecode encoded in the frame.

``video-frame-info/smpte-timecode``
String with the SMPTE timecode encoded in the frame.

``video-frame-info/estimated-smpte-timecode``
Estimated timecode based on the current playback position and frame count.

``container-fps``
Container FPS. This can easily contain bogus values. For videos that use
modern container formats or video codecs, this will often be incorrect.
Expand Down
30 changes: 30 additions & 0 deletions player/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <ass/ass.h>
#include <libavutil/avstring.h>
#include <libavutil/common.h>
#include <libavutil/timecode.h>

#include "mpv_talloc.h"
#include "client.h"
Expand Down Expand Up @@ -2524,11 +2525,40 @@ static int mp_property_video_frame_info(void *ctx, struct m_property *prop,
const char *pict_type = f->pict_type >= 1 && f->pict_type <= 3
? pict_types[f->pict_type] : NULL;

char gop_tc[AV_TIMECODE_STR_SIZE] = {0};
char s12m_tc[AV_TIMECODE_STR_SIZE] = {0};
for (int n = 0; n < f->num_ff_side_data; n++) {

struct mp_ff_side_data *mpsd = &f->ff_side_data[n];
if (mpsd->type == AV_FRAME_DATA_GOP_TIMECODE)
av_timecode_make_mpeg_tc_string(gop_tc, *(int64_t*)(mpsd->buf->data));
if (mpctx->vo_chain && mpsd->type == AV_FRAME_DATA_S12M_TIMECODE) {
av_timecode_make_smpte_tc_string2(s12m_tc,
av_d2q(mpctx->vo_chain->filter->container_fps, INT_MAX),
*(uint32_t*)(mpsd->buf->data), 0, 0);
}
}

char approx_smpte[AV_TIMECODE_STR_SIZE] = {0};
if (s12m_tc[0] == '\0' && mpctx->vo_chain) {
const AVTimecode tcr = {
.start = 0,
.flags = AV_TIMECODE_FLAG_DROPFRAME,
.rate = av_d2q(mpctx->vo_chain->filter->container_fps, INT_MAX),
.fps = lrint(mpctx->vo_chain->filter->container_fps),
};
int frame = lrint(get_current_pos_ratio(mpctx, false) * get_frame_count(mpctx));
av_timecode_make_string(&tcr, approx_smpte, frame);
}

struct m_sub_property props[] = {
{"picture-type", SUB_PROP_STR(pict_type), .unavailable = !pict_type},
{"interlaced", SUB_PROP_BOOL(!!(f->fields & MP_IMGFIELD_INTERLACED))},
{"tff", SUB_PROP_BOOL(!!(f->fields & MP_IMGFIELD_TOP_FIRST))},
{"repeat", SUB_PROP_BOOL(!!(f->fields & MP_IMGFIELD_REPEAT_FIRST))},
{"gop-timecode", SUB_PROP_STR(gop_tc), .unavailable = gop_tc[0] == '\0'},
{"smpte-timecode", SUB_PROP_STR(s12m_tc), .unavailable = s12m_tc[0] == '\0'},
{"estimated-smpte-timecode", SUB_PROP_STR(approx_smpte), .unavailable = approx_smpte[0] == '\0'},
{0}
};

Expand Down
15 changes: 15 additions & 0 deletions player/lua/stats.lua
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,21 @@ local function add_video(s)
or {prefix="Picture Type:"}
append(s, "Interlaced", attrs)
end

local timecodes = {
["gop-timecode"] = "GOP",
["smpte-timecode"] = "SMPTE",
["estimated-smpte-timecode"] = "Estimated SMPTE",
}
for prop, name in pairs(timecodes) do
if frame_info and frame_info[prop] then
local attrs = has_prefix and {prefix=name .. " Timecode:",
indent=o.prefix_sep .. o.prefix_sep, nl=""}
or {prefix=name .. " Timecode:"}
append(s, frame_info[prop], attrs)
break
end
end
end

if mp.get_property_native("current-tracks/video/image") == false then
Expand Down
Loading