[FFmpeg-devel] [PATCH]lavf/matroskaenc: Do not unecessarily consume memory for cuepoints

Carl Eugen Hoyos cehoyos at ag.or.at
Tue Jul 7 19:41:11 CEST 2015


On Tuesday 07 July 2015 06:45:04 pm Michael Niedermayer wrote:
> On Tue, Jul 07, 2015 at 03:13:06PM +0200, Carl Eugen Hoyos wrote:
> > Hi!
> >
> > Matroska streaming currently consumes memory for
> > cuepoints that are never used if the output stream
> > is no seekable. This can lead to oom.
> > Attached patch fixes ticket #4690.
> >
> > Please comment, Carl Eugen
> >
> >  matroskaenc.c |   10 +++++++++-
> >  1 file changed, 9 insertions(+), 1 deletion(-)
> > 3bf45b1a064962b7e988c3ee5739cc8f2faf023d  patchmkvseekable.diff
>
> breaks fate

New patch attached.

Thank you, Carl Eugen
-------------- next part --------------
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c
index 3b525ad..713cb33 100644
--- a/libavformat/matroskaenc.c
+++ b/libavformat/matroskaenc.c
@@ -1772,7 +1772,7 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_
 
     if (codec->codec_type != AVMEDIA_TYPE_SUBTITLE) {
         mkv_write_block(s, pb, MATROSKA_ID_SIMPLEBLOCK, pkt, keyframe);
-        if (codec->codec_type == AVMEDIA_TYPE_VIDEO && keyframe || add_cue) {
+        if (s->pb->seekable && (codec->codec_type == AVMEDIA_TYPE_VIDEO && keyframe || add_cue)) {
             ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, dash_tracknum, ts, mkv->cluster_pos, relative_packet_pos, -1);
             if (ret < 0) return ret;
         }
@@ -1792,11 +1792,13 @@ static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt, int add_
         end_ebml_master(pb, blockgroup);
     }
 
+    if (s->pb->seekable) {
     ret = mkv_add_cuepoint(mkv->cues, pkt->stream_index, dash_tracknum, ts,
                            mkv->cluster_pos, relative_packet_pos, duration);
     if (ret < 0)
         return ret;
     }
+    }
 
     mkv->duration = FFMAX(mkv->duration, ts + duration);
     return 0;


More information about the ffmpeg-devel mailing list