Skip to content

Instantly share code, notes, and snippets.

@dwbuiten
Created March 27, 2018 16:34
Show Gist options
  • Save dwbuiten/ef568a6cb20c89b5dc8ed2bd52cbb642 to your computer and use it in GitHub Desktop.
Save dwbuiten/ef568a6cb20c89b5dc8ed2bd52cbb642 to your computer and use it in GitHub Desktop.
From 49fe0ce6217dd23956032c33c3985456af0d73b3 Mon Sep 17 00:00:00 2001
From: Derek Buitenhuis <[email protected]>
Date: Tue, 27 Mar 2018 17:32:55 +0100
Subject: [PATCH] avcodec/avutil: Add timeline side data
Signed-off-by: Derek Buitenhuis <[email protected]>
---
libavcodec/avcodec.h | 9 ++++
libavutil/timeline.h | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 134 insertions(+)
create mode 100644 libavutil/timeline.h
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 50c34db..3d9fa58 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -1358,6 +1358,15 @@ enum AVPacketSideDataType {
AV_PKT_DATA_ENCRYPTION_INFO,
/**
+ * This side data contains timeline entries for a given stream. This type
+ * will only apper as stream side data, though each stream may have mutliple
+ * timelines.
+ *
+ * The format is not part of the ABI, use av_timeline_* method to access.
+ */
+ AV_PKT_DATA_TIMELINE,
+
+ /**
* The number of side data types.
* This is not part of the public API/ABI in the sense that it may
* change when new side data types are added.
diff --git a/libavutil/timeline.h b/libavutil/timeline.h
new file mode 100644
index 0000000..713d2e5
--- /dev/null
+++ b/libavutil/timeline.h
@@ -0,0 +1,125 @@
+/*
+ * Copyright (C) 2018 Derek Buitenhuis
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_TIMELINE_H
+#define AVUTIL_TIMELINE_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+typedef struct AVTimelineEntry {
+ /**
+ * The start time of the given timeline entry, in stream timebase units.
+ */
+ int64_t start;
+
+ /**
+ * The duration of the given timeline entry, in steam timebase units.
+ */
+ int64_t duration;
+
+ /**
+ * The rate at which this entry should be played back. The value is a multipier
+ * of the stream's rate, for example: 1.2 means play back this entry at 1.2x speed.
+ */
+ float media_rate;
+} AVTimelineEntry;
+
+/**
+ * Describes a timeline for a stream in terms of edits/entries. Each entry must be
+ * played back in order, according to the information in each. Each stream may have
+ * multiple timelines which need to be correlated between different streams.
+ */
+typedef struct AVTimeline {
+ /**
+ * The ID of a given timeline. Since each stream may have multiple timelines
+ * defined, this value is used to correlated different streams' timelines
+ * which should be used together. For example, if one has two streams,
+ * one video, and one audio, with two timelines each, the timelines
+ * with matching IDs should be used in conjuction, to assure everything
+ * is in sync and matches. The concept is similar to that of EditionUID
+ * in Matroska.
+ */
+ uint32_t id;
+
+ /**
+ * An in-order array of entries for the given timeline.
+ * Each entry contains information on which samples to display for a
+ * particular edit.
+ */
+ AVTimelineEntry *entries;
+
+ /**
+ * Number of entries in the timeline.
+ */
+ size_t entry_count;
+} AVTimeline;
+
+/**
+ * Allocates an AVTimeline strcture with the requested number of entires.
+ *
+ * @param entry_count The number of entries in the timeline.
+ *
+ * @return The new AVTimeline structure, or NULL on error.
+ */
+AVTimeline *av_timeline_alloc(size_t entry_count);
+
+/**
+ * Allocates a new AVTimeline structure and copies the data from an
+ * existing structure.
+ *
+ * @param timeline The existing AVTimeline structure to copy data from.
+ *
+ * @return The new AVTimeline structure, or NULL on error.
+ */
+AVTimeline *av_timeline_clone(const AVTimeline *timeline);
+
+/**
+ * Frees an AVTimeline structure and its members.
+ *
+ * @param timeline The AVTimeline structure to free.
+ */
+void av_timeline_free(AVTimeline *timeline);
+
+/**
+ * Creates a copy of the AVTimeline that is contained in the given side
+ * data. The resulting struct should be passed to av_timeline_free()
+ * when done.
+ *
+ * @param side_data The side data array.
+ * @param side_data_size The size of the side data array.
+ *
+ * @return The new AVTimeline structure, or NULL on error.
+ */
+AVTimeline *av_timeline_get_side_data(const uint8_t *side_data, size_t side_data_size);
+
+/**
+ * Allocates and initializes side data that holds a copy of the given timeline
+ * The resulting pointer should be either freed using av_free() or given to
+ * av_packet_add_side_data().
+ *
+ * @param timeline The AVTimeline to put into side data.
+ * @param side_data_size A pointer to where the size can be filled in.
+ *
+ * @return The new side-data pointer, or NULL.
+ */
+uint8_t *av_timeline_add_side_data(const AVTimeline *timeline, size_t *side_data_size);
+
+#endif /* AVUTIL_TIMELINE_H */
--
1.8.3.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment