diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2013-08-20 11:15:11 +0200 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2013-08-20 11:15:11 +0200 |
commit | ac957bc60cec69bd5724fe6f41b6fb979ac6612c (patch) | |
tree | 7da2cc23919d8a3b0cfd83e3c2f542bcc01db48d | |
parent | 976de369ddeb395af6e0aad76f63aa1d37e14aac (diff) | |
parent | 98308bd44face14ea3142b501d16226eec23b75a (diff) | |
download | ffmpeg-ac957bc60cec69bd5724fe6f41b6fb979ac6612c.tar.gz |
Merge commit '98308bd44face14ea3142b501d16226eec23b75a'
* commit '98308bd44face14ea3142b501d16226eec23b75a':
mkv: Add options for specifying cluster limits
Conflicts:
libavformat/matroskaenc.c
Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r-- | libavformat/matroskaenc.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/libavformat/matroskaenc.c b/libavformat/matroskaenc.c index 084440bae4..8c7f938645 100644 --- a/libavformat/matroskaenc.c +++ b/libavformat/matroskaenc.c @@ -104,7 +104,9 @@ typedef struct MatroskaMuxContext { int have_attachments; int reserve_cues_space; + int cluster_size_limit; int64_t cues_pos; + int64_t cluster_time_limit; uint32_t chapter_id_offset; } MatroskaMuxContext; @@ -1131,6 +1133,21 @@ static int mkv_write_header(AVFormatContext *s) mkv->cluster_pos = -1; avio_flush(pb); + + // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or + // after 4k and on a keyframe + if (pb->seekable) { + if (mkv->cluster_time_limit < 0) + mkv->cluster_time_limit = 5000; + if (mkv->cluster_size_limit < 0) + mkv->cluster_size_limit = 5 * 1024 * 1024; + } else { + if (mkv->cluster_time_limit < 0) + mkv->cluster_time_limit = 1000; + if (mkv->cluster_size_limit < 0) + mkv->cluster_size_limit = 32 * 1024; + } + return 0; } @@ -1486,9 +1503,7 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) int codec_type = s->streams[pkt->stream_index]->codec->codec_type; int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY); int cluster_size; - int cluster_size_limit; int64_t cluster_time; - int64_t cluster_time_limit; AVIOContext *pb; int ret; @@ -1502,18 +1517,14 @@ static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) if (s->pb->seekable) { pb = s->pb; cluster_size = avio_tell(pb) - mkv->cluster_pos; - cluster_time_limit = 5000; - cluster_size_limit = 5 * 1024 * 1024; } else { pb = mkv->dyn_bc; cluster_size = avio_tell(pb); - cluster_time_limit = 1000; - cluster_size_limit = 32 * 1024; } if (mkv->cluster_pos != -1 && - (cluster_size > cluster_size_limit || - cluster_time > cluster_time_limit || + (cluster_size > mkv->cluster_size_limit || + cluster_time > mkv->cluster_time_limit || (codec_type == AVMEDIA_TYPE_VIDEO && keyframe && cluster_size > 4 * 1024))) { av_log(s, AV_LOG_DEBUG, "Starting new cluster at offset %" PRIu64 @@ -1666,8 +1677,9 @@ static const AVCodecTag additional_video_tags[] = { #define OFFSET(x) offsetof(MatroskaMuxContext, x) #define FLAGS AV_OPT_FLAG_ENCODING_PARAM static const AVOption options[] = { - { "reserve_index_space", "Reserve a given amount of space (in bytes) at the beginning " - "of the file for the index (cues).", OFFSET(reserve_cues_space), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, + { "reserve_index_space", "Reserve a given amount of space (in bytes) at the beginning of the file for the index (cues).", OFFSET(reserve_cues_space), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, FLAGS }, + { "cluster_size_limit", "Store at most the provided amount of bytes in a cluster. ", OFFSET(cluster_size_limit), AV_OPT_TYPE_INT , { .i64 = -1 }, -1, INT_MAX, FLAGS }, + { "cluster_time_limit", "Store at most the provided number of milliseconds in a cluster.", OFFSET(cluster_time_limit), AV_OPT_TYPE_INT64, { .i64 = -1 }, -1, INT64_MAX, FLAGS }, { NULL }, }; |