2 * Constants for DV codec
3 * Copyright (c) 2002 Fabrice Bellard
5 * This file is part of FFmpeg.
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.
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.
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
24 * Constants for DV codec.
27 #include "libavutil/rational.h"
28 #include "libavutil/intreadwrite.h"
29 #include "libavutil/pixdesc.h"
33 static DVwork_chunk work_chunks_dv25pal [1*12*27];
34 static DVwork_chunk work_chunks_dv25pal411[1*12*27];
35 static DVwork_chunk work_chunks_dv25ntsc [1*10*27];
36 static DVwork_chunk work_chunks_dv50pal [2*12*27];
37 static DVwork_chunk work_chunks_dv50ntsc [2*10*27];
38 static DVwork_chunk work_chunks_dv100palp [2*12*27];
39 static DVwork_chunk work_chunks_dv100ntscp[2*10*27];
40 static DVwork_chunk work_chunks_dv100pali [4*12*27];
41 static DVwork_chunk work_chunks_dv100ntsci[4*10*27];
43 static uint32_t dv_idct_factor_sd [2*2*22*64];
44 static uint32_t dv_idct_factor_hd1080[2*4*16*64];
45 static uint32_t dv_idct_factor_hd720 [2*4*16*64];
47 static const uint8_t dv_audio_shuffle525[10][9] = {
48 { 0, 30, 60, 20, 50, 80, 10, 40, 70 }, /* 1st channel */
49 { 6, 36, 66, 26, 56, 86, 16, 46, 76 },
50 { 12, 42, 72, 2, 32, 62, 22, 52, 82 },
51 { 18, 48, 78, 8, 38, 68, 28, 58, 88 },
52 { 24, 54, 84, 14, 44, 74, 4, 34, 64 },
54 { 1, 31, 61, 21, 51, 81, 11, 41, 71 }, /* 2nd channel */
55 { 7, 37, 67, 27, 57, 87, 17, 47, 77 },
56 { 13, 43, 73, 3, 33, 63, 23, 53, 83 },
57 { 19, 49, 79, 9, 39, 69, 29, 59, 89 },
58 { 25, 55, 85, 15, 45, 75, 5, 35, 65 },
61 static const uint8_t dv_audio_shuffle625[12][9] = {
62 { 0, 36, 72, 26, 62, 98, 16, 52, 88}, /* 1st channel */
63 { 6, 42, 78, 32, 68, 104, 22, 58, 94},
64 { 12, 48, 84, 2, 38, 74, 28, 64, 100},
65 { 18, 54, 90, 8, 44, 80, 34, 70, 106},
66 { 24, 60, 96, 14, 50, 86, 4, 40, 76},
67 { 30, 66, 102, 20, 56, 92, 10, 46, 82},
69 { 1, 37, 73, 27, 63, 99, 17, 53, 89}, /* 2nd channel */
70 { 7, 43, 79, 33, 69, 105, 23, 59, 95},
71 { 13, 49, 85, 3, 39, 75, 29, 65, 101},
72 { 19, 55, 91, 9, 45, 81, 35, 71, 107},
73 { 25, 61, 97, 15, 51, 87, 5, 41, 77},
74 { 31, 67, 103, 21, 57, 93, 11, 47, 83},
77 /* macroblock bit budgets */
78 static const uint8_t block_sizes_dv2550[8] = {
79 112, 112, 112, 112, 80, 80, 0, 0,
82 static const uint8_t block_sizes_dv100[8] = {
83 80, 80, 80, 80, 80, 80, 64, 64,
85 static const DVprofile dv_profiles[] = {
88 .frame_size = 120000, /* IEC 61834, SMPTE-314M - 525/60 (NTSC) */
91 .time_base = { 1001, 30000 },
95 .sar = {{8, 9}, {32, 27}},
96 .work_chunks = &work_chunks_dv25ntsc[0],
97 .idct_factor = &dv_idct_factor_sd[0],
98 .pix_fmt = PIX_FMT_YUV411P,
100 .block_sizes = block_sizes_dv2550,
102 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
103 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
104 .audio_shuffle = dv_audio_shuffle525,
108 .frame_size = 144000, /* IEC 61834 - 625/50 (PAL) */
111 .time_base = { 1, 25 },
115 .sar = {{16, 15}, {64, 45}},
116 .work_chunks = &work_chunks_dv25pal[0],
117 .idct_factor = &dv_idct_factor_sd[0],
118 .pix_fmt = PIX_FMT_YUV420P,
120 .block_sizes = block_sizes_dv2550,
122 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
123 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
124 .audio_shuffle = dv_audio_shuffle625,
128 .frame_size = 144000, /* SMPTE-314M - 625/50 (PAL) */
131 .time_base = { 1, 25 },
135 .sar = {{16, 15}, {64, 45}},
136 .work_chunks = &work_chunks_dv25pal411[0],
137 .idct_factor = &dv_idct_factor_sd[0],
138 .pix_fmt = PIX_FMT_YUV411P,
140 .block_sizes = block_sizes_dv2550,
142 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
143 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
144 .audio_shuffle = dv_audio_shuffle625,
148 .frame_size = 240000, /* SMPTE-314M - 525/60 (NTSC) 50 Mbps */
149 .difseg_size = 10, /* also known as "DVCPRO50" */
151 .time_base = { 1001, 30000 },
155 .sar = {{8, 9}, {32, 27}},
156 .work_chunks = &work_chunks_dv50ntsc[0],
157 .idct_factor = &dv_idct_factor_sd[0],
158 .pix_fmt = PIX_FMT_YUV422P,
160 .block_sizes = block_sizes_dv2550,
162 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
163 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
164 .audio_shuffle = dv_audio_shuffle525,
168 .frame_size = 288000, /* SMPTE-314M - 625/50 (PAL) 50 Mbps */
169 .difseg_size = 12, /* also known as "DVCPRO50" */
171 .time_base = { 1, 25 },
175 .sar = {{16, 15}, {64, 45}},
176 .work_chunks = &work_chunks_dv50pal[0],
177 .idct_factor = &dv_idct_factor_sd[0],
178 .pix_fmt = PIX_FMT_YUV422P,
180 .block_sizes = block_sizes_dv2550,
182 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
183 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
184 .audio_shuffle = dv_audio_shuffle625,
188 .frame_size = 480000, /* SMPTE-370M - 1080i60 100 Mbps */
189 .difseg_size = 10, /* also known as "DVCPRO HD" */
191 .time_base = { 1001, 30000 },
195 .sar = {{1, 1}, {3, 2}},
196 .work_chunks = &work_chunks_dv100ntsci[0],
197 .idct_factor = &dv_idct_factor_hd1080[0],
198 .pix_fmt = PIX_FMT_YUV422P,
200 .block_sizes = block_sizes_dv100,
202 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
203 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
204 .audio_shuffle = dv_audio_shuffle525,
208 .frame_size = 576000, /* SMPTE-370M - 1080i50 100 Mbps */
209 .difseg_size = 12, /* also known as "DVCPRO HD" */
211 .time_base = { 1, 25 },
215 .sar = {{1, 1}, {4, 3}},
216 .work_chunks = &work_chunks_dv100pali[0],
217 .idct_factor = &dv_idct_factor_hd1080[0],
218 .pix_fmt = PIX_FMT_YUV422P,
220 .block_sizes = block_sizes_dv100,
222 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
223 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
224 .audio_shuffle = dv_audio_shuffle625,
228 .frame_size = 240000, /* SMPTE-370M - 720p60 100 Mbps */
229 .difseg_size = 10, /* also known as "DVCPRO HD" */
231 .time_base = { 1001, 60000 },
235 .sar = {{1, 1}, {4, 3}},
236 .work_chunks = &work_chunks_dv100ntscp[0],
237 .idct_factor = &dv_idct_factor_hd720[0],
238 .pix_fmt = PIX_FMT_YUV422P,
240 .block_sizes = block_sizes_dv100,
242 .audio_min_samples = { 1580, 1452, 1053 }, /* for 48, 44.1 and 32kHz */
243 .audio_samples_dist = { 1600, 1602, 1602, 1602, 1602 }, /* per SMPTE-314M */
244 .audio_shuffle = dv_audio_shuffle525,
248 .frame_size = 288000, /* SMPTE-370M - 720p50 100 Mbps */
249 .difseg_size = 12, /* also known as "DVCPRO HD" */
251 .time_base = { 1, 50 },
255 .sar = {{1, 1}, {4, 3}},
256 .work_chunks = &work_chunks_dv100palp[0],
257 .idct_factor = &dv_idct_factor_hd720[0],
258 .pix_fmt = PIX_FMT_YUV422P,
260 .block_sizes = block_sizes_dv100,
262 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
263 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
264 .audio_shuffle = dv_audio_shuffle625,
268 .frame_size = 144000, /* IEC 61883-5 - 625/50 (PAL) */
271 .time_base = { 1, 25 },
275 .sar = {{16, 15}, {64, 45}},
276 .work_chunks = &work_chunks_dv25pal[0],
277 .idct_factor = &dv_idct_factor_sd[0],
278 .pix_fmt = PIX_FMT_YUV420P,
280 .block_sizes = block_sizes_dv2550,
282 .audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
283 .audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
284 .audio_shuffle = dv_audio_shuffle625,
288 const DVprofile* avpriv_dv_frame_profile2(AVCodecContext* codec, const DVprofile *sys,
289 const uint8_t* frame, unsigned buf_size)
293 if(buf_size < DV_PROFILE_BYTES)
296 dsf = (frame[3] & 0x80) >> 7;
297 stype = frame[80 * 5 + 48 + 3] & 0x1f;
299 /* 576i50 25Mbps 4:1:1 is a special case */
300 if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) {
301 return &dv_profiles[2];
304 if(stype == 0 && codec && codec->codec_tag==AV_RL32("dvsd") && codec->coded_width==720 && codec->coded_height==576)
305 return &dv_profiles[1];
307 for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++)
308 if (dsf == dv_profiles[i].dsf && stype == dv_profiles[i].video_stype)
309 return &dv_profiles[i];
311 /* check if old sys matches and assumes corrupted input */
312 if (sys && buf_size == sys->frame_size)
315 /* hack for trac issue #217, dv files created with QuickTime 3 */
316 if ((frame[3] & 0x7f) == 0x3f && frame[80 * 5 + 48 + 3] == 0xff)
317 return &dv_profiles[dsf];
322 const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys,
323 const uint8_t* frame, unsigned buf_size)
325 return avpriv_dv_frame_profile2(NULL, sys, frame, buf_size);
328 const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec)
333 if (codec->coded_width || codec->coded_height) {
334 w = codec->coded_width;
335 h = codec->coded_height;
341 for (i=0; i<FF_ARRAY_ELEMS(dv_profiles); i++)
342 if (h == dv_profiles[i].height &&
343 codec->pix_fmt == dv_profiles[i].pix_fmt &&
344 w == dv_profiles[i].width)
345 return &dv_profiles[i];
350 void ff_dv_print_profiles(void *logctx, int loglevel)
353 for (i = 0; i < FF_ARRAY_ELEMS(dv_profiles); i++) {
354 const DVprofile *p = &dv_profiles[i];
355 av_log(logctx, loglevel, "Frame size: %dx%d; pixel format: %s, "
356 "framerate: %d/%d\n", p->width, p->height, av_get_pix_fmt_name(p->pix_fmt),
357 p->time_base.den, p->time_base.num);