diff mbox series

[FFmpeg-devel,2/8] fftools/ffmpeg: stop using AVCodecContext.sample_rate in decode_audio()

Message ID 20230104164246.6133-2-anton@khirnov.net
State Accepted
Commit c60941dfafbebbfcdb039aa3cd783c0b60562bce
Headers show
Series [FFmpeg-devel,1/8] doc/ffmpeg.texi: drop a non-existent option | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Jan. 4, 2023, 4:42 p.m. UTC
Use the decoded frame's sample_rate instead, which is the authoritative
value.

Drop a now-obsolete check validating AVCodecContext.sample_rate.
---
 fftools/ffmpeg.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Comments

Michael Niedermayer Jan. 5, 2023, 12:46 a.m. UTC | #1
On Wed, Jan 04, 2023 at 05:42:40PM +0100, Anton Khirnov wrote:
> Use the decoded frame's sample_rate instead, which is the authoritative
> value.
> 
> Drop a now-obsolete check validating AVCodecContext.sample_rate.
> ---
>  fftools/ffmpeg.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)

Causes division by 0 
will send you the sample privately

thx

[...]
Anton Khirnov Jan. 5, 2023, 11:09 a.m. UTC | #2
Quoting Michael Niedermayer (2023-01-05 01:46:45)
> On Wed, Jan 04, 2023 at 05:42:40PM +0100, Anton Khirnov wrote:
> > Use the decoded frame's sample_rate instead, which is the authoritative
> > value.
> > 
> > Drop a now-obsolete check validating AVCodecContext.sample_rate.
> > ---
> >  fftools/ffmpeg.c | 15 ++++++---------
> >  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> Causes division by 0 
> will send you the sample privately

Should be fixed in the patchset I just sent.

IMO lavc returning invalid frames is a bug that should be fixed in lavc,
so this patch should still go in.
diff mbox series

Patch

diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c
index 881d6f0af2..2dbfeca020 100644
--- a/fftools/ffmpeg.c
+++ b/fftools/ffmpeg.c
@@ -2017,11 +2017,6 @@  static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output,
     if (ret < 0)
         *decode_failed = 1;
 
-    if (ret >= 0 && avctx->sample_rate <= 0) {
-        av_log(avctx, AV_LOG_ERROR, "Sample rate %d invalid\n", avctx->sample_rate);
-        ret = AVERROR_INVALIDDATA;
-    }
-
     if (ret != AVERROR_EOF)
         check_decode_result(ist, got_output, ret);
 
@@ -2034,9 +2029,9 @@  static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output,
     /* increment next_dts to use for the case where the input stream does not
        have timestamps or there are multiple frames in the packet */
     ist->next_pts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
-                     avctx->sample_rate;
+                     decoded_frame->sample_rate;
     ist->next_dts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) /
-                     avctx->sample_rate;
+                     decoded_frame->sample_rate;
 
     if (decoded_frame->pts != AV_NOPTS_VALUE) {
         decoded_frame_tb   = ist->st->time_base;
@@ -2054,8 +2049,10 @@  static int decode_audio(InputStream *ist, AVPacket *pkt, int *got_output,
         ist->prev_pkt_pts = pkt->pts;
     if (decoded_frame->pts != AV_NOPTS_VALUE)
         decoded_frame->pts = av_rescale_delta(decoded_frame_tb, decoded_frame->pts,
-                                              (AVRational){1, avctx->sample_rate}, decoded_frame->nb_samples, &ist->filter_in_rescale_delta_last,
-                                              (AVRational){1, avctx->sample_rate});
+                                              (AVRational){1, decoded_frame->sample_rate},
+                                              decoded_frame->nb_samples,
+                                              &ist->filter_in_rescale_delta_last,
+                                              (AVRational){1, decoded_frame->sample_rate});
     ist->nb_samples = decoded_frame->nb_samples;
     err = send_frame_to_filters(ist, decoded_frame);