[Ffmpeg-devel] corrupt audio when cut [SOLVED]

Wolfram Gloger wmglo
Sat Feb 3 17:31:18 CET 2007


Hi,

> --- ./data/libav.regression	2007-01-30 19:21:18.000000000 +0100
> +++ /home/michael/ffmpeg-svn-tmp/trunk/tests/libav.regression.ref	2007-01-2=
> 1 13:57:27.000000000 +0100
> @@ -9,10 +9,10 @@
>  355405 ./data/b-libav.rm
>  bdb7484c68db722f66ba1630cf79844c *./data/b-libav.mpg
>  378880 ./data/b-libav.mpg
> -./data/b-libav.mpg CRC=3D0x00000001
> +./data/b-libav.mpg CRC=3D0x2b71a386

I have investigated this thoroughly, and have a better patch now that
passes regression tests.  Also added a few comments.

One-line-summary would be "make av_find_stream_info() usable
anywhere within a file".

Regards,
Wolfram.

--- trunk/libavformat/utils.c	Fri Feb  2 12:46:41 2007
+++ ffmpeg-wg/libavformat/utils.c	Sat Feb  3 12:30:13 2007
@@ -1649,13 +1649,13 @@
     }
 
     fill_all_stream_timings(ic);
-
-    url_fseek(&ic->pb, 0, SEEK_SET);
 }
 
-static void av_estimate_timings(AVFormatContext *ic)
+/* returns non-zero if the packet queue was flushed */
+static int av_estimate_timings(AVFormatContext *ic)
 {
     int64_t file_size;
+    int did_flush = 0;
 
     /* get the file size, if possible */
     if (ic->iformat->flags & AVFMT_NOFILE) {
@@ -1672,6 +1672,7 @@
         file_size && !ic->pb.is_streamed) {
         /* get accurate estimate from the PTSes */
         av_estimate_timings_from_pts(ic);
+        did_flush = 1;
     } else if (av_has_timings(ic)) {
         /* at least one components has timings - we use them for all
            the components */
@@ -1698,6 +1699,7 @@
                ic->bit_rate / 1000);
     }
 #endif
+    return did_flush;
 }
 
 static int has_codec_parameters(AVCodecContext *enc)
@@ -1765,10 +1767,12 @@
 }
 
 /**
- * Read the beginning of a media file to get stream information. This
+ * Read packets of a media file to get stream information. This
  * is useful for file formats with no headers such as MPEG. This
- * function also compute the real frame rate in case of mpeg2 repeat
+ * function also computes the real frame rate in case of mpeg2 repeat
  * frame mode.
+ * The logical file position is not changed by this function;
+ * examined packets may be buffered for later processing.
  *
  * @param ic media file handle
  * @return >=0 if OK. AVERROR_xxx if error.
@@ -1783,6 +1787,7 @@
     int64_t last_dts[MAX_STREAMS];
     int duration_count[MAX_STREAMS]={0};
     double duration_error[MAX_STREAMS][MAX_STD_TIMEBASES]={{0}}; //FIXME malloc()?
+    offset_t old_offset = url_ftell(&ic->pb);
 
     for(i=0;i<ic->nb_streams;i++) {
         st = ic->streams[i];
@@ -1989,7 +1994,12 @@
         }
     }
 
-    av_estimate_timings(ic);
+    if (av_estimate_timings(ic)) {
+        // packet queue was flushed, need to seek to original file offset
+//      av_log(ic, AV_LOG_DEBUG, "offset:%"PRId64" old:%"PRId64"\n", (int64_t)url_ftell(&ic->pb), (int64_t)old_offset);
+        url_fseek(&ic->pb, old_offset, SEEK_SET);
+    }
+
 #if 0
     /* correct DTS for b frame streams with no timestamps */
     for(i=0;i<ic->nb_streams;i++) {




More information about the ffmpeg-devel mailing list