[Ffmpeg-devel] corrupt audio when cut
Wolfram Gloger
wmglo
Tue Jan 16 10:53:55 CET 2007
Hi,
> The cutting process is:
>
> ffmpeg -ss 48.0 -t 25.8 -y -vcodec copy -acodec copy -i test.avi cutfile.avi
>
> The erroneous output is:
...
> error, non monotone timestamps -7 >= -7
> error, non monotone timestamps -4 >= -4
> error, non monotone timestamps -2 >= -2
> error, non monotone timestamps 2 >= 2
> error, non monotone timestamps 4 >= 4
Please try the appended patch and report back.
Regards,
Wolfram.
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