From patchwork Tue Mar 27 19:44:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derek Buitenhuis X-Patchwork-Id: 8197 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.1.70 with SMTP id c67csp5169275jad; Tue, 27 Mar 2018 12:50:51 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/Qmfjt4z+PeCu5pUY/H1bP6NWour3rUfkSEVu4F0MMbs9fND9GWhiteJmvGclkEFkc00r7 X-Received: by 10.223.152.80 with SMTP id v74mr522814wrb.163.1522180251289; Tue, 27 Mar 2018 12:50:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522180251; cv=none; d=google.com; s=arc-20160816; b=qeDve3ybO9h5r4eXdo3D/2Rl0apP/XjOcyUxQ8BSvBUOt/1JdVrhqzGKlWqQJQhlrS LIio/rh0amgyUbpwWvCILSg2lt5QUcdhV0l/WqsZOTyNqg8w0vxywdM5fB2acH5q9QWm slCIhATdQaZGC2p1hYhWpDNcZFWPUx5DDp7FVRqc72XPvTC63HmPcGVGlTWfDvvldzJk hVx4JgZ6py/JmHUZYKGjOfNhhio8VPKazMlKJ5P+ITSGpLBzZuVv6AKFZh5wFN4abtKT RekHaMOWf5MxGtJ35W3wBZWdDi+UIk7lBYudcwZL587XeCfvFvbsPC/u5hXeQaM553Vi VCUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=oMrgBoLvm3leTasAIZuv3/peMhmKHEyklOEhFw/vVR4=; b=DrdvmDkegBWvQ9b2ErYqj2rxhrzEHd7i4pqL4tg2pkCGHGLDttSqhnTqsU8p1BSGNN rbVApQrsPhtGRen+czLBrj2PxVB/NhNlMUvbgwD6niPPWR7askNif2QYd+QcnOYlYZOE TR2CwEBy8gAEaTc6SSse+WUg1Qeh18BOkX1HQQf3tcUHsAllz3ek0uCW0mzigq/vswo8 lKEQYZPyyrVfQa0RHy5kQ0NyAreZSvTsBeIeo5/j+uCqxCYpHH6SK9l3tPVs16+KW7DC 9funYK++ylqFyhtr2O85xlcz51ekM/+kR8z3TLTmz5EIqCrqk/xM50WTsJyNjwYJAGGH lx5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=BRIjm86c; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s130si1486750wms.224.2018.03.27.12.50.50; Tue, 27 Mar 2018 12:50:51 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20161025 header.b=BRIjm86c; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D6E70689887; Tue, 27 Mar 2018 22:50:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr0-f194.google.com (mail-wr0-f194.google.com [209.85.128.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 57736680498 for ; Tue, 27 Mar 2018 22:50:25 +0300 (EEST) Received: by mail-wr0-f194.google.com with SMTP id z73so96964wrb.0 for ; Tue, 27 Mar 2018 12:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=M9W1p5TGOF/aj4CCrDw+Yt+Ywqok2ZjSMHQdPtQbVBs=; b=BRIjm86cpPmAj2EL9WH9JvkBw1rni1ShNH05llyJ6TAXmTb4WfFyvFVBK/zI8gS+DB GtVNO/wvhiiL1249dm1lLVUjkppEwhcuj/5lSO9XLYNLbUIrglRyHA3uiDUChLls9j/n yNd6lEUFu+ceJ0wzTgC0Lao27bLalhJ7MzFA6PW98QUSYItWSEA4pA9soqDODVMcT+2F 182vhS3UPZ8hqUWYwI86c9deOYTh+43XIbiazExtHBUsaL29iieYfJkXSUJv6ZaqGK2e xkMVB2dy3Ho4TgVZQ0laZVuL5mT3cswEMhf4BHVujy5DZOw57gbxZqGuDkS5zraW498m RQ0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=M9W1p5TGOF/aj4CCrDw+Yt+Ywqok2ZjSMHQdPtQbVBs=; b=uQnbEPeSuEbPTW8L1JMK0K/tMuRch9LLhwCurLch/7UxozmaIBoG6M9Cbi0SUTvvj6 VtyT7TwiJ5ghkhyqFJSAq81fxbSyP19TIZ0tqNwUMizoUdwGxDg9ogAepUmfwiVRS1Q6 CEtRvFkntSDX4aLvI6qFElRB/RcwaI+OJ93liDKq0X9LRZY9jx9/4aM5N1tZigAwV2JE mrK6OZqcsvDNHF5foHRNozEjDYf5L2fuac99aqCf9j64O7U5nrh5IDlQX7UrUaNpjYEU 41eCbHmoJfZ+95JfCvgoSELPERf9YXPNlUK+7mDhbrTKXNzOz+svskO5u2M/dHtyCbim NxiA== X-Gm-Message-State: AElRT7EKgl426M//+Ethk3TsydPm0VO2Fi8aIp/ahIMxXpkkK/v5S5qX dFzAEIO4Re/CDLuyqJBdMpYDCjGi X-Received: by 10.223.201.133 with SMTP id f5mr535428wrh.41.1522179877276; Tue, 27 Mar 2018 12:44:37 -0700 (PDT) Received: from vimeo-vm.localdomain ([149.12.14.15]) by smtp.gmail.com with ESMTPSA id q13sm2024413wrg.56.2018.03.27.12.44.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Mar 2018 12:44:36 -0700 (PDT) From: Derek Buitenhuis To: ffmpeg-devel@ffmpeg.org Date: Tue, 27 Mar 2018 20:44:01 +0100 Message-Id: <1522179841-34881-2-git-send-email-derek.buitenhuis@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1522179841-34881-1-git-send-email-derek.buitenhuis@gmail.com> References: <1522179841-34881-1-git-send-email-derek.buitenhuis@gmail.com> Subject: [FFmpeg-devel] [PATCH][RFC] avcodec/avutil: Add timeline side data X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Derek Buitenhuis --- libavcodec/avcodec.h | 8 +++ libavutil/timeline.h | 160 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 libavutil/timeline.h +#endif /* AVUTIL_TIMELINE_H */ diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 50c34db..6f54495 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -1358,6 +1358,14 @@ enum AVPacketSideDataType { AV_PKT_DATA_ENCRYPTION_INFO, /** + * This side data contains timeline entries for a given stream. This type + * will only apear as stream side data. + * + * 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..f1f3e1b --- /dev/null +++ b/libavutil/timeline.h @@ -0,0 +1,160 @@ +/* + * 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 +#include + +#include "rational.h" + +typedef struct AVTimelineEntry { + /** + * The start time of the given timeline entry, in stream timebase units. + * If this value is AV_NOPTS_VALUE, you must display black for the duration + * of the entry. For audio, silence must be played. + */ + 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. + * If this value is 0, then the first sample (located at 'start') must be displayed + * for the duration of the entry. + */ + AVRational 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; + +typedef struct AVTimelineList { + /** + * An array of timelines associated with the stream. + */ + AVTimeline *timelines; + + /** + * Then number of timelines associated with the stream. + */ + size_t timeline_count; +} AVTimelineList; + +/** + * 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); + + +/** + * Frees an AVTimeline structure and its members. + * + * @param timeline The AVTimeline structure to free. + */ +void av_timeline_free(AVTimeline *timeline); + +/** + * Allocates an AVTimeline strcture with room for the request number of timelines. + * + * @param timeline_count The number of entries in the timeline. + * + * @return The new AVTimelineList structure, or NULL on error. + */ +AVTimelineList *av_timeline_list_alloc(size_t timeline_count); + + +/** + * Frees an AVTimelineList structure and its timelines, and their entries. + * + * @param timeline_list The AVTimelineList structure to free. + */ +void av_timeline_list_free(AVTimeline *timeline_list); + +/** + * Allocates a new AVTimelineList structure and copies the data from an + * existing structure, allocating new members. + * + * @param timeline_list The existing AVTimelineList structure to copy data from. + * + * @return The new AVTimelineList structure, or NULL on error. + */ +AVTimelineList *av_timeline_list_clone(const AVTimelineList *timeline_list); + +/** + * Creates a copy of the AVTimelineList that is contained in the given side + * data. The resulting struct should be passed to av_timeline_list_free() + * when done. + * + * @param side_data The side data array. + * @param side_data_size The size of the side data array. + * + * @return The new AVTimelineList structure, or NULL on error. + */ +AVTimelineList *av_timeline_list_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 + * list. The resulting pointer should be either freed using av_free() or given + * to av_packet_add_side_data(). + * + * @param timeline_list The AVTimelineList 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_list_add_side_data(const AVTimelineList *timeline_list, size_t *side_data_size); +