1 /* lav_common - some general utility functionality used by multiple
2 lavtool utilities. */
3
4 /* Copyright (C) 2000, Rainer Johanni, Andrew Stevens */
5 /* - added scene change detection code 2001, pHilipp Zabel */
6 /* - broke some code out to lav_common.h and lav_common.c
7 * July 2001, Shawn Sulma <lavtools@athos.cx>. In doing this,
8 * I replaced the large number of globals with a handful of structs
9 * that are passed into the appropriate methods. Check lav_common.h
10 * for the structs. I'm sure some of what I've done is inefficient,
11 * subtly incorrect or just plain Wrong. Feedback is welcome.
12 */
13 /* - removed a lot of subsumed functionality and unnecessary cruft
14 * March 2002, Matthew Marjanovic <maddog@mir.com>.
15 */
16
17
18 /*
19 This program is free software; you can redistribute it and/or modify
20 it under the terms of the GNU General Public License as published by
21 the Free Software Foundation; either version 2 of the License, or
22 (at your option) any later version.
23
24 This program is distributed in the hope that it will be useful,
25 but WITHOUT ANY WARRANTY; without even the implied warranty of
26 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 GNU General Public License for more details.
28
29 You should have received a copy of the GNU General Public License
30 along with this program; if not, write to the Free Software
31 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 */
33
34 #include <config.h>
35 #include <stdio.h>
36 #include <string.h>
37
38 #include "lav_common.h"
39 #include "jpegutils.h"
40 #include "mpegconsts.h"
41 #include "cpu_accel.h"
42
43 static uint8_t jpeg_data[MAX_JPEG_LEN];
44
45
46 #ifdef HAVE_LIBDV
47
48 dv_decoder_t *decoder;
49 uint16_t pitches[3];
50 uint8_t *dv_frame[3] = {NULL,NULL,NULL};
51
52 /*
53 * As far as I (maddog) can tell, this is what is going on with libdv-0.9
54 * and the unpacking routine...
55 * o Ft/Fb refer to top/bottom scanlines (interleaved) --- each sample
56 * is implicitly tagged by 't' or 'b' (samples are not mixed between
57 * fields)
58 * o Indices on Cb and Cr samples indicate the Y sample with which
59 * they are co-sited.
60 * o '^' indicates which samples are preserved by the unpacking
61 *
62 * libdv packs both NTSC 4:1:1 and PAL 4:2:0 into a common frame format of
63 * packed 4:2:2 pixels as follows:
64 *
65 *
66 ***** NTSC 4:1:1 *****
67 *
68 * libdv's 4:2:2-packed representation (chroma repeated horizontally)
69 *
70 *Ft Y00.Cb00.Y01.Cr00.Y02.Cb00.Y03.Cr00 Y04.Cb04.Y05.Cr04.Y06.Cb04.Y07.Cr04
71 * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
72 *Fb Y00.Cb00.Y01.Cr00.Y02.Cb00.Y03.Cr00 Y04.Cb04.Y05.Cr04.Y06.Cb04.Y07.Cr04
73 * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
74 *Ft Y10.Cb10.Y11.Cr10.Y12.Cb10.Y13.Cr10 Y14.Cb14.Y15.Cr14.Y16.Cb14.Y17.Cr14
75 * ^ ^ ^ ^ ^ ^ ^ ^
76 *Fb Y10.Cb10.Y11.Cr10.Y12.Cb10.Y13.Cr10 Y14.Cb14.Y15.Cr14.Y16.Cb14.Y17.Cr14
77 * ^ ^ ^ ^ ^ ^ ^ ^
78 *
79 * lavtools unpacking into 4:2:0-planar (note lossiness)
80 *
81 *Ft Y00.Y01.Y02.Y03.Y04.Y05.Y06.Y07...
82 *Fb Y00.Y01.Y02.Y03.Y04.Y05.Y06.Y07...
83 *Ft Y10.Y11.Y12.Y13.Y14.Y15.Y16.Y17...
84 *Fb Y10.Y11.Y12.Y13.Y14.Y15.Y16.Y17...
85 *
86 *Ft Cb00.Cb00.Cb04.Cb04... Cb00,Cb04... are doubled
87 *Fb Cb00.Cb00.Cb04.Cb04... Cb10,Cb14... are ignored
88 *
89 *Ft Cr00.Cr00.Cr04.Cr04...
90 *Fb Cr00.Cr00.Cr04.Cr04...
91 *
92 *
93 ***** PAL 4:2:0 *****
94 *
95 * libdv's 4:2:2-packed representation (chroma repeated vertically)
96 *
97 *Ft Y00.Cb00.Y01.Cr10.Y02.Cb02.Y03.Cr12 Y04.Cb04.Y05.Cr14.Y06.Cb06.Y07.Cr16
98 * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
99 *Fb Y00.Cb00.Y01.Cr10.Y02.Cb02.Y03.Cr12 Y04.Cb04.Y05.Cr14.Y06.Cb06.Y07.Cr16
100 * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
101 *Ft Y10.Cb00.Y11.Cr10.Y12.Cb02.Y13.Cr12 Y14.Cb04.Y15.Cr14.Y16.Cb06.Y17.Cr16
102 * ^ ^ ^ ^ ^ ^ ^ ^
103 *Fb Y10.Cb00.Y11.Cr10.Y12.Cb02.Y13.Cr12 Y14.Cb04.Y15.Cr14.Y16.Cb06.Y17.Cr16
104 * ^ ^ ^ ^ ^ ^ ^ ^
105 *
106 * lavtools unpacking into 4:2:0-planar
107 *
108 *Ft Y00.Y01.Y02.Y03.Y04.Y05.Y06.Y07...
109 *Fb Y00.Y01.Y02.Y03.Y04.Y05.Y06.Y07...
110 *Ft Y10.Y11.Y12.Y13.Y14.Y15.Y16.Y17...
111 *Fb Y10.Y11.Y12.Y13.Y14.Y15.Y16.Y17...
112 *
113 *Ft Cb00.Cb02.Cb04.Cb06...
114 *Fb Cb00.Cb02.Cb04.Cb06...
115 *
116 *Ft Cr10.Cr12.Cr14.Cr16...
117 *Fb Cr10.Cr12.Cr14.Cr16...
118 *
119 */
120
121 /*
122 * Unpack libdv's 4:2:2-packed into our 4:2:0-planar or 4:2:2-planar,
123 * treating each interlaced field independently
124 *
125 */
frame_YUV422_to_planar_42x(uint8_t ** output,uint8_t * input,int width,int height,int chroma)126 static void frame_YUV422_to_planar_42x(uint8_t **output, uint8_t *input,
127 int width, int height, int chroma)
128 {
129 int i, j, w2;
130 uint8_t *y, *cb, *cr;
131
132 w2 = width/2;
133 y = output[0];
134 cb = output[1];
135 cr = output[2];
136
137 for (i=0; i<height;) {
138 /* process two scanlines (one from each field, interleaved) */
139 /* ...top-field scanline */
140 for (j=0; j<w2; j++) {
141 /* packed YUV 422 is: Y[i] U[i] Y[i+1] V[i] */
142 *(y++) = *(input++);
143 *(cb++) = *(input++);
144 *(y++) = *(input++);
145 *(cr++) = *(input++);
146 }
147 i++;
148 /* ...bottom-field scanline */
149 for (j=0; j<w2; j++) {
150 /* packed YUV 422 is: Y[i] U[i] Y[i+1] V[i] */
151 *(y++) = *(input++);
152 *(cb++) = *(input++);
153 *(y++) = *(input++);
154 *(cr++) = *(input++);
155 }
156 i++;
157 if (chroma == Y4M_CHROMA_422)
158 continue;
159 /* process next two scanlines (one from each field, interleaved) */
160 /* ...top-field scanline */
161 for (j=0; j<w2; j++) {
162 /* skip every second line for U and V */
163 *(y++) = *(input++);
164 input++;
165 *(y++) = *(input++);
166 input++;
167 }
168 i++;
169 /* ...bottom-field scanline */
170 for (j=0; j<w2; j++) {
171 /* skip every second line for U and V */
172 *(y++) = *(input++);
173 input++;
174 *(y++) = *(input++);
175 input++;
176 }
177 i++;
178 }
179 }
180
181 /***** NTSC 4:1:1 *****
182 *
183 * libdv's 4:2:2-packed representation (chroma repeated horizontally)
184 *
185 * 23 Ft Y00.Cb00.Y01.Cr00.Y02.Cb00.Y03.Cr00 Y04.Cb04.Y05.Cr04.Y06.Cb04.Y07.Cr04
186 * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
187 * 285 Fb Y00.Cb00.Y01.Cr00.Y02.Cb00.Y03.Cr00 Y04.Cb04.Y05.Cr04.Y06.Cb04.Y07.Cr04
188 * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
189 * 24 Ft Y10.Cb10.Y11.Cr10.Y12.Cb10.Y13.Cr10 Y14.Cb14.Y15.Cr14.Y16.Cb14.Y17.Cr14
190 * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
191 * 286 Fb Y10.Cb10.Y11.Cr10.Y12.Cb10.Y13.Cr10 Y14.Cb14.Y15.Cr14.Y16.Cb14.Y17.Cr14
192 * ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
193 *
194 * lavtools unpacking into 4:1:1-planar
195 *
196 * 23 Ft Y00.Y01.Y02.Y03.Y04.Y05.Y06.Y07...
197 * 285 Fb Y00.Y01.Y02.Y03.Y04.Y05.Y06.Y07...
198 * 24 Ft Y10.Y11.Y12.Y13.Y14.Y15.Y16.Y17...
199 * 286 Fb Y10.Y11.Y12.Y13.Y14.Y15.Y16.Y17...
200 *
201 * 23 Ft Cb00.Cb04...
202 * 285 Fb Cb00.Cb04...
203 * 24 Ft Cb10.Cb14...
204 * 286 Fb Cb10.Cb14...
205 *
206 * 23 Ft Cr00.Cr04...
207 * 285 Fb Cr00.Cr04...
208 * 24 Ft Cr10.Cr14...
209 * 286 Fb Cr10.Cr14...
210 *
211 *
212 * cf. http://www.sony.ca/dvcam/pdfs/dvcam%20format%20overview.pdf
213 */
frame_YUV422_to_planar_411(uint8_t ** output,uint8_t * input,int width,int height)214 static void frame_YUV422_to_planar_411(uint8_t **output, uint8_t *input,
215 int width, int height)
216 {
217 int i, j, w4;
218 uint8_t *y, *cb, *cr;
219
220 w4 = width/4;
221 y = output[0];
222 cb = output[1];
223 cr = output[2];
224
225 for (i=0; i<height;) {
226 /* process two scanlines (one from each field, interleaved) */
227 /* ...top-field scanline */
228 for (j=0; j<w4; j++) {
229 /* packed YUV 422 is: Y[i] U[i] Y[i+1] V[i] */
230 *(y++) = *(input++);
231 *(cb++) = *(input++); // NTSC-specific: assert( j%2==0 || cb[-1]==cb[-2]);
232 *(y++) = *(input++);
233 *(cr++) = *(input++); // NTSC-specific: assert( j%2==0 || cr[-1]==cr[-2]);
234
235 *(y++) = *(input++);
236 (input++); // NTSC-specific: assert( j%2==0 || cb[-1]==cb[-2]);
237 *(y++) = *(input++);
238 (input++); // NTSC-specific: assert( j%2==0 || cr[-1]==cr[-2]);
239 }
240 i++;
241 /* ...bottom-field scanline */
242 for (j=0; j<w4; j++) {
243 /* packed YUV 422 is: Y[i] U[i] Y[i+1] V[i] */
244 *(y++) = *(input++);
245 *(cb++) = *(input++); // NTSC-specific: assert( j%2==0 || cb[-1]==cb[-2]);
246 *(y++) = *(input++);
247 *(cr++) = *(input++); // NTSC-specific: assert( j%2==0 || cr[-1]==cr[-2]);
248
249 *(y++) = *(input++);
250 (input++); // NTSC-specific: assert( j%2==0 || cb[-1]==cb[-2]);
251 *(y++) = *(input++);
252 (input++); // NTSC-specific: assert( j%2==0 || cr[-1]==cr[-2]);
253 }
254 i++;
255 }
256 }
257
frame_YUV422_to_planar(uint8_t ** output,uint8_t * input,int width,int height,int chroma)258 void frame_YUV422_to_planar(uint8_t **output, uint8_t *input,
259 int width, int height, int chroma)
260 {
261 if (chroma == Y4M_CHROMA_411)
262 frame_YUV422_to_planar_411(output, input, width, height);
263 else
264 frame_YUV422_to_planar_42x(output, input, width, height, chroma);
265
266 }
267 #endif /* HAVE_LIBDV */
268
269 /***********************
270 *
271 * Take a random(ish) sampled mean of a frame luma and chroma
272 * Its intended as a rough and ready hash of frame content.
273 * The idea is that changes above a certain threshold are treated as
274 * scene changes.
275 *
276 **********************/
277
luminance_mean(uint8_t * frame[],int w,int h)278 int luminance_mean(uint8_t *frame[], int w, int h )
279 {
280 uint8_t *p;
281 uint8_t *lim;
282 int sum = 0;
283 int count = 0;
284 p = frame[0];
285 lim = frame[0] + w*(h-1);
286 while( p < lim )
287 {
288 sum += (p[0] + p[1]) + (p[w-3] + p[w-2]);
289 p += 31;
290 count += 4;
291 }
292
293 w = w / 2;
294 h = h / 2;
295
296 p = frame[1];
297 lim = frame[1] + w*(h-1);
298 while( p < lim )
299 {
300 sum += (p[0] + p[1]) + (p[w-3] + p[w-2]);
301 p += 31;
302 count += 4;
303 }
304 p = frame[2];
305 lim = frame[2] + w*(h-1);
306 while( p < lim )
307 {
308 sum += (p[0] + p[1]) + (p[w-3] + p[w-2]);
309 p += 31;
310 count += 4;
311 }
312 return sum / count;
313 }
314
init(LavParam * param,uint8_t * buffer[])315 void init(LavParam *param, uint8_t *buffer[])
316 {
317 param->luma_size = param->output_width * param->output_height;
318 switch (param->chroma) {
319 default:
320 mjpeg_warn("unsupported chroma (%d), assume '420jpeg'", param->chroma);
321 param->chroma = Y4M_UNKNOWN; /* will update in writeoutYUV4MPEGheader() */
322 /* and do same as case Y4M_CHROMA_420JPEG... */
323 case Y4M_UNKNOWN:
324 case Y4M_CHROMA_420JPEG:
325 case Y4M_CHROMA_420MPEG2:
326 case Y4M_CHROMA_420PALDV:
327 param->chroma_width = param->output_width / 2;
328 param->chroma_height = param->output_height / 2;
329 break;
330 case Y4M_CHROMA_422:
331 param->chroma_width = param->output_width / 2;
332 param->chroma_height = param->output_height;
333 break;
334 case Y4M_CHROMA_411:
335 param->chroma_width = param->output_width / 4;
336 param->chroma_height = param->output_height;
337 break;
338 }
339 param->chroma_size = param->chroma_height * param->chroma_width;
340
341 buffer[0] = (uint8_t *)bufalloc(param->luma_size);
342 buffer[1] = (uint8_t *)bufalloc(param->chroma_size);
343 buffer[2] = (uint8_t *)bufalloc(param->chroma_size);
344
345 #ifdef HAVE_LIBDV
346 dv_frame[0] = (uint8_t *)bufalloc(3 * param->output_width * param->output_height);
347 dv_frame[1] = buffer[1];
348 dv_frame[2] = buffer[2];
349 #endif
350 }
351
352 /*
353 * readframe - read jpeg or dv frame into yuv buffer
354 *
355 * returns:
356 * 0 success
357 * 1 fatal error
358 * 2 corrupt data encountered;
359 * decoding can continue, but this frame may be damaged
360 */
readframe(int numframe,uint8_t * frame[],LavParam * param,EditList el)361 int readframe(int numframe,
362 uint8_t *frame[],
363 LavParam *param,
364 EditList el)
365 {
366 int len, i, res, data_format;
367 uint8_t *frame_tmp;
368 int warn;
369 warn = 0;
370
371 if (MAX_JPEG_LEN < el.max_frame_size) {
372 mjpeg_error_exit1( "Max size of JPEG frame = %ld: too big",
373 el.max_frame_size);
374 }
375
376 len = el_get_video_frame(jpeg_data, numframe, &el);
377 data_format = el_video_frame_data_format(numframe, &el);
378
379 switch(data_format) {
380
381 case DATAFORMAT_DV2 :
382 #ifndef HAVE_LIBDV
383 mjpeg_error("DV input was not configured at compile time");
384 res = 1;
385 #else
386 mjpeg_debug("DV frame %d len %d",numframe,len);
387 res = 0;
388 dv_parse_header(decoder, jpeg_data);
389 switch(decoder->sampling) {
390 case e_dv_sample_420:
391 /* libdv decodes PAL DV directly as planar YUV 420
392 * (YV12 or 4CC 0x32315659) if configured with the flag
393 * --with-pal-yuv=YV12 which is not (!) the default
394 */
395 if (libdv_pal_yv12 == 1) {
396 pitches[0] = decoder->width;
397 pitches[1] = decoder->width / 2;
398 pitches[2] = decoder->width / 2;
399 if (pitches[0] != param->output_width ||
400 pitches[1] != param->chroma_width) {
401 mjpeg_error("for DV 4:2:0 only full width output is supported");
402 res = 1;
403 } else {
404 dv_decode_full_frame(decoder, jpeg_data, e_dv_color_yuv,
405 frame, (int *)pitches);
406 /* swap the U and V components */
407 frame_tmp = frame[2];
408 frame[2] = frame[1];
409 frame[1] = frame_tmp;
410 }
411 break;
412 }
413 case e_dv_sample_411:
414 case e_dv_sample_422:
415 /* libdv decodes NTSC DV (native 411) and by default also PAL
416 * DV (native 420) as packed YUV 422 (YUY2 or 4CC 0x32595559)
417 * where the U and V information is repeated. This can be
418 * transformed to planar 420 (YV12 or 4CC 0x32315659).
419 * For NTSC DV this transformation is lossy.
420 */
421 pitches[0] = decoder->width * 2;
422 pitches[1] = 0;
423 pitches[2] = 0;
424 if (decoder->width != param->output_width) {
425 mjpeg_error("for DV only full width output is supported");
426 res = 1;
427 } else {
428 dv_decode_full_frame(decoder, jpeg_data, e_dv_color_yuv,
429 dv_frame, (int *)pitches);
430 frame_YUV422_to_planar(frame, dv_frame[0],
431 decoder->width, decoder->height,
432 param->chroma);
433 }
434 break;
435 default:
436 res = 1;
437 break;
438 }
439 #endif /* HAVE_LIBDV */
440 break;
441
442 case DATAFORMAT_YUV420 :
443 case DATAFORMAT_YUV422 :
444 mjpeg_debug("raw YUV frame %d len %d",numframe,len);
445 frame_tmp = jpeg_data;
446 memcpy(frame[0], frame_tmp, param->luma_size);
447 frame_tmp += param->luma_size;
448 memcpy(frame[1], frame_tmp, param->chroma_size);
449 frame_tmp += param->chroma_size;
450 memcpy(frame[2], frame_tmp, param->chroma_size);
451 res = 0;
452 break;
453
454 default:
455 mjpeg_debug("MJPEG frame %d len %d",numframe,len);
456 res = decode_jpeg_raw(jpeg_data, len, el.video_inter,
457 param->chroma,
458 param->output_width, param->output_height,
459 frame[0], frame[1], frame[2]);
460 }
461
462 if (res < 0) {
463 mjpeg_warn( "Fatal Error Decoding Frame %d", numframe);
464 return 1;
465 } else if (res == 1) {
466 mjpeg_warn( "Decoding of Frame %d failed", numframe);
467 warn = 1;
468 res = 0;
469 }
470
471
472 if (param->mono) {
473 for (i = 0;
474 i < param->chroma_size;
475 ++i) {
476 frame[1][i] = 0x80;
477 frame[2][i] = 0x80;
478 }
479 }
480
481 if(warn)
482 return 2;
483 else
484 return 0;
485 }
486
487
writeoutYUV4MPEGheader(int out_fd,LavParam * param,EditList el,y4m_stream_info_t * streaminfo)488 void writeoutYUV4MPEGheader(int out_fd,
489 LavParam *param,
490 EditList el,
491 y4m_stream_info_t *streaminfo)
492 {
493 int n;
494
495 y4m_si_set_width(streaminfo, param->output_width);
496 y4m_si_set_height(streaminfo, param->output_height);
497 y4m_si_set_interlace(streaminfo, param->interlace);
498 y4m_si_set_framerate(streaminfo, mpeg_conform_framerate(el.video_fps));
499 if (!Y4M_RATIO_EQL(param->sar, y4m_sar_UNKNOWN)) {
500 y4m_si_set_sampleaspect(streaminfo, param->sar);
501 } else if ((el.video_sar_width != 0) || (el.video_sar_height != 0)) {
502 y4m_ratio_t sar;
503 sar.n = el.video_sar_width;
504 sar.d = el.video_sar_height;
505 y4m_si_set_sampleaspect(streaminfo, sar);
506 } else {
507 /* no idea! ...eh, just guess. */
508 mjpeg_warn("unspecified sample-aspect-ratio --- taking a guess...");
509 y4m_si_set_sampleaspect(streaminfo,
510 y4m_guess_sar(param->output_width,
511 param->output_height,
512 param->dar));
513 }
514
515 switch (el_video_frame_data_format(0, &el)) { /* FIXME: checking only 0-th frame. */
516 case DATAFORMAT_YUV420:
517 switch (param->chroma) {
518 case Y4M_UNKNOWN:
519 case Y4M_CHROMA_420JPEG:
520 break;
521 case Y4M_CHROMA_420MPEG2:
522 case Y4M_CHROMA_420PALDV:
523 mjpeg_warn("4:2:0 chroma should be '420jpeg' with this input");
524 break;
525 default:
526 mjpeg_error_exit1("must specify 4:2:0 chroma (should be '420jpeg') with this input");
527 break;
528 }
529 break;
530
531 case DATAFORMAT_YUV422:
532 switch (param->chroma) {
533 case Y4M_CHROMA_422:
534 break;
535 default:
536 mjpeg_error_exit1("must specify chroma '422' with this input");
537 break;
538 }
539 break;
540
541 case DATAFORMAT_DV2:
542 #ifndef HAVE_LIBDV
543 mjpeg_error_exit1("DV input was not configured at compile time");
544 #else
545 el_get_video_frame(jpeg_data, 0, &el); /* FIXME: checking only 0-th frame. */
546 dv_parse_header(decoder, jpeg_data);
547 switch(decoder->sampling) {
548 case e_dv_sample_420:
549 switch (param->chroma) {
550 case Y4M_UNKNOWN:
551 mjpeg_info("set chroma '420paldv' from input");
552 param->chroma = Y4M_CHROMA_420PALDV;
553 break;
554 case Y4M_CHROMA_420PALDV:
555 break;
556 case Y4M_CHROMA_420JPEG:
557 case Y4M_CHROMA_420MPEG2:
558 mjpeg_warn("4:2:0 chroma should be '420paldv' with this input");
559 break;
560 case Y4M_CHROMA_422:
561 if(libdv_pal_yv12 == 1 )
562 mjpeg_error_exit1("must specify 4:2:0 chroma (should be '420paldv') with this input");
563 break;
564 default:
565 mjpeg_error_exit1("must specify 4:2:0 chroma (should be '420paldv') with this input");
566 break;
567 }
568 break;
569 case e_dv_sample_411:
570 if (param->chroma != Y4M_CHROMA_411)
571 mjpeg_info("chroma '411' recommended with this input");
572 switch (param->chroma) {
573 case Y4M_CHROMA_420MPEG2:
574 case Y4M_CHROMA_420PALDV:
575 mjpeg_warn("4:2:0 chroma should be '420jpeg' with this input");
576 break;
577 }
578 break;
579 case e_dv_sample_422:
580 if (param->chroma != Y4M_CHROMA_422)
581 mjpeg_info("chroma '422' recommended with this input");
582 switch (param->chroma) {
583 case Y4M_CHROMA_420MPEG2:
584 case Y4M_CHROMA_420PALDV:
585 mjpeg_warn("4:2:0 chroma should be '420jpeg' with this input");
586 break;
587 }
588 break;
589 default:
590 break;
591 }
592 #endif
593 break;
594
595 case DATAFORMAT_MJPG:
596 if (param->chroma != Y4M_CHROMA_422 && el.chroma == Y4M_CHROMA_422)
597 mjpeg_info("chroma '422' recommended with this input");
598 switch (param->chroma) {
599 case Y4M_CHROMA_420MPEG2:
600 case Y4M_CHROMA_420PALDV:
601 mjpeg_warn("4:2:0 chroma should be '420jpeg' with this input");
602 break;
603 }
604 break;
605 }
606 if (param->chroma == Y4M_UNKNOWN) {
607 mjpeg_info("set default chroma '420jpeg'");
608 param->chroma = Y4M_CHROMA_420JPEG;
609 }
610 y4m_si_set_chroma(streaminfo, param->chroma);
611
612 n = y4m_write_stream_header(out_fd, streaminfo);
613 if (n != Y4M_OK)
614 mjpeg_error("Failed to write stream header: %s", y4m_strerr(n));
615 }
616
617 #ifdef HAVE_LIBDV
lav_init_dv_decoder()618 void lav_init_dv_decoder()
619 {
620 decoder = dv_decoder_new(0,0,0);
621 decoder->quality = DV_QUALITY_BEST;
622 }
623 #endif
624