FFmpeg
gxfenc.c
Go to the documentation of this file.
1 /*
2  * GXF muxer.
3  * Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21 
22 #include "libavutil/avassert.h"
23 #include "libavutil/intfloat.h"
24 #include "libavutil/opt.h"
25 #include "libavutil/mathematics.h"
26 #include "libavutil/timecode.h"
27 #include "avformat.h"
28 #include "internal.h"
29 #include "gxf.h"
30 #include "audiointerleave.h"
31 
32 #define GXF_AUDIO_PACKET_SIZE 65536
33 
34 #define GXF_TIMECODE(c, d, h, m, s, f) \
35  ((c) << 30 | (d) << 29 | (h) << 24 | (m) << 16 | (s) << 8 | (f))
36 
37 typedef struct GXFTimecode{
38  int hh;
39  int mm;
40  int ss;
41  int ff;
42  int color;
43  int drop;
44 } GXFTimecode;
45 
46 typedef struct GXFStreamContext {
48  uint32_t track_type;
49  uint32_t sample_size;
50  uint32_t sample_rate;
51  uint16_t media_type;
52  uint16_t media_info;
55  int fields;
56  int iframes;
57  int pframes;
58  int bframes;
59  int p_per_gop;
60  int b_per_i_or_p; ///< number of B-frames per I-frame or P-frame
62  unsigned order; ///< interleaving order
64 
65 typedef struct GXFContext {
67  uint32_t nb_fields;
68  uint16_t audio_tracks;
69  uint16_t mpeg_tracks;
70  int64_t creation_time;
71  uint32_t umf_start_offset;
72  uint32_t umf_track_offset;
73  uint32_t umf_media_offset;
74  uint32_t umf_length;
75  uint16_t umf_track_size;
76  uint16_t umf_media_size;
78  int flags;
80  unsigned *flt_entries; ///< offsets of packets /1024, starts after 2nd video field
81  unsigned flt_entries_nb;
82  uint64_t *map_offsets; ///< offset of map packets
83  unsigned map_offsets_nb;
84  unsigned packet_count;
86 } GXFContext;
87 
88 static const struct {
89  int height, index;
90 } gxf_lines_tab[] = {
91  { 480, 1 }, /* NTSC */
92  { 512, 1 }, /* NTSC + VBI */
93  { 576, 2 }, /* PAL */
94  { 608, 2 }, /* PAL + VBI */
95  { 1080, 4 },
96  { 720, 6 },
97 };
98 
99 static const AVCodecTag gxf_media_types[] = {
100  { AV_CODEC_ID_MJPEG , 3 }, /* NTSC */
101  { AV_CODEC_ID_MJPEG , 4 }, /* PAL */
102  { AV_CODEC_ID_PCM_S24LE , 9 },
103  { AV_CODEC_ID_PCM_S16LE , 10 },
104  { AV_CODEC_ID_MPEG2VIDEO, 11 }, /* NTSC */
105  { AV_CODEC_ID_MPEG2VIDEO, 12 }, /* PAL */
106  { AV_CODEC_ID_DVVIDEO , 13 }, /* NTSC */
107  { AV_CODEC_ID_DVVIDEO , 14 }, /* PAL */
108  { AV_CODEC_ID_DVVIDEO , 15 }, /* 50M NTSC */
109  { AV_CODEC_ID_DVVIDEO , 16 }, /* 50M PAL */
110  { AV_CODEC_ID_AC3 , 17 },
111  //{ AV_CODEC_ID_NONE, , 18 }, /* Non compressed 24 bit audio */
112  { AV_CODEC_ID_MPEG2VIDEO, 20 }, /* MPEG HD */
113  { AV_CODEC_ID_MPEG1VIDEO, 22 }, /* NTSC */
114  { AV_CODEC_ID_MPEG1VIDEO, 23 }, /* PAL */
115  { AV_CODEC_ID_NONE, 0 },
116 };
117 
118 #define SERVER_PATH "EXT:/PDR/default/"
119 #define ES_NAME_PATTERN "EXT:/PDR/default/ES."
120 
122 {
123  GXFStreamContext *sc = st->priv_data;
124  int i;
125 
126  for (i = 0; i < 6; ++i) {
127  if (st->codecpar->height == gxf_lines_tab[i].height) {
128  sc->lines_index = gxf_lines_tab[i].index;
129  return 0;
130  }
131  }
132  return -1;
133 }
134 
135 static void gxf_write_padding(AVIOContext *pb, int64_t to_pad)
136 {
137  for (; to_pad > 0; to_pad--) {
138  avio_w8(pb, 0);
139  }
140 }
141 
142 static int64_t updatePacketSize(AVIOContext *pb, int64_t pos)
143 {
144  int64_t curpos;
145  int size;
146 
147  size = avio_tell(pb) - pos;
148  if (size % 4) {
149  gxf_write_padding(pb, 4 - size % 4);
150  size = avio_tell(pb) - pos;
151  }
152  curpos = avio_tell(pb);
153  avio_seek(pb, pos + 6, SEEK_SET);
154  avio_wb32(pb, size);
155  avio_seek(pb, curpos, SEEK_SET);
156  return curpos - pos;
157 }
158 
159 static int64_t updateSize(AVIOContext *pb, int64_t pos)
160 {
161  int64_t curpos;
162 
163  curpos = avio_tell(pb);
164  avio_seek(pb, pos, SEEK_SET);
165  avio_wb16(pb, curpos - pos - 2);
166  avio_seek(pb, curpos, SEEK_SET);
167  return curpos - pos;
168 }
169 
171 {
172  avio_wb32(pb, 0); /* packet leader for synchro */
173  avio_w8(pb, 1);
174  avio_w8(pb, type); /* map packet */
175  avio_wb32(pb, 0); /* size */
176  avio_wb32(pb, 0); /* reserved */
177  avio_w8(pb, 0xE1); /* trailer 1 */
178  avio_w8(pb, 0xE2); /* trailer 2 */
179 }
180 
182 {
183  GXFStreamContext *sc = st->priv_data;
184  char buffer[1024];
185  int size, starting_line;
186 
187  if (sc->iframes) {
188  sc->p_per_gop = sc->pframes / sc->iframes;
189  if (sc->pframes % sc->iframes)
190  sc->p_per_gop++;
191  if (sc->pframes) {
192  sc->b_per_i_or_p = sc->bframes / sc->pframes;
193  if (sc->bframes % sc->pframes)
194  sc->b_per_i_or_p++;
195  }
196  if (sc->p_per_gop > 9)
197  sc->p_per_gop = 9; /* ensure value won't take more than one char */
198  if (sc->b_per_i_or_p > 9)
199  sc->b_per_i_or_p = 9; /* ensure value won't take more than one char */
200  }
201  if (st->codecpar->height == 512 || st->codecpar->height == 608)
202  starting_line = 7; // VBI
203  else if (st->codecpar->height == 480)
204  starting_line = 20;
205  else
206  starting_line = 23; // default PAL
207 
208  size = snprintf(buffer, sizeof(buffer), "Ver 1\nBr %.6f\nIpg 1\nPpi %d\nBpiop %d\n"
209  "Pix 0\nCf %d\nCg %d\nSl %d\nnl16 %d\nVi 1\nf1 1\n",
210  (float)st->codecpar->bit_rate, sc->p_per_gop, sc->b_per_i_or_p,
211  st->codecpar->format == AV_PIX_FMT_YUV422P ? 2 : 1, sc->first_gop_closed == 1,
212  starting_line, (st->codecpar->height + 15) / 16);
213  av_assert0(size < sizeof(buffer));
214  avio_w8(pb, TRACK_MPG_AUX);
215  avio_w8(pb, size + 1);
216  avio_write(pb, (uint8_t *)buffer, size + 1);
217  return size + 3;
218 }
219 
221 {
222  int64_t track_aux_data = 0;
223 
224  avio_w8(pb, TRACK_AUX);
225  avio_w8(pb, 8);
226  if (st->codecpar->format == AV_PIX_FMT_YUV420P)
227  track_aux_data |= 0x01; /* marks stream as DVCAM instead of DVPRO */
228  track_aux_data |= 0x40000000; /* aux data is valid */
229  avio_wl64(pb, track_aux_data);
230  return 8;
231 }
232 
234 {
235  uint32_t timecode = GXF_TIMECODE(gxf->tc.color, gxf->tc.drop,
236  gxf->tc.hh, gxf->tc.mm,
237  gxf->tc.ss, gxf->tc.ff);
238 
239  avio_w8(pb, TRACK_AUX);
240  avio_w8(pb, 8);
241  avio_wl32(pb, timecode);
242  /* reserved */
243  avio_wl32(pb, 0);
244  return 8;
245 }
246 
248 {
249  GXFContext *gxf = s->priv_data;
250  AVIOContext *pb = s->pb;
251  int64_t pos;
252 
253  /* track description section */
254  avio_w8(pb, sc->media_type + 0x80);
255  avio_w8(pb, index + 0xC0);
256 
257  pos = avio_tell(pb);
258  avio_wb16(pb, 0); /* size */
259 
260  /* media file name */
261  avio_w8(pb, TRACK_NAME);
262  avio_w8(pb, strlen(ES_NAME_PATTERN) + 3);
263  avio_write(pb, ES_NAME_PATTERN, sizeof(ES_NAME_PATTERN) - 1);
264  avio_wb16(pb, sc->media_info);
265  avio_w8(pb, 0);
266 
267  switch (sc->track_type) {
268  case 3: /* timecode */
270  break;
271  case 4: /* MPEG2 */
272  case 9: /* MPEG1 */
273  gxf_write_mpeg_auxiliary(pb, s->streams[index]);
274  break;
275  case 5: /* DV25 */
276  case 6: /* DV50 */
277  gxf_write_dv_auxiliary(pb, s->streams[index]);
278  break;
279  default:
280  avio_w8(pb, TRACK_AUX);
281  avio_w8(pb, 8);
282  avio_wl64(pb, 0);
283  }
284 
285  /* file system version */
286  avio_w8(pb, TRACK_VER);
287  avio_w8(pb, 4);
288  avio_wb32(pb, 0);
289 
290  /* frame rate */
291  avio_w8(pb, TRACK_FPS);
292  avio_w8(pb, 4);
293  avio_wb32(pb, sc->frame_rate_index);
294 
295  /* lines per frame */
296  avio_w8(pb, TRACK_LINES);
297  avio_w8(pb, 4);
298  avio_wb32(pb, sc->lines_index);
299 
300  /* fields per frame */
301  avio_w8(pb, TRACK_FPF);
302  avio_w8(pb, 4);
303  avio_wb32(pb, sc->fields);
304 
305  return updateSize(pb, pos);
306 }
307 
309 {
310  GXFContext *gxf = s->priv_data;
311  AVIOContext *pb = s->pb;
312  int64_t pos;
313  int len;
314  const char *filename = strrchr(s->url, '/');
315 
316  pos = avio_tell(pb);
317  avio_wb16(pb, 0); /* size */
318 
319  /* name */
320  if (filename)
321  filename++;
322  else
323  filename = s->url;
324  len = strlen(filename);
325 
326  avio_w8(pb, MAT_NAME);
327  avio_w8(pb, strlen(SERVER_PATH) + len + 1);
328  avio_write(pb, SERVER_PATH, sizeof(SERVER_PATH) - 1);
329  avio_write(pb, filename, len);
330  avio_w8(pb, 0);
331 
332  /* first field */
334  avio_w8(pb, 4);
335  avio_wb32(pb, 0);
336 
337  /* last field */
338  avio_w8(pb, MAT_LAST_FIELD);
339  avio_w8(pb, 4);
340  avio_wb32(pb, gxf->nb_fields);
341 
342  /* reserved */
343  avio_w8(pb, MAT_MARK_IN);
344  avio_w8(pb, 4);
345  avio_wb32(pb, 0);
346 
347  avio_w8(pb, MAT_MARK_OUT);
348  avio_w8(pb, 4);
349  avio_wb32(pb, gxf->nb_fields);
350 
351  /* estimated size */
352  avio_w8(pb, MAT_SIZE);
353  avio_w8(pb, 4);
354  avio_wb32(pb, avio_size(pb) / 1024);
355 
356  return updateSize(pb, pos);
357 }
358 
360 {
361  GXFContext *gxf = s->priv_data;
362  AVIOContext *pb = s->pb;
363  int64_t pos;
364  int i;
365 
366  pos = avio_tell(pb);
367  avio_wb16(pb, 0); /* size */
368  for (i = 0; i < s->nb_streams; ++i)
369  gxf_write_track_description(s, s->streams[i]->priv_data, i);
370 
371  gxf_write_track_description(s, &gxf->timecode_track, s->nb_streams);
372 
373  return updateSize(pb, pos);
374 }
375 
376 static int gxf_write_map_packet(AVFormatContext *s, int rewrite)
377 {
378  GXFContext *gxf = s->priv_data;
379  AVIOContext *pb = s->pb;
380  int64_t pos = avio_tell(pb);
381 
382  if (!rewrite) {
383  if (!(gxf->map_offsets_nb % 30)) {
384  int err;
385  if ((err = av_reallocp_array(&gxf->map_offsets,
386  gxf->map_offsets_nb + 30,
387  sizeof(*gxf->map_offsets))) < 0) {
388  gxf->map_offsets_nb = 0;
389  av_log(s, AV_LOG_ERROR, "could not realloc map offsets\n");
390  return err;
391  }
392  }
393  gxf->map_offsets[gxf->map_offsets_nb++] = pos; // do not increment here
394  }
395 
397 
398  /* preamble */
399  avio_w8(pb, 0xE0); /* version */
400  avio_w8(pb, 0xFF); /* reserved */
401 
404 
405  return updatePacketSize(pb, pos);
406 }
407 
409 {
410  GXFContext *gxf = s->priv_data;
411  AVIOContext *pb = s->pb;
412  int64_t pos = avio_tell(pb);
413  int fields_per_flt = (gxf->nb_fields+1) / 1000 + 1;
414  int flt_entries = gxf->nb_fields / fields_per_flt;
415  int i = 0;
416 
418 
419  avio_wl32(pb, fields_per_flt); /* number of fields */
420  avio_wl32(pb, flt_entries); /* number of active flt entries */
421 
422  if (gxf->flt_entries) {
423  for (i = 0; i < flt_entries; i++)
424  avio_wl32(pb, gxf->flt_entries[(i*fields_per_flt)>>1]);
425  }
426 
427  for (; i < 1000; i++)
428  avio_wl32(pb, 0);
429 
430  return updatePacketSize(pb, pos);
431 }
432 
434 {
435  GXFContext *gxf = s->priv_data;
436  AVIOContext *pb = s->pb;
437  int timecode_base = gxf->time_base.den == 60000 ? 60 : 50;
438  int64_t timestamp = 0;
439  uint64_t nb_fields;
440  uint32_t timecode_in; // timecode at mark in
441  uint32_t timecode_out; // timecode at mark out
442 
443  ff_parse_creation_time_metadata(s, &timestamp, 1);
444 
445  timecode_in = GXF_TIMECODE(gxf->tc.color, gxf->tc.drop,
446  gxf->tc.hh, gxf->tc.mm,
447  gxf->tc.ss, gxf->tc.ff);
448 
449  nb_fields = gxf->nb_fields +
450  gxf->tc.hh * (timecode_base * 3600) +
451  gxf->tc.mm * (timecode_base * 60) +
452  gxf->tc.ss * timecode_base +
453  gxf->tc.ff;
454 
455  timecode_out = GXF_TIMECODE(gxf->tc.color, gxf->tc.drop,
456  nb_fields / (timecode_base * 3600) % 24,
457  nb_fields / (timecode_base * 60) % 60,
458  nb_fields / timecode_base % 60,
459  nb_fields % timecode_base);
460 
461  avio_wl32(pb, gxf->flags);
462  avio_wl32(pb, gxf->nb_fields); /* length of the longest track */
463  avio_wl32(pb, gxf->nb_fields); /* length of the shortest track */
464  avio_wl32(pb, 0); /* mark in */
465  avio_wl32(pb, gxf->nb_fields); /* mark out */
466  avio_wl32(pb, timecode_in); /* timecode mark in */
467  avio_wl32(pb, timecode_out); /* timecode mark out */
468  avio_wl64(pb, timestamp); /* modification time */
469  avio_wl64(pb, timestamp); /* creation time */
470  avio_wl16(pb, 0); /* reserved */
471  avio_wl16(pb, 0); /* reserved */
472  avio_wl16(pb, gxf->audio_tracks);
473  avio_wl16(pb, 1); /* timecode track count */
474  avio_wl16(pb, 0); /* reserved */
475  avio_wl16(pb, gxf->mpeg_tracks);
476  return 48;
477 }
478 
480 {
481  GXFContext *gxf = s->priv_data;
482  AVIOContext *pb = s->pb;
483 
484  avio_wl32(pb, gxf->umf_length); /* total length of the umf data */
485  avio_wl32(pb, 3); /* version */
486  avio_wl32(pb, s->nb_streams+1);
487  avio_wl32(pb, gxf->umf_track_offset); /* umf track section offset */
488  avio_wl32(pb, gxf->umf_track_size);
489  avio_wl32(pb, s->nb_streams+1);
490  avio_wl32(pb, gxf->umf_media_offset);
491  avio_wl32(pb, gxf->umf_media_size);
492  avio_wl32(pb, gxf->umf_length); /* user data offset */
493  avio_wl32(pb, 0); /* user data size */
494  avio_wl32(pb, 0); /* reserved */
495  avio_wl32(pb, 0); /* reserved */
496  return 48;
497 }
498 
500 {
501  AVIOContext *pb = s->pb;
502  GXFContext *gxf = s->priv_data;
503  int64_t pos = avio_tell(pb);
504  int i;
505 
506  gxf->umf_track_offset = pos - gxf->umf_start_offset;
507  for (i = 0; i < s->nb_streams; ++i) {
508  GXFStreamContext *sc = s->streams[i]->priv_data;
509  avio_wl16(pb, sc->media_info);
510  avio_wl16(pb, 1);
511  }
512 
514  avio_wl16(pb, 1);
515 
516  return avio_tell(pb) - pos;
517 }
518 
520 {
521  GXFStreamContext *sc = st->priv_data;
522 
523  if (st->codecpar->format == AV_PIX_FMT_YUV422P)
524  avio_wl32(pb, 2);
525  else
526  avio_wl32(pb, 1); /* default to 420 */
527  avio_wl32(pb, sc->first_gop_closed == 1); /* closed = 1, open = 0, unknown = 255 */
528  avio_wl32(pb, 3); /* top = 1, bottom = 2, frame = 3, unknown = 0 */
529  avio_wl32(pb, 1); /* I picture per GOP */
530  avio_wl32(pb, sc->p_per_gop);
531  avio_wl32(pb, sc->b_per_i_or_p);
533  avio_wl32(pb, 2);
534  else if (st->codecpar->codec_id == AV_CODEC_ID_MPEG1VIDEO)
535  avio_wl32(pb, 1);
536  else
537  avio_wl32(pb, 0);
538  avio_wl32(pb, 0); /* reserved */
539  return 32;
540 }
541 
542 static int gxf_write_umf_media_timecode(AVIOContext *pb, int drop)
543 {
544  avio_wl32(pb, drop); /* drop frame */
545  avio_wl32(pb, 0); /* reserved */
546  avio_wl32(pb, 0); /* reserved */
547  avio_wl32(pb, 0); /* reserved */
548  avio_wl32(pb, 0); /* reserved */
549  avio_wl32(pb, 0); /* reserved */
550  avio_wl32(pb, 0); /* reserved */
551  avio_wl32(pb, 0); /* reserved */
552  return 32;
553 }
554 
556 {
557  int dv_umf_data = 0;
558 
559  if (st->codecpar->format == AV_PIX_FMT_YUV420P)
560  dv_umf_data |= 0x20; /* marks as DVCAM instead of DVPRO */
561  avio_wl32(pb, dv_umf_data);
562  avio_wl32(pb, 0);
563  avio_wl32(pb, 0);
564  avio_wl32(pb, 0);
565  avio_wl32(pb, 0);
566  avio_wl32(pb, 0);
567  avio_wl32(pb, 0);
568  avio_wl32(pb, 0);
569  return 32;
570 }
571 
573 {
574  avio_wl64(pb, av_double2int(1)); /* sound level to begin to */
575  avio_wl64(pb, av_double2int(1)); /* sound level to begin to */
576  avio_wl32(pb, 0); /* number of fields over which to ramp up sound level */
577  avio_wl32(pb, 0); /* number of fields over which to ramp down sound level */
578  avio_wl32(pb, 0); /* reserved */
579  avio_wl32(pb, 0); /* reserved */
580  return 32;
581 }
582 
584 {
585  GXFContext *gxf = s->priv_data;
586  AVIOContext *pb = s->pb;
587  int64_t pos;
588  int i, j;
589 
590  pos = avio_tell(pb);
591  gxf->umf_media_offset = pos - gxf->umf_start_offset;
592  for (i = 0; i <= s->nb_streams; ++i) {
593  GXFStreamContext *sc;
594  int64_t startpos, curpos;
595 
596  if (i == s->nb_streams)
597  sc = &gxf->timecode_track;
598  else
599  sc = s->streams[i]->priv_data;
600 
601  startpos = avio_tell(pb);
602  avio_wl16(pb, 0); /* length */
603  avio_wl16(pb, sc->media_info);
604  avio_wl16(pb, 0); /* reserved */
605  avio_wl16(pb, 0); /* reserved */
606  avio_wl32(pb, gxf->nb_fields);
607  avio_wl32(pb, 0); /* attributes rw, ro */
608  avio_wl32(pb, 0); /* mark in */
609  avio_wl32(pb, gxf->nb_fields); /* mark out */
611  avio_wb16(pb, sc->media_info);
612  for (j = strlen(ES_NAME_PATTERN)+2; j < 88; j++)
613  avio_w8(pb, 0);
614  avio_wl32(pb, sc->track_type);
615  avio_wl32(pb, sc->sample_rate);
616  avio_wl32(pb, sc->sample_size);
617  avio_wl32(pb, 0); /* reserved */
618 
619  if (sc == &gxf->timecode_track)
621  else {
622  AVStream *st = s->streams[i];
623  switch (st->codecpar->codec_id) {
626  gxf_write_umf_media_mpeg(pb, st);
627  break;
630  break;
631  case AV_CODEC_ID_DVVIDEO:
632  gxf_write_umf_media_dv(pb, sc, st);
633  break;
634  }
635  }
636 
637  curpos = avio_tell(pb);
638  avio_seek(pb, startpos, SEEK_SET);
639  avio_wl16(pb, curpos - startpos);
640  avio_seek(pb, curpos, SEEK_SET);
641  }
642  return avio_tell(pb) - pos;
643 }
644 
646 {
647  GXFContext *gxf = s->priv_data;
648  AVIOContext *pb = s->pb;
649  int64_t pos = avio_tell(pb);
650 
652 
653  /* preamble */
654  avio_w8(pb, 3); /* first and last (only) packet */
655  avio_wb32(pb, gxf->umf_length); /* data length */
656 
657  gxf->umf_start_offset = avio_tell(pb);
662  gxf->umf_length = avio_tell(pb) - gxf->umf_start_offset;
663  return updatePacketSize(pb, pos);
664 }
665 
666 static const int GXF_samples_per_frame[] = { 32768, 0 };
667 
669 {
670  if (!vsc)
671  return;
672 
673  sc->media_type = vsc->sample_rate == 60 ? 7 : 8;
674  sc->sample_rate = vsc->sample_rate;
675  sc->media_info = ('T'<<8) | '0';
676  sc->track_type = 3;
678  sc->lines_index = vsc->lines_index;
679  sc->sample_size = 16;
680  sc->fields = vsc->fields;
681 }
682 
683 static int gxf_init_timecode(AVFormatContext *s, GXFTimecode *tc, const char *tcstr, int fields)
684 {
685  char c;
686 
687  if (sscanf(tcstr, "%d:%d:%d%c%d", &tc->hh, &tc->mm, &tc->ss, &c, &tc->ff) != 5) {
688  av_log(s, AV_LOG_ERROR, "unable to parse timecode, "
689  "syntax: hh:mm:ss[:;.]ff\n");
690  return -1;
691  }
692 
693  tc->color = 0;
694  tc->drop = c != ':';
695 
696  if (fields == 2)
697  tc->ff = tc->ff * 2;
698 
699  return 0;
700 }
701 
703 {
704  AVIOContext *pb = s->pb;
705  GXFContext *gxf = s->priv_data;
706  GXFStreamContext *vsc = NULL;
707  uint8_t tracks[255] = {0};
708  int i, media_info = 0;
709  int ret;
710  AVDictionaryEntry *tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
711 
712  if (!(pb->seekable & AVIO_SEEKABLE_NORMAL)) {
713  av_log(s, AV_LOG_ERROR, "gxf muxer does not support streamed output, patch welcome\n");
714  return -1;
715  }
716 
717  gxf->flags |= 0x00080000; /* material is simple clip */
718  for (i = 0; i < s->nb_streams; ++i) {
719  AVStream *st = s->streams[i];
720  GXFStreamContext *sc = av_mallocz(sizeof(*sc));
721  if (!sc)
722  return AVERROR(ENOMEM);
723  st->priv_data = sc;
724 
726  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
728  av_log(s, AV_LOG_ERROR, "only 16 BIT PCM LE allowed for now\n");
729  return -1;
730  }
731  if (st->codecpar->sample_rate != 48000) {
732  av_log(s, AV_LOG_ERROR, "only 48000hz sampling rate is allowed\n");
733  return -1;
734  }
735  if (st->codecpar->channels != 1) {
736  av_log(s, AV_LOG_ERROR, "only mono tracks are allowed\n");
737  return -1;
738  }
739  sc->track_type = 2;
740  sc->sample_rate = st->codecpar->sample_rate;
741  avpriv_set_pts_info(st, 64, 1, sc->sample_rate);
742  sc->sample_size = 16;
743  sc->frame_rate_index = -2;
744  sc->lines_index = -2;
745  sc->fields = -2;
746  gxf->audio_tracks++;
747  gxf->flags |= 0x04000000; /* audio is 16 bit pcm */
748  media_info = 'A';
749  } else if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
750  if (i != 0) {
751  av_log(s, AV_LOG_ERROR, "video stream must be the first track\n");
752  return -1;
753  }
754  /* FIXME check from time_base ? */
755  if (st->codecpar->height == 480 || st->codecpar->height == 512) { /* NTSC or NTSC+VBI */
756  sc->frame_rate_index = 5;
757  sc->sample_rate = 60;
758  gxf->flags |= 0x00000080;
759  gxf->time_base = (AVRational){ 1001, 60000 };
760  } else if (st->codecpar->height == 576 || st->codecpar->height == 608) { /* PAL or PAL+VBI */
761  sc->frame_rate_index = 6;
762  sc->media_type++;
763  sc->sample_rate = 50;
764  gxf->flags |= 0x00000040;
765  gxf->time_base = (AVRational){ 1, 50 };
766  } else {
767  av_log(s, AV_LOG_ERROR, "unsupported video resolution, "
768  "gxf muxer only accepts PAL or NTSC resolutions currently\n");
769  return -1;
770  }
771  if (!tcr)
772  tcr = av_dict_get(st->metadata, "timecode", NULL, 0);
773  avpriv_set_pts_info(st, 64, gxf->time_base.num, gxf->time_base.den);
774  if (gxf_find_lines_index(st) < 0)
775  sc->lines_index = -1;
776  sc->sample_size = st->codecpar->bit_rate;
777  sc->fields = 2; /* interlaced */
778 
779  vsc = sc;
780 
781  switch (st->codecpar->codec_id) {
782  case AV_CODEC_ID_MJPEG:
783  sc->track_type = 1;
784  gxf->flags |= 0x00004000;
785  media_info = 'J';
786  break;
788  sc->track_type = 9;
789  gxf->mpeg_tracks++;
790  media_info = 'L';
791  break;
793  sc->first_gop_closed = -1;
794  sc->track_type = 4;
795  gxf->mpeg_tracks++;
796  gxf->flags |= 0x00008000;
797  media_info = 'M';
798  break;
799  case AV_CODEC_ID_DVVIDEO:
800  if (st->codecpar->format == AV_PIX_FMT_YUV422P) {
801  sc->media_type += 2;
802  sc->track_type = 6;
803  gxf->flags |= 0x00002000;
804  media_info = 'E';
805  } else {
806  sc->track_type = 5;
807  gxf->flags |= 0x00001000;
808  media_info = 'D';
809  }
810  break;
811  default:
812  av_log(s, AV_LOG_ERROR, "video codec not supported\n");
813  return -1;
814  }
815  }
816  /* FIXME first 10 audio tracks are 0 to 9 next 22 are A to V */
817  sc->media_info = media_info<<8 | ('0'+tracks[media_info]++);
818  sc->order = s->nb_streams - st->index;
819  }
820 
822  return -1;
823 
824  if (tcr && vsc)
825  gxf_init_timecode(s, &gxf->tc, tcr->value, vsc->fields);
826 
828  gxf->flags |= 0x200000; // time code track is non-drop frame
829 
830  if ((ret = gxf_write_map_packet(s, 0)) < 0)
831  return ret;
834 
835  gxf->packet_count = 3;
836 
837  avio_flush(pb);
838  return 0;
839 }
840 
842 {
843  int64_t pos = avio_tell(pb);
844 
846  return updatePacketSize(pb, pos);
847 }
848 
850 {
851  GXFContext *gxf = s->priv_data;
852  AVIOContext *pb = s->pb;
853  int64_t end;
854  int i;
855  int ret;
856 
858 
860  end = avio_tell(pb);
861  avio_seek(pb, 0, SEEK_SET);
862  /* overwrite map, flt and umf packets with new values */
863  if ((ret = gxf_write_map_packet(s, 1)) < 0)
864  return ret;
867  avio_flush(pb);
868  /* update duration in all map packets */
869  for (i = 1; i < gxf->map_offsets_nb; i++) {
870  avio_seek(pb, gxf->map_offsets[i], SEEK_SET);
871  if ((ret = gxf_write_map_packet(s, 1)) < 0)
872  return ret;
873  avio_flush(pb);
874  }
875 
876  avio_seek(pb, end, SEEK_SET);
877 
878  av_freep(&gxf->flt_entries);
879  av_freep(&gxf->map_offsets);
880 
881  return 0;
882 }
883 
885 {
886  uint32_t c=-1;
887  int i;
888  for(i=0; i<size-4 && c!=0x100; i++){
889  c = (c<<8) + buf[i];
890  if(c == 0x1B8 && sc->first_gop_closed == -1) /* GOP start code */
891  sc->first_gop_closed= (buf[i+4]>>6)&1;
892  }
893  return (buf[i+1]>>3)&7;
894 }
895 
897 {
898  GXFContext *gxf = s->priv_data;
899  AVIOContext *pb = s->pb;
900  AVStream *st = s->streams[pkt->stream_index];
901  GXFStreamContext *sc = st->priv_data;
902  unsigned field_nb;
903  /* If the video is frame-encoded, the frame numbers shall be represented by
904  * even field numbers.
905  * see SMPTE360M-2004 6.4.2.1.3 Media field number */
906  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
907  field_nb = gxf->nb_fields;
908  } else {
909  field_nb = av_rescale_rnd(pkt->dts, gxf->time_base.den,
910  (int64_t)48000*gxf->time_base.num, AV_ROUND_UP);
911  }
912 
913  avio_w8(pb, sc->media_type);
914  avio_w8(pb, st->index);
915  avio_wb32(pb, field_nb);
916  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
917  avio_wb16(pb, 0);
918  avio_wb16(pb, size / 2);
919  } else if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
920  int frame_type = gxf_parse_mpeg_frame(sc, pkt->data, pkt->size);
921  if (frame_type == AV_PICTURE_TYPE_I) {
922  avio_w8(pb, 0x0d);
923  sc->iframes++;
924  } else if (frame_type == AV_PICTURE_TYPE_B) {
925  avio_w8(pb, 0x0f);
926  sc->bframes++;
927  } else {
928  avio_w8(pb, 0x0e);
929  sc->pframes++;
930  }
931  avio_wb24(pb, size);
932  } else if (st->codecpar->codec_id == AV_CODEC_ID_DVVIDEO) {
933  avio_w8(pb, size / 4096);
934  avio_wb24(pb, 0);
935  } else
936  avio_wb32(pb, size);
937  avio_wb32(pb, field_nb);
938  avio_w8(pb, 1); /* flags */
939  avio_w8(pb, 0); /* reserved */
940  return 16;
941 }
942 
944 {
945  GXFContext *gxf = s->priv_data;
946  AVIOContext *pb = s->pb;
947  AVStream *st = s->streams[pkt->stream_index];
948  int64_t pos = avio_tell(pb);
949  int padding = 0;
950  unsigned packet_start_offset = avio_tell(pb) / 1024;
951  int ret;
952 
954  if (st->codecpar->codec_id == AV_CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */
955  padding = 4 - pkt->size % 4;
956  else if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO)
957  padding = GXF_AUDIO_PACKET_SIZE - pkt->size;
958  gxf_write_media_preamble(s, pkt, pkt->size + padding);
959  avio_write(pb, pkt->data, pkt->size);
960  gxf_write_padding(pb, padding);
961 
962  if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
963  if (!(gxf->flt_entries_nb % 500)) {
964  int err;
965  if ((err = av_reallocp_array(&gxf->flt_entries,
966  gxf->flt_entries_nb + 500,
967  sizeof(*gxf->flt_entries))) < 0) {
968  gxf->flt_entries_nb = 0;
969  gxf->nb_fields = 0;
970  av_log(s, AV_LOG_ERROR, "could not reallocate flt entries\n");
971  return err;
972  }
973  }
974  gxf->flt_entries[gxf->flt_entries_nb++] = packet_start_offset;
975  gxf->nb_fields += 2; // count fields
976  }
977 
978  updatePacketSize(pb, pos);
979 
980  gxf->packet_count++;
981  if (gxf->packet_count == 100) {
982  if ((ret = gxf_write_map_packet(s, 0)) < 0)
983  return ret;
984  gxf->packet_count = 0;
985  }
986 
987  return 0;
988 }
989 
991 {
992  GXFContext *gxf = s->priv_data;
993  AVPacket *pkt[2] = { cur, next };
994  int i, field_nb[2];
995  GXFStreamContext *sc[2];
996 
997  for (i = 0; i < 2; i++) {
998  AVStream *st = s->streams[pkt[i]->stream_index];
999  sc[i] = st->priv_data;
1000  if (st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) {
1001  field_nb[i] = av_rescale_rnd(pkt[i]->dts, gxf->time_base.den,
1002  (int64_t)48000*gxf->time_base.num, AV_ROUND_UP);
1003  field_nb[i] &= ~1; // compare against even field number because audio must be before video
1004  } else
1005  field_nb[i] = pkt[i]->dts; // dts are field based
1006  }
1007 
1008  return field_nb[1] > field_nb[0] ||
1009  (field_nb[1] == field_nb[0] && sc[1]->order > sc[0]->order);
1010 }
1011 
1013 {
1014  if (pkt && s->streams[pkt->stream_index]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
1015  pkt->duration = 2; // enforce 2 fields
1018 }
1019 
1021  .name = "gxf",
1022  .long_name = NULL_IF_CONFIG_SMALL("GXF (General eXchange Format)"),
1023  .extensions = "gxf",
1024  .priv_data_size = sizeof(GXFContext),
1025  .audio_codec = AV_CODEC_ID_PCM_S16LE,
1026  .video_codec = AV_CODEC_ID_MPEG2VIDEO,
1031 };
AV_CODEC_ID_PCM_S16LE
@ AV_CODEC_ID_PCM_S16LE
Definition: avcodec.h:463
gxf_write_dv_auxiliary
static int gxf_write_dv_auxiliary(AVIOContext *pb, AVStream *st)
Definition: gxfenc.c:220
gxf_write_timecode_auxiliary
static int gxf_write_timecode_auxiliary(AVIOContext *pb, GXFContext *gxf)
Definition: gxfenc.c:233
gxf_write_mpeg_auxiliary
static int gxf_write_mpeg_auxiliary(AVIOContext *pb, AVStream *st)
Definition: gxfenc.c:181
GXFStreamContext::lines_index
int lines_index
Definition: gxfenc.c:54
AV_CODEC_ID_AC3
@ AV_CODEC_ID_AC3
Definition: avcodec.h:567
GXFStreamContext::sample_rate
uint32_t sample_rate
Definition: gxfenc.c:50
AVOutputFormat::name
const char * name
Definition: avformat.h:496
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
opt.h
AVCodecParameters::codec_type
enum AVMediaType codec_type
General type of the encoded data.
Definition: avcodec.h:3953
out
FILE * out
Definition: movenc.c:54
PKT_EOS
@ PKT_EOS
Definition: gxf.h:28
gxf_write_umf_media_dv
static int gxf_write_umf_media_dv(AVIOContext *pb, GXFStreamContext *sc, AVStream *st)
Definition: gxfenc.c:555
GXFTimecode
Definition: gxfenc.c:37
AVStream::priv_data
void * priv_data
Definition: avformat.h:885
TRACK_FPF
@ TRACK_FPF
Definition: gxf.h:49
GXFStreamContext::bframes
int bframes
Definition: gxfenc.c:58
TRACK_VER
@ TRACK_VER
Definition: gxf.h:45
GXFStreamContext::media_type
uint16_t media_type
Definition: gxfenc.c:51
gxf_lines_tab
static const struct @260 gxf_lines_tab[]
GXFContext::map_offsets_nb
unsigned map_offsets_nb
Definition: gxfenc.c:83
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
AVPacket::data
uint8_t * data
Definition: avcodec.h:1477
GXFContext::map_offsets
uint64_t * map_offsets
offset of map packets
Definition: gxfenc.c:82
TRACK_FPS
@ TRACK_FPS
Definition: gxf.h:47
ff_parse_creation_time_metadata
int ff_parse_creation_time_metadata(AVFormatContext *s, int64_t *timestamp, int return_seconds)
Parse creation_time in AVFormatContext metadata if exists and warn if the parsing fails.
Definition: utils.c:5677
avio_wl64
void avio_wl64(AVIOContext *s, uint64_t val)
Definition: aviobuf.c:457
GXFContext::umf_length
uint32_t umf_length
Definition: gxfenc.c:74
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1495
mathematics.h
GXFStreamContext::p_per_gop
int p_per_gop
Definition: gxfenc.c:59
gxf_write_umf_media_mpeg
static int gxf_write_umf_media_mpeg(AVIOContext *pb, AVStream *st)
Definition: gxfenc.c:519
GXF_samples_per_frame
static const int GXF_samples_per_frame[]
Definition: gxfenc.c:666
TRACK_LINES
@ TRACK_LINES
Definition: gxf.h:48
gxf_write_umf_packet
static int gxf_write_umf_packet(AVFormatContext *s)
Definition: gxfenc.c:645
intfloat.h
gxf_media_types
static const AVCodecTag gxf_media_types[]
Definition: gxfenc.c:99
avio_size
int64_t avio_size(AVIOContext *s)
Get the filesize.
Definition: aviobuf.c:336
gxf_write_header
static int gxf_write_header(AVFormatContext *s)
Definition: gxfenc.c:702
GXFContext::flt_entries_nb
unsigned flt_entries_nb
Definition: gxfenc.c:81
avio_wl16
void avio_wl16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:469
GXFStreamContext::b_per_i_or_p
int b_per_i_or_p
number of B-frames per I-frame or P-frame
Definition: gxfenc.c:60
gxf_parse_mpeg_frame
static int gxf_parse_mpeg_frame(GXFStreamContext *sc, const uint8_t *buf, int size)
Definition: gxfenc.c:884
AVCodecParameters::channels
int channels
Audio only.
Definition: avcodec.h:4063
updatePacketSize
static int64_t updatePacketSize(AVIOContext *pb, int64_t pos)
Definition: gxfenc.c:142
timecode.h
gxf_write_packet
static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt)
Definition: gxfenc.c:943
avio_tell
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
Definition: avio.h:557
PKT_MAP
@ PKT_MAP
Definition: gxf.h:26
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
interleave_packet
static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush)
Interleave an AVPacket correctly so it can be muxed.
Definition: mux.c:1181
TRACK_AUX
@ TRACK_AUX
Definition: gxf.h:44
gxf_find_lines_index
static int gxf_find_lines_index(AVStream *st)
Definition: gxfenc.c:121
AV_ROUND_UP
@ AV_ROUND_UP
Round toward +infinity.
Definition: mathematics.h:83
GXFStreamContext::sample_size
uint32_t sample_size
Definition: gxfenc.c:49
gxf_init_timecode_track
static void gxf_init_timecode_track(GXFStreamContext *sc, GXFStreamContext *vsc)
Definition: gxfenc.c:668
ff_gxf_muxer
AVOutputFormat ff_gxf_muxer
Definition: gxfenc.c:1020
AVRational::num
int num
Numerator.
Definition: rational.h:59
gxf_write_map_packet
static int gxf_write_map_packet(AVFormatContext *s, int rewrite)
Definition: gxfenc.c:376
gxf_compare_field_nb
static int gxf_compare_field_nb(AVFormatContext *s, AVPacket *next, AVPacket *cur)
Definition: gxfenc.c:990
avassert.h
PKT_UMF
@ PKT_UMF
Definition: gxf.h:30
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
buf
void * buf
Definition: avisynth_c.h:766
AVCodecTag
Definition: internal.h:44
GXFContext::mpeg_tracks
uint16_t mpeg_tracks
Definition: gxfenc.c:69
av_dict_get
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
MAT_NAME
@ MAT_NAME
Definition: gxf.h:34
s
#define s(width, name)
Definition: cbs_vp9.c:257
GXFContext::time_base
AVRational time_base
Definition: gxfenc.c:77
gxf_write_umf_media_audio
static int gxf_write_umf_media_audio(AVIOContext *pb, GXFStreamContext *sc)
Definition: gxfenc.c:572
GXFStreamContext::aic
AudioInterleaveContext aic
Definition: gxfenc.c:47
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
GXFContext::umf_track_offset
uint32_t umf_track_offset
Definition: gxfenc.c:72
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
MAT_SIZE
@ MAT_SIZE
Definition: gxf.h:39
GXFStreamContext::pframes
int pframes
Definition: gxfenc.c:57
gxf_write_padding
static void gxf_write_padding(AVIOContext *pb, int64_t to_pad)
Definition: gxfenc.c:135
MAT_MARK_OUT
@ MAT_MARK_OUT
Definition: gxf.h:38
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
updateSize
static int64_t updateSize(AVIOContext *pb, int64_t pos)
Definition: gxfenc.c:159
GXFContext::flags
int flags
Definition: gxfenc.c:78
MAT_FIRST_FIELD
@ MAT_FIRST_FIELD
Definition: gxf.h:35
fields
the definition of that something depends on the semantic of the filter The callback must examine the status of the filter s links and proceed accordingly The status of output links is stored in the status_in and status_out fields and tested by the then the processing requires a frame on this link and the filter is expected to make efforts in that direction The status of input links is stored by the fifo and status_out fields
Definition: filter_design.txt:155
AVFormatContext
Format I/O context.
Definition: avformat.h:1342
internal.h
AVStream::codecpar
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Definition: avformat.h:1017
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
flush
static void flush(AVCodecContext *avctx)
Definition: aacdec_template.c:500
NULL
#define NULL
Definition: coverity.c:32
GXFContext::nb_fields
uint32_t nb_fields
Definition: gxfenc.c:67
GXFContext::creation_time
int64_t creation_time
Definition: gxfenc.c:70
write_trailer
static int write_trailer(AVFormatContext *s1)
Definition: v4l2enc.c:94
gxf_interleave_packet
static int gxf_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
Definition: gxfenc.c:1012
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
GXFContext::umf_track_size
uint16_t umf_track_size
Definition: gxfenc.c:75
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
MAT_LAST_FIELD
@ MAT_LAST_FIELD
Definition: gxf.h:36
AVStream::metadata
AVDictionary * metadata
Definition: avformat.h:934
avio_w8
void avio_w8(AVIOContext *s, int b)
Definition: aviobuf.c:196
gxf_write_umf_material_description
static int gxf_write_umf_material_description(AVFormatContext *s)
Definition: gxfenc.c:433
GXF_TIMECODE
#define GXF_TIMECODE(c, d, h, m, s, f)
Definition: gxfenc.c:34
index
int index
Definition: gxfenc.c:89
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVCodecParameters::sample_rate
int sample_rate
Audio only.
Definition: avcodec.h:4067
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: avcodec.h:219
GXFContext::tc
GXFTimecode tc
Definition: gxfenc.c:85
gxf_write_material_data_section
static int gxf_write_material_data_section(AVFormatContext *s)
Definition: gxfenc.c:308
gxf_write_umf_media_timecode
static int gxf_write_umf_media_timecode(AVIOContext *pb, int drop)
Definition: gxfenc.c:542
av_rescale_rnd
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
AVIOContext
Bytestream IO Context.
Definition: avio.h:161
AV_CODEC_ID_PCM_S24LE
@ AV_CODEC_ID_PCM_S24LE
Definition: avcodec.h:475
GXFTimecode::color
int color
Definition: gxfenc.c:42
AVPacket::size
int size
Definition: avcodec.h:1478
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:188
gxf_write_trailer
static int gxf_write_trailer(AVFormatContext *s)
Definition: gxfenc.c:849
AVIOContext::seekable
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
Definition: avio.h:260
avpriv_set_pts_info
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:4910
size
int size
Definition: twinvq_data.h:11134
GXFStreamContext::first_gop_closed
int first_gop_closed
Definition: gxfenc.c:61
gxf_write_track_description_section
static int gxf_write_track_description_section(AVFormatContext *s)
Definition: gxfenc.c:359
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: avcodec.h:1476
avio_write
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
Definition: aviobuf.c:218
GXF_AUDIO_PACKET_SIZE
#define GXF_AUDIO_PACKET_SIZE
Definition: gxfenc.c:32
avio_wb32
void avio_wb32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:377
av_reallocp_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.
Definition: mem.c:205
avio_wl32
void avio_wl32(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:369
gxf_init_timecode
static int gxf_init_timecode(AVFormatContext *s, GXFTimecode *tc, const char *tcstr, int fields)
Definition: gxfenc.c:683
GXFContext::umf_media_offset
uint32_t umf_media_offset
Definition: gxfenc.c:73
gxf.h
ES_NAME_PATTERN
#define ES_NAME_PATTERN
Definition: gxfenc.c:119
PKT_FLT
@ PKT_FLT
Definition: gxf.h:29
gxf_write_media_preamble
static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size)
Definition: gxfenc.c:896
TRACK_NAME
@ TRACK_NAME
Definition: gxf.h:43
write_packet
static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int unqueue)
Definition: ffmpeg.c:690
GXFContext::timecode_track
GXFStreamContext timecode_track
Definition: gxfenc.c:79
TRACK_MPG_AUX
@ TRACK_MPG_AUX
Definition: gxf.h:46
AudioInterleaveContext
Definition: audiointerleave.h:29
AV_CODEC_ID_MJPEG
@ AV_CODEC_ID_MJPEG
Definition: avcodec.h:225
av_double2int
static av_always_inline uint64_t av_double2int(double f)
Reinterpret a double as a 64-bit integer.
Definition: intfloat.h:70
GXFContext::umf_start_offset
uint32_t umf_start_offset
Definition: gxfenc.c:71
AV_CODEC_ID_NONE
@ AV_CODEC_ID_NONE
Definition: avcodec.h:216
AVOutputFormat
Definition: avformat.h:495
GXFStreamContext::iframes
int iframes
Definition: gxfenc.c:56
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:259
ff_audio_interleave_close
void ff_audio_interleave_close(AVFormatContext *s)
Definition: audiointerleave.c:29
GXFContext::umf_media_size
uint16_t umf_media_size
Definition: gxfenc.c:76
AVCodecParameters::height
int height
Definition: avcodec.h:4024
gxf_write_umf_payload
static int gxf_write_umf_payload(AVFormatContext *s)
Definition: gxfenc.c:479
gxf_write_eos_packet
static int gxf_write_eos_packet(AVIOContext *pb)
Definition: gxfenc.c:841
AV_CODEC_ID_DVVIDEO
@ AV_CODEC_ID_DVVIDEO
Definition: avcodec.h:242
uint8_t
uint8_t
Definition: audio_convert.c:194
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:236
GXFContext
Definition: gxfenc.c:65
len
int len
Definition: vorbis_enc_data.h:452
GXFTimecode::drop
int drop
Definition: gxfenc.c:43
GXFStreamContext::order
unsigned order
interleaving order
Definition: gxfenc.c:62
ret
ret
Definition: filter_design.txt:187
AVStream
Stream structure.
Definition: avformat.h:870
avio_seek
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
Definition: aviobuf.c:246
ff_audio_interleave_init
int ff_audio_interleave_init(AVFormatContext *s, const int *samples_per_frame, AVRational time_base)
Definition: audiointerleave.c:41
GXFContext::av_class
AVClass * av_class
Definition: gxfenc.c:66
avformat.h
GXFTimecode::hh
int hh
Definition: gxfenc.c:38
GXFTimecode::ss
int ss
Definition: gxfenc.c:40
GXFStreamContext::media_info
uint16_t media_info
Definition: gxfenc.c:52
GXFTimecode::ff
int ff
Definition: gxfenc.c:41
gxf_write_track_description
static int gxf_write_track_description(AVFormatContext *s, GXFStreamContext *sc, int index)
Definition: gxfenc.c:247
AVStream::index
int index
stream index in AVFormatContext
Definition: avformat.h:871
GXFStreamContext::frame_rate_index
int frame_rate_index
Definition: gxfenc.c:53
gxf_write_umf_media_description
static int gxf_write_umf_media_description(AVFormatContext *s)
Definition: gxfenc.c:583
MAT_MARK_IN
@ MAT_MARK_IN
Definition: gxf.h:37
pkt
static AVPacket pkt
Definition: demuxing_decoding.c:54
GXFContext::flt_entries
unsigned * flt_entries
offsets of packets /1024, starts after 2nd video field
Definition: gxfenc.c:80
AVIO_SEEKABLE_NORMAL
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
Definition: avio.h:40
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:276
buffer
the frame and frame reference mechanism is intended to as much as expensive copies of that data while still allowing the filters to produce correct results The data is stored in buffers represented by AVFrame structures Several references can point to the same frame buffer
Definition: filter_design.txt:49
AVRational::den
int den
Denominator.
Definition: rational.h:60
SERVER_PATH
#define SERVER_PATH
Definition: gxfenc.c:118
ff_codec_get_tag
unsigned int ff_codec_get_tag(const AVCodecTag *tags, enum AVCodecID id)
Definition: utils.c:3136
PKT_MEDIA
@ PKT_MEDIA
Definition: gxf.h:27
gxf_write_flt_packet
static int gxf_write_flt_packet(AVFormatContext *s)
Definition: gxfenc.c:408
gxf_write_packet_header
static void gxf_write_packet_header(AVIOContext *pb, GXFPktType type)
Definition: gxfenc.c:170
AVPacket::stream_index
int stream_index
Definition: avcodec.h:1479
gxf_write_umf_track_description
static int gxf_write_umf_track_description(AVFormatContext *s)
Definition: gxfenc.c:499
GXFStreamContext
Definition: gxfenc.c:46
height
int height
Definition: gxfenc.c:89
tc
#define tc
Definition: regdef.h:69
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_PIX_FMT_YUV422P
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
AVCodecParameters::format
int format
Definition: avcodec.h:3981
avio_wb24
void avio_wb24(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:487
GXFStreamContext::track_type
uint32_t track_type
Definition: gxfenc.c:48
avio_flush
int void avio_flush(AVIOContext *s)
Force flushing of buffered data.
Definition: aviobuf.c:238
GXFTimecode::mm
int mm
Definition: gxfenc.c:39
AVDictionaryEntry
Definition: dict.h:81
AVCodecParameters::codec_id
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
Definition: avcodec.h:3957
AVPacket
This structure stores compressed data.
Definition: avcodec.h:1454
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
ff_audio_rechunk_interleave
int ff_audio_rechunk_interleave(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush, int(*get_packet)(AVFormatContext *, AVPacket *, AVPacket *, int), int(*compare_ts)(AVFormatContext *, AVPacket *, AVPacket *))
Rechunk audio PCM packets per AudioInterleaveContext->samples_per_frame and interleave them correctly...
Definition: audiointerleave.c:109
GXFPktType
GXFPktType
Definition: gxf.h:25
avio_wb16
void avio_wb16(AVIOContext *s, unsigned int val)
Definition: aviobuf.c:475
AVCodecParameters::bit_rate
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
Definition: avcodec.h:3986
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
GXFContext::audio_tracks
uint16_t audio_tracks
Definition: gxfenc.c:68
GXFStreamContext::fields
int fields
Definition: gxfenc.c:55
AVDictionaryEntry::value
char * value
Definition: dict.h:83
write_header
static void write_header(FFV1Context *f)
Definition: ffv1enc.c:337
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:220
GXFContext::packet_count
unsigned packet_count
Definition: gxfenc.c:84
snprintf
#define snprintf
Definition: snprintf.h:34
audiointerleave.h
ff_interleave_packet_per_dts
int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush)
Interleave a packet per dts in an output media file.
Definition: mux.c:1027