56 int lsf, mpeg25, sample_rate_index, bitrate_index,
frame_size;
58 unsigned int header = 0xFFF00000;
60 lsf = sample_rate < (24000 + 32000) / 2;
61 mpeg25 = sample_rate < (12000 + 16000) / 2;
62 sample_rate <<= lsf + mpeg25;
63 if (sample_rate < (32000 + 44100) / 2)
64 sample_rate_index = 2;
65 else if (sample_rate < (44100 + 48000) / 2)
66 sample_rate_index = 0;
68 sample_rate_index = 1;
72 for (bitrate_index = 2; bitrate_index < 30; bitrate_index++) {
75 frame_size = (frame_size * 144000) / (sample_rate << lsf) +
78 if (frame_size == size)
82 header |= (!lsf) << 19;
83 header |= (4 - layer) << 17;
88 if (bitrate_index == 30)
91 header |= (bitrate_index >> 1) << 12;
92 header |= sample_rate_index << 10;
93 header |= (bitrate_index & 1) << 9;
125 static const uint8_t headers[][5] = {
126 { 3, 0x00, 0x00, 0x01 },
127 { 4, 0x00, 0x00, 0x01, 0xB6},
137 nut->
header[i] = &headers[i - 1][1];
157 if (keyframe_0_esc) {
165 for (stream_id = 0; stream_id < s->
nb_streams; stream_id++) {
166 int start2 = start + (end - start) * stream_id / s->
nb_streams;
167 int end2 = start + (end - start) * (stream_id + 1) / s->
nb_streams;
170 int intra_only = is_audio;
173 for (key_frame = 0; key_frame < 2; key_frame++) {
174 if (!intra_only || !keyframe_0_esc || key_frame != 0) {
186 key_frame = intra_only;
188 int frame_bytes = codec->frame_size * (int64_t)codec->bit_rate /
189 (8 * codec->sample_rate);
191 for (pts = 0; pts < 2; pts++)
192 for (pred = 0; pred < 2; pred++) {
211 if (codec->has_b_frames) {
228 for (pred = 0; pred < pred_count; pred++) {
229 int start3 = start2 + (end2 - start2) * pred / pred_count;
230 int end3 = start2 + (end2 - start2) * (pred + 1) / pred_count;
232 for (index = start3; index < end3; index++) {
265 int len = strlen(
string);
277 static inline void ff_put_v_trace(
AVIOContext *bc, uint64_t v,
const char *file,
278 const char *func,
int line)
285 static inline void put_s_trace(
AVIOContext *bc, int64_t v,
const char *file,
286 const char *func,
int line)
292 #define ff_put_v(bc, v) ff_put_v_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
293 #define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
298 int calculate_checksum, uint64_t startcode)
302 int forw_ptr = dyn_size + 4 * calculate_checksum;
311 if (calculate_checksum)
314 if (calculate_checksum)
322 int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields,
339 tmp_match = 1 - (1LL << 62);
341 for (i = 0; i < 256; ) {
365 for (j = 0; i < 256; j++, i++) {
379 if (j != tmp_mul - tmp_size)
491 int count = 0, dyn_size;
517 int count=0, dyn_size, i;
549 int ret, dyn_size, count = 0;
674 if (INT64_C(1000) * time_base.
num >= time_base.
den)
745 if (pkt->
size > 4096)
765 int best_length, frame_code,
flags, needed_flags, i, header_idx,
773 "Negative pts not supported stream %d, pts %"PRId64
"\n",
805 if (dummy.
pos == INT64_MAX)
829 best_length = INT_MAX;
831 for (i = 0; i < 256; i++) {
834 int flags = fc->
flags;
842 flags = needed_flags;
845 if ((flags & needed_flags) != needed_flags)
848 if ((flags ^ needed_flags) &
FLAG_KEY)
865 if ((flags & FLAG_CODED)
872 length += 1 - nut->
header_len[best_header_idx];
881 if (length < best_length) {
882 best_length = length;
886 assert(frame_code != -1);
895 ff_put_v(bc, (flags ^ needed_flags) & ~(FLAG_CODED));
896 flags = needed_flags;
905 ff_put_v(bc, header_idx = best_header_idx);
949 .mime_type =
"video/x-nut",
void avio_wb64(AVIOContext *s, uint64_t val)
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.
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.
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.
void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale)
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
mpeg audio layer common tables.
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
const uint8_t * header[128]
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(void *key, const void *b), void *next[2])
void avio_wl32(AVIOContext *s, unsigned int val)
static void build_elision_headers(AVFormatContext *s)
static void build_frame_code(AVFormatContext *s)
if set, coded_pts is in the frame header
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)
const AVMetadataConv ff_nut_metadata_conv[]
static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
#define AVFMT_GLOBALHEADER
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b)
struct NUTContext NUTContext
static const uint8_t frame_size[4]
AVOutputFormat ff_nut_muxer
int has_b_frames
Size of the frame reordering buffer in the decoder.
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
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.
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. ...
preferred ID for decoding MPEG audio layer 1, 2 or 3
static int write_chapter(NUTContext *nut, AVIOContext *bc, int id)
void av_log(void *avcl, int level, const char *fmt,...)
if set, frame is keyframe
int flags
A combination of AV_PKT_FLAG values.
AVCodecContext * codec
Codec context associated with this stream.
static void write_mainheader(NUTContext *nut, AVIOContext *bc)
unsigned int nb_streams
A list of all streams in the file.
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint8_t out[64])
int void avio_flush(AVIOContext *s)
void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val)
int width
picture width / height.
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 ...
if set, frame_code is invalid
struct AVTreeNode * syncpoints
if set, data_size_msb is at frame header, otherwise data_size_msb is 0
if set, the frame header contains a checksum
preferred ID for MPEG-1/2 video decoding
static int write_globalinfo(NUTContext *nut, AVIOContext *bc)
static const float pred[4]
int64_t end
chapter start/end time in time_base units
#define AVSEEK_FLAG_BACKWARD
enum AVMediaType codec_type
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').
if set, coded_flags are stored in the frame header
#define AV_DICT_IGNORE_SUFFIX
rational number numerator/denominator
static int nut_write_trailer(AVFormatContext *s)
unsigned long ffio_get_checksum(AVIOContext *s)
static void put_s(AVIOContext *bc, int64_t val)
static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, AVStream *st, int i)
static int find_header_idx(AVFormatContext *s, AVCodecContext *c, int size, int frame_type)
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[]
static int find_best_header_idx(NUTContext *nut, AVPacket *pkt)
FrameCode frame_code[256]
#define AVERROR_INVALIDDATA
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.
If set, header_idx is coded in the frame header.
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)
#define AVFMT_VARIABLE_FPS
static void write_header(FFV1Context *f)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
if set, stream_id is coded in the frame header
static int add_info(AVIOContext *bc, const char *type, const char *value)
const uint16_t avpriv_mpa_bitrate_tab[2][3][15]
unsigned int av_codec_get_tag(const struct AVCodecTag *const *tags, enum AVCodecID id)
Get the codec tag for the given codec id id.
const AVCodecTag *const ff_nut_codec_tags[]
This structure stores compressed data.
unsigned int time_base_count
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
unsigned int max_distance