From patchwork Sat Jun 15 11:27:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gyan Doshi X-Patchwork-Id: 13541 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 D1C3C449AAC for ; Sat, 15 Jun 2019 14:27:32 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A25D468A544; Sat, 15 Jun 2019 14:27:32 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mx1.mailbox.org (mx1.mailbox.org [80.241.60.212]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9A02C680856 for ; Sat, 15 Jun 2019 14:27:25 +0300 (EEST) Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:105:465:1:1:0]) (using TLSv1.2 with cipher ECDHE-RSA-CHACHA20-POLY1305 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id F3DFE50890 for ; Sat, 15 Jun 2019 13:27:23 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter03.heinlein-hosting.de (spamfilter03.heinlein-hosting.de [80.241.56.117]) (amavisd-new, port 10030) with ESMTP id Dzg0Xid-SKTK for ; Sat, 15 Jun 2019 13:27:18 +0200 (CEST) To: ffmpeg-devel@ffmpeg.org References: <10a7c63c-4431-70ab-6ee5-be64521dda2f@gyani.pro> From: Gyan Message-ID: <08bdecfd-01c7-c5d9-4cc9-4db7c4354d86@gyani.pro> Date: Sat, 15 Jun 2019 16:57:06 +0530 MIME-Version: 1.0 In-Reply-To: <10a7c63c-4431-70ab-6ee5-be64521dda2f@gyani.pro> Content-Language: en-US Subject: Re: [FFmpeg-devel] [PATCH] avformat/segment: fix increment_tc 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" On 14-06-2019 10:45 PM, Gyan wrote: > > Fixes an issue brought to my attention at Super User. v2 fixes inadvertent stream TC creation when non existed. Gyan From 9d4c8efefe05566377b76a39bd11805ac5bc7dd6 Mon Sep 17 00:00:00 2001 From: Gyan Doshi Date: Fri, 14 Jun 2019 22:36:27 +0530 Subject: [PATCH v2] avformat/segment: fix increment_tc inner stream avg_frame_rate wasn't populated, so tc formation failed. Also, extended increment_tc to cover individual stream timecode. --- libavformat/segment.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/libavformat/segment.c b/libavformat/segment.c index 6e37707f9f..99f048aa39 100644 --- a/libavformat/segment.c +++ b/libavformat/segment.c @@ -180,6 +180,7 @@ static int segment_mux_init(AVFormatContext *s) } st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio; st->time_base = s->streams[i]->time_base; + st->avg_frame_rate = s->streams[i]->avg_frame_rate; av_dict_copy(&st->metadata, s->streams[i]->metadata, 0); } @@ -421,7 +422,7 @@ static int segment_end(AVFormatContext *s, int write_trailer, int is_last) rate = s->streams[i]->avg_frame_rate;/* Get fps from the video stream */ err = av_timecode_init_from_string(&tc, rate, tcr->value, s); if (err < 0) { - av_log(s, AV_LOG_WARNING, "Could not increment timecode, error occurred during timecode creation."); + av_log(s, AV_LOG_WARNING, "Could not increment global timecode, error occurred during timecode creation.\n"); break; } tc.start += (int)((seg->cur_entry.end_time - seg->cur_entry.start_time) * av_q2d(rate));/* increment timecode */ @@ -431,7 +432,23 @@ static int segment_end(AVFormatContext *s, int write_trailer, int is_last) } } } else { - av_log(s, AV_LOG_WARNING, "Could not increment timecode, no timecode metadata found"); + av_log(s, AV_LOG_WARNING, "Could not increment global timecode, no global timecode metadata found.\n"); + } + for (i = 0; i < s->nb_streams; i++) { + if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) { + char st_buf[AV_TIMECODE_STR_SIZE]; + AVTimecode st_tc; + AVRational st_rate = s->streams[i]->avg_frame_rate; + AVDictionaryEntry *st_tcr = av_dict_get(s->streams[i]->metadata, "timecode", NULL, 0); + if (st_tcr) { + if ((av_timecode_init_from_string(&st_tc, st_rate, st_tcr->value, s) < 0)) { + av_log(s, AV_LOG_WARNING, "Could not increment stream %d timecode, error occurred during timecode creation.\n", i); + continue; + } + st_tc.start += (int)((seg->cur_entry.end_time - seg->cur_entry.start_time) * av_q2d(st_rate)); // increment timecode + av_dict_set(&s->streams[i]->metadata, "timecode", av_timecode_make_string(&st_tc, st_buf, 0), 0); + } + } } }