[FFmpeg-devel] [PATCH] doc/examples/filtering_video: switch to new decoding API
Matthieu Bouron
matthieu.bouron at gmail.com
Thu Mar 30 14:35:47 EEST 2017
On Wed, Mar 29, 2017 at 3:37 PM, wm4 <nfxjfg at googlemail.com> wrote:
> On Wed, 29 Mar 2017 15:03:55 +0200
> Matthieu Bouron <matthieu.bouron at gmail.com> wrote:
>
> > ---
> > doc/examples/filtering_video.c | 32 ++++++++++++++++++++++++++------
> > 1 file changed, 26 insertions(+), 6 deletions(-)
> >
> > diff --git a/doc/examples/filtering_video.c b/doc/examples/filtering_
> video.c
> > index 15116d3881..b664c69f9d 100644
> > --- a/doc/examples/filtering_video.c
> > +++ b/doc/examples/filtering_video.c
> > @@ -211,6 +211,7 @@ int main(int argc, char **argv)
> > {
> > int ret;
> > AVPacket packet;
> > + int keep_packet = 0;
> > AVFrame *frame = av_frame_alloc();
> > AVFrame *filt_frame = av_frame_alloc();
> > int got_frame;
> > @@ -234,14 +235,30 @@ int main(int argc, char **argv)
> >
> > /* read all packets */
> > while (1) {
> > - if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
> > - break;
> > + if (!keep_packet) {
> > + if ((ret = av_read_frame(fmt_ctx, &packet)) < 0)
> > + break;
> > + keep_packet = 1;
> > + }
> >
> > if (packet.stream_index == video_stream_index) {
> > got_frame = 0;
> > - ret = avcodec_decode_video2(dec_ctx, frame, &got_frame,
> &packet);
> > - if (ret < 0) {
> > - av_log(NULL, AV_LOG_ERROR, "Error decoding video\n");
> > +
> > + ret = avcodec_send_packet(dec_ctx, &packet);
> > + if (ret >= 0) {
> > + keep_packet = 0;
> > + } else if (ret != AVERROR(EAGAIN) && ret != AVERROR_EOF) {
>
> If you have packets after the decoder entered the EOF state, you
> probably want to discard them. Either that, or reset the decoder after
> it's flushed and start over. Anyway, normally this shouldn't happen.
>
> You could also avoid the keep_packet business by running receive_frame
> in a loop after send_packet (then send_packet can never fail with
> EAGAIN).
>
> > + av_log(NULL, AV_LOG_ERROR, "Error while sending a
> packet to the decoder\n");
> > + break;
> > + }
> > +
> > + ret = avcodec_receive_frame(dec_ctx, frame);
> > + if (ret >= 0) {
> > + got_frame = 1;
> > + } else if (ret == AVERROR_EOF) {
> > + break;
> > + } else if (ret != AVERROR(EAGAIN)) {
> > + av_log(NULL, AV_LOG_ERROR, "Error while receiving a
> frame from the decoder\n");
> > break;
> > }
> >
> > @@ -266,8 +283,11 @@ int main(int argc, char **argv)
> > }
> > av_frame_unref(frame);
> > }
> > + } else {
> > + keep_packet = 0;
> > }
> > - av_packet_unref(&packet);
> > + if (!keep_packet)
> > + av_packet_unref(&packet);
> > }
> > end:
> > avfilter_graph_free(&filter_graph);
>
> Otherwise should work.
>
New patch attached (removing the keep_packet logic).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-doc-examples-filtering_video-switch-to-new-decoding-.patch
Type: text/x-patch
Size: 3712 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20170330/d90337b9/attachment.bin>
More information about the ffmpeg-devel
mailing list