summaryrefslogtreecommitdiff
path: root/libavformat/mux_utils.c
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-05-06 16:40:53 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2022-05-10 07:30:31 +0200
commitd78838414b8362a7aa7c27abacee1f6ca036199c (patch)
tree5685c2949db1ed148c3df2bb42952c0d8e7274e8 /libavformat/mux_utils.c
parent533836b8e0e5693b3d3e8403666ce216687d51b3 (diff)
avformat/utils: Move creation-time functions to mux_utils
Only used by muxers. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavformat/mux_utils.c')
-rw-r--r--libavformat/mux_utils.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libavformat/mux_utils.c b/libavformat/mux_utils.c
index 7b79ffd1fb..df264fc6a0 100644
--- a/libavformat/mux_utils.c
+++ b/libavformat/mux_utils.c
@@ -19,6 +19,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include "libavutil/dict.h"
+#include "libavutil/internal.h"
+#include "libavutil/log.h"
+#include "libavutil/mem.h"
+#include "libavutil/parseutils.h"
#include "avformat.h"
#include "avio.h"
#include "internal.h"
@@ -79,3 +84,29 @@ end:
av_free(buf);
return ret;
}
+
+int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
+{
+ AVDictionaryEntry *entry;
+ int64_t parsed_timestamp;
+ int ret;
+ if ((entry = av_dict_get(s->metadata, "creation_time", NULL, 0))) {
+ if ((ret = av_parse_time(&parsed_timestamp, entry->value, 0)) >= 0) {
+ *timestamp = return_seconds ? parsed_timestamp / 1000000 : parsed_timestamp;
+ return 1;
+ } else {
+ av_log(s, AV_LOG_WARNING, "Failed to parse creation_time %s\n", entry->value);
+ return ret;
+ }
+ }
+ return 0;
+}
+
+int ff_standardize_creation_time(AVFormatContext *s)
+{
+ int64_t timestamp;
+ int ret = ff_parse_creation_time_metadata(s, &timestamp, 0);
+ if (ret == 1)
+ return avpriv_dict_set_timestamp(&s->metadata, "creation_time", timestamp);
+ return ret;
+}