[FFmpeg-devel] UDP TS feed switching from EAC3 to AC3 audio
ryaowe at gmail.com
Thu Sep 18 22:35:42 CEST 2014
I have a TS feed that I'm reading with libavformat/libavcodec over
multicast. The feed comes from an over-the-air channel, where the video is
mpeg2 and the audio is AC3.
Occasionally there are some dropped packets, and that somehow leads
libavcodec/ac3_parser.c to think the audio codec has changed to EAC3.
When this happens, I call avcodec_open2 with the new codec info, but it
fails with the error "invalid extradata size" (the extradata size is 0).
That is probably to be expected, because the audio frame is invalid due to
the dropped packets anyway.
The problem comes when the next valid audio frame arrives. ac3_parser.c
has this logic in ac3_sync():
hdr_info->codec_id = AV_CODEC_ID_EAC3;
else if (hdr_info->codec_id == AV_CODEC_ID_NONE)
hdr_info->codec_id = AV_CODEC_ID_AC3;
Because of the previous bad frame, hdr_info->codec_id got switched to
AV_CODEC_ID_EAC3. But because of the "else if" condition, it can't switch
back to AV_CODEC_ID_AC3. Even though the new frame is valid, avcodec_open2
continues to fail because EAC3 doesn't like the extradata size to be 0.
I'm wondering if it would be ok to change the "else if" to just an "else",
or if that would break some other scenario. I don't know enough about
AC3/EAC3 to understand why it shouldn't switch back to AC3.
Any suggestions on how to work around this problem?
More information about the ffmpeg-devel