[FFmpeg-devel] ffmpeg: Integrate two checks

Submitted by Andreas Rheinhardt on July 1, 2019, 9:04 p.m.

Details

Message ID 20190701210443.2614-1-andreas.rheinhardt@gmail.com
State New
Headers show

Commit Message

Andreas Rheinhardt July 1, 2019, 9:04 p.m.
For audio packets with dts != AV_NOPTS_VALUE the dts the dts was
converted twice to the muxer's timebase during streamcopy, once as a
normal packet and once specifically as an audio packet. This has been
changed.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
You are right. Seems that this is not covered by fate.

 fftools/ffmpeg.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

Comments

Michael Niedermayer July 3, 2019, 7:50 p.m.
On Mon, Jul 01, 2019 at 11:04:43PM +0200, Andreas Rheinhardt wrote:
> For audio packets with dts != AV_NOPTS_VALUE the dts the dts was
> converted twice to the muxer's timebase during streamcopy, once as a
> normal packet and once specifically as an audio packet. This has been
> changed.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
> You are right. Seems that this is not covered by fate.
> 
>  fftools/ffmpeg.c | 19 +++++++++----------
>  1 file changed, 9 insertions(+), 10 deletions(-)
> 
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 01f04103cf..f81b1b3983 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -2044,20 +2044,19 @@ static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
>      else
>          opkt.pts = AV_NOPTS_VALUE;
>  
> -    if (pkt->dts == AV_NOPTS_VALUE)
> +    if (pkt->dts == AV_NOPTS_VALUE) {
>          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);
> -    opkt.dts -= ost_tb_start_time;
> -
> -    if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && pkt->dts != AV_NOPTS_VALUE) {
> +    } else if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
>          int duration = av_get_audio_frame_duration(ist->dec_ctx, pkt->size);
>          if(!duration)
>              duration = ist->dec_ctx->frame_size;
> -        opkt.dts = opkt.pts = av_rescale_delta(ist->st->time_base, pkt->dts,
> -                                               (AVRational){1, ist->dec_ctx->sample_rate}, duration, &ist->filter_in_rescale_delta_last,
> -                                               ost->mux_timebase) - ost_tb_start_time;
> -    }
> +        opkt.dts = av_rescale_delta(ist->st->time_base, pkt->dts,
> +                                    (AVRational){1, ist->dec_ctx->sample_rate}, duration,
> +                                    &ist->filter_in_rescale_delta_last, ost->mux_timebase);


> +        opkt.pts = opkt.dts - ost_tb_start_time;

this is ugly and confusing. As this introduces a difference betweem pts and dts
just because the adjustment for dts is factored out into a few lines later


> +    } else
> +        opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->mux_timebase);
> +    opkt.dts -= ost_tb_start_time;
>  
>      opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->mux_timebase);

[...]

Patch hide | download patch | download mbox

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 01f04103cf..f81b1b3983 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2044,20 +2044,19 @@  static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *p
     else
         opkt.pts = AV_NOPTS_VALUE;
 
-    if (pkt->dts == AV_NOPTS_VALUE)
+    if (pkt->dts == AV_NOPTS_VALUE) {
         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);
-    opkt.dts -= ost_tb_start_time;
-
-    if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && pkt->dts != AV_NOPTS_VALUE) {
+    } else if (ost->st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
         int duration = av_get_audio_frame_duration(ist->dec_ctx, pkt->size);
         if(!duration)
             duration = ist->dec_ctx->frame_size;
-        opkt.dts = opkt.pts = av_rescale_delta(ist->st->time_base, pkt->dts,
-                                               (AVRational){1, ist->dec_ctx->sample_rate}, duration, &ist->filter_in_rescale_delta_last,
-                                               ost->mux_timebase) - ost_tb_start_time;
-    }
+        opkt.dts = av_rescale_delta(ist->st->time_base, pkt->dts,
+                                    (AVRational){1, ist->dec_ctx->sample_rate}, duration,
+                                    &ist->filter_in_rescale_delta_last, ost->mux_timebase);
+        opkt.pts = opkt.dts - ost_tb_start_time;
+    } else
+        opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->mux_timebase);
+    opkt.dts -= ost_tb_start_time;
 
     opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->mux_timebase);