annotate yuv4mpeg.c @ 922:7f20b3ce1100 libavformat

dynamically increase probe buffer until format is detected
author michael
date Thu, 02 Feb 2006 11:27:35 +0000
parents edbe5c3717f9
children 8973dbae81e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
1 /*
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
2 * YUV4MPEG format
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
3 * Copyright (c) 2001, 2002, 2003 Fabrice Bellard.
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
4 *
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
9 *
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
14 *
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
18 */
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
19 #include "avformat.h"
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
20
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
21 #define Y4M_MAGIC "YUV4MPEG2"
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
22 #define Y4M_FRAME_MAGIC "FRAME"
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
23 #define Y4M_LINE_MAX 256
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
24
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 838
diff changeset
25 #ifdef CONFIG_MUXERS
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
26
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
27 static int yuv4_generate_header(AVFormatContext *s, char* buf)
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
28 {
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
29 AVStream *st;
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
30 int width, height;
288
981b0b3c95dd AVRational
michael
parents: 287
diff changeset
31 int raten, rated, aspectn, aspectd, n;
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
32 char inter;
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
33 char *colorspace = "";
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
34
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
35 st = s->streams[0];
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
36 width = st->codec->width;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
37 height = st->codec->height;
85
25062c9b1f86 per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents: 65
diff changeset
38
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
39 av_reduce(&raten, &rated, st->codec->time_base.den, st->codec->time_base.num, (1UL<<31)-1);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
40
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
41 aspectn = st->codec->sample_aspect_ratio.num;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
42 aspectd = st->codec->sample_aspect_ratio.den;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
43
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
44 if ( aspectn == 0 && aspectd == 1 ) aspectd = 0; // 0:0 means unknown
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
45
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
46 inter = 'p'; /* progressive is the default */
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
47 if (st->codec->coded_frame && st->codec->coded_frame->interlaced_frame) {
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
48 inter = st->codec->coded_frame->top_field_first ? 't' : 'b';
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
49 }
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
50
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
51 switch(st->codec->pix_fmt) {
648
340f1911cd54 add luma only support to yuv4mpeg patch by (Roine Gustafsson <roine users.sourceforge net>)
michael
parents: 634
diff changeset
52 case PIX_FMT_GRAY8:
340f1911cd54 add luma only support to yuv4mpeg patch by (Roine Gustafsson <roine users.sourceforge net>)
michael
parents: 634
diff changeset
53 colorspace = " Cmono";
340f1911cd54 add luma only support to yuv4mpeg patch by (Roine Gustafsson <roine users.sourceforge net>)
michael
parents: 634
diff changeset
54 break;
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
55 case PIX_FMT_YUV411P:
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
56 colorspace = " C411 XYSCSS=411";
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
57 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
58 case PIX_FMT_YUV420P:
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
59 colorspace = (st->codec->codec_id == CODEC_ID_DVVIDEO)?" C420paldv XYSCSS=420PALDV":" C420mpeg2 XYSCSS=420MPEG2";
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
60 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
61 case PIX_FMT_YUV422P:
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
62 colorspace = " C422 XYSCSS=422";
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
63 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
64 case PIX_FMT_YUV444P:
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
65 colorspace = " C444 XYSCSS=444";
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
66 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
67 }
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
68
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
69 /* construct stream header, if this is the first frame */
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
70 n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s\n",
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
71 Y4M_MAGIC,
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
72 width,
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
73 height,
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
74 raten, rated,
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
75 inter,
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
76 aspectn, aspectd,
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
77 colorspace);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
78
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
79 return n;
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
80 }
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
81
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 402
diff changeset
82 static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt)
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
83 {
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 402
diff changeset
84 AVStream *st = s->streams[pkt->stream_index];
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
85 ByteIOContext *pb = &s->pb;
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
86 AVPicture *picture;
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
87 int* first_pkt = s->priv_data;
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
88 int width, height, h_chroma_shift, v_chroma_shift;
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
89 int i, m;
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
90 char buf2[Y4M_LINE_MAX+1];
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
91 char buf1[20];
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 18
diff changeset
92 uint8_t *ptr, *ptr1, *ptr2;
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
93
468
60f897e8dd2d pass AVPacket into av_write_frame()
michael
parents: 402
diff changeset
94 picture = (AVPicture *)pkt->data;
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
95
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
96 /* for the first packet we have to output the header as well */
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
97 if (*first_pkt) {
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
98 *first_pkt = 0;
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
99 if (yuv4_generate_header(s, buf2) < 0) {
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
100 av_log(s, AV_LOG_ERROR, "Error. YUV4MPEG stream header write failed.\n");
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
101 return AVERROR_IO;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
102 } else {
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
103 put_buffer(pb, buf2, strlen(buf2));
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
104 }
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
105 }
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
106
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
107 /* construct frame header */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
108
256
2efd6fe95fc6 yuv4mpeg.c extra space patch by ("Steven M. Schultz" <sms at 2BSD dot COM>)
michaelni
parents: 241
diff changeset
109 m = snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC);
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
110 put_buffer(pb, buf1, strlen(buf1));
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
111
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
112 width = st->codec->width;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
113 height = st->codec->height;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
114
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
115 ptr = picture->data[0];
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
116 for(i=0;i<height;i++) {
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
117 put_buffer(pb, ptr, width);
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
118 ptr += picture->linesize[0];
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
119 }
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
120
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
121 if (st->codec->pix_fmt != PIX_FMT_GRAY8){
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
122 // Adjust for smaller Cb and Cr planes
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
123 avcodec_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift, &v_chroma_shift);
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
124 width >>= h_chroma_shift;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
125 height >>= v_chroma_shift;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
126
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
127 ptr1 = picture->data[1];
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
128 ptr2 = picture->data[2];
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
129 for(i=0;i<height;i++) { /* Cb */
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
130 put_buffer(pb, ptr1, width);
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
131 ptr1 += picture->linesize[1];
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
132 }
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
133 for(i=0;i<height;i++) { /* Cr */
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
134 put_buffer(pb, ptr2, width);
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
135 ptr2 += picture->linesize[2];
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
136 }
648
340f1911cd54 add luma only support to yuv4mpeg patch by (Roine Gustafsson <roine users.sourceforge net>)
michael
parents: 634
diff changeset
137 }
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
138 put_flush_packet(pb);
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
139 return 0;
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
140 }
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
141
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
142 static int yuv4_write_header(AVFormatContext *s)
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
143 {
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
144 int* first_pkt = s->priv_data;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
145
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
146 if (s->nb_streams != 1)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
147 return AVERROR_IO;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
148
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
149 if (s->streams[0]->codec->pix_fmt == PIX_FMT_YUV411P) {
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
150 av_log(s, AV_LOG_ERROR, "Warning: generating rarely used 4:1:1 YUV stream, some mjpegtools might not work.\n");
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
151 }
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
152 else if ((s->streams[0]->codec->pix_fmt != PIX_FMT_YUV420P) &&
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
153 (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV422P) &&
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
154 (s->streams[0]->codec->pix_fmt != PIX_FMT_GRAY8) &&
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
155 (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV444P)) {
648
340f1911cd54 add luma only support to yuv4mpeg patch by (Roine Gustafsson <roine users.sourceforge net>)
michael
parents: 634
diff changeset
156 av_log(s, AV_LOG_ERROR, "ERROR: yuv4mpeg only handles yuv444p, yuv422p, yuv420p, yuv411p and gray pixel formats. Use -pix_fmt to select one.\n");
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
157 return AVERROR_IO;
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
158 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
159
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
160 *first_pkt = 1;
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
161 return 0;
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
162 }
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
163
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
164 static int yuv4_write_trailer(AVFormatContext *s)
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
165 {
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
166 return 0;
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
167 }
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
168
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
169 AVOutputFormat yuv4mpegpipe_oformat = {
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
170 "yuv4mpegpipe",
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
171 "YUV4MPEG pipe format",
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
172 "",
739
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
173 "y4m",
284
c77ce17451a1 * providing MPEG codecs with a generic fields in AVFrame to use.
romansh
parents: 277
diff changeset
174 sizeof(int),
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
175 CODEC_ID_NONE,
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
176 CODEC_ID_RAWVIDEO,
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
177 yuv4_write_header,
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
178 yuv4_write_packet,
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
179 yuv4_write_trailer,
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
180 .flags = AVFMT_RAWPICTURE,
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
181 };
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 838
diff changeset
182 #endif //CONFIG_MUXERS
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
183
207
7865656658dc stdin patch by (Charles Yates <charles dot yates at pandora dot be>)
michaelni
parents: 184
diff changeset
184 /* Header size increased to allow room for optional flags */
7865656658dc stdin patch by (Charles Yates <charles dot yates at pandora dot be>)
michaelni
parents: 184
diff changeset
185 #define MAX_YUV4_HEADER 80
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
186 #define MAX_FRAME_HEADER 80
18
01e35bb2689a extracted yuv4mpeg from img.c (untested)
bellard
parents:
diff changeset
187
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
188 static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap)
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
189 {
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
190 char header[MAX_YUV4_HEADER+10]; // Include headroom for the longest option
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
191 char *tokstart,*tokend,*header_end;
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
192 int i;
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
193 ByteIOContext *pb = &s->pb;
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
194 int width=-1, height=-1, raten=0, rated=0, aspectn=0, aspectd=0,interlaced_frame=0,top_field_first=0;
738
dad78387544a Update yuv4mpeg to use PIX_FMT_NONE patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 648
diff changeset
195 enum PixelFormat pix_fmt=PIX_FMT_NONE,alt_pix_fmt=PIX_FMT_NONE;
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
196 AVStream *st;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
197
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
198 for (i=0; i<MAX_YUV4_HEADER; i++) {
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
199 header[i] = get_byte(pb);
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
200 if (header[i] == '\n') {
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
201 header[i+1] = 0x20; // Add a space after last option. Makes parsing "444" vs "444alpha" easier.
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
202 header[i+2] = 0;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
203 break;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
204 }
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
205 }
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
206 if (i == MAX_YUV4_HEADER) return -1;
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
207 if (strncmp(header, Y4M_MAGIC, strlen(Y4M_MAGIC))) return -1;
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
208
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
209 header_end = &header[i+1]; // Include space
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
210 for(tokstart = &header[strlen(Y4M_MAGIC) + 1]; tokstart < header_end; tokstart++) {
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
211 if (*tokstart==0x20) continue;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
212 switch (*tokstart++) {
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
213 case 'W': // Width. Required.
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
214 width = strtol(tokstart, &tokend, 10);
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
215 tokstart=tokend;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
216 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
217 case 'H': // Height. Required.
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
218 height = strtol(tokstart, &tokend, 10);
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
219 tokstart=tokend;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
220 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
221 case 'C': // Color space
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
222 if (strncmp("420jpeg",tokstart,7)==0)
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
223 pix_fmt = PIX_FMT_YUV420P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
224 else if (strncmp("420mpeg2",tokstart,8)==0)
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
225 pix_fmt = PIX_FMT_YUV420P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
226 else if (strncmp("420paldv", tokstart, 8)==0)
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
227 pix_fmt = PIX_FMT_YUV420P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
228 else if (strncmp("411", tokstart, 3)==0)
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
229 pix_fmt = PIX_FMT_YUV411P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
230 else if (strncmp("422", tokstart, 3)==0)
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
231 pix_fmt = PIX_FMT_YUV422P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
232 else if (strncmp("444alpha", tokstart, 8)==0) {
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
233 av_log(s, AV_LOG_ERROR, "Cannot handle 4:4:4:4 YUV4MPEG stream.\n");
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
234 return -1;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
235 } else if (strncmp("444", tokstart, 3)==0)
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
236 pix_fmt = PIX_FMT_YUV444P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
237 else if (strncmp("mono",tokstart, 4)==0) {
648
340f1911cd54 add luma only support to yuv4mpeg patch by (Roine Gustafsson <roine users.sourceforge net>)
michael
parents: 634
diff changeset
238 pix_fmt = PIX_FMT_GRAY8;
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
239 } else {
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
240 av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains an unknown pixel format.\n");
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
241 return -1;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
242 }
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
243 while(tokstart<header_end&&*tokstart!=0x20) tokstart++;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
244 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
245 case 'I': // Interlace type
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
246 switch (*tokstart++){
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
247 case '?':
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
248 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
249 case 'p':
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
250 interlaced_frame=0;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
251 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
252 case 't':
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
253 interlaced_frame=1;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
254 top_field_first=1;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
255 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
256 case 'b':
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
257 interlaced_frame=1;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
258 top_field_first=0;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
259 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
260 case 'm':
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
261 av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains mixed interlaced and non-interlaced frames.\n");
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
262 return -1;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
263 default:
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
264 av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n");
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
265 return -1;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
266 }
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
267 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
268 case 'F': // Frame rate
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
269 sscanf(tokstart,"%d:%d",&raten,&rated); // 0:0 if unknown
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
270 while(tokstart<header_end&&*tokstart!=0x20) tokstart++;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
271 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
272 case 'A': // Pixel aspect
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
273 sscanf(tokstart,"%d:%d",&aspectn,&aspectd); // 0:0 if unknown
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
274 while(tokstart<header_end&&*tokstart!=0x20) tokstart++;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
275 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
276 case 'X': // Vendor extensions
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
277 if (strncmp("YSCSS=",tokstart,6)==0) {
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
278 // Older nonstandard pixel format representation
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
279 tokstart+=6;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
280 if (strncmp("420JPEG",tokstart,7)==0)
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
281 alt_pix_fmt=PIX_FMT_YUV420P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
282 else if (strncmp("420MPEG2",tokstart,8)==0)
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
283 alt_pix_fmt=PIX_FMT_YUV420P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
284 else if (strncmp("420PALDV",tokstart,8)==0)
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
285 alt_pix_fmt=PIX_FMT_YUV420P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
286 else if (strncmp("411",tokstart,3)==0)
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
287 alt_pix_fmt=PIX_FMT_YUV411P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
288 else if (strncmp("422",tokstart,3)==0)
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
289 alt_pix_fmt=PIX_FMT_YUV422P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
290 else if (strncmp("444",tokstart,3)==0)
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
291 alt_pix_fmt=PIX_FMT_YUV444P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
292 }
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
293 while(tokstart<header_end&&*tokstart!=0x20) tokstart++;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
294 break;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
295 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
296 }
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
297
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
298 if ((width == -1) || (height == -1)) {
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
299 av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n");
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
300 return -1;
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
301 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
302
738
dad78387544a Update yuv4mpeg to use PIX_FMT_NONE patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 648
diff changeset
303 if (pix_fmt == PIX_FMT_NONE) {
dad78387544a Update yuv4mpeg to use PIX_FMT_NONE patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 648
diff changeset
304 if (alt_pix_fmt == PIX_FMT_NONE)
634
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
305 pix_fmt = PIX_FMT_YUV420P;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
306 else
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
307 pix_fmt = alt_pix_fmt;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
308 }
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
309
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
310 if (raten == 0 && rated == 0) {
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
311 // Frame rate unknown
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
312 raten = 25;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
313 rated = 1;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
314 }
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
315
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
316 if (aspectn == 0 && aspectd == 0) {
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
317 // Pixel aspect unknown
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
318 aspectd = 1;
6c5c8feed381 - Writes correct unknown aspect
michael
parents: 537
diff changeset
319 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
320
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
321 st = av_new_stream(s, 0);
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
322 st = s->streams[0];
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
323 st->codec->width = width;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
324 st->codec->height = height;
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
325 av_reduce(&raten, &rated, raten, rated, (1UL<<31)-1);
743
af4e24d6310c switch to native time bases
michael
parents: 739
diff changeset
326 av_set_pts_info(st, 64, rated, raten);
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
327 st->codec->pix_fmt = pix_fmt;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
328 st->codec->codec_type = CODEC_TYPE_VIDEO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
329 st->codec->codec_id = CODEC_ID_RAWVIDEO;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
330 st->codec->sample_aspect_ratio= (AVRational){aspectn, aspectd};
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
331
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
332 return 0;
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
333 }
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
334
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
335 static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt)
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
336 {
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
337 int i;
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
338 char header[MAX_FRAME_HEADER+1];
838
128838bc4bb6 kill a bunch of compiler warnings
mru
parents: 820
diff changeset
339 int packet_size, width, height;
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
340 AVStream *st = s->streams[0];
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
341
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
342 for (i=0; i<MAX_FRAME_HEADER; i++) {
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
343 header[i] = get_byte(&s->pb);
887
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
344 if (header[i] == '\n') {
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
345 header[i+1] = 0;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
346 break;
d70e50f1495f COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 885
diff changeset
347 }
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
348 }
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
349 if (i == MAX_FRAME_HEADER) return -1;
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
350 if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC))) return -1;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 858
diff changeset
351
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
352 width = st->codec->width;
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
353 height = st->codec->height;
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
354
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 775
diff changeset
355 packet_size = avpicture_get_size(st->codec->pix_fmt, width, height);
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
356 if (packet_size < 0)
537
558a093b04db do not call (av_)abort()
michael
parents: 482
diff changeset
357 return -1;
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
358
775
c5077fdab490 AVPacket.pos
michael
parents: 743
diff changeset
359 if (av_get_packet(&s->pb, pkt, packet_size) != packet_size)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 468
diff changeset
360 return AVERROR_IO;
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
361
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
362 pkt->stream_index = 0;
775
c5077fdab490 AVPacket.pos
michael
parents: 743
diff changeset
363 return 0;
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
364 }
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
365
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
366 static int yuv4_read_close(AVFormatContext *s)
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
367 {
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
368 return 0;
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
369 }
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
370
739
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
371 static int yuv4_probe(AVProbeData *pd)
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
372 {
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
373 /* check file header */
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
374 if (pd->buf_size <= sizeof(Y4M_MAGIC))
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
375 return 0;
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
376 if (strncmp(pd->buf, Y4M_MAGIC, sizeof(Y4M_MAGIC)-1)==0)
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
377 return AVPROBE_SCORE_MAX;
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
378 else
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
379 return 0;
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
380 }
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
381
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
382 AVInputFormat yuv4mpegpipe_iformat = {
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
383 "yuv4mpegpipe",
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
384 "YUV4MPEG pipe format",
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
385 0,
739
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
386 yuv4_probe,
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
387 yuv4_read_header,
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
388 yuv4_read_packet,
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
389 yuv4_read_close,
739
db0a5e0f4db5 Adds read probe to y4m, and changes the extension to .y4m patch by (Roine Gustafsson <roine users sourceforge net)
michael
parents: 738
diff changeset
390 .extensions = "y4m"
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
391 };
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
392
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
393 int yuv4mpeg_init(void)
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
394 {
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
395 av_register_input_format(&yuv4mpegpipe_iformat);
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 838
diff changeset
396 #ifdef CONFIG_MUXERS
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
397 av_register_output_format(&yuv4mpegpipe_oformat);
858
66cc656ea404 Replace CONFIG_ENCODERS/CONFIG_DECODERS with CONFIG_MUXERS/CONFIG_DEMUXERS
diego
parents: 838
diff changeset
398 #endif //CONFIG_MUXERS
184
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
399 return 0;
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
400 }
2438e76dde67 yuv4mpeg pipe reader for libavformat patch by (D Richard Felker III <dalias at aerifal dot cx>)
michaelni
parents: 178
diff changeset
401