lavf: Add a flag to enable/disable per-packet flushing

This is enabled by default and can be disabled with
"-fflags -flush_packets".

Inspired by a patch from Nicolas George <nicolas.george@normalesup.org>.

Signed-off-by: Martin Storsjö <martin@martin.st>
pull/36/head
Luca Barbato 11 years ago committed by Martin Storsjö
parent 0a9425d7cf
commit 596e5d4783
  1. 1
      libavformat/avformat.h
  2. 8
      libavformat/mux.c
  3. 3
      libavformat/options_table.h
  4. 2
      libavformat/version.h

@ -894,6 +894,7 @@ typedef struct AVFormatContext {
#define AVFMT_FLAG_NOBUFFER 0x0040 ///< Do not buffer frames when possible
#define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it.
#define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted
#define AVFMT_FLAG_FLUSH_PACKETS 0x0200 ///< Flush the AVIOContext every packet.
/**
* decoding: size of data to probe; encoding: unused.

@ -404,6 +404,7 @@ static int compute_pkt_fields2(AVFormatContext *s, AVStream *st, AVPacket *pkt)
static int write_packet(AVFormatContext *s, AVPacket *pkt)
{
int ret;
if (!(s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS))) {
AVRational time_base = s->streams[pkt->stream_index]->time_base;
int64_t offset = 0;
@ -420,7 +421,12 @@ static int write_packet(AVFormatContext *s, AVPacket *pkt)
if (pkt->pts != AV_NOPTS_VALUE)
pkt->pts += offset;
}
return s->oformat->write_packet(s, pkt);
ret = s->oformat->write_packet(s, pkt);
if (s->pb && ret >= 0 && s->flags & AVFMT_FLAG_FLUSH_PACKETS)
avio_flush(s->pb);
return ret;
}
int av_write_frame(AVFormatContext *s, AVPacket *pkt)

@ -33,7 +33,8 @@
static const AVOption avformat_options[] = {
{"probesize", "set probing size", OFFSET(probesize), AV_OPT_TYPE_INT, {.i64 = 5000000 }, 32, INT_MAX, D},
{"packetsize", "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, 0, INT_MAX, E},
{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = DEFAULT }, INT_MIN, INT_MAX, D|E, "fflags"},
{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = AVFMT_FLAG_FLUSH_PACKETS }, INT_MIN, INT_MAX, D|E, "fflags"},
{"flush_packets", "reduce the latency by flushing out packets immediately", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_FLUSH_PACKETS }, INT_MIN, INT_MAX, D, "fflags"},
{"ignidx", "ignore index", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"},
{"genpts", "generate pts", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"},
{"nofillin", "do not fill in missing values that can be exactly calculated", 0, AV_OPT_TYPE_CONST, {.i64 = AVFMT_FLAG_NOFILLIN }, INT_MIN, INT_MAX, D, "fflags"},

@ -30,7 +30,7 @@
#include "libavutil/avutil.h"
#define LIBAVFORMAT_VERSION_MAJOR 55
#define LIBAVFORMAT_VERSION_MINOR 3
#define LIBAVFORMAT_VERSION_MINOR 4
#define LIBAVFORMAT_VERSION_MICRO 0
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \

Loading…
Cancel
Save