[FFmpeg-cvslog] avformat/matroskaenc: Don't override samplerate for CodecDelay
Andreas Rheinhardt
git at videolan.org
Mon Sep 5 21:51:01 EEST 2022
ffmpeg | branch: master | Andreas Rheinhardt <andreas.rheinhardt at outlook.com> | Mon Aug 29 23:00:48 2022 +0200| [be0a2515ab25e4531464f84c4c4d5a97e1a3e8ef] | committer: Andreas Rheinhardt
avformat/matroskaenc: Don't override samplerate for CodecDelay
Opus can be decoded to multiple samplerates (namely 48kHz, 24KHz,
16Khz, 12 KHz and 8Khz); libopus as well as our encoder wrapper
support these sample rates. The OpusHead contains a field for
this original samplerate. Yet the pre-skip (and the granule-position
in the Ogg-Opus mapping in general) are always in the 48KHz clock,
irrespective of the original sample rate.
Before commit c3c22bee6362737cf290929b7f31df9fb88da983, our libopus
encoder was buggy: It did not account for the fact that the pre-skip
field is always according to a 48kHz clock and wrote a too small
value in case one uses the encoder with a sample rate other than 48kHz;
this discrepancy between CodecDelay and OpusHead led to Firefox
rejecting such streams.
In order to account for that, said commit made the muxer always use
48kHz instead of the actual sample rate to convert the initial_padding
(in samples in the stream's sample rate) to ns. This meant that both
fields are now off by the same factor, so Firefox was happy.
Then commit f4bdeddc3cab807e43e0450744dfe9a45661e1d7 fixed the issue
in libopusenc; so the OpusHead is correct, but the CodecDelay is
still off*. This commit fixes this by effectively reverting
c3c22bee6362737cf290929b7f31df9fb88da983.
*: Firefox seems to no longer abort when CodecDelay and OpusHead
are off.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=be0a2515ab25e4531464f84c4c4d5a97e1a3e8ef
---
libavformat/matroskaenc.c | 2 +-
libavformat/version.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index de6c993e6a..c525edb39f 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1830,7 +1830,7 @@ static int mkv_write_track(AVFormatContext *s, MatroskaMuxContext *mkv,
case AVMEDIA_TYPE_AUDIO:
if (par->initial_padding && par->codec_id == AV_CODEC_ID_OPUS) {
int64_t codecdelay = av_rescale_q(par->initial_padding,
- (AVRational){ 1, 48000 },
+ (AVRational){ 1, par->sample_rate },
(AVRational){ 1, 1000000000 });
if (codecdelay < 0) {
av_log(s, AV_LOG_ERROR, "Initial padding is invalid\n");
diff --git a/libavformat/version.h b/libavformat/version.h
index 7b414039ad..a54ffd6c0e 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -32,7 +32,7 @@
#include "version_major.h"
#define LIBAVFORMAT_VERSION_MINOR 30
-#define LIBAVFORMAT_VERSION_MICRO 100
+#define LIBAVFORMAT_VERSION_MICRO 101
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
More information about the ffmpeg-cvslog
mailing list