History

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

llyyr committed 2 years ago

Commit d33bcc51 parent 38632213 files · +40 −0Browse files

Unified · Split

3 files
  1. DOCS/interface-changes/video-frame-info-timecode.txt +1 −0
  2. DOCS/man/input.rst +9 −0
  3. player/command.c +30 −0
DOCS/interface-changes/video-frame-info-timecode.txt+1−0
@@ -0,0 +1 @@
1+add `video-frame-info/gop-timecode`, `video-frame-info/smpte-timecode` and `video-frame-info/estimated-smpte-timecode`
DOCS/man/input.rst+9−0
@@ -2733,6 +2733,15 @@ Property list · 2732 unmodified lines
27332733 ``video-frame-info/repeat``
27342734 Whether the frame must be delayed when decoding.
27352735
2736+ ``video-frame-info/gop-timecode``
2737+ String with the GOP timecode encoded in the frame.
2738+
2739+ ``video-frame-info/smpte-timecode``
2740+ String with the SMPTE timecode encoded in the frame.
2741+
2742+ ``video-frame-info/estimated-smpte-timecode``
2743+ Estimated timecode based on the current playback position and frame count.
2744+
27362745 ``container-fps``
27372746 Container FPS. This can easily contain bogus values. For videos that use
27382747 modern container formats or video codecs, this will often be incorrect.
player/command.c+30−0
@@ -28,6 +28,7 @@ · 27 unmodified lines
2828 #include <ass/ass.h>
2929 #include <libavutil/avstring.h>
3030 #include <libavutil/common.h>
31+#include <libavutil/timecode.h>
3132
3233 #include "mpv_talloc.h"
3334 #include "client.h"
@@ -2524,11 +2525,40 @@ static int mp_property_video_frame_info(void *ctx, struct m_property *prop, · 2490 unmodified lines
25242525 const char *pict_type = f->pict_type >= 1 && f->pict_type <= 3
25252526 ? pict_types[f->pict_type] : NULL;
25262527
2528+ char gop_tc[AV_TIMECODE_STR_SIZE] = {0};
2529+ char s12m_tc[AV_TIMECODE_STR_SIZE] = {0};
2530+ for (int n = 0; n < f->num_ff_side_data; n++) {
2531+
2532+ struct mp_ff_side_data *mpsd = &f->ff_side_data[n];
2533+ if (mpsd->type == AV_FRAME_DATA_GOP_TIMECODE)
2534+ av_timecode_make_mpeg_tc_string(gop_tc, *(int64_t*)(mpsd->buf->data));
2535+ if (mpctx->vo_chain && mpsd->type == AV_FRAME_DATA_S12M_TIMECODE) {
2536+ av_timecode_make_smpte_tc_string2(s12m_tc,
2537+ av_d2q(mpctx->vo_chain->filter->container_fps, INT_MAX),
2538+ *(uint32_t*)(mpsd->buf->data), 0, 0);
2539+ }
2540+ }
2541+
2542+ char approx_smpte[AV_TIMECODE_STR_SIZE] = {0};
2543+ if (s12m_tc[0] == '\0' && mpctx->vo_chain) {
2544+ const AVTimecode tcr = {
2545+ .start = 0,
2546+ .flags = AV_TIMECODE_FLAG_DROPFRAME,
2547+ .rate = av_d2q(mpctx->vo_chain->filter->container_fps, INT_MAX),
2548+ .fps = lrint(mpctx->vo_chain->filter->container_fps),
2549+ };
2550+ int frame = lrint(get_current_pos_ratio(mpctx, false) * get_frame_count(mpctx));
2551+ av_timecode_make_string(&tcr, approx_smpte, frame);
2552+ }
2553+
25272554 struct m_sub_property props[] = {
25282555 {"picture-type", SUB_PROP_STR(pict_type), .unavailable = !pict_type},
25292556 {"interlaced", SUB_PROP_BOOL(!!(f->fields & MP_IMGFIELD_INTERLACED))},
25302557 {"tff", SUB_PROP_BOOL(!!(f->fields & MP_IMGFIELD_TOP_FIRST))},
25312558 {"repeat", SUB_PROP_BOOL(!!(f->fields & MP_IMGFIELD_REPEAT_FIRST))},
2559+ {"gop-timecode", SUB_PROP_STR(gop_tc), .unavailable = gop_tc[0] == '\0'},
2560+ {"smpte-timecode", SUB_PROP_STR(s12m_tc), .unavailable = s12m_tc[0] == '\0'},
2561+ {"estimated-smpte-timecode", SUB_PROP_STR(approx_smpte), .unavailable = approx_smpte[0] == '\0'},
25322562 {0}
25332563 };
25342564

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t