Mercurial > libavformat.hg
comparison yuv4mpeg.c @ 820:feca73904e67 libavformat
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
author | michael |
---|---|
date | Sun, 17 Jul 2005 22:24:36 +0000 |
parents | c5077fdab490 |
children | 128838bc4bb6 |
comparison
equal
deleted
inserted
replaced
819:a6c035e7f429 | 820:feca73904e67 |
---|---|
31 int raten, rated, aspectn, aspectd, n; | 31 int raten, rated, aspectn, aspectd, n; |
32 char inter; | 32 char inter; |
33 char *colorspace = ""; | 33 char *colorspace = ""; |
34 | 34 |
35 st = s->streams[0]; | 35 st = s->streams[0]; |
36 width = st->codec.width; | 36 width = st->codec->width; |
37 height = st->codec.height; | 37 height = st->codec->height; |
38 | 38 |
39 av_reduce(&raten, &rated, st->codec.time_base.den, st->codec.time_base.num, (1UL<<31)-1); | 39 av_reduce(&raten, &rated, st->codec->time_base.den, st->codec->time_base.num, (1UL<<31)-1); |
40 | 40 |
41 aspectn = st->codec.sample_aspect_ratio.num; | 41 aspectn = st->codec->sample_aspect_ratio.num; |
42 aspectd = st->codec.sample_aspect_ratio.den; | 42 aspectd = st->codec->sample_aspect_ratio.den; |
43 | 43 |
44 if ( aspectn == 0 && aspectd == 1 ) aspectd = 0; // 0:0 means unknown | 44 if ( aspectn == 0 && aspectd == 1 ) aspectd = 0; // 0:0 means unknown |
45 | 45 |
46 inter = 'p'; /* progressive is the default */ | 46 inter = 'p'; /* progressive is the default */ |
47 if (st->codec.coded_frame && st->codec.coded_frame->interlaced_frame) { | 47 if (st->codec->coded_frame && st->codec->coded_frame->interlaced_frame) { |
48 inter = st->codec.coded_frame->top_field_first ? 't' : 'b'; | 48 inter = st->codec->coded_frame->top_field_first ? 't' : 'b'; |
49 } | 49 } |
50 | 50 |
51 switch(st->codec.pix_fmt) { | 51 switch(st->codec->pix_fmt) { |
52 case PIX_FMT_GRAY8: | 52 case PIX_FMT_GRAY8: |
53 colorspace = " Cmono"; | 53 colorspace = " Cmono"; |
54 break; | 54 break; |
55 case PIX_FMT_YUV411P: | 55 case PIX_FMT_YUV411P: |
56 colorspace = " C411 XYSCSS=411"; | 56 colorspace = " C411 XYSCSS=411"; |
57 break; | 57 break; |
58 case PIX_FMT_YUV420P: | 58 case PIX_FMT_YUV420P: |
59 colorspace = (st->codec.codec_id == CODEC_ID_DVVIDEO)?" C420paldv XYSCSS=420PALDV":" C420mpeg2 XYSCSS=420MPEG2"; | 59 colorspace = (st->codec->codec_id == CODEC_ID_DVVIDEO)?" C420paldv XYSCSS=420PALDV":" C420mpeg2 XYSCSS=420MPEG2"; |
60 break; | 60 break; |
61 case PIX_FMT_YUV422P: | 61 case PIX_FMT_YUV422P: |
62 colorspace = " C422 XYSCSS=422"; | 62 colorspace = " C422 XYSCSS=422"; |
63 break; | 63 break; |
64 case PIX_FMT_YUV444P: | 64 case PIX_FMT_YUV444P: |
107 /* construct frame header */ | 107 /* construct frame header */ |
108 | 108 |
109 m = snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC); | 109 m = snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC); |
110 put_buffer(pb, buf1, strlen(buf1)); | 110 put_buffer(pb, buf1, strlen(buf1)); |
111 | 111 |
112 width = st->codec.width; | 112 width = st->codec->width; |
113 height = st->codec.height; | 113 height = st->codec->height; |
114 | 114 |
115 ptr = picture->data[0]; | 115 ptr = picture->data[0]; |
116 for(i=0;i<height;i++) { | 116 for(i=0;i<height;i++) { |
117 put_buffer(pb, ptr, width); | 117 put_buffer(pb, ptr, width); |
118 ptr += picture->linesize[0]; | 118 ptr += picture->linesize[0]; |
119 } | 119 } |
120 | 120 |
121 if (st->codec.pix_fmt != PIX_FMT_GRAY8){ | 121 if (st->codec->pix_fmt != PIX_FMT_GRAY8){ |
122 // Adjust for smaller Cb and Cr planes | 122 // Adjust for smaller Cb and Cr planes |
123 avcodec_get_chroma_sub_sample(st->codec.pix_fmt, &h_chroma_shift, &v_chroma_shift); | 123 avcodec_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift, &v_chroma_shift); |
124 width >>= h_chroma_shift; | 124 width >>= h_chroma_shift; |
125 height >>= v_chroma_shift; | 125 height >>= v_chroma_shift; |
126 | 126 |
127 ptr1 = picture->data[1]; | 127 ptr1 = picture->data[1]; |
128 ptr2 = picture->data[2]; | 128 ptr2 = picture->data[2]; |
144 int* first_pkt = s->priv_data; | 144 int* first_pkt = s->priv_data; |
145 | 145 |
146 if (s->nb_streams != 1) | 146 if (s->nb_streams != 1) |
147 return AVERROR_IO; | 147 return AVERROR_IO; |
148 | 148 |
149 if (s->streams[0]->codec.pix_fmt == PIX_FMT_YUV411P) { | 149 if (s->streams[0]->codec->pix_fmt == PIX_FMT_YUV411P) { |
150 av_log(s, AV_LOG_ERROR, "Warning: generating rarely used 4:1:1 YUV stream, some mjpegtools might not work.\n"); | 150 av_log(s, AV_LOG_ERROR, "Warning: generating rarely used 4:1:1 YUV stream, some mjpegtools might not work.\n"); |
151 } | 151 } |
152 else if ((s->streams[0]->codec.pix_fmt != PIX_FMT_YUV420P) && | 152 else if ((s->streams[0]->codec->pix_fmt != PIX_FMT_YUV420P) && |
153 (s->streams[0]->codec.pix_fmt != PIX_FMT_YUV422P) && | 153 (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV422P) && |
154 (s->streams[0]->codec.pix_fmt != PIX_FMT_GRAY8) && | 154 (s->streams[0]->codec->pix_fmt != PIX_FMT_GRAY8) && |
155 (s->streams[0]->codec.pix_fmt != PIX_FMT_YUV444P)) { | 155 (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV444P)) { |
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"); | 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"); |
157 return AVERROR_IO; | 157 return AVERROR_IO; |
158 } | 158 } |
159 | 159 |
160 *first_pkt = 1; | 160 *first_pkt = 1; |
318 aspectd = 1; | 318 aspectd = 1; |
319 } | 319 } |
320 | 320 |
321 st = av_new_stream(s, 0); | 321 st = av_new_stream(s, 0); |
322 st = s->streams[0]; | 322 st = s->streams[0]; |
323 st->codec.width = width; | 323 st->codec->width = width; |
324 st->codec.height = height; | 324 st->codec->height = height; |
325 av_reduce(&raten, &rated, raten, rated, (1UL<<31)-1); | 325 av_reduce(&raten, &rated, raten, rated, (1UL<<31)-1); |
326 av_set_pts_info(st, 64, rated, raten); | 326 av_set_pts_info(st, 64, rated, raten); |
327 st->codec.pix_fmt = pix_fmt; | 327 st->codec->pix_fmt = pix_fmt; |
328 st->codec.codec_type = CODEC_TYPE_VIDEO; | 328 st->codec->codec_type = CODEC_TYPE_VIDEO; |
329 st->codec.codec_id = CODEC_ID_RAWVIDEO; | 329 st->codec->codec_id = CODEC_ID_RAWVIDEO; |
330 st->codec.sample_aspect_ratio= (AVRational){aspectn, aspectd}; | 330 st->codec->sample_aspect_ratio= (AVRational){aspectn, aspectd}; |
331 | 331 |
332 return 0; | 332 return 0; |
333 } | 333 } |
334 | 334 |
335 static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt) | 335 static int yuv4_read_packet(AVFormatContext *s, AVPacket *pkt) |
347 } | 347 } |
348 } | 348 } |
349 if (i == MAX_FRAME_HEADER) return -1; | 349 if (i == MAX_FRAME_HEADER) return -1; |
350 if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC))) return -1; | 350 if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC))) return -1; |
351 | 351 |
352 width = st->codec.width; | 352 width = st->codec->width; |
353 height = st->codec.height; | 353 height = st->codec->height; |
354 | 354 |
355 packet_size = avpicture_get_size(st->codec.pix_fmt, width, height); | 355 packet_size = avpicture_get_size(st->codec->pix_fmt, width, height); |
356 if (packet_size < 0) | 356 if (packet_size < 0) |
357 return -1; | 357 return -1; |
358 | 358 |
359 if (av_get_packet(&s->pb, pkt, packet_size) != packet_size) | 359 if (av_get_packet(&s->pb, pkt, packet_size) != packet_size) |
360 return AVERROR_IO; | 360 return AVERROR_IO; |