1 /* $Id: decmpeg2.c,v 1.12 2005/03/03 16:30:42 titer Exp $
3 This file is part of the HandBrake source code.
4 Homepage: <http://handbrake.fr/>.
5 It may be used under the terms of the GNU General Public License. */
9 #include "mpeg2dec/mpeg2.h"
11 /* Cadence tracking */
12 #ifndef PIC_FLAG_REPEAT_FIRST_FIELD
13 #define PIC_FLAG_REPEAT_FIRST_FIELD 256
15 #define TOP_FIRST PIC_FLAG_TOP_FIELD_FIRST
16 #define PROGRESSIVE PIC_FLAG_PROGRESSIVE_FRAME
17 #define COMPOSITE PIC_FLAG_COMPOSITE_DISPLAY
18 #define SKIP PIC_FLAG_SKIP
19 #define TAGS PIC_FLAG_TAGS
20 #define REPEAT_FIRST PIC_FLAG_REPEAT_FIRST_FIELD
21 #define COMPOSITE_MASK PIC_MASK_COMPOSITE_DISPLAY
31 /**********************************************************************
33 *********************************************************************/
34 typedef struct hb_libmpeg2_s
36 mpeg2dec_t * libmpeg2;
37 const mpeg2_info_t * info;
44 enum PixelFormat pixfmt;
45 int got_iframe; /* set when we get our first iframe */
46 int look_for_iframe; /* need an iframe to add chap break */
47 int look_for_break; /* need gop start to add chap break */
48 int cur_tag; /* index of current tag */
49 uint32_t nframes; /* number of frames we've decoded */
54 hb_list_t * list_subtitle;
55 hb_buffer_t * last_cc1_buf;
57 int64_t start; // start time of this frame
58 hb_buffer_t * cc_buf; // captions for this frame
62 /**********************************************************************
64 **********************************************************************
66 *********************************************************************/
67 static hb_libmpeg2_t * hb_libmpeg2_init()
69 hb_libmpeg2_t * m = calloc( sizeof( hb_libmpeg2_t ), 1 );
71 m->libmpeg2 = mpeg2_init();
72 m->info = mpeg2_info( m->libmpeg2 );
77 for ( i = 0; i < NTAGS; ++i )
79 m->tags[i].start = -1;
85 // send cc_buf to the CC decoder(s)
86 static void cc_send_to_decoder( hb_libmpeg2_t *m, hb_buffer_t *cc_buf )
88 hb_subtitle_t *subtitle;
90 // if there's more than one decoder for the captions send a copy
91 // of the buffer to all but the last. Then send the buffer to
92 // the last one (usually there's just one decoder so the 'while' is skipped).
93 int i = 0, n = hb_list_count( m->list_subtitle );
96 // make a copy of the buf then forward it to the decoder
97 hb_buffer_t *cpy = hb_buffer_init( cc_buf->size );
98 hb_buffer_copy_settings( cpy, cc_buf );
99 memcpy( cpy->data, cc_buf->data, cc_buf->size );
101 subtitle = hb_list_item( m->list_subtitle, i++ );
102 hb_fifo_push( subtitle->fifo_in, cpy );
104 subtitle = hb_list_item( m->list_subtitle, i );
105 hb_fifo_push( subtitle->fifo_in, cc_buf );
108 static void hb_mpeg2_cc( hb_libmpeg2_t *m, const uint8_t *cc_block )
110 uint8_t cc_hdr = *cc_block;
112 if ( ( cc_hdr & 0x4 ) == 0 )
113 // not valid - ignore
120 if ( ( cc_block[1] & 0x7f ) == 0 && ( cc_block[2] & 0x7f ) == 0 )
121 // just padding - ignore
124 if ( m->last_cc1_buf )
126 // new data from the same time as last call - add to buffer
127 int len = m->last_cc1_buf->size;
128 hb_buffer_realloc( m->last_cc1_buf, len + 2 );
129 memcpy( m->last_cc1_buf->data + len, cc_block+1, 2 );
130 m->last_cc1_buf->size = len + 2;
134 // allocate a new buffer and copy the caption data into it.
135 // (we don't send it yet because we don't know what timestamp to use).
136 hb_buffer_t *cc_buf = hb_buffer_init( 2 );
140 memcpy( cc_buf->data, cc_block+1, 2 );
141 m->last_cc1_buf = cc_buf;
146 //process608( cc_block+1, 2, &m->cc608 );
158 do_708 ((const unsigned char *) temp, 4);
167 static inline int have_captions( const uint8_t *user_data, uint32_t len )
170 ( ( user_data[0] == 0x43 && user_data[1] == 0x43 ) ||
171 ( user_data[0] == 0x47 && user_data[1] == 0x41 &&
172 user_data[2] == 0x39 && user_data[3] == 0x34 &&
173 user_data[4] == 3 && (user_data[5] & 0x40) ) );
176 static void do_one_dvd_cc( hb_libmpeg2_t *m, const uint8_t *header, int field1 )
180 data[0] = ( header[0] == 0xff && 0 == field1 )? 0x04 : 0x05;
183 hb_mpeg2_cc( m, data );
185 data[0] = ( header[3] == 0xff && 1 == field1 )? 0x04 : 0x05;
188 hb_mpeg2_cc( m, data );
191 // extract all the captions in the current frame and send them downstream
194 // (this routine should only be called if there are captions in the current
195 // frame. I.e., only if a call to 'have_captions' returns true.)
196 static void extract_mpeg2_captions( hb_libmpeg2_t *m )
198 const uint8_t *user_data = m->info->user_data;
199 int dvd_captions = user_data[0] == 0x43;
200 int capcount, field1packet = 0;
201 const uint8_t *header = &user_data[4];
204 // ATSC encapsulated captions - header starts one byte later
205 // and has an extra unused byte following it.
206 capcount = header[1] & 0x1f;
212 if ( ( header[0] & 0x80 ) == 0x00 )
213 field1packet=1; /* expect Field 1 second */
214 capcount=(header[0] & 0x1e) / 2;
219 for( i=0; i<capcount; i++ )
223 hb_mpeg2_cc( m, header );
228 do_one_dvd_cc( m, header, field1packet );
234 // Deal with extra closed captions some DVDs have.
235 while( header[0]==0xfe || header[0]==0xff )
237 do_one_dvd_cc( m, header, field1packet );
243 static void next_tag( hb_libmpeg2_t *m, hb_buffer_t *buf_es )
245 m->cur_tag = ( m->cur_tag + 1 ) & (NTAGS-1);
246 if ( m->tags[m->cur_tag].start >= 0 || m->tags[m->cur_tag].cc_buf )
248 if ( m->tags[m->cur_tag].start < 0 ||
249 ( m->got_iframe && m->tags[m->cur_tag].start >= m->first_pts ) )
250 hb_log("mpeg2 tag botch: pts %"PRId64", tag pts %"PRId64" buf 0x%p",
251 buf_es->start, m->tags[m->cur_tag].start, m->tags[m->cur_tag].cc_buf);
252 if ( m->tags[m->cur_tag].cc_buf )
253 hb_buffer_close( &m->tags[m->cur_tag].cc_buf );
255 m->tags[m->cur_tag].start = buf_es->start;
256 mpeg2_tag_picture( m->libmpeg2, m->cur_tag, 0 );
259 static hb_buffer_t *hb_copy_frame( hb_job_t *job, int width, int height,
260 enum PixelFormat pixfmt,
261 uint8_t* y, uint8_t *u, uint8_t *v )
263 int dst_w = width, dst_h = height;
266 dst_w = job->title->width;
267 dst_h = job->title->height;
269 int dst_wh = dst_w * dst_h;
270 hb_buffer_t *buf = hb_video_buffer_init( dst_w, dst_h );
273 if ( dst_w != width || dst_h != height || pixfmt == PIX_FMT_YUV422P )
275 // we're encoding and the frame dimensions don't match the title dimensions -
276 // rescale & matte Y, U, V into our output buf.
278 avpicture_alloc(&in, pixfmt, width, height );
279 avpicture_alloc(&out, PIX_FMT_YUV420P, dst_w, dst_h );
281 int src_wh = width * height;
282 if ( pixfmt == PIX_FMT_YUV422P )
284 memcpy( in.data[0], y, src_wh );
285 memcpy( in.data[1], u, src_wh >> 1 );
286 memcpy( in.data[2], v, src_wh >> 1 );
290 memcpy( in.data[0], y, src_wh );
291 memcpy( in.data[1], u, src_wh >> 2 );
292 memcpy( in.data[2], v, src_wh >> 2 );
294 struct SwsContext *context = hb_sws_get_context( width, height, pixfmt,
295 dst_w, dst_h, PIX_FMT_YUV420P,
296 SWS_LANCZOS|SWS_ACCURATE_RND);
297 sws_scale( context, in.data, in.linesize, 0, height, out.data, out.linesize );
298 sws_freeContext( context );
300 uint8_t *data = buf->data;
301 memcpy( data, out.data[0], dst_wh );
303 // U & V planes are 1/4 the size of Y plane.
305 memcpy( data, out.data[1], dst_wh );
307 memcpy( data, out.data[2], dst_wh );
309 avpicture_free( &out );
310 avpicture_free( &in );
314 // we're scanning or the frame dimensions match the title's dimensions
315 // so we can do a straight copy.
316 uint8_t *data = buf->data;
317 memcpy( data, y, dst_wh );
319 // U & V planes are 1/4 the size of Y plane.
321 memcpy( data, u, dst_wh );
323 memcpy( data, v, dst_wh );
328 /**********************************************************************
330 **********************************************************************
332 *********************************************************************/
333 static int hb_libmpeg2_decode( hb_libmpeg2_t * m, hb_buffer_t * buf_es,
334 hb_list_t * list_raw )
342 if( buf_es->start >= 0 )
344 next_tag( m, buf_es );
346 mpeg2_buffer( m->libmpeg2, buf_es->data, buf_es->data + buf_es->size );
351 state = mpeg2_parse( m->libmpeg2 );
352 if( state == STATE_BUFFER )
354 /* Require some more data */
358 // if the user requested captions, process
359 // any captions found in the current frame.
360 if ( m->list_subtitle && m->last_pts >= 0 &&
361 have_captions( m->info->user_data, m->info->user_data_len ) )
363 extract_mpeg2_captions( m );
364 // if we don't have a tag for the captions, make one
365 if ( m->last_cc1_buf && m->tags[m->cur_tag].cc_buf != m->last_cc1_buf )
367 if (m->tags[m->cur_tag].cc_buf)
369 hb_log("mpeg2 tag botch2: pts %"PRId64", tag pts %"PRId64" buf 0x%p",
370 buf_es->start, m->tags[m->cur_tag].start, m->tags[m->cur_tag].cc_buf);
371 hb_buffer_close( &m->tags[m->cur_tag].cc_buf );
373 // see if we already made a tag for the timestamp. If so we
374 // can just use it, otherwise make a new tag.
375 if (m->tags[m->cur_tag].start < 0)
377 next_tag( m, buf_es );
379 m->tags[m->cur_tag].cc_buf = m->last_cc1_buf;
382 if( state == STATE_SEQUENCE )
384 if( !( m->width && m->height && m->rate ) )
386 m->width = m->info->sequence->width;
387 m->height = m->info->sequence->height;
388 m->rate = m->info->sequence->frame_period;
389 if ( m->aspect_ratio <= 0 && m->height &&
390 m->info->sequence->pixel_height )
392 /* mpeg2_parse doesn't store the aspect ratio. Instead
393 * it keeps the pixel width & height that would cause
394 * the storage width & height to come out in the correct
395 * aspect ratio. Convert these back to aspect ratio.
397 double ar_numer = m->width * m->info->sequence->pixel_width;
398 double ar_denom = m->height * m->info->sequence->pixel_height;
399 m->aspect_ratio = ar_numer / ar_denom;
402 if ( m->info->sequence->width >> 1 == m->info->sequence->chroma_width &&
403 m->info->sequence->height >> 1 == m->info->sequence->chroma_height )
405 m->pixfmt = PIX_FMT_YUV420P;
409 m->pixfmt = PIX_FMT_YUV422P;
412 else if( state == STATE_GOP && m->look_for_break)
414 // we were looking for a gop to add a chapter break - we found it
415 // so now start looking for an iframe.
416 m->look_for_iframe = m->look_for_break;
417 m->look_for_break = 0;
419 else if( ( state == STATE_SLICE || state == STATE_END ) &&
420 m->info->display_fbuf )
422 m->last_cc1_buf = NULL;
424 if( !m->got_iframe && ( m->info->display_picture->flags &
425 PIC_MASK_CODING_TYPE ) == PIC_FLAG_CODING_TYPE_I )
427 // we got an iframe so we can start decoding video now
433 buf = hb_copy_frame( m->job, m->info->sequence->width,
434 m->info->sequence->height,
436 m->info->display_fbuf->buf[0],
437 m->info->display_fbuf->buf[1],
438 m->info->display_fbuf->buf[2] );
439 buf->sequence = buf_es->sequence;
441 hb_buffer_t *cc_buf = NULL;
442 if( m->info->display_picture->flags & PIC_FLAG_TAGS )
444 int t = m->info->display_picture->tag;
445 buf->start = m->tags[t].start;
446 cc_buf = m->tags[t].cc_buf;
447 m->tags[t].start = -1;
448 m->tags[t].cc_buf = NULL;
450 if( buf->start < 0 && m->last_pts >= 0 )
452 /* For some reason nb_fields is sometimes 1 while it
454 buf->start = m->last_pts +
455 MAX( 2, m->info->display_picture->nb_fields ) *
456 m->info->sequence->frame_period / 600;
458 if ( buf->start >= 0 )
460 m->last_pts = buf->start;
463 // if we were accumulating captions we now know the timestamp
464 // so ship them to the decoder.
467 cc_buf->start = m->last_pts;
468 cc_send_to_decoder( m, cc_buf );
471 if( m->look_for_iframe && ( m->info->display_picture->flags &
472 PIC_MASK_CODING_TYPE ) == PIC_FLAG_CODING_TYPE_I )
474 // we were waiting for an iframe to insert a chapter mark
476 buf->new_chap = m->look_for_iframe;
477 m->look_for_iframe = 0;
478 const char *chap_name = "";
479 if ( m->job && buf->new_chap > 0 &&
480 hb_list_item( m->job->title->list_chapter,
481 buf->new_chap - 1 ) )
483 hb_chapter_t * c = hb_list_item( m->job->title->list_chapter,
485 chap_name = c->title;
487 hb_log( "mpeg2: \"%s\" (%d) at frame %u time %"PRId64,
488 chap_name, buf->new_chap, m->nframes, buf->start );
490 else if ( m->nframes == 0 )
492 // this is the first frame returned by the decoder
493 m->first_pts = buf->start;
494 if ( m->job && hb_list_item( m->job->title->list_chapter,
495 m->job->chapter_start - 1 ) )
497 hb_chapter_t * c = hb_list_item( m->job->title->list_chapter,
498 m->job->chapter_start - 1 );
499 hb_log( "mpeg2: \"%s\" (%d) at frame %u time %"PRId64,
500 c->title, m->job->chapter_start, m->nframes, buf->start );
505 m->flag = m->info->display_picture->flags;
507 /* Uncomment this block to see frame-by-frame picture flags, as the video encodes.
508 hb_log("***** MPEG 2 Picture Info for PTS %"PRId64" *****", buf->start);
509 if( m->flag & TOP_FIRST )
510 hb_log("MPEG2 Flag: Top field first");
511 if( m->flag & PROGRESSIVE )
512 hb_log("MPEG2 Flag: Progressive");
513 if( m->flag & COMPOSITE )
514 hb_log("MPEG2 Flag: Composite");
516 hb_log("MPEG2 Flag: Skip!");
518 hb_log("MPEG2 Flag: TAGS");
519 if(fm->lag & REPEAT_FIRST )
520 hb_log("MPEG2 Flag: Repeat first field");
521 if( m->flag & COMPOSITE_MASK )
522 hb_log("MPEG2 Flag: Composite mask");
523 hb_log("fields: %d", m->info->display_picture->nb_fields);
525 /* Rotate the cadence tracking. */
527 for(i=11; i > 0; i--)
529 m->cadence[i] = m->cadence[i-1];
532 if ( !(m->flag & PROGRESSIVE) && !(m->flag & TOP_FIRST) )
534 /* Not progressive, not top first...
535 That means it's probably bottom
536 first, 2 fields displayed.
538 //hb_log("MPEG2 Flag: Bottom field first, 2 fields displayed.");
541 else if ( !(m->flag & PROGRESSIVE) && (m->flag & TOP_FIRST) )
543 /* Not progressive, top is first,
544 Two fields displayed.
546 //hb_log("MPEG2 Flag: Top field first, 2 fields displayed.");
549 else if ( (m->flag & PROGRESSIVE) && !(m->flag & TOP_FIRST) && !( m->flag & REPEAT_FIRST ) )
551 /* Progressive, but noting else.
552 That means Bottom first,
555 //hb_log("MPEG2 Flag: Progressive. Bottom field first, 2 fields displayed.");
556 m->cadence[0] = BT_PROG;
558 else if ( (m->flag & PROGRESSIVE) && !(m->flag & TOP_FIRST) && ( m->flag & REPEAT_FIRST ) )
560 /* Progressive, and repeat. .
561 That means Bottom first,
564 //hb_log("MPEG2 Flag: Progressive repeat. Bottom field first, 3 fields displayed.");
565 m->cadence[0] = BTB_PROG;
567 else if ( (m->flag & PROGRESSIVE) && (m->flag & TOP_FIRST) && !( m->flag & REPEAT_FIRST ) )
569 /* Progressive, top first.
570 That means top first,
573 //hb_log("MPEG2 Flag: Progressive. Top field first, 2 fields displayed.");
574 m->cadence[0] = TB_PROG;
576 else if ( (m->flag & PROGRESSIVE) && (m->flag & TOP_FIRST) && ( m->flag & REPEAT_FIRST ) )
578 /* Progressive, top, repeat.
579 That means top first,
582 //hb_log("MPEG2 Flag: Progressive repeat. Top field first, 3 fields displayed.");
583 m->cadence[0] = TBT_PROG;
586 if ( (m->cadence[2] <= TB) && (m->cadence[1] <= TB) && (m->cadence[0] > TB) && (m->cadence[11]) )
587 hb_log("%fs: Video -> Film", (float)buf->start / 90000);
588 if ( (m->cadence[2] > TB) && (m->cadence[1] <= TB) && (m->cadence[0] <= TB) && (m->cadence[11]) )
589 hb_log("%fs: Film -> Video", (float)buf->start / 90000);
591 /* Store picture flags for later use by filters */
592 buf->flags = m->info->display_picture->flags;
594 hb_list_add( list_raw, buf );
597 else if( state == STATE_INVALID )
599 mpeg2_reset( m->libmpeg2, 0 );
603 * Add closed captions to the title if we are scanning (no job).
605 * Just because we don't add this doesn't mean that there aren't any when
606 * we scan, just that noone said anything. So you should be able to add
607 * closed captions some other way (See decmpeg2Init() for alternative
608 * approach of assuming that there are always CC, which is probably
609 * safer - however I want to leave the autodetect in here for now to
612 if( !m->job && m->title &&
613 have_captions( m->info->user_data, m->info->user_data_len ) )
615 hb_subtitle_t *subtitle;
618 while ( ( subtitle = hb_list_item( m->title->list_subtitle, i++ ) ) )
621 * Let's call them 608 subs for now even if they aren't,
622 * since they are the only types we grok.
624 if( subtitle->source == CC608SUB )
632 subtitle = calloc( sizeof( hb_subtitle_t ), 1 );
635 subtitle->format = TEXTSUB;
636 subtitle->source = CC608SUB;
637 subtitle->config.dest = PASSTHRUSUB;
639 snprintf( subtitle->lang, sizeof( subtitle->lang ), "Closed Captions");
641 * The language of the subtitles will be the same as the first audio
642 * track, i.e. the same as the video.
644 hb_audio_t *audio = hb_list_item( m->title->list_audio, 0 );
647 snprintf( subtitle->iso639_2, sizeof( subtitle->iso639_2 ),
648 audio->config.lang.iso639_2);
650 snprintf( subtitle->iso639_2, sizeof( subtitle->iso639_2 ), "und");
652 hb_list_add( m->title->list_subtitle, subtitle );
659 /**********************************************************************
661 **********************************************************************
663 *********************************************************************/
664 static void hb_libmpeg2_close( hb_libmpeg2_t ** _m )
666 hb_libmpeg2_t * m = *_m;
668 mpeg2_close( m->libmpeg2 );
671 for ( i = 0; i < NTAGS; ++i )
673 if ( m->tags[i].cc_buf )
675 if ( m->tags[i].cc_buf == m->last_cc1_buf )
676 m->last_cc1_buf = NULL;
677 hb_buffer_close( &m->tags[i].cc_buf );
680 if ( m->last_cc1_buf )
682 hb_buffer_close( &m->last_cc1_buf );
689 /**********************************************************************
690 * The decmpeg2 work object
691 **********************************************************************
693 *********************************************************************/
694 struct hb_work_private_s
696 hb_libmpeg2_t * libmpeg2;
700 /**********************************************************************
701 * hb_work_decmpeg2_init
702 **********************************************************************
704 *********************************************************************/
705 static int decmpeg2Init( hb_work_object_t * w, hb_job_t * job )
707 hb_work_private_t * pv;
709 pv = calloc( 1, sizeof( hb_work_private_t ) );
710 w->private_data = pv;
712 pv->libmpeg2 = hb_libmpeg2_init();
713 pv->list = hb_list_init();
715 pv->libmpeg2->job = job;
717 if( job && job->title ) {
718 pv->libmpeg2->title = job->title;
722 * If not scanning, then are we supposed to extract Closed Captions
723 * and send them to the decoder?
725 if( job && hb_list_count( job->list_subtitle ) > 0 )
727 hb_subtitle_t *subtitle;
730 for( i = 0; i < hb_list_count( job->list_subtitle ); i++ )
731 while ( ( subtitle = hb_list_item( job->list_subtitle, i++ ) ) != NULL )
733 if( subtitle->source == CC608SUB )
735 if ( ! pv->libmpeg2->list_subtitle )
737 pv->libmpeg2->list_subtitle = hb_list_init();
739 hb_list_add(pv->libmpeg2->list_subtitle, subtitle);
747 /**********************************************************************
749 **********************************************************************
751 *********************************************************************/
752 static int decmpeg2Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
753 hb_buffer_t ** buf_out )
755 hb_work_private_t * pv = w->private_data;
756 hb_buffer_t * buf, * last = NULL;
757 int status = HB_WORK_OK;
759 if( w->title && pv && pv->libmpeg2 && !pv->libmpeg2->title ) {
760 pv->libmpeg2->title = w->title;
763 // The reader found a chapter break. Remove it from the input
764 // stream. If we're reading (as opposed to scanning) start looking
765 // for the next GOP start since that's where the chapter begins.
766 if( (*buf_in)->new_chap )
768 if ( pv->libmpeg2->job )
770 pv->libmpeg2->look_for_break = (*buf_in)->new_chap;
772 (*buf_in)->new_chap = 0;
775 hb_libmpeg2_decode( pv->libmpeg2, *buf_in, pv->list );
777 /* if we got an empty buffer signaling end-of-stream send it downstream */
778 if ( (*buf_in)->size == 0 )
780 hb_list_add( pv->list, *buf_in );
782 status = HB_WORK_DONE;
785 * Purge any pending caption buffer then let the Closed Captions decoder
786 * know that it is the end of the data.
788 if ( pv->libmpeg2->list_subtitle )
790 if ( pv->libmpeg2->last_cc1_buf )
792 cc_send_to_decoder( pv->libmpeg2, pv->libmpeg2->last_cc1_buf );
793 if ( pv->libmpeg2->tags[pv->libmpeg2->cur_tag].cc_buf ==
794 pv->libmpeg2->last_cc1_buf )
796 pv->libmpeg2->tags[pv->libmpeg2->cur_tag].cc_buf = NULL;
798 pv->libmpeg2->last_cc1_buf = NULL;
800 cc_send_to_decoder( pv->libmpeg2, hb_buffer_init( 0 ) );
805 while( ( buf = hb_list_item( pv->list, 0 ) ) )
807 hb_list_rem( pv->list, buf );
823 /**********************************************************************
825 **********************************************************************
827 *********************************************************************/
828 static void decmpeg2Close( hb_work_object_t * w )
830 hb_work_private_t * pv = w->private_data;
832 // don't log during scan
833 if ( pv->libmpeg2->job )
835 hb_log( "mpeg2 done: %d frames", pv->libmpeg2->nframes );
837 hb_list_close( &pv->list );
838 if ( pv->libmpeg2->list_subtitle )
840 hb_list_close( &pv->libmpeg2->list_subtitle );
842 hb_libmpeg2_close( &pv->libmpeg2 );
846 static int decmpeg2Info( hb_work_object_t *w, hb_work_info_t *info )
848 hb_work_private_t *pv = w->private_data;
850 memset( info, 0, sizeof(*info) );
852 if ( pv && pv->libmpeg2 && pv->libmpeg2->info && pv->libmpeg2->info->sequence )
854 hb_libmpeg2_t *m = pv->libmpeg2;
856 info->width = m->width;
857 info->height = m->height;
858 info->pixel_aspect_width = m->info->sequence->pixel_width;
859 info->pixel_aspect_height = m->info->sequence->pixel_height;
860 info->aspect = m->aspect_ratio;
862 // if the frame is progressive & NTSC DVD height report it as 23.976 FPS
863 // so that scan can autodetect NTSC film
864 info->rate = 27000000;
865 info->rate_base = ( m->info->display_fbuf && m->info->display_picture &&
866 (m->info->display_picture->flags & PROGRESSIVE) &&
867 (m->height == 480 ) ) ? 1126125 : m->rate;
869 info->bitrate = m->info->sequence->byte_rate * 8;
870 info->profile = m->info->sequence->profile_level_id >> 4;
871 info->level = m->info->sequence->profile_level_id & 0xf;
872 info->name = "mpeg2";
878 hb_work_object_t hb_decmpeg2 =
881 "MPEG-2 decoder (libmpeg2)",