62 int lsf, mpeg25, sample_rate_index, bitrate_index,
frame_size;
64 unsigned int header = 0xFFF00000;
69 if (
sample_rate < (32000 + 44100) / 2) sample_rate_index = 2;
70 else if (
sample_rate < (44100 + 48000) / 2) sample_rate_index = 0;
71 else sample_rate_index = 1;
75 for (bitrate_index = 2; bitrate_index < 30; bitrate_index++) {
86 header |= (4 - layer) << 17;
91 if (bitrate_index == 30)
94 header |= (bitrate_index >> 1) << 12;
95 header |= sample_rate_index << 10;
96 header |= (bitrate_index & 1) << 9;
128 static const uint8_t headers[][5] = {
129 { 3, 0x00, 0x00, 0x01 },
130 { 4, 0x00, 0x00, 0x01, 0xB6},
140 nut->
header[
i] = &headers[
i - 1][1];
150 int keyframe_0_esc =
s->nb_streams > 2;
160 if (keyframe_0_esc) {
168 for (stream_id = 0; stream_id <
s->nb_streams; stream_id++) {
169 int start2 = start + (end - start) * stream_id /
s->nb_streams;
170 int end2 = start + (end - start) * (stream_id + 1) /
s->nb_streams;
183 if (
f.den == 1 &&
f.num>0)
189 for (key_frame = 0; key_frame < 2; key_frame++) {
190 if (!
intra_only || !keyframe_0_esc || key_frame != 0) {
208 if (par->block_align > 0) {
209 frame_bytes = par->block_align;
212 frame_bytes =
frame_size * (int64_t)par->bit_rate / (8 * par->sample_rate);
237 if (par->video_delay) {
255 int start3 = start2 + (end2 - start2) *
pred / pred_count;
256 int end3 = start2 + (end2 - start2) * (
pred + 1) / pred_count;
317 size_t len = strlen(
string);
333 int forw_ptr = dyn_size + 4;
351 int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields,
370 tmp_match = 1 - (1LL << 62);
372 for (
i = 0;
i < 256; ) {
391 for (j = 0;
i < 256; j++,
i++) {
405 if (j != tmp_mul - tmp_size)
408 put_v(bc, tmp_flags);
409 put_v(bc, tmp_fields);
410 if (tmp_fields > 0)
put_s(bc, tmp_pts);
411 if (tmp_fields > 1)
put_v(bc, tmp_mul);
412 if (tmp_fields > 2)
put_v(bc, tmp_stream);
413 if (tmp_fields > 3)
put_v(bc, tmp_size);
414 if (tmp_fields > 4)
put_v(bc, 0 );
415 if (tmp_fields > 5)
put_v(bc, j);
416 if (tmp_fields > 6)
put_v(bc, tmp_match);
417 if (tmp_fields > 7)
put_v(bc, tmp_head_idx);
440 default:
put_v(bc, 3);
break;
500 int count = 0, dyn_size;
528 int count=0, dyn_size,
i;
545 count +=
add_info(dyn_bc,
"r_frame_rate", buf);
550 put_v(bc, stream_id + 1);
570 int ret, dyn_size, count = 0;
597 int64_t payload_size;
606 dummy.pos = next_node[1]->pos;
627 for (k= j - n; k<=j && k<nut->
sp_count; k++) {
637 payload_size =
avio_tell(bc) - startpos + 8 + 4;
639 avio_wb64(bc, 8 + payload_size +
av_log2(payload_size) / 7 + 1 + 4*(payload_size > 4096));
707 "The additional syncpoint modes require version %d, "
708 "that is currently not finalized, "
709 "please set -f_strict experimental in order to enable it.\n",
721 for (
i = 0;
i <
s->nb_streams;
i++) {
744 if (INT64_C(1000) * time_base.
num >= time_base.
den)
752 for (
i = 0;
i <
s->nb_chapters;
i++) {
776 if (
s->avoid_negative_ts < 0)
777 s->avoid_negative_ts = 1;
832 int ret,
i, dyn_size;
835 int sm_data_count = 0;
855 while (
data < data_end) {
859 if(
val >= data_end) {
899 put_s(dyn_bc, bytestream_get_le32(&
data));
903 put_str(dyn_bc,
"ChannelLayout");
912 put_s(dyn_bc, bytestream_get_le32(&
data));
917 put_s(dyn_bc, bytestream_get_le32(&
data));
919 put_s(dyn_bc, bytestream_get_le32(&
data));
945 put_v(bc, sm_data_count);
960 int best_length, frame_code,
flags, needed_flags,
i, header_idx;
971 "Negative pts not supported stream %d, pts %"PRId64
"\n",
988 data_size += sm_size;
1004 int64_t sp_pos = INT64_MAX;
1007 for (
i = 0;
i <
s->nb_streams;
i++) {
1044 if ((1ll<<60) % nut->
sp_count == 0)
1045 for (
i=0;
i<
s->nb_streams;
i++) {
1066 best_length = INT_MAX;
1068 for (
i = 0;
i < 256;
i++) {
1079 flags = needed_flags;
1082 if ((
flags & needed_flags) != needed_flags)
1091 if (data_size %
fc->size_mul !=
fc->size_lsb)
1108 length += 1 - nut->
header_len[best_header_idx];
1117 if (length < best_length) {
1118 best_length = length;
1127 header_idx =
fc->header_idx;
1133 flags = needed_flags;
1205 for (
i=0;
i<
s->nb_streams;
i++)
1213 #define OFFSET(x) offsetof(NUTContext, x)
1214 #define E AV_OPT_FLAG_ENCODING_PARAM
1217 {
"default",
"", 0,
AV_OPT_TYPE_CONST, {.i64 = 0}, INT_MIN, INT_MAX,
E,
"syncpoints" },
1218 {
"none",
"Disable syncpoints, low overhead and unseekable", 0,
AV_OPT_TYPE_CONST, {.i64 =
NUT_PIPE}, INT_MIN, INT_MAX,
E,
"syncpoints" },
1224 static const AVClass class = {
1234 .mime_type =
"video/x-nut",
1235 .extensions =
"nut",
1246 .priv_class = &
class,
static double val(void *priv, double ch)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
void avio_wl32(AVIOContext *s, unsigned int val)
void avio_w8(AVIOContext *s, int b)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
void avio_wb64(AVIOContext *s, uint64_t val)
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
int avio_get_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
unsigned long ffio_get_checksum(AVIOContext *s)
void ffio_reset_dyn_buf(AVIOContext *s)
Reset a dynamic buffer.
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
#define flags(name, subs,...)
#define fc(width, name, range_min, range_max)
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
#define CONFIG_LIBMP3LAME
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
static void write_header(FFV1Context *f)
@ AV_CODEC_ID_MP3
preferred ID for decoding MPEG audio layer 1, 2 or 3
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
int av_get_audio_frame_duration2(AVCodecParameters *par, int frame_bytes)
This function is the same as av_get_audio_frame_duration(), except it works with AVCodecParameters in...
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
@ AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT
@ AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT
@ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE
@ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS
@ AV_PKT_DATA_STRINGS_METADATA
A list of zero terminated key/value strings.
@ AV_PKT_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
@ AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL
Data found in BlockAdditional element of matroska container.
@ AV_PKT_DATA_QUALITY_STATS
This side data contains quality related information from the encoder.
@ AV_PKT_DATA_METADATA_UPDATE
A list of zero terminated key/value strings.
@ AV_PKT_DATA_PALETTE
An AV_PKT_DATA_PALETTE side data packet contains exactly AVPALETTE_SIZE bytes worth of palette.
@ AV_PKT_DATA_NEW_EXTRADATA
The AV_PKT_DATA_NEW_EXTRADATA is used to notify the codec or the format that the extradata buffer was...
@ AV_PKT_DATA_PARAM_CHANGE
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, int size, int distance, int flags)
Add an index entry into a sorted list.
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key,...
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
const char * av_default_item_name(void *ptr)
Return the context name.
static av_always_inline AVRational av_inv_q(AVRational q)
Invert a rational.
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare two timestamps each in its own time base.
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AV_ROUND_DOWN
Round toward -infinity.
void * av_calloc(size_t nmemb, size_t size)
Non-inlined equivalent of av_mallocz_array().
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
#define AV_NOPTS_VALUE
Undefined timestamp value.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
#define LIBAVUTIL_VERSION_INT
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
const uint16_t avpriv_mpa_freq_tab[3]
const uint16_t avpriv_mpa_bitrate_tab[2][3][15]
mpeg audio layer common tables.
void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val)
int ff_nut_sp_pos_cmp(const void *a, const void *b)
int64_t ff_lsb2full(StreamContext *stream, int64_t lsb)
int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
const AVCodecTag *const ff_nut_codec_tags[]
void ff_nut_free_sp(NUTContext *nut)
const Dispositions ff_nut_dispositions[]
const AVMetadataConv ff_nut_metadata_conv[]
#define SYNCPOINT_STARTCODE
#define NUT_STABLE_VERSION
static int write_headers(AVFormatContext *avctx, AVIOContext *bc)
static int get_v_length(uint64_t val)
Get the length in bytes which is needed to store val as v.
static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id)
static void nut_write_deinit(AVFormatContext *s)
static int get_needed_flags(NUTContext *nut, StreamContext *nus, FrameCode *fc, AVPacket *pkt)
static int write_index(NUTContext *nut, AVIOContext *bc)
static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc, uint64_t startcode)
static void build_elision_headers(AVFormatContext *s)
static const AVOption options[]
static int add_info(AVIOContext *bc, const char *type, const char *value)
static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, AVStream *st, int i)
static void put_v(AVIOContext *bc, uint64_t val)
Put val using a variable number of bytes.
static void build_frame_code(AVFormatContext *s)
static int write_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta)
static int write_chapter(NUTContext *nut, AVIOContext *bc, int id)
static int find_header_idx(AVFormatContext *s, AVCodecParameters *p, int size, int frame_type)
static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
static int write_globalinfo(NUTContext *nut, AVIOContext *bc)
static int find_expected_header(AVCodecParameters *p, int size, int key_frame, uint8_t out[64])
static void put_s(AVIOContext *bc, int64_t val)
AVOutputFormat ff_nut_muxer
static int nut_write_header(AVFormatContext *s)
static int find_best_header_idx(NUTContext *nut, AVPacket *pkt)
static void put_tt(NUTContext *nut, AVRational *time_base, AVIOContext *bc, uint64_t val)
static int nut_write_trailer(AVFormatContext *s)
static void put_str(AVIOContext *bc, const char *string)
Store a string as vb.
static void write_mainheader(NUTContext *nut, AVIOContext *bc)
internal header for RIFF based (de)muxers do NOT include this in end user applications
void ff_parse_specific_params(AVStream *st, int *au_rate, int *au_ssize, int *au_scale)
static const uint8_t header[24]
static const float pred[4]
int64_t end
chapter start/end time in time_base units
AVRational time_base
time base in which the start/end timestamps are specified
Describe the class of an AVClass context structure.
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
This struct describes the properties of an encoded stream.
int extradata_size
Size of the extradata content in bytes.
enum AVMediaType codec_type
General type of the encoded data.
int video_delay
Video only.
uint32_t codec_tag
Additional information about the codec (corresponds to the AVI FOURCC).
uint8_t * extradata
Extra binary data needed for initializing the decoder, codec-dependent.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
Audio only.
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
unsigned int nb_chapters
Number of chapters in AVChapter array.
void * priv_data
Format private data.
AVStream ** streams
A list of all streams in the file.
enum AVPacketSideDataType type
This structure stores compressed data.
int flags
A combination of AV_PKT_FLAG values.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
AVRational avg_frame_rate
Average framerate.
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
AVRational r_frame_rate
Real base framerate of the stream.
int disposition
AV_DISPOSITION_* bit field.
const uint8_t * header[128]
struct AVTreeNode * syncpoints
FrameCode frame_code[256]
unsigned int max_distance
int64_t last_syncpoint_pos
unsigned int time_base_count
int64_t av_gettime(void)
Get the current time in microseconds.
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(const void *key, const void *b), void *next[2])
static int write_trailer(AVFormatContext *s1)