From patchwork Wed Aug 7 15:51:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Andreas_H=C3=A5kon?= X-Patchwork-Id: 14302 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id D96894481A9 for ; Wed, 7 Aug 2019 18:51:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id AAEAB68AB12; Wed, 7 Aug 2019 18:51:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-40135.protonmail.ch (mail-40135.protonmail.ch [185.70.40.135]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E6C1B68A9DA for ; Wed, 7 Aug 2019 18:51:26 +0300 (EEST) Date: Wed, 07 Aug 2019 15:51:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=default; t=1565193085; bh=eUzHoxlUFgPcgC1zInezcBkORqKElLuq8f+mHKZ3UiY=; h=Date:To:From:Reply-To:Subject:Feedback-ID:From; b=WHe8XX9tdEtr5sLa8+yL+Nsa47ye3qbFoJSTFRkGL1YWgoUpWrp5MxXJsBghhHTiN liTXMJ8nPs3WW/ApmoZVhQNkw5cuOdA76zvQ3yR96VEE3RjGbRplriGPX58uOwfEq6 n//X9QD81gXGjucXu8Ax0sa8s4kx/Es9T0wO7Dnk= To: FFmpeg development discussions and patches From: =?UTF-8?Q?Andreas_H=C3=A5kon?= Message-ID: Feedback-ID: Mx8CaiV20jk_fqXDN0fFpg3vRaGkb9VCTrYRnZNHwEija3aOdqvFspzl6ODkmHrlSKJSx29p-LzkuvS_96L02A==:Ext:ProtonMail MIME-Version: 1.0 X-Spam-Status: No, score=-1.2 required=7.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on mail.protonmail.ch X-Content-Filtered-By: Mailman/MimeDel 2.1.20 Subject: [FFmpeg-devel] libavcodec: add timeshift bitstream filter [v3] 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Hi, This new version changes the name of the filter, and implements all suggestions. Supersedes: https://patchwork.ffmpeg.org/patch/14195/ https://patchwork.ffmpeg.org/patch/13743/ https://patchwork.ffmpeg.org/patch/13699/ Regards. A.H. --- From 9e036e0a1dc20fd5c41686a48a5a0c2142f91de4 Mon Sep 17 00:00:00 2001 From: Andreas Hakon Date: Wed, 7 Aug 2019 17:45:25 +0200 Subject: [PATCH] libavcodec: add timeshift bitstream filter [v3] This implements the new timeshift bitstream filter. Signed-off-by: Andreas Hakon --- doc/bitstream_filters.texi | 11 +++++ libavcodec/Makefile | 1 + libavcodec/bitstream_filters.c | 1 + libavcodec/timeshift_bsf.c | 87 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 100 insertions(+) create mode 100644 libavcodec/timeshift_bsf.c diff --git a/doc/bitstream_filters.texi b/doc/bitstream_filters.texi index 50a1679..f7fb0d4 100644 --- a/doc/bitstream_filters.texi +++ b/doc/bitstream_filters.texi @@ -644,6 +644,17 @@ codec) with metadata headers. See also the @ref{mov2textsub} filter. +@section timeshift + +Apply an offset to the PTS/DTS timestamps. + +@table @option +@item offset +The absolute offset value to apply to the PTS/DTS timestamps with a +90kHz resolution. + +@end table + @section trace_headers Log trace output containing all syntax elements in the coded stream diff --git a/libavcodec/Makefile b/libavcodec/Makefile index 3cd73fb..e929a99 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -1096,6 +1096,7 @@ OBJS-$(CONFIG_NULL_BSF) += null_bsf.o OBJS-$(CONFIG_PRORES_METADATA_BSF) += prores_metadata_bsf.o OBJS-$(CONFIG_REMOVE_EXTRADATA_BSF) += remove_extradata_bsf.o OBJS-$(CONFIG_TEXT2MOVSUB_BSF) += movsub_bsf.o +OBJS-$(CONFIG_TIMESHIFT_BSF) += timeshift_bsf.o OBJS-$(CONFIG_TRACE_HEADERS_BSF) += trace_headers_bsf.o OBJS-$(CONFIG_TRUEHD_CORE_BSF) += truehd_core_bsf.o mlp_parse.o mlp.o OBJS-$(CONFIG_VP9_METADATA_BSF) += vp9_metadata_bsf.o diff --git a/libavcodec/bitstream_filters.c b/libavcodec/bitstream_filters.c index 4630039..d728185 100644 --- a/libavcodec/bitstream_filters.c +++ b/libavcodec/bitstream_filters.c @@ -51,6 +51,7 @@ extern const AVBitStreamFilter ff_null_bsf; extern const AVBitStreamFilter ff_prores_metadata_bsf; extern const AVBitStreamFilter ff_remove_extradata_bsf; extern const AVBitStreamFilter ff_text2movsub_bsf; +extern const AVBitStreamFilter ff_timeshift_bsf; extern const AVBitStreamFilter ff_trace_headers_bsf; extern const AVBitStreamFilter ff_truehd_core_bsf; extern const AVBitStreamFilter ff_vp9_metadata_bsf; diff --git a/libavcodec/timeshift_bsf.c b/libavcodec/timeshift_bsf.c new file mode 100644 index 0000000..1af9152 --- /dev/null +++ b/libavcodec/timeshift_bsf.c @@ -0,0 +1,87 @@ +/* + * 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 + */ + +/** + * @file + * This bitstream filter applies an offset to the PTS/DTS timestamps. + * + */ + +#include "avcodec.h" +#include "bsf.h" + +#include "libavutil/opt.h" + +#define FILTER_MAX_PTS 0x200000000 // (2^33) + +typedef struct TimeshiftContext { + const AVClass *class; + int offset; + int first_debug_done; +} TimeshiftContext; + +static int timeshift_filter(AVBSFContext *ctx, AVPacket *pkt) +{ + int ret; + TimeshiftContext *s = ctx->priv_data; + int64_t opts,odts; + + ret = ff_bsf_get_packet_ref(ctx, pkt); + if (ret < 0) + return ret; + + opts = pkt->pts; + if (pkt->pts != AV_NOPTS_VALUE) { + pkt->pts += s->offset; + pkt->pts &= FILTER_MAX_PTS; + } + odts = pkt->dts; + if (pkt->dts != AV_NOPTS_VALUE) { + pkt->dts += s->offset; + pkt->pts &= FILTER_MAX_PTS; + } + + if (!s->first_debug_done) { + av_log(ctx, AV_LOG_DEBUG, "Updated PTS/DTS (%"PRId64"/%"PRId64" : %"PRId64"/%"PRId64") with offset:%d\n", + pkt->pts, pkt->dts, opts, odts, s->offset ); + s->first_debug_done = 1; + } + + return 0; +} + +#define OFFSET(x) offsetof(TimeshiftContext, x) +#define FLAGS (AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_SUBTITLE_PARAM|AV_OPT_FLAG_BSF_PARAM) +static const AVOption options[] = { + { "offset", NULL, OFFSET(offset), AV_OPT_TYPE_INT64, { .i64 = 0 }, 1-FILTER_MAX_PTS, FILTER_MAX_PTS, FLAGS }, + { NULL }, +}; + +static const AVClass timeshift_class = { + .class_name = "timeshift_bsf", + .item_name = av_default_item_name, + .option = options, + .version = LIBAVUTIL_VERSION_INT, +}; + +const AVBitStreamFilter ff_timeshift_bsf = { + .name = "timeshift", + .priv_data_size = sizeof(TimeshiftContext), + .priv_class = ×hift_class, + .filter = timeshift_filter, +};