video - audio sample format s16p, ffmpeg or audio codec bug? -
i have video file , had dumped video info txt file ffmpeg 3 year ago.
... stream #0:1[0x1c0]: audio: mp2, 48000 hz, stereo, s16, 256 kb/s stream #0:2[0x1c1]: audio: mp2, 48000 hz, stereo, s16, 256 kb/s
but found format changed when used update ffprobe (ffprobe version n-78046-g46f67f4 copyright (c) 2007-2016 ffmpeg developers).
... stream #0:1[0x1c0]: audio: mp2, 48000 hz, stereo, s16p, 256 kb/s stream #0:2[0x1c1]: audio: mp2, 48000 hz, stereo, s16p, 256 kb/s
with same video, sample format changes s16p.
i implemented simple video player uses ffmpeg. can play video 3 years ago, failed output correct pcm stream after changing update ffmpeg. spent lots time , found audio should have been s16 instead of s16p. decoded audio stream works after added line before calling avcodec_decode_audio4,
audio_codec_ctx->sample_fmt = av_sample_fmt_s16
but hack. encounter issue? how make ffmpeg work correctly? hint appreciated. thanks!
the output format changed. reason convoluted , technical, let me try explaining anyway.
most audio codecs structured such output of each channel best reconstructed individually, , merging of channels (interleaving of "left" , "right" buffer array of samples ordered left0 right0 left1 right1 [etc]) happens @ end. can imagine if encoder wants deinterleave again, transcoding of audio involves 2 redundant operations (interleaving/deinterleaving). therefore, decoders makes sense switched output planar audio (so s16 changed s16p, p means planar), each channel own buffer.
so: nowadays, interleaving done using resampling library (libswresample) after decoding instead of integral part of decoding, , if user explicitly wants so, rather automatically/always.
you can indeed set request sample format s16 force decoding s16 instead of s16p. consider compatibility hack @ point removed few decoders work, , 1 not work new decoders. instead, consider adding libswresample support application convert between whatever native output format of decoder, , format want use further data processing (e.g. playback using sound card).
Comments
Post a Comment