45#define MAX_AUDIO_FRAME_SIZE 192000
62 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
63 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
64 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
65 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
66 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
67 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
68 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
69 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
70 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
71 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
72 { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
73 { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
87 if (sample_rate == 32000)
return 1280;
88 else if (sample_rate == 44100)
return 1764;
105 buf[0] = (uint8_t)pack_id;
109 timecode |= 1<<23 | 1<<15 | 1<<7 | 1<<6;
113 if (
c->ast[
channel]->codecpar->sample_rate == 44100) {
115 }
else if (
c->ast[
channel]->codecpar->sample_rate == 32000)
120 c->sys->audio_min_samples[audio_type]);
125 (seq >=
c->sys->difseg_size/2);
147 c->sys->ltc_divisor * 4);
159 ((tc.tm_mday / 10) << 4) |
162 ((tc.tm_mon / 10) << 4) |
164 buf[4] = (((tc.tm_year % 100) / 10) << 4) |
175 ((tc.tm_sec / 10) << 4) |
178 ((tc.tm_min / 10) << 4) |
181 ((tc.tm_hour / 10) << 4) |
185 buf[1] = buf[2] = buf[3] = buf[4] = 0xff;
192 int i, j, d, of,
size;
194 frame_ptr +=
channel *
c->sys->difseg_size * 150 * 80;
195 for (
i = 0;
i <
c->sys->difseg_size;
i++) {
197 for (j = 0; j < 9; j++) {
199 for (d = 8; d < 80; d+=2) {
200 of =
c->sys->audio_shuffle[
i][j] + (d - 8)/2 *
c->sys->audio_stride;
206 FFSWAP(uint8_t, frame_ptr[d], frame_ptr[d + 1]);
208 frame_ptr += 16 * 80;
219 for (buf =
frame; buf <
frame +
c->sys->frame_size; buf += 150 * 80, seq++) {
221 for (j = 80; j < 80 * 3; j += 80) {
222 for (k = 6; k < 6 * 8; k += 8)
225 if (((
long)(buf-
frame)/(
c->sys->frame_size/(
c->sys->difseg_size*
c->sys->n_difchan))%
c->sys->difseg_size) > 5) {
234 for (j = 80*3 + 3; j < 80*6; j += 80) {
249 const uint8_t *
data,
int data_size, uint8_t **
frame)
253 *
frame = &
c->frame_buf[0];
259 av_log(
s,
AV_LOG_ERROR,
"Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n",
c->frames);
262 if (data_size !=
c->sys->frame_size) {
264 data_size,
c->sys->frame_size);
272 for (
i = 0;
i <
c->n_ast && st !=
c->ast[
i];
i++);
276 av_log(
s,
AV_LOG_ERROR,
"Can't process DV frame #%d. Insufficient video data or severe sync problem.\n",
c->frames);
292 if (
c->has_video == 1 &&
c->has_audio + 1 == 1 <<
c->n_ast) {
295 for (
i=0;
i <
c->n_ast;
i++) {
306 return c->sys->frame_size;
318 if (
s->nb_streams > 5) {
320 "Invalid number of streams %d, the muxer supports at most 1 video channel and 4 audio channels.\n",
326 for (
i=0;
i<
s->nb_streams;
i++) {
332 "More than one video stream found, only one is accepted.\n");
337 "Invalid codec for video stream, only DVVIDEO is supported.\n");
345 "More than two audio streams found, at most 2 are accepted.\n");
351 "Invalid codec for stream %d, only PCM_S16LE is supported\n.",
i);
356 "Invalid number of audio channels %d for stream %d, only 2 channels are supported\n.",
364 "Invalid audio sample rate %d for stream %d, only 32000, 44100, and 48000 are supported.\n",
368 c->ast[
c->n_ast++] = st;
372 "Invalid media type for stream %d, only audio and video are supported.\n",
i);
379 "Missing video stream, must be present\n");
387 "Could not find a valid video profile for size:%dx%d format:%s tb:%d%d\n",
394 if ((
c->sys->time_base.den != 25 &&
c->sys->time_base.den != 50) ||
c->sys->time_base.num != 1) {
395 for (
i = 0;
i < 2;
i++) {
396 if (
c->ast[
i] &&
c->ast[
i]->codecpar->sample_rate != 48000) {
398 "Invalid sample rate %d for audio stream #%d for this video profile, must be 48000.\n",
399 c->ast[
i]->codecpar->sample_rate,
i);
405 for (
i = 1;
i < 2;
i++) {
406 if (((
c->n_ast >
i) && (
c->sys->n_difchan < (2 *
i)))) {
407 const char *
mode =
c->n_ast > 1 ?
"50Mps" :
"25Mps";
409 "Invalid number of channels %d, only %d stereo pairs is allowed in %s mode.\n",
421 for (
i=0;
i <
c->n_ast;
i++) {
425 if (!
c->audio_data[
i]) {
441 "Make sure that you supply at least two streams:\n"
442 " video: 25fps or 29.97fps, audio: 2ch/48|44.1|32kHz/PCM\n"
443 " (50Mbps allows an optional second audio stream)\n");
450 for (
i = 0;
i <
s->nb_streams;
i++) {
485 for (
int i = 0;
i <
c->n_ast;
i++)
492 .p.extensions =
"dv",
static int64_t fsize(FILE *f)
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void avio_write(AVIOContext *s, const unsigned char *buf, int size)
#define i(width, name, range_min, range_max)
const AVDVProfile * av_dv_codec_profile2(int width, int height, enum AVPixelFormat pix_fmt, AVRational frame_rate)
Get a DV profile for the provided stream parameters.
channel
Use these values when setting the channel map with ebur128_set_channel().
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
AVFifo * av_fifo_alloc2(size_t nb_elems, size_t elem_size, unsigned int flags)
Allocate and initialize an AVFifo with a given element size.
void av_fifo_freep2(AVFifo **f)
Free an AVFifo and reset pointer to NULL.
size_t av_fifo_can_write(const AVFifo *f)
size_t av_fifo_can_read(const AVFifo *f)
int av_fifo_peek(const AVFifo *f, void *buf, size_t nb_elems, size_t offset)
Read data from a FIFO without modifying FIFO state.
int av_fifo_write(AVFifo *f, const void *buf, size_t nb_elems)
Write data into a FIFO.
void av_fifo_drain2(AVFifo *f, size_t size)
Discard the specified amount of data from an AVFifo.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
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.
@ AV_ROUND_DOWN
Round toward -infinity.
#define DV_MAX_FRAME_SIZE
largest possible DV frame, in bytes (1080i50)
#define DV_PROFILE_IS_HD(p)
static int dv_write_pack(enum DVPackType pack_id, DVEncContext *c, uint8_t *buf)
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
#define FFSWAP(type, a, b)
#define FF_OFMT_FLAG_ONLY_DEFAULT_CODECS
If this flag is set, then the only permitted audio/video/subtitle codec ids are AVOutputFormat....
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.
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
int nb_channels
Number of channels in this layout.
Describe the class of an AVClass context structure.
int height
The height of the video frame in pixels.
AVChannelLayout ch_layout
The channel layout and number of channels.
int width
The width of the video frame in pixels.
enum AVMediaType codec_type
General type of the encoded data.
enum AVCodecID codec_id
Specific type of the encoded data (the codec used).
int sample_rate
The number of audio samples per second.
int audio_samples_dist[5]
This structure stores compressed data.
Rational number (pair of numerator and denominator).
AVCodecParameters * codecpar
Codec parameters associated with this stream.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
uint8_t frame_buf[DV_MAX_FRAME_SIZE]
int av_timecode_init_from_string(AVTimecode *tc, AVRational rate, const char *str, void *log_ctx)
Parse timecode representation (hh:mm:ss[:;.
int av_timecode_init(AVTimecode *tc, AVRational rate, int flags, int frame_start, void *log_ctx)
Init a timecode struct with the passed parameters.
uint32_t av_timecode_get_smpte_from_framenum(const AVTimecode *tc, int framenum)
Convert frame number to SMPTE 12M binary representation.