62 int lsf, mpeg25, sample_rate_index, bitrate_index,
frame_size;
64 unsigned int header = 0xFFF00000;
66 lsf = sample_rate < (24000 + 32000) / 2;
67 mpeg25 = sample_rate < (12000 + 16000) / 2;
68 sample_rate <<= lsf + mpeg25;
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++) {
78 frame_size = (frame_size * 144000) / (sample_rate << lsf) +
81 if (frame_size == size)
85 header |= (!lsf) << 19;
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;
127 static const uint8_t headers[][5] = {
128 { 3, 0x00, 0x00, 0x01 },
129 { 4, 0x00, 0x00, 0x01, 0xB6},
139 nut->
header[i] = &headers[i - 1][1];
159 if (keyframe_0_esc) {
167 for (stream_id = 0; stream_id < s->
nb_streams; stream_id++) {
169 int end2 = start + (end - start) * (stream_id + 1) / s->
nb_streams;
182 if (f.
den == 1 && f.
num>0)
188 for (key_frame = 0; key_frame < 2; key_frame++) {
189 if (!
intra_only || !keyframe_0_esc || key_frame != 0) {
204 int frame_bytes = codec->frame_size * (int64_t)codec->bit_rate /
205 (8 * codec->sample_rate);
207 for (pts = 0; pts < 2; pts++) {
208 for (pred = 0; pred < 2; pred++) {
229 if (codec->has_b_frames) {
246 for (pred = 0; pred < pred_count; pred++) {
247 int start3 = start2 + (end2 - start2) * pred / pred_count;
248 int end3 = start2 + (end2 - start2) * (pred + 1) / pred_count;
252 for (index = start3; index < end3; index++) {
283 size_t len = strlen(
string);
295 static inline void ff_put_v_trace(
AVIOContext *bc, uint64_t v,
const char *file,
303 static inline void put_s_trace(
AVIOContext *bc, int64_t v,
const char *file,
const char *
func,
int line)
309 #define ff_put_v(bc, v) ff_put_v_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
310 #define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
315 int calculate_checksum, uint64_t startcode)
319 int forw_ptr = dyn_size + 4 * calculate_checksum;
328 if (calculate_checksum)
331 if (calculate_checksum)
339 int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields,
358 tmp_match = 1 - (1LL << 62);
360 for (i = 0; i < 256; ) {
379 for (j = 0; i < 256; j++, i++) {
393 if (j != tmp_mul - tmp_size)
398 if (tmp_fields > 0)
put_s(bc, tmp_pts);
399 if (tmp_fields > 1)
ff_put_v(bc, tmp_mul);
400 if (tmp_fields > 2)
ff_put_v(bc, tmp_stream);
401 if (tmp_fields > 3)
ff_put_v(bc, tmp_size);
402 if (tmp_fields > 4)
ff_put_v(bc, 0 );
403 if (tmp_fields > 5)
ff_put_v(bc, j);
404 if (tmp_fields > 6)
ff_put_v(bc, tmp_match);
405 if (tmp_fields > 7)
ff_put_v(bc, tmp_head_idx);
487 int count = 0, dyn_size;
514 int count=0, dyn_size, i;
531 count +=
add_info(dyn_bc,
"r_frame_rate", buf);
556 int ret, dyn_size,
count = 0;
583 int64_t payload_size;
591 ff_put_v(bc, (next_node[1]->pos >> 4) - (dummy.
pos>>4));
592 dummy.
pos = next_node[1]->
pos;
613 for (k= j - n; k<=j && k<nut->
sp_count; k++) {
623 payload_size =
avio_tell(bc) - startpos + 8 + 4;
625 avio_wb64(bc, 8 + payload_size +
av_log2(payload_size) / 7 + 1 + 4*(payload_size > 4096));
701 "The additional syncpoint modes require version %d, "
702 "that is currently not finalized, "
703 "please set -f_strict experimental in order to enable it.\n",
742 if (INT64_C(1000) * time_base.
num >= time_base.
den)
816 if (pkt->
size > 4096)
831 int ret, i, dyn_size;
834 int sm_data_count = 0;
850 if (!size || data[size-1]) {
854 while (data < data_end) {
858 if(val >= data_end) {
865 data = val + strlen(val) + 1;
880 snprintf(tmp,
sizeof(tmp),
"CodecSpecificSide%"PRId64
"",
AV_RB64(data));
883 snprintf(tmp,
sizeof(tmp),
"UserData%s-SD-%d",
895 flags = bytestream_get_le32(&data);
898 put_s(dyn_bc, bytestream_get_le32(&data));
902 put_str(dyn_bc,
"ChannelLayout");
911 put_s(dyn_bc, bytestream_get_le32(&data));
916 put_s(dyn_bc, bytestream_get_le32(&data));
918 put_s(dyn_bc, bytestream_get_le32(&data));
959 int best_length, frame_code,
flags, needed_flags, i, header_idx;
965 int data_size = pkt->
size;
970 "Negative pts not supported stream %d, pts %"PRId64
"\n",
987 data_size += sm_size;
1003 int64_t sp_pos = INT64_MAX;
1042 if ((1ll<<60) % nut->
sp_count == 0)
1064 best_length = INT_MAX;
1066 for (i = 0; i < 256; i++) {
1069 int flags = fc->
flags;
1077 flags = needed_flags;
1080 if ((flags & needed_flags) != needed_flags)
1083 if ((flags ^ needed_flags) &
FLAG_KEY)
1100 if ( (flags & FLAG_CODED)
1106 length += 1 - nut->
header_len[best_header_idx];
1115 if (length < best_length) {
1130 ff_put_v(bc, (flags ^ needed_flags) & ~(FLAG_CODED));
1131 flags = needed_flags;
1207 #define OFFSET(x) offsetof(NUTContext, x)
1208 #define E AV_OPT_FLAG_ENCODING_PARAM
1211 {
"default",
"", 0,
AV_OPT_TYPE_CONST, {.i64 = 0}, INT_MIN, INT_MAX,
E,
"syncpoints" },
1212 {
"none",
"Disable syncpoints, low overhead and unseekable", 0,
AV_OPT_TYPE_CONST, {.i64 =
NUT_PIPE}, INT_MIN, INT_MAX,
E,
"syncpoints" },
1218 static const AVClass class = {
1228 .mime_type =
"video/x-nut",
1229 .extensions =
"nut",
1240 .priv_class = &
class,
unsigned int nb_chapters
Number of chapters in AVChapter array.
#define FF_COMPLIANCE_EXPERIMENTAL
Allow nonstandardized experimental things.
#define NUT_STABLE_VERSION
void avio_wb64(AVIOContext *s, uint64_t val)
const char const char void * val
A list of zero terminated key/value strings.
int64_t last_syncpoint_pos
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
ptrdiff_t const GLvoid * data
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.
static void nut_write_deinit(AVFormatContext *s)
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.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define LIBAVUTIL_VERSION_INT
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(const void *key, const void *b), void *next[2])
int ff_nut_sp_pos_cmp(const void *a, const void *b)
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
mpeg audio layer common tables.
int strict_std_compliance
Allow non-standard and experimental extension.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
const uint8_t * header[128]
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void avio_wl32(AVIOContext *s, unsigned int val)
static void build_elision_headers(AVFormatContext *s)
static void build_frame_code(AVFormatContext *s)
static av_cold int end(AVCodecContext *avctx)
static const AVOption options[]
const uint16_t avpriv_mpa_freq_tab[3]
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
static void put_tt(NUTContext *nut, AVRational *time_base, AVIOContext *bc, uint64_t val)
AVStream ** streams
A list of all streams in the file.
const AVMetadataConv ff_nut_metadata_conv[]
static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int flags
Flags modifying the (de)muxer behaviour.
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
static const uint8_t header[24]
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
AVOutputFormat ff_nut_muxer
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionary * metadata
Metadata that applies to the whole file.
int has_b_frames
Size of the frame reordering buffer in the decoder.
void ff_nut_free_sp(NUTContext *nut)
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
void ff_parse_specific_params(AVStream *st, int *au_rate, int *au_ssize, int *au_scale)
An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows:
static int nut_write_header(AVFormatContext *s)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
AVRational av_div_q(AVRational b, AVRational c)
Divide one rational by another.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
preferred ID for decoding MPEG audio layer 1, 2 or 3
static int write_chapter(NUTContext *nut, AVIOContext *bc, int id)
simple assert() macros that are a bit more flexible than ISO C assert().
enum AVPacketSideDataType type
int flags
A combination of AV_PKT_FLAG values.
int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b)
Compare 2 timestamps each in its own timebases.
AVCodecContext * codec
Codec context associated with this stream.
static void write_mainheader(NUTContext *nut, AVIOContext *bc)
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
static const uint16_t fc[]
static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint8_t out[64])
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val)
This side data contains quality related information from the encoder.
int width
picture width / height.
GLsizei GLboolean const GLfloat * value
static int write_trailer(AVFormatContext *s1)
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
int64_t ff_lsb2full(StreamContext *stream, int64_t lsb)
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
struct AVTreeNode * syncpoints
int avoid_negative_ts
Avoid negative timestamps during muxing.
preferred ID for MPEG-1/2 video decoding
static int write_globalinfo(NUTContext *nut, AVIOContext *bc)
#define AVERROR_EXPERIMENTAL
Requested feature is flagged experimental. Set strict_std_compliance if you really want to use it...
void ffio_free_dyn_buf(AVIOContext **s)
Free a dynamic buffer.
static const float pred[4]
int64_t av_gettime(void)
Get the current time in microseconds.
int64_t end
chapter start/end time in time_base units
enum AVMediaType codec_type
A list of zero terminated key/value strings.
#define AV_TIME_BASE_Q
Internal time base represented as fractional value.
int sample_rate
samples per second
AVIOContext * pb
I/O context.
void avio_w8(AVIOContext *s, int b)
main external API structure.
static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id)
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
static int write_index(NUTContext *nut, AVIOContext *bc)
Data found in BlockAdditional element of matroska container.
static int write_sm_data(AVFormatContext *s, AVIOContext *bc, AVPacket *pkt, int is_meta)
Describe the class of an AVClass context structure.
rational number numerator/denominator
static int nut_write_trailer(AVFormatContext *s)
Recommmends skipping the specified number of samples.
unsigned long ffio_get_checksum(AVIOContext *s)
int(* func)(AVBPrint *dst, const char *in, const char *arg)
static void put_s(AVIOContext *bc, int64_t val)
static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, AVStream *st, int i)
int av_get_audio_frame_duration(AVCodecContext *avctx, int frame_bytes)
Return audio frame duration.
static int find_header_idx(AVFormatContext *s, AVCodecContext *c, int size, int frame_type)
void * av_calloc(size_t nmemb, size_t size)
Allocate a block of nmemb * size bytes with alignment suitable for all memory accesses (including vec...
static int64_t pts
Global timestamp for the audio frames.
int ff_get_v_length(uint64_t val)
Get the length in bytes which is needed to store val as v.
static int write_headers(AVFormatContext *avctx, AVIOContext *bc)
const Dispositions ff_nut_dispositions[]
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_RB64
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
static int find_best_header_idx(NUTContext *nut, AVPacket *pkt)
FrameCode frame_code[256]
int disposition
AV_DISPOSITION_* bit field.
int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
AVRational time_base
time base in which the start/end timestamps are specified
#define SYNCPOINT_STARTCODE
static void put_str(AVIOContext *bc, const char *string)
Store a string as vb.
static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc, int calculate_checksum, uint64_t startcode)
void ff_put_v(AVIOContext *bc, uint64_t val)
Put val using a variable number of bytes.
int channels
number of audio channels
void * priv_data
Format private data.
static int get_needed_flags(NUTContext *nut, StreamContext *nus, FrameCode *fc, AVPacket *pkt)
static void write_header(FFV1Context *f)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static int add_info(AVIOContext *bc, const char *type, const char *value)
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
const uint16_t avpriv_mpa_bitrate_tab[2][3][15]
AVRational r_frame_rate
Real base framerate of the stream.
const AVCodecTag *const ff_nut_codec_tags[]
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.
unsigned int time_base_count
static int write_packet(AVFormatContext *s1, AVPacket *pkt)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
#define AV_NOPTS_VALUE
Undefined timestamp value.
unsigned int max_distance