[Ffmpeg-devel] corrupt audio when cut

Wolfram Gloger wmglo
Wed Jan 17 11:54:57 CET 2007


Hi,

> I first got the most recent svn to my home directory.  Then, I copied 
> the patch file to my home directory. I used the command "patch -p0 < 
> patch.diff" to apply the patch, then ran configure --enable-mp3lame and 
> then make.

That is correct if you intend to change sources in the 'trunk'
directory, and configure and compile within the 'trunk' directory.

Actually I missed adding a prototype for av_get_cur_dts as an exercise
for the reader :-/.  Sorry.  Perhaps that is the reason for your
continued problem?

Augmented patch attached.

Regards,
Wolfram.

diff -ur trunk/libavformat/avformat.h ffmpeg-wg/libavformat/avformat.h
--- trunk/libavformat/avformat.h	Sun Dec 24 11:06:34 2006
+++ ffmpeg/libavformat/avformat.h	Tue Jan 16 10:14:05 2007
@@ -437,6 +437,8 @@
                        int64_t pos, int64_t timestamp, int size, int distance, int flags);
 int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags);
 void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp);
+/* current dts in AV_TIME_BASE units */
+int64_t av_get_cur_dts(AVFormatContext *s, int stream_index);
 int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t ));
 
 /* media file output */
diff -ur trunk/ffmpeg.c ffmpeg/ffmpeg.c
--- trunk/ffmpeg.c	Sat Jan 13 20:47:31 2007
+++ ffmpeg/ffmpeg.c	Tue Jan 16 10:46:51 2007
@@ -2613,6 +2613,16 @@
         }
         /* reset seek info */
         start_time = 0;
+        if (av_get_cur_dts(ic, -1) != AV_NOPTS_VALUE) {
+            timestamp = av_get_cur_dts(ic, -1);
+            fprintf(stderr, "*** after seek timestamp= %lld\n", timestamp);
+        }
+        /* reload stream parameters */
+        ret = av_find_stream_info(ic);
+        if (ret < 0 && verbose >= 0) {
+            fprintf(stderr, "%s: could not find codec parameters\n", filename);
+            exit(1);
+        }
     }
 
     /* update the current parameters so that they match the one of the input stream */
diff -ur trunk/libavformat/avidec.c ffmpeg/libavformat/avidec.c
--- trunk/libavformat/avidec.c	Tue Jan 16 09:34:41 2007
+++ ffmpeg/libavformat/avidec.c	Tue Jan 16 10:34:16 2007
@@ -26,8 +26,8 @@
 #undef NDEBUG
 #include <assert.h>
 
-//#define DEBUG
-//#define DEBUG_SEEK
+#define DEBUG
+#define DEBUG_SEEK
 
 typedef struct AVIStream {
     int64_t frame_offset; /* current frame (video) or byte (audio) counter
@@ -961,7 +961,7 @@
 
 //        av_log(NULL, AV_LOG_DEBUG, "%"PRId64" %d %"PRId64"\n", timestamp, index, st2->index_entries[index].timestamp);
         /* extract the current frame number */
-        ast2->frame_offset = st2->index_entries[index].timestamp;
+        st2->cur_dts = ast2->frame_offset = st2->index_entries[index].timestamp;
         if(ast2->sample_size)
             ast2->frame_offset *=ast2->sample_size;
     }
diff -ur trunk/libavformat/utils.c ffmpeg/libavformat/utils.c
--- trunk/libavformat/utils.c	Mon Jan  8 16:01:14 2007
+++ ffmpeg/libavformat/utils.c	Tue Jan 16 10:46:51 2007
@@ -1437,6 +1437,27 @@
         return av_seek_frame_generic(s, stream_index, timestamp, flags);
 }
 
+/**
+ * Obtain the current dts in AV_TIME_BASE units.
+ * @param stream_index If stream_index is (-1), a default
+ * stream is selected.
+ */
+int64_t av_get_cur_dts(AVFormatContext *s, int stream_index)
+{
+    AVStream *st;
+
+    if (stream_index < 0){
+        stream_index= av_find_default_stream_index(s);
+        if(stream_index < 0)
+            return AV_NOPTS_VALUE;
+    }
+    st= s->streams[stream_index];
+    if (st->cur_dts == AV_NOPTS_VALUE)
+        return AV_NOPTS_VALUE;
+    return av_rescale(st->cur_dts, AV_TIME_BASE * (int64_t)st->time_base.num,
+                      st->time_base.den);
+}
+
 /*******************************************************/
 
 /**
@@ -1561,6 +1582,7 @@
     int read_size, i, ret;
     int64_t end_time;
     int64_t filesize, offset, duration;
+    offset_t old_offset;
 
     /* free previous packet */
     if (ic->cur_st && ic->cur_st->parser)
@@ -1580,7 +1602,8 @@
 
     /* we read the first packets to get the first PTS (not fully
        accurate, but it is enough now) */
-    url_fseek(&ic->pb, 0, SEEK_SET);
+    old_offset = url_ftell(&ic->pb);
+    url_fseek(&ic->pb, 0, SEEK_CUR);
     read_size = 0;
     for(;;) {
         if (read_size >= DURATION_MAX_READ_SIZE)
@@ -1646,7 +1669,7 @@
 
     fill_all_stream_timings(ic);
 
-    url_fseek(&ic->pb, 0, SEEK_SET);
+    url_fseek(&ic->pb, old_offset, SEEK_SET);
 }
 
 static void av_estimate_timings(AVFormatContext *ic)




More information about the ffmpeg-devel mailing list