---
Now it does not write the optional flags if the version isn't 4.
doc/muxers.texi | 16 ++++++++++++++++
doc/nut.texi | 21 +++++++++++++++++++++
libavformat/avformat.h | 6 ++++++
libavformat/nut.h | 9 ++++++++-
libavformat/nutdec.c | 28 +++++++++++++++++++++++-----
libavformat/nutenc.c | 42 +++++++++++++++++++++++++++++++++++++++---
libavformat/options_table.h | 5 +++++
libavformat/version.h | 2 +-
8 files changed, 119 insertions(+), 10 deletions(-)
diff --git a/doc/muxers.texi b/doc/muxers.texi
index 143e595..0a26e39 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -419,6 +419,22 @@ avconv -i file.mpg -c copy \
-y out.ts
@end example
+@section nut
+
+@table @option
+@item -nut_flags @var{flags}
+Modify the nut muxing behaviour in specific ways:
+@table @option
+@item @var{pipe} disables the syncpoints, reducing the overhead but making the
stream non-seekable;
+@item @var{broadcast} extends the syncpoint with a wallclock field.
+@end table
+None of the flags are supposed to be used for storage purposes.
+@end table
+
+@example
+avconv -i INPUT -f_strict experimental -nut_flags pipe - | processor
+@end example
+
@section null
Null muxer.
diff --git a/doc/nut.texi b/doc/nut.texi
index 39a22ff..042c88a 100644
--- a/doc/nut.texi
+++ b/doc/nut.texi
@@ -17,6 +17,27 @@ subtitle and user-defined streams in a simple, yet
efficient, way.
It was created by a group of FFmpeg and MPlayer developers in 2003
and was finalized in 2008.
+@chapter Modes
+NUT has some variants signaled by using the flags field in its main header.
+
+@multitable @columnfractions .4 .4
+@item BROADCAST @tab Extend the syncpoint to report the sender wallclock
+@item PIPE @tab Omit completely the syncpoint
+@end multitable
+
+@section BROADCAST
+
+The BROADCAST variant provides a secondary time reference to facilitate
+detecting endpoint latency and network delays.
+It assumes all the endpoint clocks are syncronized.
+To be used in real-time scenarios.
+
+@section PIPE
+
+The PIPE variant assumes NUT is used as non-seekable intermediate container,
+by not using syncpoint removes unneeded overhead and reduces the overall
+memory usage.
+
@chapter Container-specific codec tags
@section Generic raw YUVA formats
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index ec9c262..215476e 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1166,6 +1166,12 @@ typedef struct AVFormatContext {
* Must not be accessed in any way by callers.
*/
AVFormatInternal *internal;
+
+ /**
+ * Allow non-standard and experimental extension
+ * @see AVCodecContext.strict_std_compliance
+ */
+ int strict_std_compliance;
} AVFormatContext;
typedef struct AVPacketList {
diff --git a/libavformat/nut.h b/libavformat/nut.h
index 6357b3d..16f3c12 100644
--- a/libavformat/nut.h
+++ b/libavformat/nut.h
@@ -36,7 +36,9 @@
#define MAX_DISTANCE (1024*32-1)
-#define NUT_VERSION 3
+#define NUT_MAX_VERSION 4
+#define NUT_STABLE_VERSION 3
+#define NUT_MIN_VERSION 2
typedef enum{
FLAG_KEY = 1, ///<if set, frame is keyframe
@@ -85,6 +87,7 @@ typedef struct ChapterContext {
} ChapterContext;
typedef struct NUTContext {
+ const AVClass *av_class;
AVFormatContext *avf;
// int written_packet_size;
// int64_t packet_start;
@@ -100,6 +103,10 @@ typedef struct NUTContext {
int header_count;
AVRational *time_base;
struct AVTreeNode *syncpoints;
+#define NUT_BROADCAST 1 // use extended syncpoints
+#define NUT_PIPE 2 // do not write syncpoints
+ int flags;
+ int version; // version currently in use
} NUTContext;
extern const AVCodecTag ff_nut_subtitle_tags[];
diff --git a/libavformat/nutdec.c b/libavformat/nutdec.c
index 6328549..069863b 100644
--- a/libavformat/nutdec.c
+++ b/libavformat/nutdec.c
@@ -213,8 +213,8 @@ static int decode_main_header(NUTContext *nut)
end = get_packetheader(nut, bc, 1, MAIN_STARTCODE);
end += avio_tell(bc);
- tmp = ffio_read_varlen(bc);
- if (tmp < 2 && tmp > NUT_VERSION) {
+ nut->version = ffio_read_varlen(bc);
+ if (tmp < 2 && tmp > NUT_MAX_VERSION) {
av_log(s, AV_LOG_ERROR, "Version %"PRId64" not supported.\n",
tmp);
return AVERROR(ENOSYS);
@@ -320,6 +320,10 @@ static int decode_main_header(NUTContext *nut)
assert(nut->header_len[0] == 0);
}
+ if (nut->version > 3) {
+ nut->flags = ffio_read_varlen(bc);
+ }
+
if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
av_log(s, AV_LOG_ERROR, "main header checksum mismatch\n");
return AVERROR_INVALIDDATA;
@@ -547,6 +551,14 @@ static int decode_syncpoint(NUTContext *nut, int64_t *ts,
int64_t *back_ptr)
ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count],
tmp / nut->time_base_count);
+ if (nut->flags & NUT_BROADCAST) {
+ tmp = ffio_read_varlen(bc);
+ av_log(s, AV_LOG_VERBOSE, "Syncpoint wallclock %"PRId64"\n",
+ av_rescale_q(tmp / nut->time_base_count,
+ nut->time_base[tmp % nut->time_base_count],
+ AV_TIME_BASE_Q));
+ }
+
if (skip_reserved(bc, end) || ffio_get_checksum(bc)) {
av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n");
return AVERROR_INVALIDDATA;
@@ -728,7 +740,8 @@ static int decode_frame_header(NUTContext *nut, int64_t
*pts, int *stream_id,
int size, flags, size_mul, pts_delta, i, reserved_count;
uint64_t tmp;
- if (avio_tell(bc) > nut->last_syncpoint_pos + nut->max_distance) {
+ if (!(nut->flags & NUT_PIPE) &&
+ avio_tell(bc) > nut->last_syncpoint_pos + nut->max_distance) {
av_log(s, AV_LOG_ERROR,
"Last frame must have been damaged %"PRId64" > %"PRId64" +
%d\n",
avio_tell(bc), nut->last_syncpoint_pos, nut->max_distance);
@@ -781,8 +794,9 @@ static int decode_frame_header(NUTContext *nut, int64_t
*pts, int *stream_id,
if (flags & FLAG_CHECKSUM) {
avio_rb32(bc); // FIXME check this
- } else if (size > 2 * nut->max_distance || FFABS(stc->last_pts - *pts) >
- stc->max_pts_distance) {
+ } else if (!(nut->flags & NUT_PIPE) &&
+ size > 2 * nut->max_distance ||
+ FFABS(stc->last_pts - *pts) > stc->max_pts_distance) {
av_log(s, AV_LOG_ERROR, "frame size > 2max_distance and no
checksum\n");
return AVERROR_INVALIDDATA;
}
@@ -933,6 +947,10 @@ static int read_seek(AVFormatContext *s, int stream_index,
int64_t pos, pos2, ts;
int i;
+ if (nut->flags & NUT_PIPE) {
+ return AVERROR(ENOSYS);
+ }
+
if (st->index_entries) {
int index = av_index_search_timestamp(st, pts, flags);
if (index < 0)
diff --git a/libavformat/nutenc.c b/libavformat/nutenc.c
index 2d3862d..80702e5 100644
--- a/libavformat/nutenc.c
+++ b/libavformat/nutenc.c
@@ -25,6 +25,8 @@
#include "libavutil/mathematics.h"
#include "libavutil/tree.h"
#include "libavutil/dict.h"
+#include "libavutil/time.h"
+#include "libavutil/opt.h"
#include "libavcodec/mpegaudiodata.h"
#include "nut.h"
#include "internal.h"
@@ -325,7 +327,7 @@ static void write_mainheader(NUTContext *nut, AVIOContext
*bc)
tmp_head_idx;
int64_t tmp_match;
- ff_put_v(bc, NUT_VERSION);
+ ff_put_v(bc, nut->version);
ff_put_v(bc, nut->avf->nb_streams);
ff_put_v(bc, nut->max_distance);
ff_put_v(bc, nut->time_base_count);
@@ -405,6 +407,8 @@ static void write_mainheader(NUTContext *nut, AVIOContext
*bc)
ff_put_v(bc, nut->header_len[i]);
avio_write(bc, nut->header[i], nut->header_len[i]);
}
+ if (nut->version > 3)
+ ff_put_v(bc, nut->flags);
}
static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc,
@@ -643,6 +647,15 @@ static int nut_write_header(AVFormatContext *s)
nut->avf = s;
+ nut->version = NUT_STABLE_VERSION + !!nut->flags;
+ if (nut->flags && s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
+ av_log(s, AV_LOG_ERROR,
+ "Version %d requested, please set -strict experimental in "
+ "order to enable it.\n",
+ nut->version);
+ return AVERROR_EXPERIMENTAL;
+ }
+
nut->stream = av_mallocz(sizeof(StreamContext) * s->nb_streams);
if (s->nb_chapters)
nut->chapter = av_mallocz(sizeof(ChapterContext) * s->nb_chapters);
@@ -789,7 +802,8 @@ static int nut_write_packet(AVFormatContext *s, AVPacket
*pkt)
//FIXME: Ensure store_sp is 1 in the first place.
- if (store_sp) {
+ if (store_sp &&
+ (!(nut->flags & NUT_PIPE) || nut->last_syncpoint_pos == INT_MIN)) {
Syncpoint *sp, dummy = { .pos = INT64_MAX };
ff_nut_reset_ts(nut, *nus->time_base, pkt->dts);
@@ -815,6 +829,11 @@ static int nut_write_packet(AVFormatContext *s, AVPacket
*pkt)
return ret;
put_tt(nut, nus->time_base, dyn_bc, pkt->dts);
ff_put_v(dyn_bc, sp ? (nut->last_syncpoint_pos - sp->pos) >> 4 : 0);
+
+ if (nut->flags & NUT_BROADCAST) {
+ put_tt(nut, nus->time_base, dyn_bc,
+ av_rescale_q(av_gettime(), AV_TIME_BASE_Q,
*nus->time_base));
+ }
put_packet(nut, bc, dyn_bc, 1, SYNCPOINT_STARTCODE);
if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, 0 /*unused*/,
pkt->dts)) < 0)
@@ -917,7 +936,7 @@ static int nut_write_packet(AVFormatContext *s, AVPacket
*pkt)
nus->last_pts = pkt->pts;
//FIXME just store one per syncpoint
- if (flags & FLAG_KEY)
+ if (flags & FLAG_KEY && !(nut->flags & NUT_PIPE))
av_add_index_entry(
s->streams[pkt->stream_index],
nut->last_syncpoint_pos,
@@ -945,6 +964,22 @@ static int nut_write_trailer(AVFormatContext *s)
return 0;
}
+#define OFFSET(x) offsetof(NUTContext, x)
+#define E AV_OPT_FLAG_ENCODING_PARAM
+static const AVOption options[] = {
+ { "nut_flags", "NUT muxer flags",
OFFSET(flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN,
INT_MAX, E, "nutflags" },
+ { "pipe", "NUT pipe mode, syncpoints and max_distance ignored",
0, AV_OPT_TYPE_CONST, {.i64 = NUT_PIPE}, INT_MIN,
INT_MAX, E, "nutflags" },
+ { "broadcast", "NUT broadcast mode, add a wallclock time reference to
syncpoints", 0, AV_OPT_TYPE_CONST, {.i64 = NUT_BROADCAST}, INT_MIN,
INT_MAX, E, "nutflags" },
+ { NULL },
+};
+
+static const AVClass class = {
+ .class_name = "nutenc",
+ .item_name = av_default_item_name,
+ .option = options,
+ .version = LIBAVUTIL_VERSION_INT,
+};
+
AVOutputFormat ff_nut_muxer = {
.name = "nut",
.long_name = NULL_IF_CONFIG_SMALL("NUT"),
@@ -959,4 +994,5 @@ AVOutputFormat ff_nut_muxer = {
.write_trailer = nut_write_trailer,
.flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS,
.codec_tag = ff_nut_codec_tags,
+ .priv_class = &class,
};
diff --git a/libavformat/options_table.h b/libavformat/options_table.h
index cc84e1c..61f9bd5 100644
--- a/libavformat/options_table.h
+++ b/libavformat/options_table.h
@@ -59,6 +59,11 @@ static const AVOption avformat_options[] = {
{"buffer", "detect improper bitstream length", 0, AV_OPT_TYPE_CONST, {.i64 =
AV_EF_BUFFER }, INT_MIN, INT_MAX, D, "err_detect"},
{"explode", "abort decoding on minor error detection", 0, AV_OPT_TYPE_CONST,
{.i64 = AV_EF_EXPLODE }, INT_MIN, INT_MAX, D, "err_detect"},
{"max_interleave_delta", "maximum buffering duration for interleaving",
OFFSET(max_interleave_delta), AV_OPT_TYPE_INT64, { .i64 = 10000000 }, 0,
INT64_MAX, E },
+{"f_strict", "how strictly to follow the standards (deprecated; use strict,
save via avconv)", OFFSET(strict_std_compliance), AV_OPT_TYPE_INT, {.i64 =
DEFAULT }, INT_MIN, INT_MAX, D|E, "strict"},
+{"strict", "how strictly to follow the standards",
OFFSET(strict_std_compliance), AV_OPT_TYPE_INT, {.i64 = DEFAULT }, INT_MIN,
INT_MAX, D|E, "strict"},
+{"strict", "strictly conform to all the things in the spec no matter what the
consequences", 0, AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_STRICT }, INT_MIN,
INT_MAX, D|E, "strict"},
+{"normal", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_NORMAL },
INT_MIN, INT_MAX, D|E, "strict"},
+{"experimental", "allow non-standardized experimental variants", 0,
AV_OPT_TYPE_CONST, {.i64 = FF_COMPLIANCE_EXPERIMENTAL }, INT_MIN, INT_MAX, D|E,
"strict"},
{NULL},
};
diff --git a/libavformat/version.h b/libavformat/version.h
index 3d1e21f..ef5a148 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -30,7 +30,7 @@
#include "libavutil/version.h"
#define LIBAVFORMAT_VERSION_MAJOR 55
-#define LIBAVFORMAT_VERSION_MINOR 12
+#define LIBAVFORMAT_VERSION_MINOR 13
#define LIBAVFORMAT_VERSION_MICRO 0
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
--
1.8.5.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel