[FFmpeg-devel] [PATCH 2/2] avformat: add avformat_flush()

wm4 nfxjfg at googlemail.com
Mon Sep 29 19:41:28 CEST 2014


Useful for Bluray and DVD, since the libraries used to read them just
change the byte stream under your feet on seeking.

Maybe there should be a AVInputFormat callback for this. But the
mpeg-ps (DVD) and the mpeg-ts (Bluray) demuxers don't change much
state during seeking - they just try to find a new packet with
timestamps (in read_timestamp), so I haven't found a need for this
yet. I don't want to add unused things.

I've also thought about adding a flush callback, and implementing
them in mpeg.c and mpegts.c by just calling ff_read_frame_flush().
Might be slightly better, because you can have avformat_flush() fail
on formats which don't support this?

Or maybe a flag?

TODO: add entry to APIchanges, bump minor version.
---
 libavformat/avformat.h | 13 +++++++++++++
 libavformat/utils.c    |  6 ++++++
 2 files changed, 19 insertions(+)

diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 78054de..eaa52fa 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -2173,6 +2173,19 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp,
 int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags);
 
 /**
+ * Discard all internally buffered data. This can be useful when dealing with
+ * discontinuities in the byte stream. Generally works only with some simple
+ * formats.
+ *
+ * This does not flush the AVIOContext (s->pb). If necessary, call
+ * avio_flush(s->pb) before calling this function.
+ *
+ * @param s media file handle
+ * @return >=0 on success, error code otherwise
+ */
+int avformat_flush(AVFormatContext *s);
+
+/**
  * Start playing a network-based stream (e.g. RTSP stream) at the
  * current position.
  */
diff --git a/libavformat/utils.c b/libavformat/utils.c
index e0e78a7..9689aa0 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2159,6 +2159,12 @@ int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts,
     return -1; //unreachable
 }
 
+int avformat_flush(AVFormatContext *s)
+{
+    ff_read_frame_flush(s);
+    return 0;
+}
+
 /*******************************************************/
 
 /**
-- 
2.1.0



More information about the ffmpeg-devel mailing list