[FFmpeg-devel] doc/examples/demuxing.c is broken
Stefano Sabatini
stefasab at gmail.com
Wed Jul 10 11:44:09 CEST 2013
On date Tuesday 2013-07-09 23:21:11 +0200, wm4 encoded:
> There are at least two problems with it wrt. audio: it doesn't attempt
> to decode a packet multiple times, and it doesn't handle planar formats.
>
> Here's a patch to fix the first issue. I'm not sure whether the output
> is fine, because I don't feel like researching how it writes planar
> audio to a file.
> diff --git a/doc/examples/demuxing.c b/doc/examples/demuxing.c
please send git format patch
> index 8a1b69b..774f99c 100644
> --- a/doc/examples/demuxing.c
> +++ b/doc/examples/demuxing.c
> @@ -60,6 +60,7 @@ static int audio_frame_count = 0;
> static int decode_packet(int *got_frame, int cached)
> {
> int ret = 0;
> + int decoded = 0;
>
> if (pkt.stream_index == video_stream_idx) {
> /* decode video frame */
> @@ -68,6 +69,7 @@ static int decode_packet(int *got_frame, int cached)
> fprintf(stderr, "Error decoding video frame\n");
> return ret;
> }
> + decoded = pkt.size;
>
> if (*got_frame) {
> printf("video_frame%s n:%d coded_n:%d pts:%s\n",
> @@ -91,6 +93,7 @@ static int decode_packet(int *got_frame, int cached)
> fprintf(stderr, "Error decoding audio frame\n");
> return ret;
> }
> + decoded = ret;
>
> if (*got_frame) {
> printf("audio_frame%s n:%d nb_samples:%d pts:%s\n",
> @@ -121,6 +124,7 @@ static int decode_packet(int *got_frame, int cached)
> }
> }
>
> + ret = FFMIN(decoded, pkt.size);
> return ret;
return decoded;
?
> }
>
> @@ -293,7 +297,15 @@ int main (int argc, char **argv)
>
> /* read frames from the file */
> while (av_read_frame(fmt_ctx, &pkt) >= 0) {
> - decode_packet(&got_frame, 0);
> + AVPacket orig = pkt;
> + do {
> + ret = decode_packet(&got_frame, 0);
> + if (ret < 0)
> + break;
> + pkt.data += ret;
> + pkt.size -= ret;
> + } while (pkt.size > 0);
> + pkt = orig;
> av_free_packet(&pkt);
Slightly simpler:
AVPacket orig_pkt = pkt;
do {
...
} while (pkt.size > 0)
av_free_packet(&orig_pkt);
--
FFmpeg = Fanciful & Formidable Monstrous Political Enlightened Gadget
More information about the ffmpeg-devel
mailing list