Libav
nutenc.c
Go to the documentation of this file.
1 /*
2  * nut muxer
3  * Copyright (c) 2004-2007 Michael Niedermayer
4  *
5  * This file is part of Libav.
6  *
7  * Libav is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * Libav is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with Libav; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include <stdint.h>
23 
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/mathematics.h"
26 #include "libavutil/tree.h"
27 #include "libavutil/dict.h"
29 #include "nut.h"
30 #include "internal.h"
31 #include "avio_internal.h"
32 #include "riff.h"
33 
34 static int find_expected_header(AVCodecContext *c, int size, int key_frame,
35  uint8_t out[64])
36 {
37  int sample_rate = c->sample_rate;
38 
39  if (size > 4096)
40  return 0;
41 
42  AV_WB24(out, 1);
43 
44  if (c->codec_id == AV_CODEC_ID_MPEG4) {
45  if (key_frame) {
46  return 3;
47  } else {
48  out[3] = 0xB6;
49  return 4;
50  }
51  } else if (c->codec_id == AV_CODEC_ID_MPEG1VIDEO ||
53  return 3;
54  } else if (c->codec_id == AV_CODEC_ID_H264) {
55  return 3;
56  } else if (c->codec_id == AV_CODEC_ID_MP3 ||
57  c->codec_id == AV_CODEC_ID_MP2) {
58  int lsf, mpeg25, sample_rate_index, bitrate_index, frame_size;
59  int layer = c->codec_id == AV_CODEC_ID_MP3 ? 3 : 2;
60  unsigned int header = 0xFFF00000;
61 
62  lsf = sample_rate < (24000 + 32000) / 2;
63  mpeg25 = sample_rate < (12000 + 16000) / 2;
64  sample_rate <<= lsf + mpeg25;
65  if (sample_rate < (32000 + 44100) / 2)
66  sample_rate_index = 2;
67  else if (sample_rate < (44100 + 48000) / 2)
68  sample_rate_index = 0;
69  else
70  sample_rate_index = 1;
71 
72  sample_rate = avpriv_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25);
73 
74  for (bitrate_index = 2; bitrate_index < 30; bitrate_index++) {
75  frame_size =
76  avpriv_mpa_bitrate_tab[lsf][layer - 1][bitrate_index >> 1];
77  frame_size = (frame_size * 144000) / (sample_rate << lsf) +
78  (bitrate_index & 1);
79 
80  if (frame_size == size)
81  break;
82  }
83 
84  header |= (!lsf) << 19;
85  header |= (4 - layer) << 17;
86  header |= 1 << 16; //no crc
87  AV_WB32(out, header);
88  if (size <= 0)
89  return 2; //we guess there is no crc, if there is one the user clearly does not care about overhead
90  if (bitrate_index == 30)
91  return -1; //something is wrong ...
92 
93  header |= (bitrate_index >> 1) << 12;
94  header |= sample_rate_index << 10;
95  header |= (bitrate_index & 1) << 9;
96 
97  return 2; //FIXME actually put the needed ones in build_elision_headers()
98  //return 3; //we guess that the private bit is not set
99 //FIXME the above assumptions should be checked, if these turn out false too often something should be done
100  }
101  return 0;
102 }
103 
105  int frame_type)
106 {
107  NUTContext *nut = s->priv_data;
108  uint8_t out[64];
109  int i;
110  int len = find_expected_header(c, size, frame_type, out);
111 
112  for (i = 1; i < nut->header_count; i++) {
113  if (len == nut->header_len[i] && !memcmp(out, nut->header[i], len)) {
114  return i;
115  }
116  }
117 
118  return 0;
119 }
120 
122 {
123  NUTContext *nut = s->priv_data;
124  int i;
125  //FIXME this is lame
126  //FIXME write a 2pass mode to find the maximal headers
127  static const uint8_t headers[][5] = {
128  { 3, 0x00, 0x00, 0x01 },
129  { 4, 0x00, 0x00, 0x01, 0xB6},
130  { 2, 0xFF, 0xFA }, //mp3+crc
131  { 2, 0xFF, 0xFB }, //mp3
132  { 2, 0xFF, 0xFC }, //mp2+crc
133  { 2, 0xFF, 0xFD }, //mp2
134  };
135 
136  nut->header_count = 7;
137  for (i = 1; i < nut->header_count; i++) {
138  nut->header_len[i] = headers[i - 1][0];
139  nut->header[i] = &headers[i - 1][1];
140  }
141 }
142 
144 {
145  NUTContext *nut = s->priv_data;
146  int key_frame, index, pred, stream_id;
147  int start = 1;
148  int end = 254;
149  int keyframe_0_esc = s->nb_streams > 2;
150  int pred_table[10];
151  FrameCode *ft;
152 
153  ft = &nut->frame_code[start];
154  ft->flags = FLAG_CODED;
155  ft->size_mul = 1;
156  ft->pts_delta = 1;
157  start++;
158 
159  if (keyframe_0_esc) {
160  /* keyframe = 0 escape */
161  FrameCode *ft = &nut->frame_code[start];
163  ft->size_mul = 1;
164  start++;
165  }
166 
167  for (stream_id = 0; stream_id < s->nb_streams; stream_id++) {
168  int start2 = start + (end - start) * stream_id / s->nb_streams;
169  int end2 = start + (end - start) * (stream_id + 1) / s->nb_streams;
170  AVCodecContext *codec = s->streams[stream_id]->codec;
171  int is_audio = codec->codec_type == AVMEDIA_TYPE_AUDIO;
172  int intra_only = /*codec->intra_only || */ is_audio;
173  int pred_count;
174 
175  for (key_frame = 0; key_frame < 2; key_frame++) {
176  if (!intra_only || !keyframe_0_esc || key_frame != 0) {
177  FrameCode *ft = &nut->frame_code[start2];
178  ft->flags = FLAG_KEY * key_frame;
180  ft->stream_id = stream_id;
181  ft->size_mul = 1;
182  if (is_audio)
183  ft->header_idx = find_header_idx(s, codec, -1, key_frame);
184  start2++;
185  }
186  }
187 
188  key_frame = intra_only;
189  if (is_audio) {
190  int frame_bytes = codec->frame_size * (int64_t)codec->bit_rate /
191  (8 * codec->sample_rate);
192  int pts;
193  for (pts = 0; pts < 2; pts++)
194  for (pred = 0; pred < 2; pred++) {
195  FrameCode *ft = &nut->frame_code[start2];
196  ft->flags = FLAG_KEY * key_frame;
197  ft->stream_id = stream_id;
198  ft->size_mul = frame_bytes + 2;
199  ft->size_lsb = frame_bytes + pred;
200  ft->pts_delta = pts;
201  ft->header_idx = find_header_idx(s, codec, frame_bytes + pred, key_frame);
202  start2++;
203  }
204  } else {
205  FrameCode *ft = &nut->frame_code[start2];
206  ft->flags = FLAG_KEY | FLAG_SIZE_MSB;
207  ft->stream_id = stream_id;
208  ft->size_mul = 1;
209  ft->pts_delta = 1;
210  start2++;
211  }
212 
213  if (codec->has_b_frames) {
214  pred_count = 5;
215  pred_table[0] = -2;
216  pred_table[1] = -1;
217  pred_table[2] = 1;
218  pred_table[3] = 3;
219  pred_table[4] = 4;
220  } else if (codec->codec_id == AV_CODEC_ID_VORBIS) {
221  pred_count = 3;
222  pred_table[0] = 2;
223  pred_table[1] = 9;
224  pred_table[2] = 16;
225  } else {
226  pred_count = 1;
227  pred_table[0] = 1;
228  }
229 
230  for (pred = 0; pred < pred_count; pred++) {
231  int start3 = start2 + (end2 - start2) * pred / pred_count;
232  int end3 = start2 + (end2 - start2) * (pred + 1) / pred_count;
233 
234  for (index = start3; index < end3; index++) {
235  FrameCode *ft = &nut->frame_code[index];
236  ft->flags = FLAG_KEY * key_frame;
237  ft->flags |= FLAG_SIZE_MSB;
238  ft->stream_id = stream_id;
239 //FIXME use single byte size and pred from last
240  ft->size_mul = end3 - start3;
241  ft->size_lsb = index - start3;
242  ft->pts_delta = pred_table[pred];
243  if (is_audio)
244  ft->header_idx = find_header_idx(s, codec, -1, key_frame);
245  }
246  }
247  }
248  memmove(&nut->frame_code['N' + 1], &nut->frame_code['N'],
249  sizeof(FrameCode) * (255 - 'N'));
250  nut->frame_code[0].flags =
251  nut->frame_code[255].flags =
252  nut->frame_code['N'].flags = FLAG_INVALID;
253 }
254 
255 static void put_tt(NUTContext *nut, AVRational *time_base, AVIOContext *bc,
256  uint64_t val)
257 {
258  val *= nut->time_base_count;
259  val += time_base - nut->time_base;
260  ff_put_v(bc, val);
261 }
265 static void put_str(AVIOContext *bc, const char *string)
266 {
267  int len = strlen(string);
268 
269  ff_put_v(bc, len);
270  avio_write(bc, string, len);
271 }
272 
273 static void put_s(AVIOContext *bc, int64_t val)
274 {
275  ff_put_v(bc, 2 * FFABS(val) - (val > 0));
276 }
277 
278 #ifdef TRACE
279 static inline void ff_put_v_trace(AVIOContext *bc, uint64_t v, const char *file,
280  const char *func, int line)
281 {
282  av_log(NULL, AV_LOG_DEBUG, "ff_put_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
283 
284  ff_put_v(bc, v);
285 }
286 
287 static inline void put_s_trace(AVIOContext *bc, int64_t v, const char *file,
288  const char *func, int line)
289 {
290  av_log(NULL, AV_LOG_DEBUG, "put_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line);
291 
292  put_s(bc, v);
293 }
294 #define ff_put_v(bc, v) ff_put_v_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
295 #define put_s(bc, v) put_s_trace(bc, v, __FILE__, __PRETTY_FUNCTION__, __LINE__)
296 #endif
297 
298 //FIXME remove calculate_checksum
299 static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc,
300  int calculate_checksum, uint64_t startcode)
301 {
302  uint8_t *dyn_buf = NULL;
303  int dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
304  int forw_ptr = dyn_size + 4 * calculate_checksum;
305 
306  if (forw_ptr > 4096)
308  avio_wb64(bc, startcode);
309  ff_put_v(bc, forw_ptr);
310  if (forw_ptr > 4096)
311  avio_wl32(bc, ffio_get_checksum(bc));
312 
313  if (calculate_checksum)
315  avio_write(bc, dyn_buf, dyn_size);
316  if (calculate_checksum)
317  avio_wl32(bc, ffio_get_checksum(bc));
318 
319  av_free(dyn_buf);
320 }
321 
323 {
324  int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields,
325  tmp_head_idx;
326  int64_t tmp_match;
327 
328  ff_put_v(bc, NUT_VERSION);
329  ff_put_v(bc, nut->avf->nb_streams);
330  ff_put_v(bc, nut->max_distance);
331  ff_put_v(bc, nut->time_base_count);
332 
333  for (i = 0; i < nut->time_base_count; i++) {
334  ff_put_v(bc, nut->time_base[i].num);
335  ff_put_v(bc, nut->time_base[i].den);
336  }
337 
338  tmp_pts = 0;
339  tmp_mul = 1;
340  tmp_stream = 0;
341  tmp_match = 1 - (1LL << 62);
342  tmp_head_idx = 0;
343  for (i = 0; i < 256; ) {
344  tmp_fields = 0;
345  tmp_size = 0;
346 // tmp_res=0;
347  if (tmp_pts != nut->frame_code[i].pts_delta)
348  tmp_fields = 1;
349  if (tmp_mul != nut->frame_code[i].size_mul)
350  tmp_fields = 2;
351  if (tmp_stream != nut->frame_code[i].stream_id)
352  tmp_fields = 3;
353  if (tmp_size != nut->frame_code[i].size_lsb)
354  tmp_fields = 4;
355 // if(tmp_res != nut->frame_code[i].res ) tmp_fields=5;
356  if (tmp_head_idx != nut->frame_code[i].header_idx)
357  tmp_fields = 8;
358 
359  tmp_pts = nut->frame_code[i].pts_delta;
360  tmp_flags = nut->frame_code[i].flags;
361  tmp_stream = nut->frame_code[i].stream_id;
362  tmp_mul = nut->frame_code[i].size_mul;
363  tmp_size = nut->frame_code[i].size_lsb;
364 // tmp_res = nut->frame_code[i].res;
365  tmp_head_idx = nut->frame_code[i].header_idx;
366 
367  for (j = 0; i < 256; j++, i++) {
368  if (i == 'N') {
369  j--;
370  continue;
371  }
372  if (nut->frame_code[i].pts_delta != tmp_pts ||
373  nut->frame_code[i].flags != tmp_flags ||
374  nut->frame_code[i].stream_id != tmp_stream ||
375  nut->frame_code[i].size_mul != tmp_mul ||
376  nut->frame_code[i].size_lsb != tmp_size + j ||
377 // nut->frame_code[i].res != tmp_res ||
378  nut->frame_code[i].header_idx != tmp_head_idx)
379  break;
380  }
381  if (j != tmp_mul - tmp_size)
382  tmp_fields = 6;
383 
384  ff_put_v(bc, tmp_flags);
385  ff_put_v(bc, tmp_fields);
386  if (tmp_fields > 0)
387  put_s(bc, tmp_pts);
388  if (tmp_fields > 1)
389  ff_put_v(bc, tmp_mul);
390  if (tmp_fields > 2)
391  ff_put_v(bc, tmp_stream);
392  if (tmp_fields > 3)
393  ff_put_v(bc, tmp_size);
394  if (tmp_fields > 4)
395  ff_put_v(bc, 0 /*tmp_res*/);
396  if (tmp_fields > 5)
397  ff_put_v(bc, j);
398  if (tmp_fields > 6)
399  ff_put_v(bc, tmp_match);
400  if (tmp_fields > 7)
401  ff_put_v(bc, tmp_head_idx);
402  }
403  ff_put_v(bc, nut->header_count - 1);
404  for (i = 1; i < nut->header_count; i++) {
405  ff_put_v(bc, nut->header_len[i]);
406  avio_write(bc, nut->header[i], nut->header_len[i]);
407  }
408 }
409 
411  AVStream *st, int i)
412 {
413  NUTContext *nut = avctx->priv_data;
414  AVCodecContext *codec = st->codec;
415  unsigned codec_tag = av_codec_get_tag(ff_nut_codec_tags, codec->codec_id);
416 
417  ff_put_v(bc, i);
418  switch (codec->codec_type) {
419  case AVMEDIA_TYPE_VIDEO:
420  ff_put_v(bc, 0);
421  break;
422  case AVMEDIA_TYPE_AUDIO:
423  ff_put_v(bc, 1);
424  break;
426  ff_put_v(bc, 2);
427  break;
428  default:
429  ff_put_v(bc, 3);
430  break;
431  }
432  ff_put_v(bc, 4);
433 
434  if (!codec_tag || codec->codec_id == AV_CODEC_ID_RAWVIDEO)
435  codec_tag = codec->codec_tag;
436 
437  if (codec_tag) {
438  avio_wl32(bc, codec_tag);
439  } else {
440  av_log(avctx, AV_LOG_ERROR, "No codec tag defined for stream %d\n", i);
441  return AVERROR(EINVAL);
442  }
443 
444  ff_put_v(bc, nut->stream[i].time_base - nut->time_base);
445  ff_put_v(bc, nut->stream[i].msb_pts_shift);
446  ff_put_v(bc, nut->stream[i].max_pts_distance);
447  ff_put_v(bc, codec->has_b_frames);
448  avio_w8(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */
449 
450  ff_put_v(bc, codec->extradata_size);
451  avio_write(bc, codec->extradata, codec->extradata_size);
452 
453  switch (codec->codec_type) {
454  case AVMEDIA_TYPE_AUDIO:
455  ff_put_v(bc, codec->sample_rate);
456  ff_put_v(bc, 1);
457  ff_put_v(bc, codec->channels);
458  break;
459  case AVMEDIA_TYPE_VIDEO:
460  ff_put_v(bc, codec->width);
461  ff_put_v(bc, codec->height);
462 
463  if (st->sample_aspect_ratio.num <= 0 ||
464  st->sample_aspect_ratio.den <= 0) {
465  ff_put_v(bc, 0);
466  ff_put_v(bc, 0);
467  } else {
470  }
471  ff_put_v(bc, 0); /* csp type -- unknown */
472  break;
473  default:
474  break;
475  }
476  return 0;
477 }
478 
479 static int add_info(AVIOContext *bc, const char *type, const char *value)
480 {
481  put_str(bc, type);
482  put_s(bc, -1);
483  put_str(bc, value);
484  return 1;
485 }
486 
488 {
489  AVFormatContext *s = nut->avf;
491  AVIOContext *dyn_bc;
492  uint8_t *dyn_buf = NULL;
493  int count = 0, dyn_size;
494  int ret = avio_open_dyn_buf(&dyn_bc);
495  if (ret < 0)
496  return ret;
497 
498  while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX)))
499  count += add_info(dyn_bc, t->key, t->value);
500 
501  ff_put_v(bc, 0); //stream_if_plus1
502  ff_put_v(bc, 0); //chapter_id
503  ff_put_v(bc, 0); //timestamp_start
504  ff_put_v(bc, 0); //length
505 
506  ff_put_v(bc, count);
507 
508  dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
509  avio_write(bc, dyn_buf, dyn_size);
510  av_free(dyn_buf);
511  return 0;
512 }
513 
514 static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id){
515  AVFormatContext *s= nut->avf;
516  AVStream* st = s->streams[stream_id];
517  AVIOContext *dyn_bc;
518  uint8_t *dyn_buf=NULL;
519  int count=0, dyn_size, i;
520  int ret = avio_open_dyn_buf(&dyn_bc);
521  if(ret < 0)
522  return ret;
523 
524  for (i=0; ff_nut_dispositions[i].flag; ++i) {
525  if (st->disposition & ff_nut_dispositions[i].flag)
526  count += add_info(dyn_bc, "Disposition", ff_nut_dispositions[i].str);
527  }
528  dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
529 
530  if (count) {
531  ff_put_v(bc, stream_id + 1); //stream_id_plus1
532  ff_put_v(bc, 0); //chapter_id
533  ff_put_v(bc, 0); //timestamp_start
534  ff_put_v(bc, 0); //length
535 
536  ff_put_v(bc, count);
537 
538  avio_write(bc, dyn_buf, dyn_size);
539  }
540 
541  av_free(dyn_buf);
542  return count;
543 }
544 
545 static int write_chapter(NUTContext *nut, AVIOContext *bc, int id)
546 {
547  AVIOContext *dyn_bc;
548  uint8_t *dyn_buf = NULL;
550  AVChapter *ch = nut->avf->chapters[id];
551  int ret, dyn_size, count = 0;
552 
553  ret = avio_open_dyn_buf(&dyn_bc);
554  if (ret < 0)
555  return ret;
556 
557  ff_put_v(bc, 0); // stream_id_plus1
558  put_s(bc, id + 1); // chapter_id
559  put_tt(nut, nut->chapter[id].time_base, bc, ch->start); // chapter_start
560  ff_put_v(bc, ch->end - ch->start); // chapter_len
561 
562  while ((t = av_dict_get(ch->metadata, "", t, AV_DICT_IGNORE_SUFFIX)))
563  count += add_info(dyn_bc, t->key, t->value);
564 
565  ff_put_v(bc, count);
566 
567  dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf);
568  avio_write(bc, dyn_buf, dyn_size);
569  av_freep(&dyn_buf);
570  return 0;
571 }
572 
574 {
575  NUTContext *nut = avctx->priv_data;
576  AVIOContext *dyn_bc;
577  int i, ret;
578 
580 
581  ret = avio_open_dyn_buf(&dyn_bc);
582  if (ret < 0)
583  return ret;
584  write_mainheader(nut, dyn_bc);
585  put_packet(nut, bc, dyn_bc, 1, MAIN_STARTCODE);
586 
587  for (i = 0; i < nut->avf->nb_streams; i++) {
588  ret = avio_open_dyn_buf(&dyn_bc);
589  if (ret < 0)
590  return ret;
591  ret = write_streamheader(avctx, dyn_bc, nut->avf->streams[i], i);
592  if (ret < 0)
593  return ret;
594  put_packet(nut, bc, dyn_bc, 1, STREAM_STARTCODE);
595  }
596 
597  ret = avio_open_dyn_buf(&dyn_bc);
598  if (ret < 0)
599  return ret;
600  write_globalinfo(nut, dyn_bc);
601  put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE);
602 
603  for (i = 0; i < nut->avf->nb_streams; i++) {
604  ret = avio_open_dyn_buf(&dyn_bc);
605  if (ret < 0)
606  return ret;
607  ret = write_streaminfo(nut, dyn_bc, i);
608  if (ret < 0)
609  return ret;
610  if (ret > 0)
611  put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE);
612  else {
613  uint8_t *buf;
614  avio_close_dyn_buf(dyn_bc, &buf);
615  av_free(buf);
616  }
617  }
618 
619  for (i = 0; i < nut->avf->nb_chapters; i++) {
620  ret = avio_open_dyn_buf(&dyn_bc);
621  if (ret < 0)
622  return ret;
623  ret = write_chapter(nut, dyn_bc, i);
624  if (ret < 0) {
625  uint8_t *buf;
626  avio_close_dyn_buf(dyn_bc, &buf);
627  av_freep(&buf);
628  return ret;
629  }
630  put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE);
631  }
632 
633  nut->last_syncpoint_pos = INT_MIN;
634  nut->header_count++;
635  return 0;
636 }
637 
639 {
640  NUTContext *nut = s->priv_data;
641  AVIOContext *bc = s->pb;
642  int i, j, ret;
643 
644  nut->avf = s;
645 
646  nut->stream = av_mallocz(sizeof(StreamContext) * s->nb_streams);
647  if (s->nb_chapters)
648  nut->chapter = av_mallocz(sizeof(ChapterContext) * s->nb_chapters);
649  nut->time_base = av_mallocz(sizeof(AVRational) * (s->nb_streams +
650  s->nb_chapters));
651  if (!nut->stream || (s->nb_chapters && !nut->chapter) || !nut->time_base) {
652  av_freep(&nut->stream);
653  av_freep(&nut->chapter);
654  av_freep(&nut->time_base);
655  return AVERROR(ENOMEM);
656  }
657 
658  for (i = 0; i < s->nb_streams; i++) {
659  AVStream *st = s->streams[i];
660  int ssize;
661  AVRational time_base;
662  ff_parse_specific_params(st->codec, &time_base.den, &ssize,
663  &time_base.num);
664 
665  avpriv_set_pts_info(st, 64, time_base.num, time_base.den);
666 
667  for (j = 0; j < nut->time_base_count; j++)
668  if (!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))) {
669  break;
670  }
671  nut->time_base[j] = time_base;
672  nut->stream[i].time_base = &nut->time_base[j];
673  if (j == nut->time_base_count)
674  nut->time_base_count++;
675 
676  if (INT64_C(1000) * time_base.num >= time_base.den)
677  nut->stream[i].msb_pts_shift = 7;
678  else
679  nut->stream[i].msb_pts_shift = 14;
680  nut->stream[i].max_pts_distance =
681  FFMAX(time_base.den, time_base.num) / time_base.num;
682  }
683 
684  for (i = 0; i < s->nb_chapters; i++) {
685  AVChapter *ch = s->chapters[i];
686 
687  for (j = 0; j < nut->time_base_count; j++)
688  if (!memcmp(&ch->time_base, &nut->time_base[j], sizeof(AVRational)))
689  break;
690 
691  nut->time_base[j] = ch->time_base;
692  nut->chapter[i].time_base = &nut->time_base[j];
693  if (j == nut->time_base_count)
694  nut->time_base_count++;
695  }
696 
697  nut->max_distance = MAX_DISTANCE;
699  build_frame_code(s);
700  assert(nut->frame_code['N'].flags == FLAG_INVALID);
701 
702  avio_write(bc, ID_STRING, strlen(ID_STRING));
703  avio_w8(bc, 0);
704 
705  if ((ret = write_headers(s, bc)) < 0)
706  return ret;
707 
708  avio_flush(bc);
709 
710  //FIXME index
711 
712  return 0;
713 }
714 
716  AVPacket *pkt)
717 {
718  int flags = 0;
719 
720  if (pkt->flags & AV_PKT_FLAG_KEY)
721  flags |= FLAG_KEY;
722  if (pkt->stream_index != fc->stream_id)
723  flags |= FLAG_STREAM_ID;
724  if (pkt->size / fc->size_mul)
725  flags |= FLAG_SIZE_MSB;
726  if (pkt->pts - nus->last_pts != fc->pts_delta)
727  flags |= FLAG_CODED_PTS;
728  if (pkt->size > 2 * nut->max_distance)
729  flags |= FLAG_CHECKSUM;
730  if (FFABS(pkt->pts - nus->last_pts) > nus->max_pts_distance)
731  flags |= FLAG_CHECKSUM;
732  if (pkt->size < nut->header_len[fc->header_idx] ||
733  (pkt->size > 4096 && fc->header_idx) ||
734  memcmp(pkt->data, nut->header[fc->header_idx],
735  nut->header_len[fc->header_idx]))
736  flags |= FLAG_HEADER_IDX;
737 
738  return flags | (fc->flags & FLAG_CODED);
739 }
740 
742 {
743  int i;
744  int best_i = 0;
745  int best_len = 0;
746 
747  if (pkt->size > 4096)
748  return 0;
749 
750  for (i = 1; i < nut->header_count; i++)
751  if (pkt->size >= nut->header_len[i]
752  && nut->header_len[i] > best_len
753  && !memcmp(pkt->data, nut->header[i], nut->header_len[i])) {
754  best_i = i;
755  best_len = nut->header_len[i];
756  }
757  return best_i;
758 }
759 
761 {
762  NUTContext *nut = s->priv_data;
763  StreamContext *nus = &nut->stream[pkt->stream_index];
764  AVIOContext *bc = s->pb, *dyn_bc;
765  FrameCode *fc;
766  int64_t coded_pts;
767  int best_length, frame_code, flags, needed_flags, i, header_idx,
768  best_header_idx;
769  int key_frame = !!(pkt->flags & AV_PKT_FLAG_KEY);
770  int store_sp = 0;
771  int ret;
772 
773  if (pkt->pts < 0) {
774  av_log(s, AV_LOG_ERROR,
775  "Negative pts not supported stream %d, pts %"PRId64"\n",
776  pkt->stream_index, pkt->pts);
777  return AVERROR_INVALIDDATA;
778  }
779 
780  if (1LL << (20 + 3 * nut->header_count) <= avio_tell(bc))
781  write_headers(s, bc);
782 
783  if (key_frame && !(nus->last_flags & FLAG_KEY))
784  store_sp = 1;
785 
786  if (pkt->size + 30 /*FIXME check*/ + avio_tell(bc) >=
787  nut->last_syncpoint_pos + nut->max_distance)
788  store_sp = 1;
789 
790 //FIXME: Ensure store_sp is 1 in the first place.
791 
792  if (store_sp) {
793  Syncpoint *sp, dummy = { .pos = INT64_MAX };
794 
795  ff_nut_reset_ts(nut, *nus->time_base, pkt->dts);
796  for (i = 0; i < s->nb_streams; i++) {
797  AVStream *st = s->streams[i];
798  int64_t dts_tb = av_rescale_rnd(pkt->dts,
799  nus->time_base->num * (int64_t)nut->stream[i].time_base->den,
800  nus->time_base->den * (int64_t)nut->stream[i].time_base->num,
801  AV_ROUND_DOWN);
802  int index = av_index_search_timestamp(st, dts_tb,
804  if (index >= 0)
805  dummy.pos = FFMIN(dummy.pos, st->index_entries[index].pos);
806  }
807  if (dummy.pos == INT64_MAX)
808  dummy.pos = 0;
809  sp = av_tree_find(nut->syncpoints, &dummy, (void *)ff_nut_sp_pos_cmp,
810  NULL);
811 
812  nut->last_syncpoint_pos = avio_tell(bc);
813  ret = avio_open_dyn_buf(&dyn_bc);
814  if (ret < 0)
815  return ret;
816  put_tt(nut, nus->time_base, dyn_bc, pkt->dts);
817  ff_put_v(dyn_bc, sp ? (nut->last_syncpoint_pos - sp->pos) >> 4 : 0);
818  put_packet(nut, bc, dyn_bc, 1, SYNCPOINT_STARTCODE);
819 
820  if ((ret = ff_nut_add_sp(nut, nut->last_syncpoint_pos, 0 /*unused*/, pkt->dts)) < 0)
821  return ret;
822  }
823  assert(nus->last_pts != AV_NOPTS_VALUE);
824 
825  coded_pts = pkt->pts & ((1 << nus->msb_pts_shift) - 1);
826  if (ff_lsb2full(nus, coded_pts) != pkt->pts)
827  coded_pts = pkt->pts + (1 << nus->msb_pts_shift);
828 
829  best_header_idx = find_best_header_idx(nut, pkt);
830 
831  best_length = INT_MAX;
832  frame_code = -1;
833  for (i = 0; i < 256; i++) {
834  int length = 0;
835  FrameCode *fc = &nut->frame_code[i];
836  int flags = fc->flags;
837 
838  if (flags & FLAG_INVALID)
839  continue;
840  needed_flags = get_needed_flags(nut, nus, fc, pkt);
841 
842  if (flags & FLAG_CODED) {
843  length++;
844  flags = needed_flags;
845  }
846 
847  if ((flags & needed_flags) != needed_flags)
848  continue;
849 
850  if ((flags ^ needed_flags) & FLAG_KEY)
851  continue;
852 
853  if (flags & FLAG_STREAM_ID)
854  length += ff_get_v_length(pkt->stream_index);
855 
856  if (pkt->size % fc->size_mul != fc->size_lsb)
857  continue;
858  if (flags & FLAG_SIZE_MSB)
859  length += ff_get_v_length(pkt->size / fc->size_mul);
860 
861  if (flags & FLAG_CHECKSUM)
862  length += 4;
863 
864  if (flags & FLAG_CODED_PTS)
865  length += ff_get_v_length(coded_pts);
866 
867  if ((flags & FLAG_CODED)
868  && nut->header_len[best_header_idx] >
869  nut->header_len[fc->header_idx] + 1) {
870  flags |= FLAG_HEADER_IDX;
871  }
872 
873  if (flags & FLAG_HEADER_IDX) {
874  length += 1 - nut->header_len[best_header_idx];
875  } else {
876  length -= nut->header_len[fc->header_idx];
877  }
878 
879  length *= 4;
880  length += !(flags & FLAG_CODED_PTS);
881  length += !(flags & FLAG_CHECKSUM);
882 
883  if (length < best_length) {
884  best_length = length;
885  frame_code = i;
886  }
887  }
888  assert(frame_code != -1);
889  fc = &nut->frame_code[frame_code];
890  flags = fc->flags;
891  needed_flags = get_needed_flags(nut, nus, fc, pkt);
892  header_idx = fc->header_idx;
893 
895  avio_w8(bc, frame_code);
896  if (flags & FLAG_CODED) {
897  ff_put_v(bc, (flags ^ needed_flags) & ~(FLAG_CODED));
898  flags = needed_flags;
899  }
900  if (flags & FLAG_STREAM_ID)
901  ff_put_v(bc, pkt->stream_index);
902  if (flags & FLAG_CODED_PTS)
903  ff_put_v(bc, coded_pts);
904  if (flags & FLAG_SIZE_MSB)
905  ff_put_v(bc, pkt->size / fc->size_mul);
906  if (flags & FLAG_HEADER_IDX)
907  ff_put_v(bc, header_idx = best_header_idx);
908 
909  if (flags & FLAG_CHECKSUM)
910  avio_wl32(bc, ffio_get_checksum(bc));
911  else
912  ffio_get_checksum(bc);
913 
914  avio_write(bc, pkt->data + nut->header_len[header_idx],
915  pkt->size - nut->header_len[header_idx]);
916  nus->last_flags = flags;
917  nus->last_pts = pkt->pts;
918 
919  //FIXME just store one per syncpoint
920  if (flags & FLAG_KEY)
922  s->streams[pkt->stream_index],
923  nut->last_syncpoint_pos,
924  pkt->pts,
925  0,
926  0,
928 
929  return 0;
930 }
931 
933 {
934  NUTContext *nut = s->priv_data;
935  AVIOContext *bc = s->pb;
936 
937  while (nut->header_count < 3)
938  write_headers(s, bc);
939 
940  ff_nut_free_sp(nut);
941  av_freep(&nut->stream);
942  av_freep(&nut->chapter);
943  av_freep(&nut->time_base);
944 
945  return 0;
946 }
947 
949  .name = "nut",
950  .long_name = NULL_IF_CONFIG_SMALL("NUT"),
951  .mime_type = "video/x-nut",
952  .extensions = "nut",
953  .priv_data_size = sizeof(NUTContext),
954  .audio_codec = CONFIG_LIBVORBIS ? AV_CODEC_ID_VORBIS :
956  .video_codec = AV_CODEC_ID_MPEG4,
961  .codec_tag = ff_nut_codec_tags,
962 };
unsigned int nb_chapters
Number of chapters in AVChapter array.
Definition: avformat.h:1053
#define AVSEEK_FLAG_BACKWARD
Definition: avformat.h:1518
void avio_wb64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:330
uint8_t header_len[128]
Definition: nut.h:92
Bytestream IO Context.
Definition: avio.h:68
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:54
#define MAIN_STARTCODE
Definition: nut.h:29
void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv, const AVMetadataConv *s_conv)
Definition: metadata.c:59
int size
int64_t last_syncpoint_pos
Definition: nut.h:99
Definition: nut.h:62
int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)
Return the written size and a pointer to the buffer.
Definition: aviobuf.c:960
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.
Definition: utils.c:1312
enum AVCodecID id
Definition: mxfenc.c:84
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.
Definition: mathematics.c:58
void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale)
Definition: riffenc.c:212
void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, unsigned int pts_num, unsigned int pts_den)
Set the time base and wrapping info for a given stream.
Definition: utils.c:3208
int64_t pos
Definition: avformat.h:644
static int write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: assenc.c:58
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown)
Definition: avformat.h:747
int num
numerator
Definition: rational.h:44
int size
Definition: avcodec.h:974
AVIndexEntry * index_entries
Only used if the format does not support seeking natively.
Definition: avformat.h:827
Definition: nut.h:55
Definition: nut.h:87
uint8_t stream_id
Definition: nut.h:64
AVDictionary * metadata
Definition: avformat.h:858
AVDictionaryEntry * av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:39
int avio_open_dyn_buf(AVIOContext **s)
Open a write only memory stream.
Definition: aviobuf.c:948
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 ...
Definition: mem.c:198
const uint8_t * header[128]
Definition: nut.h:93
Format I/O context.
Definition: avformat.h:871
Public dictionary API.
void * av_tree_find(const AVTreeNode *t, void *key, int(*cmp)(void *key, const void *b), void *next[2])
Definition: tree.c:41
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:260
uint8_t
AVRational * time_base
Definition: nut.h:101
uint16_t flags
Definition: nut.h:63
A tree container.
#define AV_WB32(p, d)
Definition: intreadwrite.h:239
#define ID_STRING
Definition: ffmeta.h:25
static void build_elision_headers(AVFormatContext *s)
Definition: nutenc.c:121
static void build_frame_code(AVFormatContext *s)
Definition: nutenc.c:143
if set, coded_pts is in the frame header
Definition: nut.h:44
const uint16_t avpriv_mpa_freq_tab[3]
Definition: mpegaudiodata.c:40
#define STREAM_STARTCODE
Definition: nut.h:30
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1162
static void put_tt(NUTContext *nut, AVRational *time_base, AVIOContext *bc, uint64_t val)
Definition: nutenc.c:255
uint8_t pi<< 24) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8, uint8_t,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16, int16_t,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, int16_t,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32, int32_t,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC_GROUP(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, int32_t,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, float, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, float, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, float, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, double, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, double, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC_GROUP(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, double, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31))))#defineSET_CONV_FUNC_GROUP(ofmt, ifmt) staticvoidset_generic_function(AudioConvert *ac){}voidff_audio_convert_free(AudioConvert **ac){if(!*ac) return;ff_dither_free(&(*ac) ->dc);av_freep(ac);}AudioConvert *ff_audio_convert_alloc(AVAudioResampleContext *avr, enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, intsample_rate, intapply_map){AudioConvert *ac;intin_planar, out_planar;ac=av_mallocz(sizeof(*ac));if(!ac) returnNULL;ac->avr=avr;ac->out_fmt=out_fmt;ac->in_fmt=in_fmt;ac->channels=channels;ac->apply_map=apply_map;if(avr->dither_method!=AV_RESAMPLE_DITHER_NONE &&av_get_packed_sample_fmt(out_fmt)==AV_SAMPLE_FMT_S16 &&av_get_bytes_per_sample(in_fmt)>2){ac->dc=ff_dither_alloc(avr, out_fmt, in_fmt, channels, sample_rate, apply_map);if(!ac->dc){av_free(ac);returnNULL;}returnac;}in_planar=av_sample_fmt_is_planar(in_fmt);out_planar=av_sample_fmt_is_planar(out_fmt);if(in_planar==out_planar){ac->func_type=CONV_FUNC_TYPE_FLAT;ac->planes=in_planar?ac->channels:1;}elseif(in_planar) ac->func_type=CONV_FUNC_TYPE_INTERLEAVE;elseac->func_type=CONV_FUNC_TYPE_DEINTERLEAVE;set_generic_function(ac);if(ARCH_ARM) ff_audio_convert_init_arm(ac);if(ARCH_X86) ff_audio_convert_init_x86(ac);returnac;}intff_audio_convert(AudioConvert *ac, AudioData *out, AudioData *in){intuse_generic=1;intlen=in->nb_samples;intp;if(ac->dc){av_dlog(ac->avr,"%dsamples-audio_convert:%sto%s(dithered)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt));returnff_convert_dither(ac-> out
AVStream ** streams
A list of all streams in the file.
Definition: avformat.h:935
const AVMetadataConv ff_nut_metadata_conv[]
Definition: nut.c:233
static int nut_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: nutenc.c:760
uint8_t * data
Definition: avcodec.h:973
int last_flags
Definition: nut.h:73
static int flags
Definition: log.c:44
#define MAX_DISTANCE
Definition: nut.h:37
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:219
static float t
Definition: output.c:52
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:165
static int write_trailer(AVFormatContext *s)
Definition: assenc.c:64
int ff_nut_sp_pos_cmp(const Syncpoint *a, const Syncpoint *b)
Definition: nut.c:178
AVFormatContext * avf
Definition: nut.h:88
int64_t last_pts
Definition: nut.h:75
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1023
static const uint8_t frame_size[4]
Definition: g723_1_data.h:47
AVOutputFormat ff_nut_muxer
Definition: nutenc.c:948
#define AVINDEX_KEYFRAME
Definition: avformat.h:646
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
AVDictionary * metadata
Metadata that applies to the whole file.
Definition: avformat.h:1064
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:1332
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:186
void ff_nut_free_sp(NUTContext *nut)
Definition: nut.c:217
int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags)
Get the index for a specific timestamp.
Definition: utils.c:1353
#define AVERROR(e)
Definition: error.h:43
static int nut_write_header(AVFormatContext *s)
Definition: nutenc.c:638
uint64_t pos
Definition: nut.h:56
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:142
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:144
preferred ID for decoding MPEG audio layer 1, 2 or 3
Definition: avcodec.h:369
AVChapter ** chapters
Definition: avformat.h:1054
Definition: graph2dot.c:49
static int write_chapter(NUTContext *nut, AVIOContext *bc, int id)
Definition: nutenc.c:545
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
int header_count
Definition: nut.h:100
AVRational * time_base
Definition: nut.h:77
#define FFMAX(a, b)
Definition: common.h:55
if set, frame is keyframe
Definition: nut.h:42
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:979
AVCodecContext * codec
Codec context associated with this stream.
Definition: avformat.h:702
static void write_mainheader(NUTContext *nut, AVIOContext *bc)
Definition: nutenc.c:322
unsigned int nb_streams
Number of elements in AVFormatContext.streams.
Definition: avformat.h:923
#define CONFIG_LIBMP3LAME
Definition: config.h:287
void ffio_init_checksum(AVIOContext *s, unsigned long(*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), unsigned long checksum)
Definition: aviobuf.c:425
static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint8_t out[64])
Definition: nutenc.c:34
int void avio_flush(AVIOContext *s)
Definition: aviobuf.c:180
void ff_nut_reset_ts(NUTContext *nut, AVRational time_base, int64_t val)
Definition: nut.c:160
#define FFMIN(a, b)
Definition: common.h:57
uint8_t header_idx
Definition: nut.h:69
int width
picture width / height.
Definition: avcodec.h:1217
uint16_t size_lsb
Definition: nut.h:66
#define AVFMT_GLOBALHEADER
Format wants global header.
Definition: avformat.h:406
unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, unsigned int len)
Definition: aviobuf.c:411
int16_t pts_delta
Definition: nut.h:67
int64_t ff_lsb2full(StreamContext *stream, int64_t lsb)
Definition: nut.c:171
const char * name
Definition: avformat.h:437
internal header for RIFF based (de)muxers do NOT include this in end user applications ...
#define AV_WB24(p, d)
Definition: intreadwrite.h:412
if set, frame_code is invalid
Definition: nut.h:52
#define FFABS(a)
Definition: common.h:52
struct AVTreeNode * syncpoints
Definition: nut.h:102
if set, data_size_msb is at frame header, otherwise data_size_msb is 0
Definition: nut.h:46
ChapterContext * chapter
Definition: nut.h:96
if set, the frame header contains a checksum
Definition: nut.h:47
uint16_t size_mul
Definition: nut.h:65
#define NUT_VERSION
Definition: nut.h:39
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:110
static int write_globalinfo(NUTContext *nut, AVIOContext *bc)
Definition: nutenc.c:487
static const float pred[4]
Definition: siprdata.h:259
Stream structure.
Definition: avformat.h:683
int msb_pts_shift
Definition: nut.h:78
int64_t end
chapter start/end time in time_base units
Definition: avformat.h:857
NULL
Definition: eval.c:55
enum AVMediaType codec_type
Definition: avcodec.h:1062
enum AVCodecID codec_id
Definition: avcodec.h:1065
int sample_rate
samples per second
Definition: avcodec.h:1779
AVIOContext * pb
I/O context.
Definition: avformat.h:913
int max_pts_distance
Definition: nut.h:79
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:144
main external API structure.
Definition: avcodec.h:1054
static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id)
Definition: nutenc.c:514
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1080
if set, coded_flags are stored in the frame header
Definition: nut.h:51
int extradata_size
Definition: avcodec.h:1163
int index
Definition: gxfenc.c:72
rational number numerator/denominator
Definition: rational.h:43
static int nut_write_trailer(AVFormatContext *s)
Definition: nutenc.c:932
AVRational * time_base
Definition: nut.h:84
unsigned long ffio_get_checksum(AVIOContext *s)
Definition: aviobuf.c:417
StreamContext * stream
Definition: nut.h:95
static void put_s(AVIOContext *bc, int64_t val)
Definition: nutenc.c:273
static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, AVStream *st, int i)
Definition: nutenc.c:410
Round toward -infinity.
Definition: mathematics.h:52
static int find_header_idx(AVFormatContext *s, AVCodecContext *c, int size, int frame_type)
Definition: nutenc.c:104
#define INFO_STARTCODE
Definition: nut.h:33
int ff_get_v_length(uint64_t val)
Get the length in bytes which is needed to store val as v.
Definition: aviobuf.c:304
static int write_headers(AVFormatContext *avctx, AVIOContext *bc)
Definition: nutenc.c:573
int64_t start
Definition: avformat.h:857
const Dispositions ff_nut_dispositions[]
Definition: nut.c:223
static int find_best_header_idx(NUTContext *nut, AVPacket *pkt)
Definition: nutenc.c:741
FrameCode frame_code[256]
Definition: nut.h:91
#define CONFIG_LIBVORBIS
Definition: config.h:300
int disposition
AV_DISPOSITION_* bit field.
Definition: avformat.h:738
int ff_nut_add_sp(NUTContext *nut, int64_t pos, int64_t back_ptr, int64_t ts)
Definition: nut.c:188
AVRational time_base
time base in which the start/end timestamps are specified
Definition: avformat.h:856
char * key
Definition: dict.h:75
int den
denominator
Definition: rational.h:45
#define SYNCPOINT_STARTCODE
Definition: nut.h:31
int flag
Definition: nut.h:114
static void put_str(AVIOContext *bc, const char *string)
Store a string as vb.
Definition: nutenc.c:265
#define AVFMT_VARIABLE_FPS
Format allows variable fps.
Definition: avformat.h:410
char * value
Definition: dict.h:76
static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc, int calculate_checksum, uint64_t startcode)
Definition: nutenc.c:299
void ff_put_v(AVIOContext *bc, uint64_t val)
Put val using a variable number of bytes.
Definition: aviobuf.c:314
If set, header_idx is coded in the frame header.
Definition: nut.h:49
int len
int channels
number of audio channels
Definition: avcodec.h:1780
void * priv_data
Format private data.
Definition: avformat.h:899
static int get_needed_flags(NUTContext *nut, StreamContext *nus, FrameCode *fc, AVPacket *pkt)
Definition: nutenc.c:715
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:380
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:972
if set, stream_id is coded in the frame header
Definition: nut.h:45
static int add_info(AVIOContext *bc, const char *type, const char *value)
Definition: nutenc.c:479
#define AV_DICT_IGNORE_SUFFIX
Definition: dict.h:62
const uint16_t avpriv_mpa_bitrate_tab[2][3][15]
Definition: mpegaudiodata.c:30
int stream_index
Definition: avcodec.h:975
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[]
Definition: nut.c:155
This structure stores compressed data.
Definition: avcodec.h:950
unsigned int time_base_count
Definition: nut.h:98
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:966
for(j=16;j >0;--j)
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:228
unsigned int max_distance
Definition: nut.h:97