[FFmpeg-soc] [soc]: r4553 - in concat/libavformat: m3u.c playlist.c playlist.h

gkovacs subversion at mplayerhq.hu
Tue Jun 30 21:28:59 CEST 2009


Author: gkovacs
Date: Tue Jun 30 21:28:59 2009
New Revision: 4553

Log:
fixed timestamps on outputted files, ffmpeg with same-format inputs should now be working

Modified:
   concat/libavformat/m3u.c
   concat/libavformat/playlist.c
   concat/libavformat/playlist.h

Modified: concat/libavformat/m3u.c
==============================================================================
--- concat/libavformat/m3u.c	Tue Jun 30 19:43:58 2009	(r4552)
+++ concat/libavformat/m3u.c	Tue Jun 30 21:28:59 2009	(r4553)
@@ -87,18 +87,13 @@ static int m3u_read_header(AVFormatConte
                            AVFormatParameters *ap)
 {
     printf("m3u read header called\n");
-    PlaylistD *playld = av_malloc(sizeof(PlaylistD));
-    ff_split_wd_fn(s->filename,
-                &playld->workingdir,
-                &playld->filename);
+    PlaylistD *playld = ff_make_playlistd(s->filename);
     m3u_list_files(s->pb,
                    &(playld->flist),
                    &(playld->pelist_size),
                    playld->workingdir);
-//    playld = av_make_playlistd(flist, flist_len);
     playld->pelist = av_malloc(playld->pelist_size * sizeof(PlayElem*));
     memset(playld->pelist, 0, playld->pelist_size * sizeof(PlayElem*));
-    playld->pe_curidx = 0;
     s->priv_data = playld;
     ff_playlist_populate_context(playld, s);
     return 0;
@@ -107,20 +102,36 @@ static int m3u_read_header(AVFormatConte
 static int m3u_read_packet(AVFormatContext *s,
                            AVPacket *pkt)
 {
-    int i;
     int ret;
-    int time_offset = 0;
     PlaylistD *playld;
     AVFormatContext *ic;
     playld = s->priv_data;
     retr:
     ic = playld->pelist[playld->pe_curidx]->ic;
     ret = ic->iformat->read_packet(ic, pkt);
-//    if (pkt) {
-//        pkt->stream_index += get_stream_offset(s);
-//    }
-    if (ret < 0 && playld->pe_curidx < playld->pelist_size - 1)
-    {
+    if (ret >= 0) {
+            // TODO storing previous packet pts/dts is ugly hack
+            // ic->stream[]->cur_dts correct
+            // ic->strea[]->duration correct
+            // pkt->pts incorrect (huge negative)
+            // pkt->dts correct, depended on by ffmpeg (need to change)
+            // ic->stream[]->pts incorrect (0)
+            // ic->start_time always 0
+            // changing ic->start_time has no effect
+            // ic->duration correct, divide by AV_TIME_BASE to get seconds
+        if (pkt) {
+            playld->dts_prevpacket = pkt->dts;
+            pkt->dts += playld->dts_offset;
+        }
+    }
+    // TODO switch from AVERROR_EOF to AVERROR_EOS
+    else if (ret == AVERROR_EOF && playld->pe_curidx < playld->pelist_size - 1) {
+        // TODO account for out-of-sync audio/video by using per-stream offsets
+        // using streams[]->duration slightly overestimates offset
+//        playld->dts_offset += ic->streams[0]->duration;
+        // using streams[]->cur_dts slightly overestimates offset
+//        playld->dts_offset += ic->streams[0]->cur_dts;
+        playld->dts_offset += playld->dts_prevpacket;
         ++playld->pe_curidx;
 //        pkt->destruct(pkt);
         pkt = av_malloc(sizeof(AVPacket));

Modified: concat/libavformat/playlist.c
==============================================================================
--- concat/libavformat/playlist.c	Tue Jun 30 19:43:58 2009	(r4552)
+++ concat/libavformat/playlist.c	Tue Jun 30 21:28:59 2009	(r4553)
@@ -45,7 +45,7 @@ int ff_alloc_playelem(unsigned char *fil
     return 0;
 }
 
-PlayElem* ff_make_playelem(unsigned char *filename)
+PlayElem* ff_make_playelem(char *filename)
 {
     int err;
     PlayElem *pe = av_malloc(sizeof(PlayElem));
@@ -77,15 +77,17 @@ PlayElem* ff_make_playelem(unsigned char
     return pe;
 }
 
-PlaylistD* ff_make_playlistd(unsigned char **flist,
-                             int flist_len)
+PlaylistD* ff_make_playlistd(char *filename)
 {
-    int i;
     PlaylistD *playld = av_malloc(sizeof(PlaylistD));
+//    playld->pts_offset = 0;
+    playld->dts_offset = 0;
+//    playld->pts_prevpacket = 0;
+    playld->dts_prevpacket = 0;
     playld->pe_curidx = 0;
-    playld->pelist_size = flist_len;
-    playld->pelist = av_malloc(playld->pelist_size * sizeof(PlayElem*));
-    memset(playld->pelist, 0, playld->pelist_size * sizeof(PlayElem*));
+    ff_split_wd_fn(filename,
+                   &playld->workingdir,
+                   &playld->filename);
     return playld;
 }
 
@@ -170,7 +172,6 @@ int ff_playlist_populate_context(Playlis
                                  AVFormatContext *s)
 {
     int i;
-//    unsigned int stream_offset;
     AVFormatContext *ic;
     AVFormatParameters *nap;
     printf("playlist_populate_context called\n");
@@ -178,12 +179,9 @@ int ff_playlist_populate_context(Playlis
     ic = playld->pelist[playld->pe_curidx]->ic;
     nap = playld->pelist[playld->pe_curidx]->ap;
     ic->iformat->read_header(ic, 0);
-//    stream_offset = get_stream_offset(s);
     s->nb_streams = ic->nb_streams;
-//    s->nb_streams = ic->nb_streams + stream_offset;
     for (i = 0; i < ic->nb_streams; ++i) {
         s->streams[i] = ic->streams[i];
-//        s->streams[i+stream_offset] = ic->streams[i];
     }
     // TODO remove this ugly hack
     s->av_class = ic->av_class;

Modified: concat/libavformat/playlist.h
==============================================================================
--- concat/libavformat/playlist.h	Tue Jun 30 19:43:58 2009	(r4552)
+++ concat/libavformat/playlist.h	Tue Jun 30 21:28:59 2009	(r4553)
@@ -41,11 +41,15 @@ typedef struct PlaylistD {
     int ch_curidx;
     char *workingdir;
     char *filename;
+//    int64_t pts_offset;
+    int64_t dts_offset;
+//    int64_t pts_prevpacket;
+    int64_t dts_prevpacket;
 } PlaylistD;
 
-PlayElem* ff_make_playelem(unsigned char *filename);
+PlayElem* ff_make_playelem(char *filename);
 
-PlaylistD* ff_make_playlistd(unsigned char **flist, int flist_len);
+PlaylistD* ff_make_playlistd(char *filename);
 
 int ff_playlist_populate_context(PlaylistD *playld, AVFormatContext *s);
 


More information about the FFmpeg-soc mailing list