FFmpeg: libavformat/gxfenc.c Source File
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
31
32 #define GXF_SAMPLES_PER_FRAME 32768
33 #define GXF_AUDIO_PACKET_SIZE 65536
34
35 #define GXF_TIMECODE(c, d, h, m, s, f) \
36 ((c) << 30 | (d) << 29 | (h) << 24 | (m) << 16 | (s) << 8 | (f))
37
46
63 unsigned order;
///< interleaving order
65
81 unsigned *
flt_entries;
///< offsets of packets /1024, starts after 2nd video field
88
89 static const struct {
92 { 480, 1 }, /* NTSC */
93 { 512, 1 }, /* NTSC + VBI */
94 { 576, 2 }, /* PAL */
95 { 608, 2 }, /* PAL + VBI */
96 { 1080, 4 },
97 { 720, 6 },
98 };
99
112 //{ AV_CODEC_ID_NONE, , 18 }, /* Non compressed 24 bit audio */
117 };
118
119 #define SERVER_PATH "EXT:/PDR/default/"
120 #define ES_NAME_PATTERN "EXT:/PDR/default/ES."
121
123 {
126
127 for (
i = 0;
i < 6; ++
i) {
130 return 0;
131 }
132 }
133 return -1;
134 }
135
137 {
139 }
140
142 {
145
150 }
156 }
157
159 {
161
167 }
168
170 {
171 avio_wb32(pb, 0);
/* packet leader for synchro */
176 avio_w8(pb, 0xE1);
/* trailer 1 */
177 avio_w8(pb, 0xE2);
/* trailer 2 */
178 }
179
181 {
184 int size, starting_line;
185
194 }
196 sc->
p_per_gop = 9;
/* ensure value won't take more than one char */
198 sc->
b_per_i_or_p = 9;
/* ensure value won't take more than one char */
199 }
201 starting_line = 7; // VBI
203 starting_line = 20;
204 else
205 starting_line = 23; // default PAL
206
208 "Pix 0\nCf %d\nCg %d\nSl %d\nnl16 %d\nVi 1\nf1 1\n",
217 }
218
220 {
222
226 track_aux_data |= 0x01; /* marks stream as DVCAM instead of DVPRO */
227 track_aux_data |= 0x40000000; /* aux data is valid */
229 return 8;
230 }
231
233 {
237
241 /* reserved */
243 return 8;
244 }
245
247 {
251
252 /* track description section */
255
258
259 /* media file name */
265
267 case 3: /* timecode */
269 break;
270 case 4: /* MPEG2 */
271 case 9: /* MPEG1 */
273 break;
274 case 5: /* DV25 */
275 case 6: /* DV50 */
277 break;
278 default:
282 }
283
284 /* file system version */
288
289 /* frame rate */
293
294 /* lines per frame */
298
299 /* fields per frame */
303
305 }
306
308 {
313 const char *filename = strrchr(
s->url,
'/');
314
317
318 /* name */
319 if (filename)
320 filename++;
321 else
323 len = strlen(filename);
324
330
331 /* first field */
335
336 /* last field */
340
341 /* reserved */
345
349
350 /* estimated size */
354
356 }
357
359 {
364
367 for (
i = 0;
i <
s->nb_streams; ++
i)
369
371
373 }
374
376 {
380
381 if (!rewrite) {
383 int err;
389 return err;
390 }
391 }
393 }
394
396
397 /* preamble */
398 avio_w8(pb, 0xE0);
/* version */
399 avio_w8(pb, 0xFF);
/* reserved */
400
403
405 }
406
408 {
412 int fields_per_flt = (gxf->
nb_fields+1) / 1000 + 1;
413 int flt_entries = gxf->
nb_fields / fields_per_flt;
415
417
418 avio_wl32(pb, fields_per_flt);
/* number of fields */
419 avio_wl32(pb, flt_entries);
/* number of active flt entries */
420
422 for (
i = 0;
i < flt_entries;
i++)
424 }
425
427
429 }
430
432 {
435 int timecode_base = gxf->
time_base.
den == 60000 ? 60 : 50;
437 uint64_t nb_fields;
438 uint32_t timecode_in; // timecode at mark in
439 uint32_t timecode_out; // timecode at mark out
440
442
446
448 gxf->
tc.
hh * (timecode_base * 3600) +
449 gxf->
tc.
mm * (timecode_base * 60) +
450 gxf->
tc.
ss * timecode_base +
452
454 nb_fields / (timecode_base * 3600) % 24,
455 nb_fields / (timecode_base * 60) % 60,
456 nb_fields / timecode_base % 60,
457 nb_fields % timecode_base);
458
464 avio_wl32(pb, timecode_in);
/* timecode mark in */
465 avio_wl32(pb, timecode_out);
/* timecode mark out */
466 avio_wl64(pb, timestamp);
/* modification time */
467 avio_wl64(pb, timestamp);
/* creation time */
471 avio_wl16(pb, 1);
/* timecode track count */
474 return 48;
475 }
476
478 {
481
494 return 48;
495 }
496
498 {
503
505 for (
i = 0;
i <
s->nb_streams; ++
i) {
509 }
510
513
515 }
516
518 {
520
523 else
526 avio_wl32(pb, 3);
/* top = 1, bottom = 2, frame = 3, unknown = 0 */
527 avio_wl32(pb, 1);
/* I picture per GOP */
534 else
537 return 32;
538 }
539
541 {
544 return 32;
545 }
546
548 {
549 int dv_umf_data = 0;
550
552 dv_umf_data |= 0x20; /* marks as DVCAM instead of DVPRO */
555 return 32;
556 }
557
559 {
562 avio_wl32(pb, 0);
/* number of fields over which to ramp up sound level */
563 avio_wl32(pb, 0);
/* number of fields over which to ramp down sound level */
566 return 32;
567 }
568
570 {
574
577 for (
unsigned i = 0;
i <=
s->nb_streams; ++
i) {
580
581 if (
i ==
s->nb_streams)
583 else
584 sc =
s->streams[
i]->priv_data;
585
592 avio_wl32(pb, 0);
/* attributes rw, ro */
602
605 else {
611 break;
614 break;
617 break;
618 }
619 }
620
625 }
627 }
628
630 {
634
636
637 /* preamble */
638 avio_w8(pb, 3);
/* first and last (only) packet */
640
648 }
649
651 {
652 if (!vsc)
653 return;
654
663 }
664
666 {
668
669 if (sscanf(tcstr,
"%d:%d:%d%c%d", &tc->
hh, &tc->
mm, &tc->
ss, &
c, &tc->
ff) != 5) {
671 "syntax: hh:mm:ss[:;.]ff\n");
672 return -1;
673 }
674
677
680
681 return 0;
682 }
683
685 {
689 uint8_t tracks[255] = {0};
690 int i, media_info = 0;
693
697 }
698
699 gxf->
flags |= 0x00080000;
/* material is simple clip */
700 for (
i = 0;
i <
s->nb_streams; ++
i) {
703 if (!sc)
706
712 }
716 }
720 }
732 gxf->
flags |= 0x04000000;
/* audio is 16 bit pcm */
733 media_info = 'A';
738 }
739 /* FIXME check from time_base ? */
743 gxf->
flags |= 0x00000080;
749 gxf->
flags |= 0x00000040;
751 } else {
753 "gxf muxer only accepts PAL or NTSC resolutions currently\n");
755 }
756 if (!tcr)
762 sc->
fields = 2;
/* interlaced */
763
764 vsc = sc;
765
769 gxf->
flags |= 0x00004000;
770 media_info = 'J';
771 break;
775 media_info = 'L';
776 break;
781 gxf->
flags |= 0x00008000;
782 media_info = 'M';
783 break;
788 gxf->
flags |= 0x00002000;
789 media_info = 'E';
790 } else {
792 gxf->
flags |= 0x00001000;
793 media_info = 'D';
794 }
795 break;
796 default:
798 return -1;
799 }
800 }
801 /* FIXME first 10 audio tracks are 0 to 9 next 22 are A to V */
802 sc->
media_info = media_info<<8 | (
'0'+tracks[media_info]++);
804 }
805
806 if (tcr && vsc)
808
810 gxf->
flags |= 0x200000;
// time code track is non-drop frame
811
816
818
819 return 0;
820 }
821
823 {
825
828 }
829
831 {
837
841 /* overwrite map, flt and umf packets with new values */
846 /* update duration in all map packets */
851 }
852
854
855 return 0;
856 }
857
859 {
861
864 }
865
867 {
870 for(
i=0;
i<
size-4 &&
c!=0x100;
i++){
874 }
875 return (buf[
i+1]>>3)&7;
876 }
877
879 {
884 unsigned field_nb;
885 /* If the video is frame-encoded, the frame numbers shall be represented by
886 * even field numbers.
887 * see SMPTE360M-2004 6.4.2.1.3 Media field number */
890 } else {
893 }
894
909 } else {
912 }
917 } else
922 return 16;
923 }
924
926 {
931 int padding = 0;
932 unsigned packet_start_offset =
avio_tell(pb) / 1024;
934
943
946 int err;
953 return err;
954 }
955 }
958 }
959
961
967 }
968
969 return 0;
970 }
971
974 {
979
980 for (
i = 0;
i < 2;
i++) {
986 field_nb[
i] &= ~1;
// compare against even field number because audio must be before video
987 } else
988 field_nb[
i] =
pkt[
i]->
dts;
// dts are field based
989 }
990
991 return field_nb[1] > field_nb[0] ||
992 (field_nb[1] == field_nb[0] && sc[1]->
order > sc[0]->
order);
993 }
994
996 int flush,
int has_packet)
997 {
999 if (has_packet) {
1004 else
1009 }
1011 }
1012
1016 .p.extensions = "gxf",
1025 };
@ AV_ROUND_UP
Round toward +infinity.
static int gxf_write_dv_auxiliary(AVIOContext *pb, AVStream *st)
static int gxf_write_timecode_auxiliary(AVIOContext *pb, GXFContext *gxf)
static int gxf_write_mpeg_auxiliary(AVIOContext *pb, AVStream *st)
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
enum AVMediaType codec_type
General type of the encoded data.
static int64_t update_size(AVIOContext *pb, int64_t pos)
static int gxf_write_umf_media_dv(AVIOContext *pb, GXFStreamContext *sc, AVStream *st)
uint64_t * map_offsets
offset of map packets
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.
void avio_wl64(AVIOContext *s, uint64_t val)
static int gxf_write_umf_media_mpeg(AVIOContext *pb, AVStream *st)
int nb_channels
Number of channels in this layout.
static int gxf_write_umf_packet(AVFormatContext *s)
static const AVCodecTag gxf_media_types[]
int64_t avio_size(AVIOContext *s)
Get the filesize.
static int gxf_write_header(AVFormatContext *s)
void avio_wl16(AVIOContext *s, unsigned int val)
int b_per_i_or_p
number of B-frames per I-frame or P-frame
static int gxf_parse_mpeg_frame(GXFStreamContext *sc, const uint8_t *buf, int size)
static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt)
static av_always_inline int64_t avio_tell(AVIOContext *s)
ftell() equivalent for AVIOContext.
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
static int gxf_find_lines_index(AVStream *st)
static void gxf_init_timecode_track(GXFStreamContext *sc, GXFStreamContext *vsc)
static int gxf_write_map_packet(AVFormatContext *s, int rewrite)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
static int gxf_write_umf_media_audio(AVIOContext *pb, GXFStreamContext *sc)
uint32_t umf_track_offset
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static void gxf_write_padding(AVIOContext *pb, int64_t to_pad)
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
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
AVCodecParameters * codecpar
Codec parameters associated with this stream.
Describe the class of an AVClass context structure.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Rational number (pair of numerator and denominator).
@ AV_PICTURE_TYPE_I
Intra.
void(* flush)(AVBSFContext *ctx)
void avio_w8(AVIOContext *s, int b)
void ffio_fill(AVIOContext *s, int b, int64_t count)
AVChannelLayout ch_layout
Audio only.
static int gxf_write_umf_material_description(AVFormatContext *s)
#define GXF_TIMECODE(c, d, h, m, s, f)
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
int sample_rate
Audio only.
static int gxf_write_material_data_section(AVFormatContext *s)
static int gxf_write_umf_media_timecode(AVIOContext *pb, int drop)
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.
static int gxf_interleave_packet(AVFormatContext *s, AVPacket *pkt, int flush, int has_packet)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
static int gxf_write_trailer(AVFormatContext *s)
int seekable
A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable.
static int gxf_write_track_description_section(AVFormatContext *s)
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
#define GXF_AUDIO_PACKET_SIZE
void avio_wb32(AVIOContext *s, unsigned int val)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate an array through a pointer to a pointer.
void avio_wl32(AVIOContext *s, unsigned int val)
static int gxf_init_timecode(AVFormatContext *s, GXFTimecode *tc, const char *tcstr, int fields)
uint32_t umf_media_offset
#define GXF_SAMPLES_PER_FRAME
static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size)
GXFStreamContext timecode_track
static av_always_inline uint64_t av_double2int(double f)
Reinterpret a double as a 64-bit integer.
uint32_t umf_start_offset
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static int gxf_write_umf_payload(AVFormatContext *s)
static int gxf_write_eos_packet(AVIOContext *pb)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
unsigned order
interleaving order
int64_t avio_seek(AVIOContext *s, int64_t offset, int whence)
fseek() equivalent for AVIOContext.
static void gxf_deinit(AVFormatContext *s)
static int gxf_write_track_description(AVFormatContext *s, GXFStreamContext *sc, int index)
int index
stream index in AVFormatContext
static int gxf_write_umf_media_description(AVFormatContext *s)
unsigned * flt_entries
offsets of packets /1024, starts after 2nd video field
#define AVIO_SEEKABLE_NORMAL
Seeking works like for a local file.
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
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
static int gxf_write_flt_packet(AVFormatContext *s)
static int64_t update_packet_size(AVIOContext *pb, int64_t pos)
static void gxf_write_packet_header(AVIOContext *pb, GXFPktType type)
static int gxf_write_umf_track_description(AVFormatContext *s)
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
void avio_wb24(AVIOContext *s, unsigned int val)
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
This structure stores compressed data.
void avio_wb16(AVIOContext *s, unsigned int val)
const FFOutputFormat ff_gxf_muxer
int64_t bit_rate
The average bitrate of the encoded data (in bits per second).
static int gxf_compare_field_nb(AVFormatContext *s, const AVPacket *next, const AVPacket *cur)
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
static const struct @379 gxf_lines_tab[]
Generated on Fri Aug 22 2025 13:59:27 for FFmpeg by
doxygen
1.8.17