From 342f6d2be8079291992f331b889dc2b37a211d89 Mon Sep 17 00:00:00 2001 From: moi15moi Date: Sat, 14 Feb 2026 15:07:55 -0500 Subject: [PATCH] Add FFMS_GetContainerFirstTimeI This expose `AVFormatContext::start_time` to user. --- configure.ac | 2 +- doc/ffms2-api.md | 10 ++++++++++ doc/ffms2-changelog.md | 1 + include/ffms.h | 3 ++- src/core/ffms.cpp | 4 ++++ src/core/indexing.cpp | 13 +++++++++++++ src/core/indexing.h | 1 + 7 files changed, 32 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 49ba714e31..f3075f57a0 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ AM_INIT_AUTOMAKE([1.11 subdir-objects]) AM_SILENT_RULES([yes]) AM_MAINTAINER_MODE([disable]) -VERSION_INFO="5:1:1" +VERSION_INFO="5:1:2" AC_MSG_CHECKING([if debug build is enabled]) diff --git a/doc/ffms2-api.md b/doc/ffms2-api.md index ace92aa5c6..43ae196c9d 100644 --- a/doc/ffms2-api.md +++ b/doc/ffms2-api.md @@ -577,6 +577,16 @@ Returns the human-readable name ("long name" in FFmpeg terms) of the codec used Useful if you want to, say, pop up a menu asking the user which tracks he or she wishes to index. Note that specifying an invalid track number may lead to undefined behavior. +### FFMS_GetContainerFirstTimeI - gets the container first time + +[GetContainerFirstTimeI]: #ffms_getcontainerfirsttimei---gets-the-container-first-time +```c++ +bool FFMS_GetContainerFirstTimeI(FFMS_Indexer *Indexer, int64_t *pts, int *timebase); +``` +Returns the container start time of the media file represented by the given `FFMS_Indexer` object. +On success, *pts* is set to the container start timestamps (which correspond to `AVFormatContext::start_time` in FFmpeg). +Return true on success, otherwise, false. + ### FFMS_GetFormatNameI - gets the name of the container format used in the given indexer [GetFormatNameI]: #ffms_getformatnamei---gets-the-name-of-the-container-format-used-in-the-given-indexer diff --git a/doc/ffms2-changelog.md b/doc/ffms2-changelog.md index e340995377..0ce91a8bd9 100644 --- a/doc/ffms2-changelog.md +++ b/doc/ffms2-changelog.md @@ -3,6 +3,7 @@ - FFmpeg 7.1 is now the minimum requirement. - Added layered decoding support, for e.g. spatial MV-HEVC. - Added LastEndPTS to FFMS_VideoProperties. This field is the equivalent of LastEndTime, but it is expressed in the video timebase. + - Added FFMS_GetContainerFirstTimeI. - 5.0 - Fixed all issues with FFmpeg 6.1 which is now the minimum requirement diff --git a/include/ffms.h b/include/ffms.h index 4e28fb7ff6..bd06730145 100644 --- a/include/ffms.h +++ b/include/ffms.h @@ -22,7 +22,7 @@ #define FFMS_H // Version format: major - minor - micro - bump -#define FFMS_VERSION ((5 << 24) | (1 << 16) | (1 << 8) | 0) +#define FFMS_VERSION ((5 << 24) | (1 << 16) | (2 << 8) | 0) #include #include @@ -462,6 +462,7 @@ FFMS_API(int) FFMS_GetTrackType(FFMS_Track *T); FFMS_API(int) FFMS_GetTrackTypeI(FFMS_Indexer *Indexer, int Track); FFMS_API(FFMS_IndexErrorHandling) FFMS_GetErrorHandling(FFMS_Index *Index); FFMS_API(const char *) FFMS_GetCodecNameI(FFMS_Indexer *Indexer, int Track); +FFMS_API(bool) FFMS_GetContainerFirstTimeI(FFMS_Indexer *Indexer, int64_t *pts, int *timebase); /* Introduced in FFMS_VERSION ((5 << 24) | (1 << 16) | (2 << 8) | 0) */ FFMS_API(const char *) FFMS_GetFormatNameI(FFMS_Indexer *Indexer); FFMS_API(int) FFMS_GetNumFrames(FFMS_Track *T); FFMS_API(const FFMS_FrameInfo *) FFMS_GetFrameInfo(FFMS_Track *T, int Frame); diff --git a/src/core/ffms.cpp b/src/core/ffms.cpp index 8ee6974d8e..99075a2671 100644 --- a/src/core/ffms.cpp +++ b/src/core/ffms.cpp @@ -270,6 +270,10 @@ FFMS_API(const char *) FFMS_GetCodecNameI(FFMS_Indexer *Indexer, int Track) { return Indexer->GetTrackCodec(Track); } +FFMS_API(bool) FFMS_GetContainerFirstTimeI(FFMS_Indexer *Indexer, int64_t *pts, int *timebase) { + return Indexer->GetFirstTime(pts, timebase); +} + FFMS_API(int) FFMS_GetNumFrames(FFMS_Track *T) { return T->VisibleFrameCount(); } diff --git a/src/core/indexing.cpp b/src/core/indexing.cpp index c13b8ee599..7e9630df32 100644 --- a/src/core/indexing.cpp +++ b/src/core/indexing.cpp @@ -431,6 +431,19 @@ const char *FFMS_Indexer::GetTrackCodec(int Track) { return codec ? codec->name : nullptr; } +bool FFMS_Indexer::GetFirstTime(int64_t *pts, int *timebase) { + if (FormatContext->start_time == AV_NOPTS_VALUE) + return false; + + if (pts) + *pts = FormatContext->start_time; + + if (timebase) + *timebase = AV_TIME_BASE; + + return true; +} + FFMS_Index *FFMS_Indexer::DoIndexing() { std::vector AVContexts(FormatContext->nb_streams); diff --git a/src/core/indexing.h b/src/core/indexing.h index a108648028..9eda600808 100644 --- a/src/core/indexing.h +++ b/src/core/indexing.h @@ -100,6 +100,7 @@ struct FFMS_Indexer { int GetNumberOfTracks(); FFMS_TrackType GetTrackType(int Track); const char *GetTrackCodec(int Track); + bool GetFirstTime(int64_t *pts, int *timebase); const char *GetFormatName(); };