You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-08-15 14:13:16 +02:00
examples/decode_video: switch to the new decoding API
This commit is contained in:
@@ -54,15 +54,23 @@ static void decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket *pkt,
|
|||||||
const char *filename)
|
const char *filename)
|
||||||
{
|
{
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
int ret, got_picture;
|
int ret;
|
||||||
|
|
||||||
while (pkt->size > 0) {
|
ret = avcodec_send_packet(dec_ctx, pkt);
|
||||||
ret = avcodec_decode_video2(dec_ctx, frame, &got_picture, pkt);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
fprintf(stderr, "Error while decoding frame %d\n", dec_ctx->frame_number);
|
fprintf(stderr, "Error sending a packet for decoding\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
if (got_picture) {
|
|
||||||
|
while (ret >= 0) {
|
||||||
|
ret = avcodec_receive_frame(dec_ctx, frame);
|
||||||
|
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
|
||||||
|
return;
|
||||||
|
else if (ret < 0) {
|
||||||
|
fprintf(stderr, "Error during decoding\n");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
printf("saving frame %3d\n", dec_ctx->frame_number);
|
printf("saving frame %3d\n", dec_ctx->frame_number);
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
@@ -72,9 +80,6 @@ static void decode(AVCodecContext *dec_ctx, AVFrame *frame, AVPacket *pkt,
|
|||||||
pgm_save(frame->data[0], frame->linesize[0],
|
pgm_save(frame->data[0], frame->linesize[0],
|
||||||
frame->width, frame->height, buf);
|
frame->width, frame->height, buf);
|
||||||
}
|
}
|
||||||
pkt->size -= ret;
|
|
||||||
pkt->data += ret;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
@@ -161,9 +166,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* flush the decoder */
|
/* flush the decoder */
|
||||||
avpkt.data = NULL;
|
decode(c, picture, NULL, outfilename);
|
||||||
avpkt.size = 0;
|
|
||||||
decode(c, picture, &avpkt, outfilename);
|
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user