From patchwork Fri Oct 19 23:29:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Leo Izen X-Patchwork-Id: 10721 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 F0EE8447CDD for ; Sat, 20 Oct 2018 02:29:30 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4BF3C68A790; Sat, 20 Oct 2018 02:29:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 10AB368A75F for ; Sat, 20 Oct 2018 02:29:05 +0300 (EEST) Received: by mail-yb1-f195.google.com with SMTP id h1-v6so13917390ybm.4 for ; Fri, 19 Oct 2018 16:29:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=oS7lppS2p8eoV9IQ5zOglRpsNh7/pU8unl59nrcdLCE=; b=WSxuYRRQgQuIJJBcPjJ33qrcCmlGaatfmniIVt7UNK06tEk1jGc9huZGtSOxLPHXAz /WCg8US4lxiIIkIpalGgOTWYx8qkc1IqQQf08jweDurFPo5+pu5nKDYHUZsjtPdh/kJ/ Iv96AMW4dZZLZ2NNLXYEgh8Kdy5hQQvuOh9fGt71/JgBFeza87vRA6HhRDq4kRry4qJK Yk3EMqDkOFPPbuqatFUTEU4Y44cKZQkGC54ALZVEmxqSEgF06oPArE00HgKz6szWOfW+ dr0xwq6UaPS2TeA6ofrgvv8me9kYtwG8IkQihYHbgYSpj5/efhSut0jUUEXDzPjGb8xF J27A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=oS7lppS2p8eoV9IQ5zOglRpsNh7/pU8unl59nrcdLCE=; b=LVEF7jx8Hhton1zjQWbwG5/52TrAicbsbQzyNHwLh/fhQZixvIm41Tq7Ze+GAKGhlx N3e6YJedTH2qa6NBlLZMriK/Q6zsosZ/tvZ8Q2k93Is0Divmw9iwoatLLenTAIMDq9f0 tXX5apax45t/aFfRoht/7jQSUiNgkcbVCWIuffDyxhFH+6XJK59R8GpYFvPhb2rOif/O feSudqHT8cGI3pxMwsTUOHoEQkoiQlF3n4KKuaM/hsWEWs33REmu7QRbv9u4vnUvLsea p+wcyOgmSFvfpStnsozt1+HKrl7wqQJZq72MlS/axgYY9IM+3wqH8YDwHBGNHnExg7Ak 6DZg== X-Gm-Message-State: ABuFfohLPiqW8vMSVWdrKX3jjx9IquEmM05PZqfcTMP3+l0FR6fZMEZg sUkTAjiFxoMKckzOfv1N2Ankd1Gt X-Google-Smtp-Source: ACcGV60Z5lRTgijd8YQEDWD0Tud0KDve9titCLawe4x5wygh6iFkbgpoVBnEpA8YKwwiCHn99KXhQA== X-Received: by 2002:a25:df86:: with SMTP id w128-v6mr3724223ybg.333.1539991770020; Fri, 19 Oct 2018 16:29:30 -0700 (PDT) Received: from [192.168.1.35] (64-233-244-163.static.clv.wideopenwest.com. [64.233.244.163]) by smtp.gmail.com with ESMTPSA id n7-v6sm6247495ywb.8.2018.10.19.16.29.28 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 19 Oct 2018 16:29:29 -0700 (PDT) To: ffmpeg-devel@ffmpeg.org References: <20181019025821.23120-1-leo.izen@gmail.com> <195eb348-174c-a1b2-8054-d59bf8a3babd@gmail.com> From: Leo Izen Message-ID: <55c1c681-d8df-376c-7c37-60ad0c9dfdee@gmail.com> Date: Fri, 19 Oct 2018 19:29:28 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-PH Subject: Re: [FFmpeg-devel] [PATCH] fftools/ffmpeg.c: allow forcing input framerate on streamcopy 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 10/19/18 3:02 PM, Carl Eugen Hoyos wrote: > 2018-10-19 20:39 GMT+02:00, Leo Izen : >> On 10/19/18 2:26 PM, Carl Eugen Hoyos wrote: >>> 2018-10-19 4:58 GMT+02:00, Leo Izen : >>>> --- >>>> fftools/ffmpeg.c | 8 +++++--- >>>> 1 file changed, 5 insertions(+), 3 deletions(-) >>>> >>>> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c >>>> index da4259a9a8..5d68194676 100644 >>>> --- a/fftools/ffmpeg.c >>>> +++ b/fftools/ffmpeg.c >>>> @@ -2045,12 +2045,14 @@ static void do_streamcopy(InputStream *ist, >>>> OutputStream *ost, const AVPacket *p >>>> if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO) >>>> ost->sync_opts++; >>>> >>>> - if (pkt->pts != AV_NOPTS_VALUE) >>>> + if (ist->framerate.num) >>>> + opkt.pts = av_rescale_q(ist->pts, AV_TIME_BASE_Q, >>>> ost->mux_timebase) - ost_tb_start_time; >>>> + else if (pkt->pts != AV_NOPTS_VALUE) >>>> opkt.pts = av_rescale_q(pkt->pts, ist->st->time_base, >>>> ost->mux_timebase) - ost_tb_start_time; >>>> else >>>> opkt.pts = AV_NOPTS_VALUE; >>>> >>>> - if (pkt->dts == AV_NOPTS_VALUE) >>>> + if (pkt->dts == AV_NOPTS_VALUE || ist->framerate.num) >>>> opkt.dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, >>>> ost->mux_timebase); >>>> else >>>> opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, >>>> ost->mux_timebase); >>>> @@ -2602,7 +2604,7 @@ static int process_input_packet(InputStream *ist, >>>> const AVPacket *pkt, int no_eo >>>> avpkt = *pkt; >>>> } >>>> >>>> - if (pkt && pkt->dts != AV_NOPTS_VALUE) { >>>> + if (pkt && pkt->dts != AV_NOPTS_VALUE && !ist->framerate.num) { >>>> ist->next_dts = ist->dts = av_rescale_q(pkt->dts, >>>> ist->st->time_base, AV_TIME_BASE_Q); >>>> if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_VIDEO || >>>> !ist->decoding_needed) >>>> ist->next_pts = ist->pts = ist->dts; >>> How can this be tested? >>> >>> Carl Eugen >> I'm not entirely sure. I ran "make fate" and it passed, and I >> successfully rescaled a 30fps clip to 15fps, 20fps, 45fps, and 60fps >> using -r:v as an input option. I'm not entirely sure what the standard >> procedure is for performing more rigorous tests. > What I meant was: > Which kind of input and output did you use to test your patch? > > Carl Eugen > _______________________________________________ It worked perfectly at various framerates for AVI files. It also worked in practice for MP4 and Matroska files, although my patch doesn't properly set the avg_frame_rate and r_frame_rate of the output stream. Intelligent players like MPV play it fine and ignore the incorrect *_frame_rate metadata. Anyway, here's an updated patch that fixes that problem so it shouldn't be an issue. Leo Izen ---  fftools/ffmpeg.c | 19 ++++++++++++++-----  1 file changed, 14 insertions(+), 5 deletions(-)          opkt.dts = av_rescale_q(ist->dts, AV_TIME_BASE_Q, ost->mux_timebase);      else          opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->mux_timebase); @@ -2602,7 +2604,7 @@ static int process_input_packet(InputStream *ist, const AVPacket *pkt, int no_eo          avpkt = *pkt;      } -    if (pkt && pkt->dts != AV_NOPTS_VALUE) { +    if (pkt && pkt->dts != AV_NOPTS_VALUE && !ist->framerate.num) {          ist->next_dts = ist->dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q);          if (ist->dec_ctx->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed)              ist->next_pts = ist->pts = ist->dts; @@ -3158,8 +3160,15 @@ static int init_output_stream_streamcopy(OutputStream *ost)          else              sar = par_src->sample_aspect_ratio;          ost->st->sample_aspect_ratio = par_dst->sample_aspect_ratio = sar; -        ost->st->avg_frame_rate = ist->st->avg_frame_rate; -        ost->st->r_frame_rate = ist->st->r_frame_rate; + +        if (ist->framerate.num) { +            ost->st->avg_frame_rate = ist->framerate; +            ost->st->r_frame_rate = ist->framerate; +        } else { +            ost->st->avg_frame_rate = ist->st->avg_frame_rate; +            ost->st->r_frame_rate = ist->st->r_frame_rate; +        } +          break;      } diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index da4259a9a8..6e81716795 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -2045,12 +2045,14 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p      if (ost->enc_ctx->codec_type == AVMEDIA_TYPE_VIDEO)          ost->sync_opts++; -    if (pkt->pts != AV_NOPTS_VALUE) +    if (ist->framerate.num) +        opkt.pts = av_rescale_q(ist->pts, AV_TIME_BASE_Q, ost->mux_timebase) - ost_tb_start_time; +    else if (pkt->pts != AV_NOPTS_VALUE)          opkt.pts = av_rescale_q(pkt->pts, ist->st->time_base, ost->mux_timebase) - ost_tb_start_time;      else          opkt.pts = AV_NOPTS_VALUE; -    if (pkt->dts == AV_NOPTS_VALUE) +    if (pkt->dts == AV_NOPTS_VALUE || ist->framerate.num)