[MPlayer-cvslog] r23778 - in trunk: command.c libmpdemux/demux_lavf.c

aurel subversion at mplayerhq.hu
Fri Jul 13 23:15:25 CEST 2007


Author: aurel
Date: Fri Jul 13 23:15:24 2007
New Revision: 23778

Log:
add support for subtitles thru lavf

Modified:
   trunk/command.c
   trunk/libmpdemux/demux_lavf.c

Modified: trunk/command.c
==============================================================================
--- trunk/command.c	(original)
+++ trunk/command.c	Fri Jul 13 23:15:24 2007
@@ -1149,6 +1149,8 @@ static int mp_property_sub_pos(m_option_
     }
 }
 
+char *demux_lavf_sub_lang(demuxer_t *demuxer, int track_num);
+
 /// Selected subtitles (RW)
 static int mp_property_sub(m_option_t * prop, int action, void *arg,
 			   MPContext * mpctx)
@@ -1203,6 +1205,13 @@ static int mp_property_sub(m_option_t * 
 	}
 #endif
 
+#ifdef USE_LIBAVFORMAT
+	if (mpctx->demuxer->type == DEMUXER_TYPE_LAVF && dvdsub_id >= 0) {
+	    char *lang = demux_lavf_sub_lang(mpctx->demuxer, dvdsub_id);
+	    snprintf(*(char **) arg, 63, "(%d) %s", dvdsub_id, lang);
+	    return M_PROPERTY_OK;
+	}
+#endif
 	if (mpctx->demuxer->type == DEMUXER_TYPE_MATROSKA && dvdsub_id >= 0) {
 	    char lang[40] = MSGTR_Unknown;
 	    demux_mkv_get_sub_lang(mpctx->demuxer, dvdsub_id, lang, 9);

Modified: trunk/libmpdemux/demux_lavf.c
==============================================================================
--- trunk/libmpdemux/demux_lavf.c	(original)
+++ trunk/libmpdemux/demux_lavf.c	Fri Jul 13 23:15:24 2007
@@ -29,6 +29,7 @@
 #include "demuxer.h"
 #include "stheader.h"
 #include "m_option.h"
+#include "libvo/sub.h"
 
 #ifdef USE_LIBAVFORMAT_SO
 #include <ffmpeg/avformat.h>
@@ -61,9 +62,11 @@ typedef struct lavf_priv_t{
     ByteIOContext pb;
     int audio_streams;
     int video_streams;
+    int sub_streams;
     int64_t last_pts;
     int astreams[MAX_A_STREAMS];
     int vstreams[MAX_V_STREAMS];
+    int sstreams[MAX_S_STREAMS];
 }lavf_priv_t;
 
 extern void print_wave_header(WAVEFORMATEX *h, int verbose_level);
@@ -432,6 +435,20 @@ static demuxer_t* demux_open_lavf(demuxe
                 demuxer->video->sh= demuxer->v_streams[i];
             }
             break;}
+        case CODEC_TYPE_SUBTITLE:{
+            sh_sub_t* sh_sub;
+            if(priv->sub_streams >= MAX_S_STREAMS)
+                break;
+            /* only support text subtitles for now */
+            if(codec->codec_id != CODEC_ID_TEXT)
+                break;
+            sh_sub = new_sh_sub_sid(demuxer, i, priv->sub_streams);
+            mp_msg(MSGT_DEMUX, MSGL_INFO, MSGTR_SubtitleID, "lavf", priv->sub_streams);
+            if(!sh_sub) break;
+            priv->sstreams[priv->sub_streams] = i;
+            sh_sub->type = 't';
+            demuxer->sub->sh = demuxer->s_streams[priv->sub_streams++];
+            break;}
         default:
             st->discard= AVDISCARD_ALL;
         }
@@ -481,6 +498,10 @@ static int demux_lavf_fill_buffer(demuxe
             ds->sh=demux->v_streams[id];
             mp_msg(MSGT_DEMUX,MSGL_V,"Auto-selected LAVF video ID = %d\n",ds->id);
         }
+    } else if(id==demux->sub->id){
+        // subtitle
+        ds=demux->sub;
+        sub_utf8=1;
     } else {
         av_free_packet(&pkt);
         return 1;
@@ -504,6 +525,8 @@ static int demux_lavf_fill_buffer(demuxe
     if(pkt.pts != AV_NOPTS_VALUE){
         dp->pts=pkt.pts * av_q2d(priv->avfc->streams[id]->time_base);
         priv->last_pts= dp->pts * AV_TIME_BASE;
+        if(pkt.duration)
+            dp->endpts = dp->pts + pkt.duration * av_q2d(priv->avfc->streams[id]->time_base);
     }
     dp->pos=demux->filepos;
     dp->flags= !!(pkt.flags&PKT_FLAG_KEY);
@@ -612,6 +635,19 @@ static int demux_lavf_control(demuxer_t 
     }
 }
 
+/** \brief Get the language code for a subtitle track.
+
+  Retrieves the language code for a subtitle track.
+
+  \param demuxer The demuxer to work on
+  \param track_num The subtitle track number to get the language from
+*/
+char *demux_lavf_sub_lang(demuxer_t *demuxer, int track_num)
+{
+    lavf_priv_t *priv = demuxer->priv;
+    return priv->avfc->streams[priv->sstreams[track_num]]->language;
+}
+
 static void demux_close_lavf(demuxer_t *demuxer)
 {
     lavf_priv_t* priv = demuxer->priv;



More information about the MPlayer-cvslog mailing list