Initialize native PCM decoders from mpv codec parameters
The PCM path only copied lav_codecpar or extradata into its decoder context. mpv's native Matroska demuxer stores the sample rate, channel layout and sample depth in mp_codec_params instead. PCM tracks in MKA therefore reached avcodec_open2 with sample_rate=0 and failed before binaural rendering or WAV output could start. Use mp_set_avctx_codec_headers, as ad_lavc does, to initialize the PCM decoder for both native and libavformat demuxers. Check the conversion result and report initialization failures. Keep the renderer, EOF drain and decoder routing unchanged. Verified the failing 48 kHz, 6-channel, 24-bit PCM MKA now exports through the native Matroska path to a stereo float32 binaural WAV with all 37125120 samples (773.44 seconds). WAV and full FLAC exports still reach EOF with their exact sample counts. E-AC-3 JOC and ad-joc-pcm=no output are bit-identical to the baseline in their regression cases.
This commit is contained in:
1 parent
ad9419fa7d
commit
ea0532df88
1 file changed
+7
-10
@@ -43,6 +43,7 @@
|
||||
#include "audio/aframe.h"
|
||||
#include "audio/chmap.h"
|
||||
#include "audio/format.h"
|
||||
#include "common/av_common.h"
|
||||
#include "common/msg.h"
|
||||
#include "demux/packet.h"
|
||||
#include "demux/stheader.h"
|
||||
@@ -1088,16 +1089,12 @@ static struct mp_decoder *create(struct mp_filter *parent,
|
||||
talloc_free(da);
|
||||
return NULL;
|
||||
}
|
||||
if (codec->lav_codecpar) {
|
||||
avcodec_parameters_to_context(p->pcm_avctx, codec->lav_codecpar);
|
||||
} else if (codec->extradata && codec->extradata_size > 0) {
|
||||
p->pcm_avctx->extradata = av_mallocz(codec->extradata_size +
|
||||
AV_INPUT_BUFFER_PADDING_SIZE);
|
||||
if (p->pcm_avctx->extradata) {
|
||||
memcpy(p->pcm_avctx->extradata, codec->extradata,
|
||||
codec->extradata_size);
|
||||
p->pcm_avctx->extradata_size = codec->extradata_size;
|
||||
}
|
||||
/* Native demuxers (e.g. Matroska) supply mpv codec parameters rather
|
||||
* than lav_codecpar. Use the same conversion as ad_lavc for both. */
|
||||
if (mp_set_avctx_codec_headers(p->pcm_avctx, codec) < 0) {
|
||||
MP_ERR(da, "cannot set the '%s' decoder parameters\n", codec->codec);
|
||||
talloc_free(da);
|
||||
return NULL;
|
||||
}
|
||||
p->pcm_avctx->pkt_timebase = (AVRational){1, 48000};
|
||||
if (avcodec_open2(p->pcm_avctx, pcm_lavc, NULL) < 0) {
|
||||
|
||||
Reference in new issue
Block a user