Ticket #11592: ffmpeg-bug.cpp

File ffmpeg-bug.cpp, 1.5 KB (added by Mika Fischer, 17 months ago)
Line 
1#include <assert.h>
2extern "C" {
3#include <libavcodec/avcodec.h>
4#include <libavcodec/packet.h>
5#include <libavformat/avformat.h>
6#include <libavutil/avutil.h>
7#include <libavutil/frame.h>
8}
9
10static void check(int64_t ret, int64_t expected) {
11 assert(ret == expected);
12}
13
14int main() {
15 AVFormatContext* ic = NULL;
16 check(avformat_open_input(&ic, "D:/videmo360/giftschrank/chromium_testdata/blackwhite_yuv444p.ogv", NULL, NULL), 0);
17 check(avformat_find_stream_info(ic, NULL), 0);
18 check(ic->nb_streams, 1);
19 AVCodecContext* avctx = avcodec_alloc_context3(avcodec_find_decoder(ic->streams[0]->codecpar->codec_id));
20 assert(avctx);
21 avctx->thread_count = 0;
22 check(avcodec_parameters_to_context(avctx, ic->streams[0]->codecpar), 0);
23 check(avcodec_open2(avctx, NULL, NULL), 0);
24
25 AVPacket *pkt = av_packet_alloc(), *pkt2 = av_packet_alloc();
26 check(av_read_frame(ic, pkt), 0);
27 check(av_read_frame(ic, pkt2), AVERROR_EOF);
28
29 AVFrame* frame = av_frame_alloc();
30
31 avcodec_flush_buffers(avctx);
32 check(avcodec_send_packet(avctx, pkt), 0);
33 check(avcodec_send_packet(avctx, nullptr), 0);
34 check(avcodec_receive_frame(avctx, frame), 0);
35 check(avcodec_receive_frame(avctx, frame), AVERROR_EOF);
36
37 avcodec_flush_buffers(avctx);
38 check(avcodec_send_packet(avctx, pkt), 0);
39 check(avcodec_send_packet(avctx, nullptr), 0);
40 check(avcodec_receive_frame(avctx, frame), 0);
41 check(avcodec_receive_frame(avctx, frame), AVERROR_EOF);
42}