Mercurial > mplayer.hg
comparison libmpdemux/demux_lavf.c @ 23758:795631068b92
add support for subtitles thru lavf
author | aurel |
---|---|
date | Fri, 13 Jul 2007 21:15:24 +0000 |
parents | f3e72ce8a9fd |
children | 13893a33f5ba |
comparison
equal
deleted
inserted
replaced
23757:6d1e09675a4f | 23758:795631068b92 |
---|---|
27 | 27 |
28 #include "stream/stream.h" | 28 #include "stream/stream.h" |
29 #include "demuxer.h" | 29 #include "demuxer.h" |
30 #include "stheader.h" | 30 #include "stheader.h" |
31 #include "m_option.h" | 31 #include "m_option.h" |
32 #include "libvo/sub.h" | |
32 | 33 |
33 #ifdef USE_LIBAVFORMAT_SO | 34 #ifdef USE_LIBAVFORMAT_SO |
34 #include <ffmpeg/avformat.h> | 35 #include <ffmpeg/avformat.h> |
35 #include <ffmpeg/avutil.h> | 36 #include <ffmpeg/avutil.h> |
36 #include <ffmpeg/opt.h> | 37 #include <ffmpeg/opt.h> |
59 AVInputFormat *avif; | 60 AVInputFormat *avif; |
60 AVFormatContext *avfc; | 61 AVFormatContext *avfc; |
61 ByteIOContext pb; | 62 ByteIOContext pb; |
62 int audio_streams; | 63 int audio_streams; |
63 int video_streams; | 64 int video_streams; |
65 int sub_streams; | |
64 int64_t last_pts; | 66 int64_t last_pts; |
65 int astreams[MAX_A_STREAMS]; | 67 int astreams[MAX_A_STREAMS]; |
66 int vstreams[MAX_V_STREAMS]; | 68 int vstreams[MAX_V_STREAMS]; |
69 int sstreams[MAX_S_STREAMS]; | |
67 }lavf_priv_t; | 70 }lavf_priv_t; |
68 | 71 |
69 extern void print_wave_header(WAVEFORMATEX *h, int verbose_level); | 72 extern void print_wave_header(WAVEFORMATEX *h, int verbose_level); |
70 extern void print_video_header(BITMAPINFOHEADER *h, int verbose_level); | 73 extern void print_video_header(BITMAPINFOHEADER *h, int verbose_level); |
71 | 74 |
430 else{ | 433 else{ |
431 demuxer->video->id = i; | 434 demuxer->video->id = i; |
432 demuxer->video->sh= demuxer->v_streams[i]; | 435 demuxer->video->sh= demuxer->v_streams[i]; |
433 } | 436 } |
434 break;} | 437 break;} |
438 case CODEC_TYPE_SUBTITLE:{ | |
439 sh_sub_t* sh_sub; | |
440 if(priv->sub_streams >= MAX_S_STREAMS) | |
441 break; | |
442 /* only support text subtitles for now */ | |
443 if(codec->codec_id != CODEC_ID_TEXT) | |
444 break; | |
445 sh_sub = new_sh_sub_sid(demuxer, i, priv->sub_streams); | |
446 mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_SubtitleID, "lavf", priv->sub_streams); | |
447 if(!sh_sub) break; | |
448 priv->sstreams[priv->sub_streams] = i; | |
449 sh_sub->type = 't'; | |
450 demuxer->sub->sh = demuxer->s_streams[priv->sub_streams++]; | |
451 break;} | |
435 default: | 452 default: |
436 st->discard= AVDISCARD_ALL; | 453 st->discard= AVDISCARD_ALL; |
437 } | 454 } |
438 } | 455 } |
439 | 456 |
479 ds=demux->video; | 496 ds=demux->video; |
480 if(!ds->sh){ | 497 if(!ds->sh){ |
481 ds->sh=demux->v_streams[id]; | 498 ds->sh=demux->v_streams[id]; |
482 mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected LAVF video ID = %d\n",ds->id); | 499 mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected LAVF video ID = %d\n",ds->id); |
483 } | 500 } |
501 } else if(id==demux->sub->id){ | |
502 // subtitle | |
503 ds=demux->sub; | |
504 sub_utf8=1; | |
484 } else { | 505 } else { |
485 av_free_packet(&pkt); | 506 av_free_packet(&pkt); |
486 return 1; | 507 return 1; |
487 } | 508 } |
488 | 509 |
502 } | 523 } |
503 | 524 |
504 if(pkt.pts != AV_NOPTS_VALUE){ | 525 if(pkt.pts != AV_NOPTS_VALUE){ |
505 dp->pts=pkt.pts * av_q2d(priv->avfc->streams[id]->time_base); | 526 dp->pts=pkt.pts * av_q2d(priv->avfc->streams[id]->time_base); |
506 priv->last_pts= dp->pts * AV_TIME_BASE; | 527 priv->last_pts= dp->pts * AV_TIME_BASE; |
528 if(pkt.duration) | |
529 dp->endpts = dp->pts + pkt.duration * av_q2d(priv->avfc->streams[id]->time_base); | |
507 } | 530 } |
508 dp->pos=demux->filepos; | 531 dp->pos=demux->filepos; |
509 dp->flags= !!(pkt.flags&PKT_FLAG_KEY); | 532 dp->flags= !!(pkt.flags&PKT_FLAG_KEY); |
510 // append packet to DS stream: | 533 // append packet to DS stream: |
511 ds_add_packet(ds,dp); | 534 ds_add_packet(ds,dp); |
610 default: | 633 default: |
611 return DEMUXER_CTRL_NOTIMPL; | 634 return DEMUXER_CTRL_NOTIMPL; |
612 } | 635 } |
613 } | 636 } |
614 | 637 |
638 /** \brief Get the language code for a subtitle track. | |
639 | |
640 Retrieves the language code for a subtitle track. | |
641 | |
642 \param demuxer The demuxer to work on | |
643 \param track_num The subtitle track number to get the language from | |
644 */ | |
645 char *demux_lavf_sub_lang(demuxer_t *demuxer, int track_num) | |
646 { | |
647 lavf_priv_t *priv = demuxer->priv; | |
648 return priv->avfc->streams[priv->sstreams[track_num]]->language; | |
649 } | |
650 | |
615 static void demux_close_lavf(demuxer_t *demuxer) | 651 static void demux_close_lavf(demuxer_t *demuxer) |
616 { | 652 { |
617 lavf_priv_t* priv = demuxer->priv; | 653 lavf_priv_t* priv = demuxer->priv; |
618 if (priv){ | 654 if (priv){ |
619 if(priv->avfc) | 655 if(priv->avfc) |