[FFmpeg-devel] ffmpeg: Integrate two checks

Submitted by Andreas Rheinhardt on June 29, 2019, 10:34 p.m.

Details

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

Commit Message

Andreas Rheinhardt June 29, 2019, 10:34 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>
---
 fftools/ffmpeg.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Comments

Michael Niedermayer July 1, 2019, 4:35 p.m.
On Sun, Jun 30, 2019 at 12:34:06AM +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>
> ---
>  fftools/ffmpeg.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
> index 01f04103cf..755bc05bc1 100644
> --- a/fftools/ffmpeg.c
> +++ b/fftools/ffmpeg.c
> @@ -2044,20 +2044,18 @@ 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;
> -    }
> +                                               (AVRational){1, ist->dec_ctx->sample_rate}, duration,
> +                                               &ist->filter_in_rescale_delta_last, ost->mux_timebase);
> +    } else
> +        opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->mux_timebase);
> +    opkt.dts -= ost_tb_start_time;

Is this intended to have no effect on the output ?
it does have an effect, opkt.pts differs by ost_tb_start_time

thanks

[...]

Patch hide | download patch | download mbox

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 01f04103cf..755bc05bc1 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2044,20 +2044,18 @@  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;
-    }
+                                               (AVRational){1, ist->dec_ctx->sample_rate}, duration,
+                                               &ist->filter_in_rescale_delta_last, ost->mux_timebase);
+    } 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);