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 = sws_getContext( width, height, pixfmt,
295 dst_w, dst_h, PIX_FMT_YUV420P,
296 SWS_LANCZOS|SWS_ACCURATE_RND,
298 sws_scale( context, in.data, in.linesize, 0, height, out.data, out.linesize );
299 sws_freeContext( context );
301 uint8_t *data = buf->data;
302 memcpy( data, out.data[0], dst_wh );
304 // U & V planes are 1/4 the size of Y plane.
306 memcpy( data, out.data[1], dst_wh );
308 memcpy( data, out.data[2], dst_wh );
310 avpicture_free( &out );
311 avpicture_free( &in );
315 // we're scanning or the frame dimensions match the title's dimensions
316 // so we can do a straight copy.
317 uint8_t *data = buf->data;
318 memcpy( data, y, dst_wh );
320 // U & V planes are 1/4 the size of Y plane.
322 memcpy( data, u, dst_wh );
324 memcpy( data, v, dst_wh );
329 /**********************************************************************
331 **********************************************************************
333 *********************************************************************/
334 static int hb_libmpeg2_decode( hb_libmpeg2_t * m, hb_buffer_t * buf_es,
335 hb_list_t * list_raw )
343 if( buf_es->start >= 0 )
345 next_tag( m, buf_es );
347 mpeg2_buffer( m->libmpeg2, buf_es->data, buf_es->data + buf_es->size );
352 state = mpeg2_parse( m->libmpeg2 );
353 if( state == STATE_BUFFER )
355 /* Require some more data */
359 // if the user requested captions, process
360 // any captions found in the current frame.
361 if ( m->list_subtitle && m->last_pts >= 0 &&
362 have_captions( m->info->user_data, m->info->user_data_len ) )
364 extract_mpeg2_captions( m );
365 // if we don't have a tag for the captions, make one
366 if ( m->last_cc1_buf && m->tags[m->cur_tag].cc_buf != m->last_cc1_buf )
368 if (m->tags[m->cur_tag].cc_buf)
370 hb_log("mpeg2 tag botch2: pts %"PRId64", tag pts %"PRId64" buf 0x%p",
371 buf_es->start, m->tags[m->cur_tag].start, m->tags[m->cur_tag].cc_buf);
372 hb_buffer_close( &m->tags[m->cur_tag].cc_buf );
374 // see if we already made a tag for the timestamp. If so we
375 // can just use it, otherwise make a new tag.
376 if (m->tags[m->cur_tag].start < 0)
378 next_tag( m, buf_es );
380 m->tags[m->cur_tag].cc_buf = m->last_cc1_buf;
383 if( state == STATE_SEQUENCE )
385 if( !( m->width && m->height && m->rate ) )
387 m->width = m->info->sequence->width;
388 m->height = m->info->sequence->height;
389 m->rate = m->info->sequence->frame_period;
390 if ( m->aspect_ratio <= 0 && m->height &&
391 m->info->sequence->pixel_height )
393 /* mpeg2_parse doesn't store the aspect ratio. Instead
394 * it keeps the pixel width & height that would cause
395 * the storage width & height to come out in the correct
396 * aspect ratio. Convert these back to aspect ratio.
398 double ar_numer = m->width * m->info->sequence->pixel_width;
399 double ar_denom = m->height * m->info->sequence->pixel_height;
400 m->aspect_ratio = ar_numer / ar_denom;
403 if ( m->info->sequence->width >> 1 == m->info->sequence->chroma_width &&
404 m->info->sequence->height >> 1 == m->info->sequence->chroma_height )
406 m->pixfmt = PIX_FMT_YUV420P;
410 m->pixfmt = PIX_FMT_YUV422P;
413 else if( state == STATE_GOP && m->look_for_break)
415 // we were looking for a gop to add a chapter break - we found it
416 // so now start looking for an iframe.
417 m->look_for_iframe = m->look_for_break;
418 m->look_for_break = 0;
420 else if( ( state == STATE_SLICE || state == STATE_END ) &&
421 m->info->display_fbuf )
423 m->last_cc1_buf = NULL;
425 if( !m->got_iframe && ( m->info->display_picture->flags &
426 PIC_MASK_CODING_TYPE ) == PIC_FLAG_CODING_TYPE_I )
428 // we got an iframe so we can start decoding video now
434 buf = hb_copy_frame( m->job, m->info->sequence->width,
435 m->info->sequence->height,
437 m->info->display_fbuf->buf[0],
438 m->info->display_fbuf->buf[1],
439 m->info->display_fbuf->buf[2] );
440 buf->sequence = buf_es->sequence;
442 hb_buffer_t *cc_buf = NULL;
443 if( m->info->display_picture->flags & PIC_FLAG_TAGS )
445 int t = m->info->display_picture->tag;
446 buf->start = m->tags[t].start;
447 cc_buf = m->tags[t].cc_buf;
448 m->tags[t].start = -1;
449 m->tags[t].cc_buf = NULL;
451 if( buf->start < 0 && m->last_pts >= 0 )
453 /* For some reason nb_fields is sometimes 1 while it
455 buf->start = m->last_pts +
456 MAX( 2, m->info->display_picture->nb_fields ) *
457 m->info->sequence->frame_period / 600;
459 if ( buf->start >= 0 )
461 m->last_pts = buf->start;
464 // if we were accumulating captions we now know the timestamp
465 // so ship them to the decoder.
468 cc_buf->start = m->last_pts;
469 cc_send_to_decoder( m, cc_buf );
472 if( m->look_for_iframe && ( m->info->display_picture->flags &
473 PIC_MASK_CODING_TYPE ) == PIC_FLAG_CODING_TYPE_I )
475 // we were waiting for an iframe to insert a chapter mark
477 buf->new_chap = m->look_for_iframe;
478 m->look_for_iframe = 0;
479 const char *chap_name = "";
480 if ( m->job && buf->new_chap > 0 &&
481 hb_list_item( m->job->title->list_chapter,
482 buf->new_chap - 1 ) )
484 hb_chapter_t * c = hb_list_item( m->job->title->list_chapter,
486 chap_name = c->title;
488 hb_log( "mpeg2: \"%s\" (%d) at frame %u time %"PRId64,
489 chap_name, buf->new_chap, m->nframes, buf->start );
491 else if ( m->nframes == 0 )
493 // this is the first frame returned by the decoder
494 m->first_pts = buf->start;
495 if ( m->job && hb_list_item( m->job->title->list_chapter,
496 m->job->chapter_start - 1 ) )
498 hb_chapter_t * c = hb_list_item( m->job->title->list_chapter,
499 m->job->chapter_start - 1 );
500 hb_log( "mpeg2: \"%s\" (%d) at frame %u time %"PRId64,
501 c->title, m->job->chapter_start, m->nframes, buf->start );
506 m->flag = m->info->display_picture->flags;
508 /* Uncomment this block to see frame-by-frame picture flags, as the video encodes.
509 hb_log("***** MPEG 2 Picture Info for PTS %lld *****", buf->start);
510 if( m->flag & TOP_FIRST )
511 hb_log("MPEG2 Flag: Top field first");
512 if( m->flag & PROGRESSIVE )
513 hb_log("MPEG2 Flag: Progressive");
514 if( m->flag & COMPOSITE )
515 hb_log("MPEG2 Flag: Composite");
517 hb_log("MPEG2 Flag: Skip!");
519 hb_log("MPEG2 Flag: TAGS");
520 if(fm->lag & REPEAT_FIRST )
521 hb_log("MPEG2 Flag: Repeat first field");
522 if( m->flag & COMPOSITE_MASK )
523 hb_log("MPEG2 Flag: Composite mask");
524 hb_log("fields: %d", m->info->display_picture->nb_fields);
526 /* Rotate the cadence tracking. */
528 for(i=11; i > 0; i--)
530 m->cadence[i] = m->cadence[i-1];
533 if ( !(m->flag & PROGRESSIVE) && !(m->flag & TOP_FIRST) )
535 /* Not progressive, not top first...
536 That means it's probably bottom
537 first, 2 fields displayed.
539 //hb_log("MPEG2 Flag: Bottom field first, 2 fields displayed.");
542 else if ( !(m->flag & PROGRESSIVE) && (m->flag & TOP_FIRST) )
544 /* Not progressive, top is first,
545 Two fields displayed.
547 //hb_log("MPEG2 Flag: Top field first, 2 fields displayed.");
550 else if ( (m->flag & PROGRESSIVE) && !(m->flag & TOP_FIRST) && !( m->flag & REPEAT_FIRST ) )
552 /* Progressive, but noting else.
553 That means Bottom first,
556 //hb_log("MPEG2 Flag: Progressive. Bottom field first, 2 fields displayed.");
557 m->cadence[0] = BT_PROG;
559 else if ( (m->flag & PROGRESSIVE) && !(m->flag & TOP_FIRST) && ( m->flag & REPEAT_FIRST ) )
561 /* Progressive, and repeat. .
562 That means Bottom first,
565 //hb_log("MPEG2 Flag: Progressive repeat. Bottom field first, 3 fields displayed.");
566 m->cadence[0] = BTB_PROG;
568 else if ( (m->flag & PROGRESSIVE) && (m->flag & TOP_FIRST) && !( m->flag & REPEAT_FIRST ) )
570 /* Progressive, top first.
571 That means top first,
574 //hb_log("MPEG2 Flag: Progressive. Top field first, 2 fields displayed.");
575 m->cadence[0] = TB_PROG;
577 else if ( (m->flag & PROGRESSIVE) && (m->flag & TOP_FIRST) && ( m->flag & REPEAT_FIRST ) )
579 /* Progressive, top, repeat.
580 That means top first,
583 //hb_log("MPEG2 Flag: Progressive repeat. Top field first, 3 fields displayed.");
584 m->cadence[0] = TBT_PROG;
587 if ( (m->cadence[2] <= TB) && (m->cadence[1] <= TB) && (m->cadence[0] > TB) && (m->cadence[11]) )
588 hb_log("%fs: Video -> Film", (float)buf->start / 90000);
589 if ( (m->cadence[2] > TB) && (m->cadence[1] <= TB) && (m->cadence[0] <= TB) && (m->cadence[11]) )
590 hb_log("%fs: Film -> Video", (float)buf->start / 90000);
592 /* Store picture flags for later use by filters */
593 buf->flags = m->info->display_picture->flags;
595 hb_list_add( list_raw, buf );
598 else if( state == STATE_INVALID )
600 mpeg2_reset( m->libmpeg2, 0 );
604 * Add closed captions to the title if we are scanning (no job).
606 * Just because we don't add this doesn't mean that there aren't any when
607 * we scan, just that noone said anything. So you should be able to add
608 * closed captions some other way (See decmpeg2Init() for alternative
609 * approach of assuming that there are always CC, which is probably
610 * safer - however I want to leave the autodetect in here for now to
613 if( !m->job && m->title &&
614 have_captions( m->info->user_data, m->info->user_data_len ) )
616 hb_subtitle_t *subtitle;
619 while ( ( subtitle = hb_list_item( m->title->list_subtitle, i++ ) ) )
622 * Let's call them 608 subs for now even if they aren't,
623 * since they are the only types we grok.
625 if( subtitle->source == CC608SUB )
633 subtitle = calloc( sizeof( hb_subtitle_t ), 1 );
636 subtitle->format = TEXTSUB;
637 subtitle->source = CC608SUB;
638 subtitle->config.dest = PASSTHRUSUB;
640 snprintf( subtitle->lang, sizeof( subtitle->lang ), "Closed Captions");
642 * The language of the subtitles will be the same as the first audio
643 * track, i.e. the same as the video.
645 hb_audio_t *audio = hb_list_item( m->title->list_audio, 0 );
648 snprintf( subtitle->iso639_2, sizeof( subtitle->iso639_2 ),
649 audio->config.lang.iso639_2);
651 snprintf( subtitle->iso639_2, sizeof( subtitle->iso639_2 ), "und");
653 hb_list_add( m->title->list_subtitle, subtitle );
660 /**********************************************************************
662 **********************************************************************
664 *********************************************************************/
665 static void hb_libmpeg2_close( hb_libmpeg2_t ** _m )
667 hb_libmpeg2_t * m = *_m;
669 mpeg2_close( m->libmpeg2 );
672 for ( i = 0; i < NTAGS; ++i )
674 if ( m->tags[i].cc_buf )
675 hb_buffer_close( &m->tags[i].cc_buf );
682 /**********************************************************************
683 * The decmpeg2 work object
684 **********************************************************************
686 *********************************************************************/
687 struct hb_work_private_s
689 hb_libmpeg2_t * libmpeg2;
693 /**********************************************************************
694 * hb_work_decmpeg2_init
695 **********************************************************************
697 *********************************************************************/
698 static int decmpeg2Init( hb_work_object_t * w, hb_job_t * job )
700 hb_work_private_t * pv;
702 pv = calloc( 1, sizeof( hb_work_private_t ) );
703 w->private_data = pv;
705 pv->libmpeg2 = hb_libmpeg2_init();
706 pv->list = hb_list_init();
708 pv->libmpeg2->job = job;
710 if( job && job->title ) {
711 pv->libmpeg2->title = job->title;
715 * If not scanning, then are we supposed to extract Closed Captions
716 * and send them to the decoder?
718 if( job && hb_list_count( job->list_subtitle ) > 0 )
720 hb_subtitle_t *subtitle;
723 for( i = 0; i < hb_list_count( job->list_subtitle ); i++ )
724 while ( ( subtitle = hb_list_item( job->list_subtitle, i++ ) ) != NULL )
726 if( subtitle->source == CC608SUB )
728 if ( ! pv->libmpeg2->list_subtitle )
730 pv->libmpeg2->list_subtitle = hb_list_init();
732 hb_list_add(pv->libmpeg2->list_subtitle, subtitle);
740 /**********************************************************************
742 **********************************************************************
744 *********************************************************************/
745 static int decmpeg2Work( hb_work_object_t * w, hb_buffer_t ** buf_in,
746 hb_buffer_t ** buf_out )
748 hb_work_private_t * pv = w->private_data;
749 hb_buffer_t * buf, * last = NULL;
750 int status = HB_WORK_OK;
752 if( w->title && pv && pv->libmpeg2 && !pv->libmpeg2->title ) {
753 pv->libmpeg2->title = w->title;
756 // The reader found a chapter break. Remove it from the input
757 // stream. If we're reading (as opposed to scanning) start looking
758 // for the next GOP start since that's where the chapter begins.
759 if( (*buf_in)->new_chap )
761 if ( pv->libmpeg2->job )
763 pv->libmpeg2->look_for_break = (*buf_in)->new_chap;
765 (*buf_in)->new_chap = 0;
768 hb_libmpeg2_decode( pv->libmpeg2, *buf_in, pv->list );
770 /* if we got an empty buffer signaling end-of-stream send it downstream */
771 if ( (*buf_in)->size == 0 )
773 hb_list_add( pv->list, *buf_in );
775 status = HB_WORK_DONE;
778 * Purge any pending caption buffer then let the Closed Captions decoder
779 * know that it is the end of the data.
781 if ( pv->libmpeg2->list_subtitle )
783 if ( pv->libmpeg2->last_cc1_buf )
785 cc_send_to_decoder( pv->libmpeg2, pv->libmpeg2->last_cc1_buf );
786 pv->libmpeg2->last_cc1_buf = NULL;
788 cc_send_to_decoder( pv->libmpeg2, hb_buffer_init( 0 ) );
793 while( ( buf = hb_list_item( pv->list, 0 ) ) )
795 hb_list_rem( pv->list, buf );
811 /**********************************************************************
813 **********************************************************************
815 *********************************************************************/
816 static void decmpeg2Close( hb_work_object_t * w )
818 hb_work_private_t * pv = w->private_data;
820 // don't log during scan
821 if ( pv->libmpeg2->job )
823 hb_log( "mpeg2 done: %d frames", pv->libmpeg2->nframes );
825 if ( pv->libmpeg2->last_cc1_buf )
827 hb_buffer_close( &pv->libmpeg2->last_cc1_buf );
829 hb_list_close( &pv->list );
830 if ( pv->libmpeg2->list_subtitle )
832 hb_list_close( &pv->libmpeg2->list_subtitle );
834 hb_libmpeg2_close( &pv->libmpeg2 );
838 static int decmpeg2Info( hb_work_object_t *w, hb_work_info_t *info )
840 hb_work_private_t *pv = w->private_data;
842 memset( info, 0, sizeof(*info) );
844 if ( pv && pv->libmpeg2 && pv->libmpeg2->info && pv->libmpeg2->info->sequence )
846 hb_libmpeg2_t *m = pv->libmpeg2;
848 info->width = m->width;
849 info->height = m->height;
850 info->pixel_aspect_width = m->info->sequence->pixel_width;
851 info->pixel_aspect_height = m->info->sequence->pixel_height;
852 info->aspect = m->aspect_ratio;
854 // if the frame is progressive & NTSC DVD height report it as 23.976 FPS
855 // so that scan can autodetect NTSC film
856 info->rate = 27000000;
857 info->rate_base = ( m->info->display_fbuf && m->info->display_picture &&
858 (m->info->display_picture->flags & PROGRESSIVE) &&
859 (m->height == 480 ) ) ? 1126125 : m->rate;
861 info->bitrate = m->info->sequence->byte_rate * 8;
862 info->profile = m->info->sequence->profile_level_id >> 4;
863 info->level = m->info->sequence->profile_level_id & 0xf;
864 info->name = "mpeg2";
870 hb_work_object_t hb_decmpeg2 =
873 "MPEG-2 decoder (libmpeg2)",