doc/examples/filtering_video: switch to new decoding API
This commit is contained in:
parent
b22c4d822b
commit
afd257b43f
@ -213,7 +213,6 @@ int main(int argc, char **argv)
|
|||||||
AVPacket packet;
|
AVPacket packet;
|
||||||
AVFrame *frame = av_frame_alloc();
|
AVFrame *frame = av_frame_alloc();
|
||||||
AVFrame *filt_frame = av_frame_alloc();
|
AVFrame *filt_frame = av_frame_alloc();
|
||||||
int got_frame;
|
|
||||||
|
|
||||||
if (!frame || !filt_frame) {
|
if (!frame || !filt_frame) {
|
||||||
perror("Could not allocate frame");
|
perror("Could not allocate frame");
|
||||||
@ -238,33 +237,42 @@ int main(int argc, char **argv)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
if (packet.stream_index == video_stream_index) {
|
if (packet.stream_index == video_stream_index) {
|
||||||
got_frame = 0;
|
ret = avcodec_send_packet(dec_ctx, &packet);
|
||||||
ret = avcodec_decode_video2(dec_ctx, frame, &got_frame, &packet);
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
av_log(NULL, AV_LOG_ERROR, "Error decoding video\n");
|
av_log(NULL, AV_LOG_ERROR, "Error while sending a packet to the decoder\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (got_frame) {
|
while (ret >= 0) {
|
||||||
frame->pts = av_frame_get_best_effort_timestamp(frame);
|
ret = avcodec_receive_frame(dec_ctx, frame);
|
||||||
|
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {
|
||||||
/* push the decoded frame into the filtergraph */
|
|
||||||
if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) {
|
|
||||||
av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
|
|
||||||
break;
|
break;
|
||||||
|
} else if (ret < 0) {
|
||||||
|
av_log(NULL, AV_LOG_ERROR, "Error while receiving a frame from the decoder\n");
|
||||||
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pull filtered frames from the filtergraph */
|
if (ret >= 0) {
|
||||||
while (1) {
|
frame->pts = av_frame_get_best_effort_timestamp(frame);
|
||||||
ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
|
|
||||||
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
|
/* push the decoded frame into the filtergraph */
|
||||||
|
if (av_buffersrc_add_frame_flags(buffersrc_ctx, frame, AV_BUFFERSRC_FLAG_KEEP_REF) < 0) {
|
||||||
|
av_log(NULL, AV_LOG_ERROR, "Error while feeding the filtergraph\n");
|
||||||
break;
|
break;
|
||||||
if (ret < 0)
|
}
|
||||||
goto end;
|
|
||||||
display_frame(filt_frame, buffersink_ctx->inputs[0]->time_base);
|
/* pull filtered frames from the filtergraph */
|
||||||
av_frame_unref(filt_frame);
|
while (1) {
|
||||||
|
ret = av_buffersink_get_frame(buffersink_ctx, filt_frame);
|
||||||
|
if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
|
||||||
|
break;
|
||||||
|
if (ret < 0)
|
||||||
|
goto end;
|
||||||
|
display_frame(filt_frame, buffersink_ctx->inputs[0]->time_base);
|
||||||
|
av_frame_unref(filt_frame);
|
||||||
|
}
|
||||||
|
av_frame_unref(frame);
|
||||||
}
|
}
|
||||||
av_frame_unref(frame);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
av_packet_unref(&packet);
|
av_packet_unref(&packet);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user