Libav
mxf.c
Go to the documentation of this file.
1 /*
2  * MXF
3  * Copyright (c) 2006 SmartJog S.A., Baptiste Coudurier <baptiste dot coudurier at smartjog dot com>
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 "libavutil/common.h"
23 #include "mxf.h"
24 
29  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x01,0x00,0x00,0x00 }, 13, AVMEDIA_TYPE_VIDEO },
30  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x01,0x03,0x02,0x02,0x02,0x00,0x00,0x00 }, 13, AVMEDIA_TYPE_AUDIO },
31  { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, AVMEDIA_TYPE_DATA },
32 };
33 
35  /* PictureEssenceCoding */
36  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x01,0x11,0x00 }, 14, AV_CODEC_ID_MPEG2VIDEO }, /* MP@ML Long GoP */
37  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x01,0x02,0x01,0x01 }, 14, AV_CODEC_ID_MPEG2VIDEO }, /* D-10 50Mbps PAL */
38  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, 14, AV_CODEC_ID_MPEG2VIDEO }, /* MP@HL Long GoP */
39  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, 14, AV_CODEC_ID_MPEG2VIDEO }, /* 422P@HL I-Frame */
40  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x20,0x02,0x03 }, 14, AV_CODEC_ID_MPEG4 }, /* XDCAM proxy_pal030926.mxf */
41  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x02,0x01,0x02,0x00 }, 13, AV_CODEC_ID_DVVIDEO }, /* DV25 IEC PAL */
42  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 }, 14, AV_CODEC_ID_JPEG2000 }, /* JPEG2000 Codestream */
43  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x01,0x7F,0x00,0x00,0x00 }, 13, AV_CODEC_ID_RAWVIDEO }, /* Uncompressed */
44  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x01,0x00 }, 15, AV_CODEC_ID_RAWVIDEO }, /* Uncompressed 422 8-bit */
45  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x71,0x00,0x00,0x00 }, 13, AV_CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD */
46  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x03,0x02,0x00,0x00 }, 14, AV_CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD */
47  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x00,0x00 }, 14, AV_CODEC_ID_H264 }, /* H.264/MPEG-4 AVC Intra */
48  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x31,0x11,0x01 }, 14, AV_CODEC_ID_H264 }, /* H.264/MPEG-4 AVC SPS/PPS in-band */
49  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x02,0x00 }, 15, AV_CODEC_ID_V210 }, /* V210 */
50  /* SoundEssenceCompression */
51  { { 0x06,0x0e,0x2b,0x34,0x04,0x01,0x01,0x03,0x04,0x02,0x02,0x02,0x03,0x03,0x01,0x00 }, 14, AV_CODEC_ID_AAC }, /* MPEG2 AAC ADTS (legacy) */
52  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, 13, AV_CODEC_ID_PCM_S16LE }, /* Uncompressed */
53  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x7F,0x00,0x00,0x00 }, 13, AV_CODEC_ID_PCM_S16LE },
54  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x02,0x02,0x01,0x7E,0x00,0x00,0x00 }, 13, AV_CODEC_ID_PCM_S16BE }, /* From Omneon MXF file */
55  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x04,0x04,0x02,0x02,0x02,0x03,0x01,0x01,0x00 }, 15, AV_CODEC_ID_PCM_ALAW }, /* XDCAM Proxy C0023S01.mxf */
56  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x01,0x00 }, 15, AV_CODEC_ID_AC3 },
57  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x05,0x00 }, 15, AV_CODEC_ID_MP2 }, /* MP2 or MP3 */
58  //{ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x02,0x03,0x02,0x1C,0x00 }, 15, AV_CODEC_ID_DOLBY_E }, /* Dolby-E */
59  { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, AV_CODEC_ID_NONE },
60 };
61 
63  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x01,0x01 }, 16, AV_PIX_FMT_UYVY422 },
64  { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x01,0x02 }, 16, AV_PIX_FMT_YUYV422 },
65  { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, AV_PIX_FMT_NONE },
66 };
67 
68 static const struct {
70  const char data[16];
81  {AV_PIX_FMT_ABGR, {'A', 8, 'B', 8, 'G', 8, 'R', 8 }},
82  {AV_PIX_FMT_ARGB, {'A', 8, 'R', 8, 'G', 8, 'B', 8 }},
83  {AV_PIX_FMT_BGR24, {'B', 8, 'G', 8, 'R', 8 }},
84  {AV_PIX_FMT_BGRA, {'B', 8, 'G', 8, 'R', 8, 'A', 8 }},
85  {AV_PIX_FMT_RGB24, {'R', 8, 'G', 8, 'B', 8 }},
86  {AV_PIX_FMT_RGB444BE,{'F', 4, 'R', 4, 'G', 4, 'B', 4 }},
87  {AV_PIX_FMT_RGB48BE, {'R', 8, 'r', 8, 'G', 8, 'g', 8, 'B', 8, 'b', 8 }},
88  {AV_PIX_FMT_RGB48BE, {'R', 16, 'G', 16, 'B', 16 }},
89  {AV_PIX_FMT_RGB48LE, {'r', 8, 'R', 8, 'g', 8, 'G', 8, 'b', 8, 'B', 8 }},
90  {AV_PIX_FMT_RGB555BE,{'F', 1, 'R', 5, 'G', 5, 'B', 5 }},
91  {AV_PIX_FMT_RGB565BE,{'R', 5, 'G', 6, 'B', 5 }},
92  {AV_PIX_FMT_RGBA, {'R', 8, 'G', 8, 'B', 8, 'A', 8 }},
93  {AV_PIX_FMT_PAL8, {'P', 8 }},
94 };
95 
97 
98 int ff_mxf_decode_pixel_layout(const char pixel_layout[16], enum AVPixelFormat *pix_fmt)
99 {
100  int x;
101 
102  for(x = 0; x < num_pixel_layouts; x++) {
103  if (!memcmp(pixel_layout, ff_mxf_pixel_layouts[x].data, 16)) {
104  *pix_fmt = ff_mxf_pixel_layouts[x].pix_fmt;
105  return 0;
106  }
107  }
108 
109  return -1;
110 }
111 
112 static const MXFSamplesPerFrame mxf_spf[] = {
113  { { 1001, 24000 }, { 2002, 0, 0, 0, 0, 0 } }, // FILM 23.976
114  { { 1, 24}, { 2000, 0, 0, 0, 0, 0 } }, // FILM 24
115  { { 1001, 30000 }, { 1602, 1601, 1602, 1601, 1602, 0 } }, // NTSC 29.97
116  { { 1001, 60000 }, { 801, 801, 801, 801, 800, 0 } }, // NTSC 59.94
117  { { 1, 25 }, { 1920, 0, 0, 0, 0, 0 } }, // PAL 25
118  { { 1, 50 }, { 960, 0, 0, 0, 0, 0 } }, // PAL 50
119 };
120 
121 static const AVRational mxf_time_base[] = {
122  { 1001, 24000 },
123  { 1, 24},
124  { 1001, 30000 },
125  { 1001, 60000 },
126  { 1, 25 },
127  { 1, 50 },
128  { 0, 0}
129 };
130 
132  AVRational time_base)
133 {
134  int idx = av_find_nearest_q_idx(time_base, mxf_time_base);
135  AVRational diff = av_sub_q(time_base, mxf_time_base[idx]);
136 
137  diff.num = abs(diff.num);
138 
139  if (av_cmp_q(diff, (AVRational){1, 1000}) >= 0)
140  return NULL;
141 
142  if (av_cmp_q(time_base, mxf_time_base[idx]))
144  "%d/%d input time base matched %d/%d container time base\n",
145  time_base.num, time_base.den,
146  mxf_spf[idx].time_base.num,
147  mxf_spf[idx].time_base.den);
148 
149  return &mxf_spf[idx];
150 }
packed ARGB 8:8:8:8, 32bpp, ARGBARGB...
Definition: pixfmt.h:95
static const int num_pixel_layouts
Definition: mxf.c:96
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:67
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:129
packed BGRA 8:8:8:8, 32bpp, BGRABGRA...
Definition: pixfmt.h:98
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:66
static const struct @116 ff_mxf_pixel_layouts[]
static const AVRational mxf_time_base[]
Definition: mxf.c:121
int num
numerator
Definition: rational.h:44
void av_log(void *avcl, int level, const char *fmt,...) av_printf_format(3
Send the specified message to the log if the level is less than or equal to the current av_log_level...
static int av_cmp_q(AVRational a, AVRational b)
Compare two rationals.
Definition: rational.h:55
struct AVRational time_base
Definition: mxf.h:71
Format I/O context.
Definition: avformat.h:922
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:112
const MXFSamplesPerFrame * ff_mxf_get_samples_per_frame(AVFormatContext *s, AVRational time_base)
Definition: mxf.c:131
Opaque data information usually continuous.
Definition: avutil.h:189
const char data[16]
Definition: mxf.c:70
const MXFCodecUL ff_mxf_codec_uls[]
Definition: mxf.c:34
packed RGB 5:5:5, 16bpp, (msb)1A 5R 5G 5B(lsb), big-endian, most significant bit to 0 ...
Definition: pixfmt.h:117
AVPixelFormat
Pixel format.
Definition: pixfmt.h:63
int ff_mxf_decode_pixel_layout(const char pixel_layout[16], enum AVPixelFormat *pix_fmt)
Definition: mxf.c:98
const MXFCodecUL ff_mxf_pixel_format_uls[]
Definition: mxf.c:62
AVRational av_sub_q(AVRational b, AVRational c) av_const
Subtract one rational from another.
Definition: rational.c:100
static const MXFSamplesPerFrame mxf_spf[]
Definition: mxf.c:112
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:97
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:113
#define FF_ARRAY_ELEMS(a)
Definition: common.h:61
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:84
const MXFCodecUL ff_mxf_data_definition_uls[]
SMPTE RP224 http://www.smpte-ra.org/mdd/index.html.
Definition: mxf.c:28
preferred ID for MPEG-1/2 video decoding
Definition: avcodec.h:110
int av_find_nearest_q_idx(AVRational q, const AVRational *q_list)
Find the nearest value in q_list to q.
Definition: rational.c:137
8 bit with PIX_FMT_RGB32 palette
Definition: pixfmt.h:76
NULL
Definition: eval.c:55
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:68
rational number numerator/denominator
Definition: rational.h:43
Definition: mxf.h:64
enum AVPixelFormat pix_fmt
Definition: mxf.c:69
packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0 ...
Definition: pixfmt.h:141
int den
denominator
Definition: rational.h:45
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:96
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:115