51 int lsf, mpeg25, sample_rate_index, bitrate_index, frame_size;
53 unsigned int header= 0xFFF00000;
55 lsf = sample_rate < (24000+32000)/2;
56 mpeg25 = sample_rate < (12000+16000)/2;
57 sample_rate <<= lsf + mpeg25;
58 if (sample_rate < (32000 + 44100)/2) sample_rate_index=2;
59 else if(sample_rate < (44100 + 48000)/2) sample_rate_index=0;
60 else sample_rate_index=1;
64 for(bitrate_index=2; bitrate_index<30; bitrate_index++){
66 frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1);
68 if(frame_size == size)
73 header |= (4-layer)<<17;
78 if(bitrate_index == 30)
81 header |= (bitrate_index>>1)<<12;
82 header |= sample_rate_index<<10;
83 header |= (bitrate_index&1)<<9;
102 && !memcmp(out, nut->
header[i], len)){
116 static const uint8_t headers[][5]={
117 {3, 0x00, 0x00, 0x01},
118 {4, 0x00, 0x00, 0x01, 0xB6},
128 nut->
header [i]= &headers[i-1][1];
155 for(stream_id= 0; stream_id<s->
nb_streams; stream_id++){
156 int start2= start + (end-start)*stream_id / s->
nb_streams;
157 int end2 = start + (end-start)*(stream_id+1) / s->
nb_streams;
163 for(key_frame=0; key_frame<2; key_frame++){
164 if(
intra_only && keyframe_0_esc && key_frame==0)
181 int frame_bytes= codec->frame_size*(int64_t)codec->bit_rate / (8*codec->sample_rate);
183 for(pts=0; pts<2; pts++){
184 for(pred=0; pred<2; pred++){
204 if(codec->has_b_frames){
221 for(pred=0; pred<pred_count; pred++){
222 int start3= start2 + (end2-start2)*pred / pred_count;
223 int end3 = start2 + (end2-start2)*(pred+1) / pred_count;
225 for(index=start3; index<end3; index++){
255 int len= strlen(
string);
266 static inline void ff_put_v_trace(
AVIOContext *bc, uint64_t
v,
char *file,
char *func,
int line){
272 static inline void put_s_trace(
AVIOContext *bc, int64_t
v,
char *file,
char *func,
int line){
277 #define ff_put_v(bc, v) ff_put_v_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
278 #define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
283 uint8_t *dyn_buf=
NULL;
285 int forw_ptr= dyn_size + 4*calculate_checksum;
294 if(calculate_checksum)
297 if(calculate_checksum)
304 int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields, tmp_head_idx;
320 tmp_match= 1-(1LL<<62);
341 for(j=0; i<256; j++,i++){
354 if(j != tmp_mul - tmp_size) tmp_fields=6;
358 if(tmp_fields>0)
put_s(bc, tmp_pts);
359 if(tmp_fields>1)
ff_put_v(bc, tmp_mul);
360 if(tmp_fields>2)
ff_put_v(bc, tmp_stream);
361 if(tmp_fields>3)
ff_put_v(bc, tmp_size);
364 if(tmp_fields>6)
ff_put_v(bc, tmp_match);
365 if(tmp_fields>7)
ff_put_v(bc, tmp_head_idx);
437 uint8_t *dyn_buf=
NULL;
438 int count=0, dyn_size;
463 uint8_t *dyn_buf=
NULL;
464 int count=0, dyn_size, i;
493 uint8_t *dyn_buf =
NULL;
496 int ret, dyn_size, count = 0;
618 if(INT64_C(1000) * time_base.
num >= time_base.
den)
700 int best_length, frame_code,
flags, needed_flags, i, header_idx, best_header_idx;
757 for(i=0; i<256; i++){
760 int flags= fc->
flags;
768 flags = needed_flags;
771 if((flags & needed_flags) != needed_flags)
774 if((flags ^ needed_flags) &
FLAG_KEY)
791 if( (flags & FLAG_CODED)
797 length += 1 - nut->
header_len[best_header_idx];
806 if(length < best_length){
811 assert(frame_code != -1);
820 ff_put_v(bc, (flags^needed_flags) & ~(FLAG_CODED));
821 flags = needed_flags;
866 .mime_type =
"video/x-nut",
void avio_wb64(AVIOContext *s, uint64_t val)
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
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.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
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)
void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b)
preferred ID for MPEG-1/2 video decoding
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. ...
static int write_chapter(NUTContext *nut, AVIOContext *bc, int id)
void av_log(void *avcl, int level, const char *fmt,...)
const AVCodecTag ff_codec_wav_tags[]
if set, frame is keyframe
int flags
A combination of AV_PKT_FLAG values.
AVCodecContext * codec
codec context
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)
const AVCodecTag ff_codec_bmp_tags[]
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)
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
void ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
static int write_globalinfo(NUTContext *nut, AVIOContext *bc)
static const float pred[4]
int64_t end
chapter start/end time in time_base units
enum AVMediaType codec_type
const AVCodecTag ff_nut_subtitle_tags[]
int sample_rate
samples per second
void avio_w8(AVIOContext *s, int b)
main external API structure.
static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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
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)
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
FrameCode frame_code[256]
int disposition
AV_DISPOSITION_* bit field.
const AVCodecTag ff_nut_video_tags[]
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)
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)
#define AV_DICT_IGNORE_SUFFIX
const uint16_t avpriv_mpa_bitrate_tab[2][3][15]
unsigned int time_base_count
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.
preferred ID for decoding MPEG audio layer 1, 2 or 3
unsigned int max_distance