diff options
author | Marton Balint <cus@passwd.hu> | 2016-02-04 01:30:31 +0100 |
---|---|---|
committer | Marton Balint <cus@passwd.hu> | 2016-02-05 21:32:14 +0100 |
commit | 6d14e32555ef0b83a354e0e765706f253e0a4505 (patch) | |
tree | 892d95902ef3eddbfc7198a1058013e6552d11df | |
parent | 22bbd6e8b7544f29db85da93730641a3a25916bd (diff) | |
download | ffmpeg-6d14e32555ef0b83a354e0e765706f253e0a4505.tar.gz |
lavf/asfenc: add support for setting packet size
This can provide a manual workaround for ticket #4230.
Reviewed-by: Michael Niedermayer <michael@niedermayer.cc>
Signed-off-by: Marton Balint <cus@passwd.hu>
-rw-r--r-- | doc/muxers.texi | 20 | ||||
-rw-r--r-- | libavformat/asf.h | 2 | ||||
-rw-r--r-- | libavformat/asfenc.c | 41 | ||||
-rw-r--r-- | libavformat/version.h | 2 |
4 files changed, 46 insertions, 19 deletions
diff --git a/doc/muxers.texi b/doc/muxers.texi index 4ba88831c3..2e6bb4ca2a 100644 --- a/doc/muxers.texi +++ b/doc/muxers.texi @@ -37,6 +37,26 @@ ID3v2.3 and ID3v2.4) are supported. The default is version 4. @end table +@anchor{asf} +@section asf + +Advanced Systems Format muxer. + +Note that Windows Media Audio (wma) and Windows Media Video (wmv) use this +muxer too. + +@subsection Options + +It accepts the following options: + +@table @option +@item packet_size +Set the muxer packet size. By tuning this setting you may reduce data +fragmentation or muxer overhead depending on your source. Default value is +3200, minimum is 100, maximum is 64k. + +@end table + @anchor{chromaprint} @section chromaprint diff --git a/libavformat/asf.h b/libavformat/asf.h index 1070293b77..914ddef48e 100644 --- a/libavformat/asf.h +++ b/libavformat/asf.h @@ -26,8 +26,6 @@ #include "metadata.h" #include "riff.h" -#define PACKET_SIZE 3200 - typedef enum ASFDataType { ASF_UNICODE = 0, ASF_BYTE_ARRAY = 1, diff --git a/libavformat/asfenc.c b/libavformat/asfenc.c index 9c6c9cf3ca..a6a8242bc0 100644 --- a/libavformat/asfenc.c +++ b/libavformat/asfenc.c @@ -23,6 +23,7 @@ #include "libavutil/dict.h" #include "libavutil/mathematics.h" #include "libavutil/parseutils.h" +#include "libavutil/opt.h" #include "avformat.h" #include "avlanguage.h" #include "avio_internal.h" @@ -172,19 +173,20 @@ ASF_PAYLOAD_REPLICATED_DATA_LENGTH + \ ASF_PAYLOAD_LENGTH_FIELD_SIZE) -#define SINGLE_PAYLOAD_DATA_LENGTH \ - (PACKET_SIZE - \ - PACKET_HEADER_MIN_SIZE - \ +#define SINGLE_PAYLOAD_HEADERS \ + (PACKET_HEADER_MIN_SIZE + \ PAYLOAD_HEADER_SIZE_SINGLE_PAYLOAD) -#define MULTI_PAYLOAD_CONSTANT \ - (PACKET_SIZE - \ - PACKET_HEADER_MIN_SIZE - \ - 1 - /* Payload Flags */ \ +#define MULTI_PAYLOAD_HEADERS \ + (PACKET_HEADER_MIN_SIZE + \ + 1 + /* Payload Flags */ \ 2 * PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS) #define DATA_HEADER_SIZE 50 +#define PACKET_SIZE_MAX 65536 +#define PACKET_SIZE_MIN 100 + typedef struct ASFPayload { uint8_t type; uint16_t size; @@ -234,7 +236,7 @@ typedef struct ASFContext { int64_t packet_timestamp_start; int64_t packet_timestamp_end; unsigned int packet_nb_payloads; - uint8_t packet_buf[PACKET_SIZE]; + uint8_t packet_buf[PACKET_SIZE_MAX]; AVIOContext pb; /* only for reading */ uint64_t data_offset; ///< beginning of the first data packet @@ -247,6 +249,7 @@ typedef struct ASFContext { uint64_t next_packet_offset; int next_start_sec; int end_sec; + int packet_size; } ASFContext; static const AVCodecTag codec_asf_bmp_tags[] = { @@ -755,7 +758,7 @@ static int asf_write_header(AVFormatContext *s) { ASFContext *asf = s->priv_data; - s->packet_size = PACKET_SIZE; + s->packet_size = asf->packet_size; s->max_interleave_delta = 0; asf->nb_packets = 0; @@ -866,7 +869,7 @@ static void flush_packet(AVFormatContext *s) asf->packet_nb_payloads, asf->packet_size_left); - packet_filled_size = PACKET_SIZE - asf->packet_size_left; + packet_filled_size = asf->packet_size - asf->packet_size_left; av_assert0(packet_hdr_size <= asf->packet_size_left); memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left); @@ -923,13 +926,14 @@ static void put_frame(AVFormatContext *s, ASFStream *stream, AVStream *avst, while (m_obj_offset < m_obj_size) { payload_len = m_obj_size - m_obj_offset; if (asf->packet_timestamp_start == -1) { - asf->multi_payloads_present = (payload_len < MULTI_PAYLOAD_CONSTANT); + const int multi_payload_constant = (asf->packet_size - MULTI_PAYLOAD_HEADERS); + asf->multi_payloads_present = (payload_len < multi_payload_constant); - asf->packet_size_left = PACKET_SIZE; + asf->packet_size_left = asf->packet_size; if (asf->multi_payloads_present) { - frag_len1 = MULTI_PAYLOAD_CONSTANT - 1; + frag_len1 = multi_payload_constant - 1; } else { - frag_len1 = SINGLE_PAYLOAD_DATA_LENGTH; + frag_len1 = asf->packet_size - SINGLE_PAYLOAD_HEADERS; } asf->packet_timestamp_start = timestamp; } else { @@ -1124,11 +1128,16 @@ static int asf_write_trailer(AVFormatContext *s) return 0; } +static const AVOption asf_options[] = { + { "packet_size", "Packet size", offsetof(ASFContext, packet_size), AV_OPT_TYPE_INT, {.i64 = 3200}, PACKET_SIZE_MIN, PACKET_SIZE_MAX, AV_OPT_FLAG_ENCODING_PARAM }, + { NULL }, +}; + #if CONFIG_ASF_MUXER static const AVClass asf_muxer_class = { .class_name = "ASF muxer", .item_name = av_default_item_name, - .option = 0, + .option = asf_options, .version = LIBAVUTIL_VERSION_INT, }; @@ -1155,7 +1164,7 @@ AVOutputFormat ff_asf_muxer = { static const AVClass asf_stream_muxer_class = { .class_name = "ASF stream muxer", .item_name = av_default_item_name, - .option = 0, + .option = asf_options, .version = LIBAVUTIL_VERSION_INT, }; diff --git a/libavformat/version.h b/libavformat/version.h index 16df2b88aa..0fdfee7a36 100644 --- a/libavformat/version.h +++ b/libavformat/version.h @@ -31,7 +31,7 @@ #define LIBAVFORMAT_VERSION_MAJOR 57 #define LIBAVFORMAT_VERSION_MINOR 24 -#define LIBAVFORMAT_VERSION_MICRO 100 +#define LIBAVFORMAT_VERSION_MICRO 101 #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ LIBAVFORMAT_VERSION_MINOR, \ |