SHOW:
|
|
- or go back to the newest paste.
1 | #include <stdio.h> | |
2 | #include <stdlib.h> | |
3 | #include <string.h> | |
4 | #include <libavformat/avformat.h> | |
5 | ||
6 | AVOutputFormat *get_yuv4mpeg_format() { | |
7 | AVOutputFormat *format = NULL; | |
8 | while((format = av_oformat_next(format))) { | |
9 | if(strcmp(format->name, "yuv4mpegpipe") == 0) { | |
10 | return format; | |
11 | } | |
12 | } | |
13 | return NULL; | |
14 | } | |
15 | ||
16 | int main(int argc, char *argv[]) { | |
17 | av_register_all(); | |
18 | char *filename = "test.y4m"; | |
19 | ||
20 | AVFormatContext *fc = avformat_alloc_context(); | |
21 | fc->oformat = get_yuv4mpeg_format(); | |
22 | if(!fc->oformat) { | |
23 | fprintf(stderr, "Could not find yuv4mpeg\n"); | |
24 | exit(1); | |
25 | } | |
26 | snprintf(fc->filename, sizeof(fc->filename), "%s", filename); | |
27 | ||
28 | AVCodecContext *c; | |
29 | AVStream *st; | |
30 | if (fc->oformat->video_codec != CODEC_ID_NONE) { | |
31 | st = avformat_new_stream(fc, 0); | |
32 | c = st->codec; | |
33 | c->codec_id = fc->oformat->video_codec; | |
34 | c->codec_type = AVMEDIA_TYPE_VIDEO; | |
35 | c->pix_fmt = PIX_FMT_YUV420P; | |
36 | c->width = 352; | |
37 | c->height = 288; | |
38 | } | |
39 | ||
40 | ||
41 | if (!(fc->oformat->flags & AVFMT_NOFILE)) { | |
42 | if (avio_open(&fc->pb, filename, URL_WRONLY) < 0) { | |
43 | fprintf(stderr, "Could not open '%s'\n", filename); | |
44 | exit(1); | |
45 | } | |
46 | } | |
47 | ||
48 | fc->oformat->write_header(fc); | |
49 | ||
50 | return 0; | |
51 | - | } |
51 | + | |
52 | ||
53 | #if 0 | |
54 | Backtrace: | |
55 | #0 0x00007ffff7b9c185 in ?? () from /usr/lib/x86_64-linux-gnu/libavformat.so.53 | |
56 | #1 0x0000000000400ac6 in main (argc=1, argv=0x7fffffffe0e8) at test.c:48 | |
57 | #endif |