summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/advtime.c2
-rw-r--r--src/frame_to_pgm.c2
-rw-r--r--src/video_decode.c8
-rw-r--r--src/video_decode.h6
4 files changed, 14 insertions, 4 deletions
diff --git a/src/advtime.c b/src/advtime.c
index 402da31..265d18c 100644
--- a/src/advtime.c
+++ b/src/advtime.c
@@ -97,7 +97,7 @@ main(int argc, char **argv)
if (ret < 0)
return -ret;
- for (int i = 0; video_decode_get_frame(vd, &frame_b) == 0; ++i) {
+ for (int i = 0; video_decode_get_frame(vd, &frame_b) > 0; ++i) {
printf("%d\t", i);
diff --git a/src/frame_to_pgm.c b/src/frame_to_pgm.c
index 5295c56..36e9ac8 100644
--- a/src/frame_to_pgm.c
+++ b/src/frame_to_pgm.c
@@ -36,7 +36,7 @@ main(int argc, char **argv)
return -ret;
ret = video_decode_get_frame(vd, &frame);
- if (ret < 0)
+ if (ret < 1)
return -ret;
pgm_save(frame->data, frame->stride, frame->width, frame->height,
diff --git a/src/video_decode.c b/src/video_decode.c
index 4a2eaf4..c1f7c5a 100644
--- a/src/video_decode.c
+++ b/src/video_decode.c
@@ -99,6 +99,7 @@ video_decode_get_frame(struct video_decode *vd, struct video_frame **frame)
struct video_frame_priv *f;
AVPacket packet;
int decoded, got_picture;
+ int ret;
f = calloc(1, sizeof *f);
if (f == NULL)
@@ -108,7 +109,10 @@ video_decode_get_frame(struct video_decode *vd, struct video_frame **frame)
do {
if (packet.data != NULL)
av_free_packet(&packet);
- if (av_read_frame(vd->fmt_ctx, &packet) < 0) {
+ ret = av_read_frame(vd->fmt_ctx, &packet);
+ if (ret < 0) {
+ if (ret == AVERROR_EOF)
+ return 0;
#if DEBUG
fprintf(stderr, "Found no video stream packet!\n");
#endif
@@ -146,7 +150,7 @@ video_decode_get_frame(struct video_decode *vd, struct video_frame **frame)
*frame = &f->base;
- return 0;
+ return 1;
}
void
diff --git a/src/video_decode.h b/src/video_decode.h
index f9cdfb4..2505b8b 100644
--- a/src/video_decode.h
+++ b/src/video_decode.h
@@ -15,6 +15,12 @@ video_decode_init(struct video_decode **vd, char *file, int64_t timestamp);
void
video_decode_uninit(struct video_decode **vd);
+/*
+ * Returns number of decoded frames:
+ * 1 - One frame decoded
+ * 0 - Zero frames decoded - EOF
+ * < 0 - Zero frames decoded - Error
+ */
int
video_decode_get_frame(struct video_decode *vd, struct video_frame **frame);