[FFmpeg-devel] [PATCH] libavformat: Add H264 API test
Ronald S. Bultje
rsbultje at gmail.com
Tue Jun 23 15:30:05 CEST 2015
Hi,
On Tue, Jun 23, 2015 at 9:27 AM, wm4 <nfxjfg at googlemail.com> wrote:
> On Tue, 23 Jun 2015 16:05:38 +0300
> Ludmila Glinskih <lglinskih at gmail.com> wrote:
>
> > Result differs in pkt_duration and time_base.den for some reason.
> > Right now it tests only one example (adjusted to match the output).
> >
> > Signed-off-by: Ludmila Glinskih <lglinskih at gmail.com>
> > ---
> > libavformat/Makefile | 1 +
> > libavformat/api-h264-test.c | 187
> ++++++++++++++++++++++++++++++++++++++++++++
> > tests/fate/libavformat.mak | 4 +
> > tests/ref/fate/api-h264 | 18 +++++
> > 4 files changed, 210 insertions(+)
> > create mode 100644 libavformat/api-h264-test.c
> > create mode 100644 tests/ref/fate/api-h264
> >
> > diff --git a/libavformat/Makefile b/libavformat/Makefile
> > index 993ec09..5cc0f6c 100644
> > --- a/libavformat/Makefile
> > +++ b/libavformat/Makefile
> > @@ -547,6 +547,7 @@ TESTPROGS = seek
> \
> > url
> \
> >
> > TESTPROGS-$(CONFIG_NETWORK) += noproxy
> > +TESTPROGS-yes += api-h264
> > TESTPROGS-$(CONFIG_FFRTMPCRYPT_PROTOCOL) += rtmpdh
> >
> > TOOLS = aviocat
> \
> > diff --git a/libavformat/api-h264-test.c b/libavformat/api-h264-test.c
> > new file mode 100644
> > index 0000000..ac4acc4
> > --- /dev/null
> > +++ b/libavformat/api-h264-test.c
> > @@ -0,0 +1,187 @@
> > +/*
> > + * Copyright (c) 2015 Ludmila Glinskih
> > + *
> > + * Permission is hereby granted, free of charge, to any person
> obtaining a copy
> > + * of this software and associated documentation files (the
> "Software"), to deal
> > + * in the Software without restriction, including without limitation
> the rights
> > + * to use, copy, modify, merge, publish, distribute, sublicense, and/or
> sell
> > + * copies of the Software, and to permit persons to whom the Software is
> > + * furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be
> included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
> SHALL
> > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
> OTHER
> > + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
> ARISING FROM,
> > + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
> DEALINGS IN
> > + * THE SOFTWARE.
> > + */
> > +
> > +/**
> > + * H264 codec test.
> > + */
> > +
> > +#include "libavutil/adler32.h"
> > +#include "libavcodec/avcodec.h"
> > +#include "libavformat/avformat.h"
> > +#include "libavutil/imgutils.h"
> > +
> > +static int video_decode_example(const char *input_filename)
> > +{
> > + AVCodec *codec = NULL;
> > + AVCodecContext *origin_ctx = NULL, *ctx= NULL;
> > + AVFrame *fr = NULL;
> > + uint8_t *byte_buffer = NULL;
> > + AVPacket pkt;
> > + AVFormatContext *fmt_ctx = NULL;
> > + int number_of_written_bytes;
> > + int video_stream;
> > + int get_frame = 0;
> > + int byte_buffer_size;
> > + int i = 0;
> > + int result;
> > +
> > + result = avformat_open_input(&fmt_ctx, input_filename, NULL, NULL);
> > + if (result < 0) {
> > + av_log(NULL, AV_LOG_ERROR, "Can't open file\n");
> > + return result;
> > + }
> > +
> > + result = avformat_find_stream_info(fmt_ctx, NULL);
> > + if (result < 0) {
> > + av_log(NULL, AV_LOG_ERROR, "Can't get stream info\n");
> > + return result;
> > + }
> > +
> > + video_stream = -1;
> > + for (i = 0; i < fmt_ctx->nb_streams; i++) {
> > + if (fmt_ctx->streams[i]->codec->codec_type ==
> AVMEDIA_TYPE_VIDEO) {
> > + video_stream = i;
> > + break;
> > + }
> > + }
> > +
> > + origin_ctx = fmt_ctx->streams[video_stream]->codec;
>
> Maybe error out if video_stream is < 0.
Actually, this should use av_find_best_stream().
Ronald
More information about the ffmpeg-devel
mailing list