57
57
inter = st->codec->coded_frame->top_field_first ? 't' : 'b';
59
59
switch (st->codec->pix_fmt) {
60
case AV_PIX_FMT_GRAY8:
61
61
colorspace = " Cmono";
63
case AV_PIX_FMT_YUV411P:
64
64
colorspace = " C411 XYSCSS=411";
66
case AV_PIX_FMT_YUV420P:
67
67
switch (st->codec->chroma_sample_location) {
68
68
case AVCHROMA_LOC_TOPLEFT: colorspace = " C420paldv XYSCSS=420PALDV"; break;
69
69
case AVCHROMA_LOC_LEFT: colorspace = " C420mpeg2 XYSCSS=420MPEG2"; break;
70
70
default: colorspace = " C420jpeg XYSCSS=420JPEG"; break;
73
case AV_PIX_FMT_YUV422P:
74
74
colorspace = " C422 XYSCSS=422";
76
case AV_PIX_FMT_YUV444P:
77
77
colorspace = " C444 XYSCSS=444";
126
126
ptr += picture->linesize[0];
129
if (st->codec->pix_fmt != PIX_FMT_GRAY8) {
129
if (st->codec->pix_fmt != AV_PIX_FMT_GRAY8) {
130
130
// Adjust for smaller Cb and Cr planes
131
131
avcodec_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift,
132
132
&v_chroma_shift);
155
155
if (s->nb_streams != 1)
156
156
return AVERROR(EIO);
158
if (s->streams[0]->codec->codec_id != CODEC_ID_RAWVIDEO) {
158
if (s->streams[0]->codec->codec_id != AV_CODEC_ID_RAWVIDEO) {
159
159
av_log(s, AV_LOG_ERROR, "ERROR: Only rawvideo supported.\n");
160
160
return AVERROR_INVALIDDATA;
163
if (s->streams[0]->codec->pix_fmt == PIX_FMT_YUV411P) {
163
if (s->streams[0]->codec->pix_fmt == AV_PIX_FMT_YUV411P) {
164
164
av_log(s, AV_LOG_ERROR, "Warning: generating rarely used 4:1:1 YUV "
165
165
"stream, some mjpegtools might not work.\n");
166
} else if ((s->streams[0]->codec->pix_fmt != PIX_FMT_YUV420P) &&
167
(s->streams[0]->codec->pix_fmt != PIX_FMT_YUV422P) &&
168
(s->streams[0]->codec->pix_fmt != PIX_FMT_GRAY8) &&
169
(s->streams[0]->codec->pix_fmt != PIX_FMT_YUV444P)) {
166
} else if ((s->streams[0]->codec->pix_fmt != AV_PIX_FMT_YUV420P) &&
167
(s->streams[0]->codec->pix_fmt != AV_PIX_FMT_YUV422P) &&
168
(s->streams[0]->codec->pix_fmt != AV_PIX_FMT_GRAY8) &&
169
(s->streams[0]->codec->pix_fmt != AV_PIX_FMT_YUV444P)) {
170
170
av_log(s, AV_LOG_ERROR, "ERROR: yuv4mpeg only handles yuv444p, "
171
171
"yuv422p, yuv420p, yuv411p and gray pixel formats. "
172
172
"Use -pix_fmt to select one.\n");
180
180
AVOutputFormat ff_yuv4mpegpipe_muxer = {
181
181
.name = "yuv4mpegpipe",
182
.long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"),
182
.long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
184
184
.extensions = "y4m",
185
185
.priv_data_size = sizeof(int),
186
.audio_codec = CODEC_ID_NONE,
187
.video_codec = CODEC_ID_RAWVIDEO,
186
.audio_codec = AV_CODEC_ID_NONE,
187
.video_codec = AV_CODEC_ID_RAWVIDEO,
188
188
.write_header = yuv4_write_header,
189
189
.write_packet = yuv4_write_packet,
190
190
.flags = AVFMT_RAWPICTURE,
195
195
#define MAX_YUV4_HEADER 80
196
196
#define MAX_FRAME_HEADER 80
198
static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap)
198
static int yuv4_read_header(AVFormatContext *s)
200
200
char header[MAX_YUV4_HEADER + 10]; // Include headroom for
201
201
// the longest option
204
204
AVIOContext *pb = s->pb;
205
205
int width = -1, height = -1, raten = 0,
206
206
rated = 0, aspectn = 0, aspectd = 0;
207
enum PixelFormat pix_fmt = PIX_FMT_NONE, alt_pix_fmt = PIX_FMT_NONE;
207
enum AVPixelFormat pix_fmt = AV_PIX_FMT_NONE, alt_pix_fmt = AV_PIX_FMT_NONE;
208
208
enum AVChromaLocation chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED;
210
210
struct frame_attributes *s1 = s->priv_data;
242
242
case 'C': // Color space
243
243
if (strncmp("420jpeg", tokstart, 7) == 0) {
244
pix_fmt = PIX_FMT_YUV420P;
244
pix_fmt = AV_PIX_FMT_YUV420P;
245
245
chroma_sample_location = AVCHROMA_LOC_CENTER;
246
246
} else if (strncmp("420mpeg2", tokstart, 8) == 0) {
247
pix_fmt = PIX_FMT_YUV420P;
247
pix_fmt = AV_PIX_FMT_YUV420P;
248
248
chroma_sample_location = AVCHROMA_LOC_LEFT;
249
249
} else if (strncmp("420paldv", tokstart, 8) == 0) {
250
pix_fmt = PIX_FMT_YUV420P;
250
pix_fmt = AV_PIX_FMT_YUV420P;
251
251
chroma_sample_location = AVCHROMA_LOC_TOPLEFT;
252
} else if (strncmp("420", tokstart, 3) == 0) {
253
pix_fmt = AV_PIX_FMT_YUV420P;
254
chroma_sample_location = AVCHROMA_LOC_CENTER;
252
255
} else if (strncmp("411", tokstart, 3) == 0)
253
pix_fmt = PIX_FMT_YUV411P;
256
pix_fmt = AV_PIX_FMT_YUV411P;
254
257
else if (strncmp("422", tokstart, 3) == 0)
255
pix_fmt = PIX_FMT_YUV422P;
258
pix_fmt = AV_PIX_FMT_YUV422P;
256
259
else if (strncmp("444alpha", tokstart, 8) == 0 ) {
257
260
av_log(s, AV_LOG_ERROR, "Cannot handle 4:4:4:4 "
258
261
"YUV4MPEG stream.\n");
260
263
} else if (strncmp("444", tokstart, 3) == 0)
261
pix_fmt = PIX_FMT_YUV444P;
264
pix_fmt = AV_PIX_FMT_YUV444P;
262
265
else if (strncmp("mono", tokstart, 4) == 0) {
263
pix_fmt = PIX_FMT_GRAY8;
266
pix_fmt = AV_PIX_FMT_GRAY8;
265
268
av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains an unknown "
266
269
"pixel format.\n");
308
311
// Older nonstandard pixel format representation
310
313
if (strncmp("420JPEG", tokstart, 7) == 0)
311
alt_pix_fmt = PIX_FMT_YUV420P;
314
alt_pix_fmt = AV_PIX_FMT_YUV420P;
312
315
else if (strncmp("420MPEG2", tokstart, 8) == 0)
313
alt_pix_fmt = PIX_FMT_YUV420P;
316
alt_pix_fmt = AV_PIX_FMT_YUV420P;
314
317
else if (strncmp("420PALDV", tokstart, 8) == 0)
315
alt_pix_fmt = PIX_FMT_YUV420P;
318
alt_pix_fmt = AV_PIX_FMT_YUV420P;
316
319
else if (strncmp("411", tokstart, 3) == 0)
317
alt_pix_fmt = PIX_FMT_YUV411P;
320
alt_pix_fmt = AV_PIX_FMT_YUV411P;
318
321
else if (strncmp("422", tokstart, 3) == 0)
319
alt_pix_fmt = PIX_FMT_YUV422P;
322
alt_pix_fmt = AV_PIX_FMT_YUV422P;
320
323
else if (strncmp("444", tokstart, 3) == 0)
321
alt_pix_fmt = PIX_FMT_YUV444P;
324
alt_pix_fmt = AV_PIX_FMT_YUV444P;
323
326
while (tokstart < header_end && *tokstart != 0x20)
334
if (pix_fmt == PIX_FMT_NONE) {
335
if (alt_pix_fmt == PIX_FMT_NONE)
336
pix_fmt = PIX_FMT_YUV420P;
337
if (pix_fmt == AV_PIX_FMT_NONE) {
338
if (alt_pix_fmt == AV_PIX_FMT_NONE)
339
pix_fmt = AV_PIX_FMT_YUV420P;
338
341
pix_fmt = alt_pix_fmt;
358
361
avpriv_set_pts_info(st, 64, rated, raten);
359
362
st->codec->pix_fmt = pix_fmt;
360
363
st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
361
st->codec->codec_id = CODEC_ID_RAWVIDEO;
364
st->codec->codec_id = AV_CODEC_ID_RAWVIDEO;
362
365
st->sample_aspect_ratio = (AVRational){ aspectn, aspectd };
363
366
st->codec->chroma_sample_location = chroma_sample_location;
424
427
#if CONFIG_YUV4MPEGPIPE_DEMUXER
425
428
AVInputFormat ff_yuv4mpegpipe_demuxer = {
426
429
.name = "yuv4mpegpipe",
427
.long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"),
430
.long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe"),
428
431
.priv_data_size = sizeof(struct frame_attributes),
429
432
.read_probe = yuv4_probe,
430
433
.read_header = yuv4_read_header,
431
434
.read_packet = yuv4_read_packet,