Ticket #10755: ogg-png-stream.c

File ogg-png-stream.c, 1.5 KB (added by doeme, 3 years ago)

The test program

Line 
1/*
2 * compile: gcc `pkg-config --cflags --libs libavformat libavcodec libavutil` ogg-png-stream.c -o ogg-png-stream
3 * run: ./ogg-png-stream bug-ogg-pngstream-avseek-abort.ogg
4 */
5
6#include <libavcodec/avcodec.h>
7#include <libavformat/avformat.h>
8#include <stdio.h>
9#include <stdarg.h>
10#include <stdlib.h>
11
12int main(int argc, const char *argv[])
13{
14 if (argc < 2) {
15 printf("You need to specify a media file.\n");
16 return -1;
17 }
18
19 AVFormatContext *pFormatContext = avformat_alloc_context();
20 if (!pFormatContext) {
21 return -1;
22 }
23 if (avformat_open_input(&pFormatContext, argv[1], NULL, NULL) != 0) {
24 return -1;
25 }
26
27 if (avformat_find_stream_info(pFormatContext, NULL) < 0) {
28 return -1;
29 }
30
31 // Print the available streams
32 for (int i = 0; i < pFormatContext->nb_streams; i++)
33 {
34 const AVCodecParameters * pLocalCodecParameters = pFormatContext->streams[i]->codecpar;
35 const AVCodecDescriptor *codecDescriptor = avcodec_descriptor_get(pLocalCodecParameters->codec_id);
36
37 printf("stream index %d: id %d, name %s\n", i, codecDescriptor->id, codecDescriptor->name);
38 }
39
40 /* Prints:
41 stream index 0: id 86021, name vorbis
42 stream index 1: id 61, name png
43 */
44
45 printf("Seeking to default stream\n");
46 av_seek_frame(pFormatContext, -1, 0, AVSEEK_FLAG_ANY); // Works
47 printf("Seeking to audio stream\n");
48 av_seek_frame(pFormatContext, 0, 0, AVSEEK_FLAG_ANY); // Works
49 printf("Seeking to video stream\n");
50 av_seek_frame(pFormatContext, 1, 0, AVSEEK_FLAG_ANY); // abort()
51
52 avformat_close_input(&pFormatContext);
53 return 0;
54}