summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/video_decode.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/video_decode.c b/src/video_decode.c
index 7ce6f42..b923f93 100644
--- a/src/video_decode.c
+++ b/src/video_decode.c
@@ -117,7 +117,7 @@ video_decode_get_frame(struct video_decode *_vd, struct video_frame **frame)
struct video_decode_priv *vd = (struct video_decode_priv *) _vd;
struct video_frame_priv *f;
AVPacket packet;
- int decoded, got_picture;
+ int decoded, got_picture = 0;
int ret;
if (*frame != NULL) {
@@ -131,8 +131,6 @@ video_decode_get_frame(struct video_decode *_vd, struct video_frame **frame)
packet.data = NULL;
do {
- if (packet.data != NULL)
- av_free_packet(&packet);
ret = av_read_frame(vd->fmt_ctx, &packet);
if (ret < 0) {
if (ret == AVERROR_EOF) {
@@ -148,28 +146,25 @@ video_decode_get_frame(struct video_decode *_vd, struct video_frame **frame)
#endif
return -1;
}
- } while (packet.stream_index != vd->stream);
-
- do {
+ if (packet.stream_index == vd->stream) {
#if DEBUG
- printf("packet.data: %p, packet.siz: %d, packet.strm_idx: %d\n",
- packet.data, packet.size, packet.stream_index);
+ printf("packet.data: %p, packet.siz: %d, packet.strm_idx: %d\n",
+ packet.data, packet.size, packet.stream_index);
#endif
- decoded = avcodec_decode_video2(vd->codec_ctx, f->frame,
- &got_picture, &packet);
- if (decoded < 0) {
- fprintf(stderr, "Error while decoding frame!\n");
- return -2;
- }
+ decoded = avcodec_decode_video2(vd->codec_ctx, f->frame,
+ &got_picture, &packet);
+ if (decoded < 0) {
+ fprintf(stderr, "Error while decoding frame!\n");
+ return -2;
+ }
+
#if DEBUG
- printf("bytes_decoded: %d, got_picture: %d\n",
- decoded, got_picture);
+ printf("bytes_decoded: %d, got_picture: %d\n",
+ decoded, got_picture);
#endif
-
- } while (got_picture == 0 && packet.size > 0);
- av_free_packet(&packet);
- if (got_picture == 0)
- return -3;
+ }
+ av_free_packet(&packet);
+ } while (got_picture == 0);
f->base.data = f->frame->data[0];
f->base.width = vd->codec_ctx->width;