Commit e0a8e2bd1f for ffmpeg
commit e0a8e2bd1fef53642a7bd8d1c1b1cdb38131e146
Author: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Date: Sun Nov 22 00:32:35 2026 -0800
dv: align encoding and muxing with SMPTE and IEC
Write the required VAUX, AAUX and subcode packs, rebuild invalid
subcode and set SMPTE DIF validity flags. Keep compatibility copies
of timecode in SSYBs 0 and 6. Number regenerated IEC SSYBs by slot,
including blank and partial IDs, while preserving the other ID bits
and TF3. Use legal DV100 quantizer steps.
Carry 720p audio and timecode across pairs. The 720p50 shuffle stride
is 108 PCM words. Older FFmpeg files written with stride 90 can decode
to different PCM.
Co-authored-by: Michael Niedermayer <michael@niedermayer.cc>
Assisted-by: Fairy
Signed-off-by: Baptiste Coudurier <baptiste.coudurier@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
diff --git a/doc/muxers.texi b/doc/muxers.texi
index a585bfe75c..c565420cb8 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1464,10 +1464,16 @@ versions audio is automatically packetized to 36000 byte (2000 sample) packets.
@section dv
DV (Digital Video) muxer.
-It accepts exactly one @samp{dvvideo} video stream and at most two
-@samp{pcm_s16} audio streams. More constraints are defined by the
-property of the video, which must correspond to a DV video supported
-profile, and on the framerate.
+It accepts exactly one @samp{dvvideo} video stream and optional stereo
+@samp{pcm_s16le} audio streams. The video profile determines the audio
+limit: one stereo pair for DV25, two for DVCPRO50, and four for DVCPRO HD.
+Audio must be 48 kHz except for 625/50 4:2:0, which also accepts 32 kHz
+and 44.1 kHz. Supplied PCM replaces any audio embedded in the video packets.
+
+When audio streams are supplied with 720p video, the first picture must
+carry DIF channels 0 and 1, and the pictures must alternate between the
+two channel pairs. With three or four stereo streams, the last audio from
+every stream requires both pictures of the final pair.
@subsection Example
Use @command{ffmpeg} to convert the input:
diff --git a/libavcodec/dv.h b/libavcodec/dv.h
index 7c925ae971..f3788f7f31 100644
--- a/libavcodec/dv.h
+++ b/libavcodec/dv.h
@@ -41,6 +41,7 @@ enum DVPackType {
DV_HEADER525 = 0x3f, /* see dv_write_pack for important details on */
DV_HEADER625 = 0xbf, /* these two packs */
DV_TIMECODE = 0x13,
+ DV_BINARY_GROUP = 0x14,
DV_AUDIO_SOURCE = 0x50,
DV_AUDIO_CONTROL = 0x51,
DV_AUDIO_RECDATE = 0x52,
@@ -52,6 +53,17 @@ enum DVPackType {
DV_UNKNOWN_PACK = 0xff,
};
+static inline void ff_dv_write_ssyb_id(uint8_t *buf, int number, int first_half,
+ int apt, int ap3)
+{
+ /* AP3 in SSYBs 0 and 6, APT in 11, reserved elsewhere. */
+ int id = number == 0 || number == 6 ? ap3 : number == 11 ? apt : 7;
+
+ buf[0] = (first_half << 7) | (id << 4) | 0x0f;
+ buf[1] = 0xf0 | number;
+ buf[2] = 0xff;
+}
+
/**
* Check the display select mode of a VAUX source control pack for 16:9.
*
diff --git a/libavcodec/dv_profile.c b/libavcodec/dv_profile.c
index 02ece47e01..f4ec8896f4 100644
--- a/libavcodec/dv_profile.c
+++ b/libavcodec/dv_profile.c
@@ -221,7 +221,7 @@ static const AVDVProfile dv_profiles[] = {
.pix_fmt = AV_PIX_FMT_YUV422P,
.bpm = 8,
.block_sizes = block_sizes_dv100,
- .audio_stride = 90,
+ .audio_stride = 108, /* interleaved 16-bit PCM words, as for 1080i50 */
.audio_min_samples = { 1896, 1742, 1264 }, /* for 48, 44.1 and 32kHz */
.audio_samples_dist = { 1920, 1920, 1920, 1920, 1920 },
.audio_shuffle = dv_audio_shuffle625, },
diff --git a/libavcodec/dvenc.c b/libavcodec/dvenc.c
index b58e300048..ab26e1b290 100644
--- a/libavcodec/dvenc.c
+++ b/libavcodec/dvenc.c
@@ -334,8 +334,7 @@ static const uint8_t dv100_qlevels[DV100_NUM_QLEVELS] = {
DV100_MAKE_QLEVEL(11,2), // 20*4=80
DV100_MAKE_QLEVEL(12,2), // 22*4=88
DV100_MAKE_QLEVEL(13,2), // 24*4=96
- // ...
- DV100_MAKE_QLEVEL(15,3), // 52*8=416
+ DV100_MAKE_QLEVEL(14,2), // 28*4=112, coarsest step allowed by SMPTE 370M Table 26
};
static const int dv100_min_bias = 0;
@@ -637,12 +636,29 @@ static int dv100_actual_quantize(EncBlockInfo *b, int qlevel)
return b->bit_size[0];
}
+/* Unlink small AC coefficients and recalculate VLC costs, including EOB. */
+static int dv_prune_ac(EncBlockInfo *b, int threshold, int prev)
+{
+ int size = 4;
+
+ for (int k = b->next[prev]; k < 64; k = b->next[k]) {
+ if (b->mb[k] < threshold && b->mb[k] > -threshold) {
+ b->next[prev] = b->next[k];
+ } else {
+ size += dv_rl2vlc_size(k - prev - 1, b->mb[k]);
+ prev = k;
+ }
+ }
+ return size;
+}
+
static inline void dv_guess_qnos_hd(EncBlockInfo *blks, int *qnos)
{
EncBlockInfo *b;
int min_qlevel[5];
int qlevels[5];
int size[5];
+ int total = 0;
int i, j;
/* cache block sizes at hypothetical qlevels */
uint16_t size_cache[5*8][DV100_NUM_QLEVELS] = {{0}};
@@ -769,13 +785,16 @@ static inline void dv_guess_qnos_hd(EncBlockInfo *blks, int *qnos)
/* now do the actual quantization */
for (i = 0; i < 5; i++) {
- /* for each block */
b = &blks[8*i];
- size[i] = 0;
- for (j = 0; j < 8; j++, b++) {
- /* accumulate block size into macroblock */
- size[i] += dv100_actual_quantize(b, qlevels[i]);
- } /* for each block */
+ for (j = 0; j < 8; j++, b++)
+ total += dv100_actual_quantize(b, qlevels[i]);
+ }
+
+ /* the coarsest step can still overflow, drop small AC coefficients */
+ for (int a = 2; total > vs_total_ac_bits_hd; a += a) {
+ total = 0;
+ for (i = 0; i < 5 * 8; i++)
+ total += dv_prune_ac(&blks[i], a, 0);
}
}
@@ -836,18 +855,9 @@ static inline void dv_guess_qnos(EncBlockInfo *blks, int *qnos)
for (a = 2; a == 2 || vs_total_ac_bits < size[0]; a += a) {
b = blks;
- size[0] = 5 * 6 * 4; // EOB
- for (j = 0; j < 6 * 5; j++, b++) {
- prev = b->prev[0];
- for (k = b->next[prev]; k < 64; k = b->next[k]) {
- if (b->mb[k] < a && b->mb[k] > -a) {
- b->next[prev] = b->next[k];
- } else {
- size[0] += dv_rl2vlc_size(k - prev - 1, b->mb[k]);
- prev = k;
- }
- }
- }
+ size[0] = 0;
+ for (j = 0; j < 6 * 5; j++, b++)
+ size[0] += dv_prune_ac(b, a, b->prev[0]);
}
}
@@ -1021,7 +1031,7 @@ static int dv_encode_video_segment(AVCodecContext *avctx, void *arg)
return 0;
}
-static inline int dv_write_pack(enum DVPackType pack_id, DVEncContext *c,
+static inline int dv_write_pack(enum DVPackType pack_id, DVEncContext *c, int apt,
uint8_t *buf)
{
/*
@@ -1043,7 +1053,6 @@ static inline int dv_write_pack(enum DVPackType pack_id, DVEncContext *c,
* compression scheme (if any).
*/
uint8_t aspect = 0;
- int apt = (c->sys->pix_fmt == AV_PIX_FMT_YUV420P ? 0 : 1);
int fs;
if (c->avctx->height >= 720)
@@ -1063,7 +1072,7 @@ static inline int dv_write_pack(enum DVPackType pack_id, DVEncContext *c,
case DV_HEADER625: /* packs in SMPTE314M -- they definitely look like ones */
buf[1] = 0xf8 | /* reserved -- always 1 */
(apt & 0x07); /* APT: Track application ID */
- buf[2] = (0 << 7) | /* TF1: audio data is 0 - valid; 1 - invalid */
+ buf[2] = (apt << 7) | /* TF1: SMPTE video-only output has no audio */
(0x0f << 3) | /* reserved -- always 1 */
(apt & 0x07); /* AP1: Audio application ID */
buf[3] = (0 << 7) | /* TF2: video data is 0 - valid; 1 - invalid */
@@ -1082,7 +1091,9 @@ static inline int dv_write_pack(enum DVPackType pack_id, DVEncContext *c,
buf[3] = (3 << 6) | /* reserved -- always 1 */
(c->sys->dsf << 5) | /* system: 60fields/50fields */
c->sys->video_stype; /* signal type video compression */
- buf[4] = 0xff; /* VISC: 0xff -- no information */
+ /* SMPTE 314M: VISC unavailable. SMPTE 370M: 0 and reserved ones.
+ * IEC 61834: tuner category unavailable. */
+ buf[4] = apt ? 0x7f : 0xff;
break;
case DV_VIDEO_CONTROL:
buf[1] = (0 << 6) | /* Copy generation management (CGMS) 0 -- free */
@@ -1092,7 +1103,7 @@ static inline int dv_write_pack(enum DVPackType pack_id, DVEncContext *c,
buf[3] = (1 << 7) | /* frame/field flag 1 -- frame, 0 -- field */
fs | /* first/second field flag 0 -- field 2, 1 -- field 1 */
(1 << 5) | /* frame change flag 0 -- same picture as before, 1 -- different */
- (1 << 4) | /* 1 - interlaced, 0 - noninterlaced */
+ (1 << 4) | /* SD: interlaced; SMPTE 370M: reserved */
0xc; /* reserved -- always b1100 */
buf[4] = 0xff; /* reserved -- always 1 */
break;
@@ -1121,31 +1132,13 @@ static inline int dv_write_dif_id(enum DVSectionType t, uint8_t chan_num,
return 3;
}
-static inline int dv_write_ssyb_id(uint8_t syb_num, uint8_t fr, uint8_t *buf)
-{
- if (syb_num == 0 || syb_num == 6) {
- buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */
- (0 << 4) | /* AP3 (Subcode application ID) */
- 0x0f; /* reserved -- always 1 */
- } else if (syb_num == 11) {
- buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */
- 0x7f; /* reserved -- always 1 */
- } else {
- buf[0] = (fr << 7) | /* FR ID 1 - first half of each channel; 0 - second */
- (0 << 4) | /* APT (Track application ID) */
- 0x0f; /* reserved -- always 1 */
- }
- buf[1] = 0xf0 | /* reserved -- always 1 */
- (syb_num & 0x0f); /* SSYB number 0 - 11 */
- buf[2] = 0xff; /* reserved -- always 1 */
- return 3;
-}
-
static void dv_format_frame(DVEncContext *c, uint8_t *buf)
{
int chan, i, j, k;
/* We work with 720p frames split in half. The odd half-frame is chan 2,3 */
int chan_offset = 2*(c->sys->height == 720 && c->avctx->frame_num & 1);
+ /* Track application ID 0 for IEC 61834 and 1 for SMPTE 314M/370M. */
+ int apt = c->sys->pix_fmt != AV_PIX_FMT_YUV420P;
for (chan = 0; chan < c->sys->n_difchan; chan++) {
for (i = 0; i < c->sys->difseg_size; i++) {
@@ -1154,26 +1147,28 @@ static void dv_format_frame(DVEncContext *c, uint8_t *buf)
/* DV header: 1DIF */
buf += dv_write_dif_id(DV_SECT_HEADER, chan+chan_offset, i, 0, buf);
buf += dv_write_pack((c->sys->dsf ? DV_HEADER625 : DV_HEADER525),
- c, buf);
+ c, apt, buf);
buf += 72; /* unused bytes */
- /* DV subcode: 2DIFs */
+ /* DV subcode: 2DIFs, SSYB 0-5 and 6-11 */
for (j = 0; j < 2; j++) {
buf += dv_write_dif_id(DV_SECT_SUBCODE, chan+chan_offset, i, j, buf);
- for (k = 0; k < 6; k++)
- buf += dv_write_ssyb_id(k, (i < c->sys->difseg_size / 2), buf) + 5;
+ for (k = 0; k < 6; k++, buf += 8)
+ ff_dv_write_ssyb_id(buf, j * 6 + k, i < c->sys->difseg_size / 2,
+ apt, apt);
buf += 29; /* unused bytes */
}
- /* DV VAUX: 3DIFS */
+ /* DV VAUX: 3DIFS, the VS and VSC packs are pack numbers 39 and 40
+ * in even DIF sequences, 0 and 1 in odd ones */
for (j = 0; j < 3; j++) {
buf += dv_write_dif_id(DV_SECT_VAUX, chan+chan_offset, i, j, buf);
- buf += dv_write_pack(DV_VIDEO_SOURCE, c, buf);
- buf += dv_write_pack(DV_VIDEO_CONTROL, c, buf);
- buf += 7 * 5;
- buf += dv_write_pack(DV_VIDEO_SOURCE, c, buf);
- buf += dv_write_pack(DV_VIDEO_CONTROL, c, buf);
- buf += 4 * 5 + 2; /* unused bytes */
+ if (j == (i & 1 ? 0 : 2)) {
+ uint8_t *pack = buf + (i & 1 ? 0 : 9 * 5);
+ dv_write_pack(DV_VIDEO_SOURCE, c, apt, pack);
+ dv_write_pack(DV_VIDEO_CONTROL, c, apt, pack + 5);
+ }
+ buf += 15 * 5 + 2;
}
/* DV Audio/Video: 135 Video DIFs + 9 Audio DIFs */
diff --git a/libavformat/dvenc.c b/libavformat/dvenc.c
index 773c05d394..5b9a17ce5c 100644
--- a/libavformat/dvenc.c
+++ b/libavformat/dvenc.c
@@ -39,38 +39,52 @@
#include "libavutil/fifo.h"
#include "libavutil/mathematics.h"
#include "libavutil/intreadwrite.h"
+#include "libavutil/intmath.h"
#include "libavutil/pixdesc.h"
#include "libavutil/timecode.h"
-#define MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32-bit audio
+#define DV_AUDIO_FRAME_BYTES (4 * 1920) /* Maximum PCM bytes per stereo pair */
+#define DV_AUDIO_FIFO_LIMIT (100 * 48000 * 4) /* 100 seconds of stereo PCM at 48 kHz */
typedef struct DVMuxContext {
AVClass *av_class;
const AVDVProfile* sys; /* current DV profile, e.g.: 525/60, 625/50 */
- int n_ast; /* number of stereo audio streams (up to 2) */
- AVStream *ast[4]; /* stereo audio streams */
+ int n_ast; /* number of stereo audio streams (up to 4) */
+ AVStream *ast[4]; /* stereo audio streams, one per DIF channel */
AVFifo *audio_data[4]; /* FIFO for storing excessive amounts of PCM */
- int frames; /* current frame number */
+ int frames; /* number of DV frames written */
+ int smpte; /* SMPTE 314M/370M (APT != 0) or IEC 61834 data layout */
int64_t start_time; /* recording start time */
- int has_audio; /* frame under construction has audio */
- int has_video; /* frame under construction has video */
- uint8_t frame_buf[DV_MAX_FRAME_SIZE]; /* frame under construction */
+ int has_video; /* number of queued video frames */
+ int pair_phase; /* initial 720p picture: 0 for channels 0-1, 1 for 2-3 */
+ uint8_t frame_buf[DV_MAX_FRAME_SIZE]; /* queued video frames */
+ uint8_t pcm[DV_AUDIO_FRAME_BYTES]; /* linearized PCM for one DIF channel */
AVTimecode tc; /* timecode context */
} DVMuxContext;
-static const int dv_aaux_packs_dist[12][9] = {
- { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
- { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
- { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
- { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
- { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
- { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
- { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
- { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
- { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
- { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
- { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff },
- { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff },
+/* AAUX packs, IEC 61834 main area: source, source control, rec date, rec time */
+static const uint8_t dv_aaux_packs_iec[2][9] = {
+ { 0xff, 0xff, 0xff, 0x50, 0x51, 0x52, 0x53, 0xff, 0xff }, /* even DIF sequence */
+ { 0x50, 0x51, 0x52, 0x53, 0xff, 0xff, 0xff, 0xff, 0xff }, /* odd DIF sequence */
+};
+
+/* AAUX packs, SMPTE 314M Table 15 and 370M Table 18, the others are reserved */
+static const uint8_t dv_aaux_packs_smpte[2][9] = {
+ { 0xff, 0xff, 0xff, 0x50, 0x51, 0xff, 0xff, 0xff, 0xff },
+ { 0x50, 0x51, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff },
+};
+
+/* Subcode packs per SSYB number */
+static const uint8_t dv_ssyb_packs_iec[2][12] = {
+ { 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13, 0x13 }, /* first half */
+ { 0x13, 0x62, 0x63, 0x13, 0x62, 0x63, 0x13, 0x62, 0x63, 0x13, 0x62, 0x63 }, /* second half */
+};
+
+/* SMPTE 314M Table 9 and 370M Table 10, plus a time code pack in the
+ * reserved SSYB 0 and 6, the only ones Apple and older readers look at */
+static const uint8_t dv_ssyb_packs_smpte[2][12] = {
+ { 0x13, 0xff, 0xff, 0x13, 0x14, 0x13, 0x13, 0xff, 0xff, 0x13, 0x14, 0x13 },
+ { 0x13, 0xff, 0xff, 0x13, 0xff, 0xff, 0x13, 0xff, 0xff, 0x13, 0xff, 0xff },
};
static void brktimegm(time_t secs, struct tm *tm)
@@ -83,70 +97,64 @@ static void brktimegm(time_t secs, struct tm *tm)
static int dv_audio_frame_size(const AVDVProfile* sys, int frame, int sample_rate)
{
- if ((sys->time_base.den == 25 || sys->time_base.den == 50) && sys->time_base.num == 1) {
- if (sample_rate == 32000) return 1280;
- else if (sample_rate == 44100) return 1764;
- else return 1920;
- }
+ if (sys->dsf)
+ return sample_rate / 25;
av_assert0(sample_rate == 48000);
- return sys->audio_samples_dist[frame % (sizeof(sys->audio_samples_dist) /
- sizeof(sys->audio_samples_dist[0]))];
+ return sys->audio_samples_dist[frame % FF_ARRAY_ELEMS(sys->audio_samples_dist)];
+}
+
+static void dv_write_audio_source(const DVMuxContext *c, uint8_t *buf,
+ int sample_rate, int samples, int second_half)
+{
+ int audio_type = sample_rate == 32000 ? 2 : sample_rate == 44100;
+
+ buf[0] = DV_AUDIO_SOURCE;
+ buf[1] = ((audio_type == 1) << 7) | /* 44.1 kHz is unlocked */
+ (1 << 6) | /* reserved */
+ (samples - c->sys->audio_min_samples[audio_type]);
+ buf[2] = (c->smpte << 4) | /* IEC pair bit, reserved in SMPTE */
+ second_half; /* first or second channel */
+ buf[3] = (3 << 6) | (c->sys->dsf << 5) |
+ (DV_PROFILE_IS_HD(c->sys) ? 3 : c->sys->video_stype ? 2 : 0);
+ buf[4] = (3 << 6) | (audio_type << 3); /* 16-bit linear audio */
}
-static int dv_write_pack(enum DVPackType pack_id, DVMuxContext *c, uint8_t* buf, int channel, int seq)
+static void dv_write_pack(enum DVPackType pack_id, DVMuxContext *c, uint8_t *buf,
+ uint32_t timecode)
{
struct tm tc;
time_t ct;
- uint32_t timecode;
- int audio_type = 0;
buf[0] = (uint8_t)pack_id;
switch (pack_id) {
case DV_TIMECODE:
- timecode = av_timecode_get_smpte_from_framenum(&c->tc, c->frames);
- timecode |= 1<<23 | 1<<15 | 1<<7 | 1<<6; // biphase and binary group flags
AV_WB32(buf + 1, timecode);
break;
- case DV_AUDIO_SOURCE: /* AAUX source pack */
- if (c->ast[channel]->codecpar->sample_rate == 44100) {
- audio_type = 1;
- } else if (c->ast[channel]->codecpar->sample_rate == 32000)
- audio_type = 2;
- buf[1] = (1 << 7) | /* locked mode -- SMPTE only supports locked mode */
- (1 << 6) | /* reserved -- always 1 */
- (dv_audio_frame_size(c->sys, c->frames, c->ast[channel]->codecpar->sample_rate) -
- c->sys->audio_min_samples[audio_type]);
- /* # of samples */
- buf[2] = (0 << 7) | /* multi-stereo */
- (0 << 5) | /* #of audio channels per block: 0 -- 1 channel */
- (0 << 4) | /* pair bit: 0 -- one pair of channels */
- (seq >= c->sys->difseg_size/2); /* audio mode (1st or 2nd channel) */
- buf[3] = (1 << 7) | /* res */
- (1 << 6) | /* multi-language flag */
- (c->sys->dsf << 5) | /* system: 60fields/50fields */
- (DV_PROFILE_IS_HD(c->sys) ? 0x3 : c->sys->video_stype ? 2 : 0); /* stype */
- buf[4] = (1 << 7) | /* emphasis: 1 -- off */
- (0 << 6) | /* emphasis time constant: 0 -- reserved */
- (audio_type << 3) | /* frequency: 0 -- 48kHz, 1 -- 44,1kHz, 2 -- 32kHz */
- 0; /* quantization: 0 -- 16-bit linear, 1 -- 12-bit nonlinear */
-
+ case DV_BINARY_GROUP:
+ AV_WB32(buf + 1, 0);
break;
case DV_AUDIO_CONTROL:
- buf[1] = (0 << 6) | /* copy protection: 0 -- unrestricted */
- (1 << 4) | /* input source: 1 -- digital input */
- (3 << 2) | /* compression: 3 -- no information */
- 0; /* misc. info/SMPTE emphasis off */
+ if (c->smpte) {
+ buf[1] = (0 << 6) | /* copy protection: 0 -- unrestricted */
+ 0x3c | /* reserved -- always 1 */
+ 0; /* EFC: 0 -- emphasis off */
+ } else {
+ buf[1] = (0 << 6) | /* copy protection: 0 -- unrestricted */
+ (1 << 4) | /* input source: 1 -- digital input */
+ (3 << 2) | /* compression: 3 -- no information */
+ 3; /* source situation: 3 -- no information */
+ }
buf[2] = (1 << 7) | /* recording start point: 1 -- no */
(1 << 6) | /* recording end point: 1 -- no */
- (1 << 3) | /* recording mode: 1 -- original */
- 7;
+ (1 << 3) | /* IEC recording mode: original; SMPTE reserved */
+ 7; /* IEC insert channel: none; SMPTE reserved */
buf[3] = (1 << 7) | /* direction: 1 -- forward */
- (c->sys->pix_fmt == AV_PIX_FMT_YUV420P ? 0x20 : /* speed */
- c->sys->ltc_divisor * 4);
- buf[4] = (1 << 7) | /* reserved -- always 1 */
- 0x7f; /* genre category */
+ (!c->smpte ? 0x20 : /* speed: normal */
+ c->sys->dsf ? 100 : 120); /* speed: 100/100 or 120/120 */
+ buf[4] = (1 << 7) | /* reserved in both layouts */
+ 0x7f; /* IEC genre category; SMPTE reserved */
break;
case DV_AUDIO_RECDATE:
case DV_VIDEO_RECDATE: /* VAUX recording date */
@@ -158,7 +166,7 @@ static int dv_write_pack(enum DVPackType pack_id, DVMuxContext *c, uint8_t* buf,
buf[2] = (3 << 6) | /* reserved -- always 1 */
((tc.tm_mday / 10) << 4) | /* Tens of day */
(tc.tm_mday % 10); /* Units of day */
- buf[3] = /* we set high 4 bits to 0, shouldn't we set them to week? */
+ buf[3] = (tc.tm_wday << 5) | /* Day of week */
((tc.tm_mon / 10) << 4) | /* Tens of month */
(tc.tm_mon % 10); /* Units of month */
buf[4] = (((tc.tm_year % 100) / 10) << 4) | /* Tens of year */
@@ -184,126 +192,243 @@ static int dv_write_pack(enum DVPackType pack_id, DVMuxContext *c, uint8_t* buf,
default:
buf[1] = buf[2] = buf[3] = buf[4] = 0xff;
}
- return 5;
}
-static void dv_inject_audio(DVMuxContext *c, int channel, uint8_t* frame_ptr)
+static void dv_inject_audio(DVMuxContext *c, int channel, int difchan, uint8_t* frame_ptr, int size)
{
- int i, j, d, of, size;
- size = 4 * dv_audio_frame_size(c->sys, c->frames, c->ast[channel]->codecpar->sample_rate);
- frame_ptr += channel * c->sys->difseg_size * 150 * 80;
- for (i = 0; i < c->sys->difseg_size; i++) {
+ const uint8_t (*packs)[9] = c->smpte ? dv_aaux_packs_smpte : dv_aaux_packs_iec;
+ int stride = 2 * c->sys->audio_stride;
+
+ /* dv_write_frame() has already checked that the entire unit is ready. */
+ av_assert0(size <= DV_AUDIO_FRAME_BYTES);
+ if (size)
+ av_fifo_peek(c->audio_data[channel], c->pcm, size, 0);
+
+ frame_ptr += difchan * c->sys->difseg_size * 150 * 80;
+ for (int i = 0; i < c->sys->difseg_size; i++) {
+ if (c->smpte)
+ frame_ptr[5] = (frame_ptr[5] & 0x7f) | (!size << 7); /* TF1 */
frame_ptr += 6 * 80; /* skip DIF segment header */
- for (j = 0; j < 9; j++) {
- dv_write_pack(dv_aaux_packs_dist[i][j], c, &frame_ptr[3], channel, i);
- for (d = 8; d < 80; d+=2) {
- of = c->sys->audio_shuffle[i][j] + (d - 8)/2 * c->sys->audio_stride;
- if (of*2 >= size)
- continue;
-
- // FIXME: maybe we have to admit that DV is a big-endian PCM
- av_fifo_peek(c->audio_data[channel], frame_ptr + d, 2, of * 2);
- FFSWAP(uint8_t, frame_ptr[d], frame_ptr[d + 1]);
+ for (int j = 0; j < 9; j++, frame_ptr += 16 * 80) {
+ int offset = 2 * c->sys->audio_shuffle[i][j];
+
+ /* Clear the old AAUX and PCM, including unused sample words. */
+ memset(frame_ptr + 3, 0xff, 77);
+ if (!size)
+ continue;
+
+ if (packs[i & 1][j] == DV_AUDIO_SOURCE)
+ dv_write_audio_source(c, frame_ptr + 3, c->ast[channel]->codecpar->sample_rate,
+ size / 4, i >= c->sys->difseg_size / 2);
+ else
+ dv_write_pack(packs[i & 1][j], c, frame_ptr + 3, 0);
+ for (int d = 8; d < 80 && offset < size; d += 2, offset += stride) {
+ unsigned sample = AV_RL16(c->pcm + offset);
+
+ AV_WB16(frame_ptr + d, sample == 0x8000 ? 0x8001 : sample);
}
- frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */
}
}
}
-static void dv_inject_metadata(DVMuxContext *c, uint8_t* frame)
+static void dv_inject_metadata(DVMuxContext *c, uint8_t *frame, int frame_num)
{
+ const uint8_t (*ssyb_packs)[12] = c->smpte ? dv_ssyb_packs_smpte : dv_ssyb_packs_iec;
+ uint32_t timecode = av_timecode_get_smpte_from_framenum(&c->tc, frame_num);
int j, k;
uint8_t* buf;
- int seq = 0;
-
- for (buf = frame; buf < frame + c->sys->frame_size; buf += 150 * 80, seq++) {
- /* DV subcode: 2nd and 3d DIFs */
- for (j = 80; j < 80 * 3; j += 80) {
- for (k = 6; k < 6 * 8; k += 8)
- dv_write_pack(DV_TIMECODE, c, &buf[j+k], 0, seq);
-
- if (((long)(buf-frame)/(c->sys->frame_size/(c->sys->difseg_size*c->sys->n_difchan))%c->sys->difseg_size) > 5) { /* FIXME: is this really needed ? */
- dv_write_pack(DV_VIDEO_RECDATE, c, &buf[j+14], 0, seq);
- dv_write_pack(DV_VIDEO_RECTIME, c, &buf[j+22], 0, seq);
- dv_write_pack(DV_VIDEO_RECDATE, c, &buf[j+38], 0, seq);
- dv_write_pack(DV_VIDEO_RECTIME, c, &buf[j+46], 0, seq);
+ int seq;
+
+ if (c->smpte)
+ /* LTC polarity correction, with zero binary groups (ST 12-1 9.2.3). */
+ timecode |= (1U ^ (av_popcount(timecode) & 1)) << (c->sys->dsf ? 7 : 23);
+ else /* IEC 61834-4 title time code: BF, reserved bits and the PAL arbitrary bit. */
+ timecode |= 1U<<31 | c->sys->dsf<<30 | 1<<23 | 1<<15 | 1<<7 | 1<<6;
+
+ for (buf = frame; buf < frame + c->sys->frame_size; buf += 150 * 80) {
+ int rebuild = c->smpte && (buf[7] & 0x80); /* TF3 */
+ int second_half;
+
+ seq = (buf[1] >> 4) % c->sys->difseg_size;
+ second_half = seq >= c->sys->difseg_size / 2;
+
+ /* DV subcode: 2nd and 3d DIFs, SSYB 0-5 and 6-11 */
+ for (j = 0; j < 2; j++) {
+ uint8_t *block = buf + 80 * (j + 1);
+
+ if (rebuild) {
+ block[0] = DV_SECT_SUBCODE;
+ block[1] = buf[1];
+ block[2] = j;
+ memset(block + 51, 0xff, 29); /* reserved */
}
+ for (k = 0; k < 6; k++) {
+ int number = j * 6 + k;
+ uint8_t *ssyb = block + 3 + 8 * k;
+
+ if (c->smpte)
+ ff_dv_write_ssyb_id(ssyb, number, !second_half, buf[4] & 7, buf[7] & 7);
+ else /* Number IEC SSYBs by slot, including blank IDs. */
+ ssyb[1] = (ssyb[1] & 0xf0) | number;
+ dv_write_pack(ssyb_packs[second_half][number], c, ssyb + 3, timecode);
+ }
+ }
+ if (rebuild)
+ buf[7] &= 0x7f;
+
+ /* DV VAUX: IEC 61834 main area, after the VS and VSC packs */
+ if (!c->smpte) {
+ uint8_t *p = seq & 1 ? &buf[80 * 3 + 3 + 5 * 2] : &buf[80 * 5 + 3 + 5 * 11];
+ dv_write_pack(DV_VIDEO_RECDATE, c, p, 0);
+ dv_write_pack(DV_VIDEO_RECTIME, c, p + 5, 0);
}
+ }
+}
- /* DV VAUX: 4th, 5th and 6th 3DIFs */
- for (j = 80*3 + 3; j < 80*6; j += 80) {
- dv_write_pack(DV_VIDEO_RECDATE, c, &buf[j+5* 2], 0, seq);
- dv_write_pack(DV_VIDEO_RECTIME, c, &buf[j+5* 3], 0, seq);
- dv_write_pack(DV_VIDEO_RECDATE, c, &buf[j+5*11], 0, seq);
- dv_write_pack(DV_VIDEO_RECTIME, c, &buf[j+5*12], 0, seq);
+static int dv_init_timecode(AVFormatContext *s)
+{
+ DVMuxContext *dvc = s->priv_data;
+ AVDictionaryEntry *tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
+ AVRational rate;
+
+ /* Interpret metadata and -timecode at the video rate, as before. */
+ rate.num = dvc->sys->ltc_divisor;
+ rate.den = 1;
+ if (!tcr) { // no global timecode, look into the streams
+ int i;
+ for (i = 0; i < s->nb_streams; i++) {
+ tcr = av_dict_get(s->streams[i]->metadata, "timecode", NULL, 0);
+ if (tcr)
+ break;
}
}
+ if (tcr && av_timecode_init_from_string(&dvc->tc, rate, tcr->value, s) >= 0) {
+ /* Both pictures carry the same LTC label without a field bit. */
+ if (dvc->sys->height == 720) {
+ if (dvc->tc.start & 1)
+ av_log(s, AV_LOG_WARNING, "Rounding 720p timecode down to picture-pair precision.\n");
+ dvc->tc.start &= ~1;
+ }
+ return 0;
+ }
+ return av_timecode_init(&dvc->tc, rate, 0, 0, s);
}
/*
* The following 3 functions constitute our interface to the world
*/
-static int dv_assemble_frame(AVFormatContext *s,
- DVMuxContext *c, AVStream* st,
- const uint8_t *data, int data_size, uint8_t **frame)
+/* Write the frame once every participating DIF channel has enough audio. */
+static int dv_write_frame(AVFormatContext *s, DVMuxContext *c, uint8_t *frame)
{
- int i, reqasize;
+ /* 720p frames carry DIF channels 0-1 or 2-3 */
+ int is_720p = c->sys->height == 720;
+ int first_chan = is_720p && !(frame[1] & 0x04) ? 2 : 0;
+ int end_chan = FFMIN(first_chan + c->sys->n_difchan, c->n_ast);
+ /* Audio and time code span two 720p pictures (SMPTE 370M 3.1.4). */
+ int audio_frame = is_720p ? (c->frames + c->pair_phase) / 2 : c->frames;
+ int sizes[FF_ARRAY_ELEMS(c->ast)] = { 0 };
+
+ for (int i = first_chan; i < end_chan; i++) {
+ sizes[i] = 4 * dv_audio_frame_size(c->sys, audio_frame, c->ast[i]->codecpar->sample_rate);
+ if (av_fifo_can_read(c->audio_data[i]) < sizes[i])
+ return 0;
+ }
- *frame = &c->frame_buf[0];
+ c->smpte = !!(frame[4] & 0x07); /* APT */
+ dv_inject_metadata(c, frame, is_720p ? 2 * audio_frame : audio_frame);
+ if (c->n_ast) {
+ for (int i = 0; i < c->sys->n_difchan; i++) {
+ int channel = first_chan + i;
+ int audio_size = sizes[channel];
+
+ dv_inject_audio(c, channel, i, frame, audio_size);
+ if (audio_size)
+ av_fifo_drain2(c->audio_data[channel], audio_size);
+ }
+ }
+
+ avio_write(s->pb, frame, c->sys->frame_size);
+
+ c->frames++;
+ return 1;
+}
+
+static int dv_write_packet(AVFormatContext *s, AVPacket *pkt)
+{
+ DVMuxContext *c = s->priv_data;
+ AVStream *st = s->streams[pkt->stream_index];
+ const uint8_t *data = pkt->data;
+ int data_size = pkt->size;
+ /* 720p audio frames span two video frames, so allow one more to be
+ * queued while waiting for the audio */
+ int max_video = c->sys->height == 720 ? 2 : 1;
+ int i, ret;
+
+ /* A rejected second-picture start must also block buffered packets. */
+ if (c->n_ast && c->pair_phase == 1)
+ return AVERROR_INVALIDDATA;
switch (st->codecpar->codec_type) {
case AVMEDIA_TYPE_VIDEO:
/* FIXME: we have to have more sensible approach than this one */
- if (c->has_video) {
+ if (c->has_video == max_video) {
av_log(s, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames);
return AVERROR(EINVAL);
}
+ if (c->sys->height == 720 && c->pair_phase < 0) {
+ const AVDVProfile *coded = av_dv_frame_profile(NULL, data, data_size);
+ if (coded && coded->height == 720 && coded->frame_size == data_size)
+ c->sys = coded;
+ }
if (data_size != c->sys->frame_size) {
av_log(s, AV_LOG_ERROR, "Unexpected frame size, %d != %d\n",
data_size, c->sys->frame_size);
return AVERROR(ENOSYS);
}
- memcpy(*frame, data, c->sys->frame_size);
- c->has_video = 1;
+ if (c->sys->height == 720) {
+ int phase = !(data[1] & 0x04);
+ if (c->pair_phase < 0) {
+ if (phase && c->n_ast) {
+ c->pair_phase = phase;
+ av_log(s, AV_LOG_ERROR, "A second-picture 720p start with supplied audio requires timestamp alignment.\n");
+ return AVERROR_INVALIDDATA;
+ }
+ ret = dv_init_timecode(s);
+ if (ret < 0)
+ return ret;
+ c->pair_phase = phase;
+ }
+ /* Audio replacement needs alternating pairs and a first-picture start. */
+ if (c->n_ast && phase != ((c->frames + c->has_video) & 1)) {
+ av_log(s, AV_LOG_ERROR, "Nonalternating 720p DIF channel pairs cannot be muxed with audio.\n");
+ return AVERROR_INVALIDDATA;
+ }
+ }
+
+ memcpy(c->frame_buf + c->has_video * c->sys->frame_size, data, c->sys->frame_size);
+ c->has_video++;
break;
case AVMEDIA_TYPE_AUDIO:
for (i = 0; i < c->n_ast && st != c->ast[i]; i++);
- /* FIXME: we have to have more sensible approach than this one */
- if (av_fifo_can_write(c->audio_data[i]) < data_size) {
+ ret = av_fifo_write(c->audio_data[i], data, data_size);
+ if (ret == AVERROR(ENOSPC)) {
av_log(s, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames);
return AVERROR(EINVAL);
}
- av_fifo_write(c->audio_data[i], data, data_size);
-
- reqasize = 4 * dv_audio_frame_size(c->sys, c->frames, st->codecpar->sample_rate);
-
- /* Let us see if we've got enough audio for one DV frame. */
- c->has_audio |= ((reqasize <= av_fifo_can_read(c->audio_data[i])) << i);
-
+ if (ret < 0)
+ return ret;
break;
default:
break;
}
- /* Let us see if we have enough data to construct one DV frame. */
- if (c->has_video == 1 && c->has_audio + 1 == 1 << c->n_ast) {
- dv_inject_metadata(c, *frame);
- c->has_audio = 0;
- for (i=0; i < c->n_ast; i++) {
- dv_inject_audio(c, i, *frame);
- reqasize = 4 * dv_audio_frame_size(c->sys, c->frames, c->ast[i]->codecpar->sample_rate);
- av_fifo_drain2(c->audio_data[i], reqasize);
- c->has_audio |= ((reqasize <= av_fifo_can_read(c->audio_data[i])) << i);
- }
-
- c->has_video = 0;
-
- c->frames++;
-
- return c->sys->frame_size;
+ /* Let us see if we have enough data to construct DV frames. */
+ while (c->has_video && dv_write_frame(s, c, c->frame_buf)) {
+ if (--c->has_video)
+ memmove(c->frame_buf, c->frame_buf + c->sys->frame_size, c->sys->frame_size);
}
return 0;
@@ -313,14 +438,7 @@ static int dv_init_mux(AVFormatContext* s)
{
DVMuxContext *c = s->priv_data;
AVStream *vst = NULL;
- int i;
-
- if (s->nb_streams > 5) {
- av_log(s, AV_LOG_ERROR,
- "Invalid number of streams %d, the muxer supports at most 1 video channel and 4 audio channels.\n",
- s->nb_streams);
- return AVERROR_INVALIDDATA;
- }
+ int i, max_ast;
/* We have to sort out where audio and where video stream is */
for (i=0; i<s->nb_streams; i++) {
@@ -340,9 +458,8 @@ static int dv_init_mux(AVFormatContext* s)
vst = st;
break;
case AVMEDIA_TYPE_AUDIO:
- if (c->n_ast > 1) {
- av_log(s, AV_LOG_ERROR,
- "More than two audio streams found, at most 2 are accepted.\n");
+ if (c->n_ast == FF_ARRAY_ELEMS(c->ast)) {
+ av_log(s, AV_LOG_ERROR, "Too many DV audio streams.\n");
return AVERROR_INVALIDDATA;
}
/* Some checks -- DV format is very picky about its incoming streams */
@@ -380,8 +497,11 @@ static int dv_init_mux(AVFormatContext* s)
return AVERROR_INVALIDDATA;
}
+ /* A container time base need not be the coded picture rate. */
c->sys = av_dv_codec_profile2(vst->codecpar->width, vst->codecpar->height,
- vst->codecpar->format, vst->time_base);
+ vst->codecpar->format,
+ vst->codecpar->framerate.num ? av_inv_q(vst->codecpar->framerate) :
+ vst->avg_frame_rate.num ? av_inv_q(vst->avg_frame_rate) : vst->time_base);
if (!c->sys) {
av_log(s, AV_LOG_ERROR,
"Could not find a valid video profile for size:%dx%d format:%s tb:%d%d\n",
@@ -391,9 +511,11 @@ static int dv_init_mux(AVFormatContext* s)
return AVERROR_INVALIDDATA;
}
- if ((c->sys->time_base.den != 25 && c->sys->time_base.den != 50) || c->sys->time_base.num != 1) {
- for (i = 0; i < 2; i++) {
- if (c->ast[i] && c->ast[i]->codecpar->sample_rate != 48000) {
+ /* SMPTE profiles require 48kHz, other IEC sample rates are only
+ * supported for 625/50 4:2:0 */
+ if (!c->sys->dsf || c->sys->pix_fmt != AV_PIX_FMT_YUV420P) {
+ for (i = 0; i < c->n_ast; i++) {
+ if (c->ast[i]->codecpar->sample_rate != 48000) {
av_log(s, AV_LOG_ERROR,
"Invalid sample rate %d for audio stream #%d for this video profile, must be 48000.\n",
c->ast[i]->codecpar->sample_rate, i);
@@ -402,29 +524,27 @@ static int dv_init_mux(AVFormatContext* s)
}
}
- for (i = 1; i < 2; i++) {
- if (((c->n_ast > i) && (c->sys->n_difchan < (2 * i)))) {
- const char *mode = c->n_ast > 1 ? "50Mps" : "25Mps";
- av_log(s, AV_LOG_ERROR,
- "Invalid number of channels %d, only %d stereo pairs is allowed in %s mode.\n",
- c->n_ast, i, mode);
- return AVERROR_INVALIDDATA;
- }
+ /* one stereo pair per DIF channel, 720p has 4 DIF channels split in 2 frames */
+ max_ast = c->sys->height == 720 ? 4 : c->sys->n_difchan;
+ if (c->n_ast > max_ast) {
+ av_log(s, AV_LOG_ERROR,
+ "Invalid number of audio streams %d, only %d stereo pairs are allowed in this video profile.\n",
+ c->n_ast, max_ast);
+ return AVERROR_INVALIDDATA;
}
/* Ok, everything seems to be in working order */
c->frames = 0;
- c->has_audio = 0;
c->has_video = 0;
+ c->pair_phase = -1;
ff_parse_creation_time_metadata(s, &c->start_time, 1);
for (i=0; i < c->n_ast; i++) {
- if (!c->ast[i])
- continue;
- c->audio_data[i] = av_fifo_alloc2(100 * MAX_AUDIO_FRAME_SIZE, 1, 0);
+ c->audio_data[i] = av_fifo_alloc2(DV_AUDIO_FRAME_BYTES, 1, AV_FIFO_FLAG_AUTO_GROW);
if (!c->audio_data[i]) {
return AVERROR(ENOMEM);
}
+ av_fifo_auto_grow_limit(c->audio_data[i], DV_AUDIO_FIFO_LIMIT);
}
return 0;
@@ -432,52 +552,43 @@ static int dv_init_mux(AVFormatContext* s)
static int dv_write_header(AVFormatContext *s)
{
- AVRational rate;
+ int ret;
DVMuxContext *dvc = s->priv_data;
- AVDictionaryEntry *tcr = av_dict_get(s->metadata, "timecode", NULL, 0);
- if (dv_init_mux(s) < 0) {
+ if ((ret = dv_init_mux(s)) < 0) {
av_log(s, AV_LOG_ERROR, "Can't initialize DV format!\n"
- "Make sure that you supply at least two streams:\n"
- " video: 25fps or 29.97fps, audio: 2ch/48|44.1|32kHz/PCM\n"
- " (50Mbps allows an optional second audio stream)\n");
- return AVERROR_INVALIDDATA;
- }
- rate.num = dvc->sys->ltc_divisor;
- rate.den = 1;
- if (!tcr) { // no global timecode, look into the streams
- int i;
- for (i = 0; i < s->nb_streams; i++) {
- tcr = av_dict_get(s->streams[i]->metadata, "timecode", NULL, 0);
- if (tcr)
- break;
- }
+ "Make sure that you supply one DV video stream and\n"
+ "optional stereo PCM audio streams\n");
+ return ret;
}
- if (tcr && av_timecode_init_from_string(&dvc->tc, rate, tcr->value, s) >= 0)
- return 0;
- return av_timecode_init(&dvc->tc, rate, 0, 0, s);
+ /* Both 720p families have the same constraints at init; the first
+ * packet can determine the actual coded rate for the timecode. */
+ return dvc->sys->height == 720 ? 0 : dv_init_timecode(s);
}
-static int dv_write_packet(struct AVFormatContext *s, AVPacket *pkt)
+static int dv_write_trailer(AVFormatContext *s)
{
- uint8_t* frame;
- int fsize;
+ DVMuxContext *c = s->priv_data;
- fsize = dv_assemble_frame(s, s->priv_data, s->streams[pkt->stream_index],
- pkt->data, pkt->size, &frame);
- if (fsize < 0) {
- return fsize;
+ if (c->has_video) {
+ av_log(s, c->frames ? AV_LOG_WARNING : AV_LOG_ERROR,
+ "Discarding %d DV picture(s) with insufficient audio data.\n",
+ c->has_video);
+ if (!c->frames)
+ return AVERROR(EINVAL);
+ } else if (c->sys->height == 720 && (c->frames & 1)) {
+ for (int i = 2; i < c->n_ast; i++) {
+ if (av_fifo_can_read(c->audio_data[i])) {
+ av_log(s, AV_LOG_WARNING,
+ "Discarding audio for an absent final second 720p picture.\n");
+ break;
+ }
+ }
}
- avio_write(s->pb, frame, fsize);
+
return 0;
}
-/*
- * We might end up with some extra A/V data without matching counterpart.
- * E.g. video data without enough audio to write the complete frame.
- * Currently we simply drop the last frame. I don't know whether this
- * is the best strategy of all
- */
static void dv_deinit(AVFormatContext *s)
{
DVMuxContext *c = s->priv_data;
@@ -496,5 +607,6 @@ const FFOutputFormat ff_dv_muxer = {
.flags_internal = FF_OFMT_FLAG_ONLY_DEFAULT_CODECS,
.write_header = dv_write_header,
.write_packet = dv_write_packet,
+ .write_trailer = dv_write_trailer,
.deinit = dv_deinit,
};
diff --git a/tests/fate-run.sh b/tests/fate-run.sh
index 3c265fce2d..34c0312b5a 100755
--- a/tests/fate-run.sh
+++ b/tests/fate-run.sh
@@ -337,6 +337,35 @@ transcode(){
run ffprobe${PROGSUF}${EXECSUF} -bitexact -threads $threads $ffprobe_opts $tencfile || return
}
+dv_720p_sparse_audio(){
+ full="${outdir}/${test}-full.dv"
+ sparse="${outdir}/${test}-sparse.dv"
+ joined="${outdir}/${test}-joined.dv"
+ remuxed="${outdir}/${test}-remuxed.dv"
+ graph='testsrc2=s=960x720:r=24,format=yuv422p[out0]'
+ test "$keep" -ge 1 || cleanfiles="$cleanfiles $full $sparse $joined $remuxed"
+ for i in 1 2 3 4; do
+ graph="$graph;sine=r=48000:f=$((997*i)),aformat=sample_fmts=s16:channel_layouts=stereo[out$i]"
+ done
+ ffmpeg -f lavfi -i "$graph" -map 0 -frames:v 2 -c:v dvvideo -threads:v 1 \
+ -dct int -enc_time_base:v 1/50 -c:a pcm_s16le $FLAGS -f dv -y "$(target_path "$full")" || return
+ ffmpeg -i "$(target_path "$full")" -map 0:v -map 0:a:0 -map 0:a:1 -c copy \
+ $FLAGS -f dv -y "$(target_path "$sparse")" || return
+ cat "$full" "$sparse" > "$joined" || return
+ # In a second sparse pair, mark the first picture's two stereo pairs
+ # invalid without changing AF SIZE. The second picture is still empty.
+ seq=0
+ while test "$seq" -lt 24; do
+ aaux_mode=$((seq * 12000 + 6 * 80 + 5 + (1 - seq % 2) * 3 * 16 * 80))
+ patch_bytes "$sparse" "$aaux_mode" '\0037' || return
+ seq=$((seq + 1))
+ done
+ cat "$sparse" "$full" >> "$joined" || return
+ ffmpeg -i "$(target_path "$joined")" -map 0 -c copy $FLAGS -f dv \
+ -y "$(target_path "$remuxed")" || return
+ framecrc -i "$(target_path "$remuxed")" -map 0 -c copy
+}
+
stream_demux(){
src_fmt=$1
srcfile=$2
diff --git a/tests/fate/dvvideo.mak b/tests/fate/dvvideo.mak
index 43eb813a09..5196db3f98 100644
--- a/tests/fate/dvvideo.mak
+++ b/tests/fate/dvvideo.mak
@@ -20,5 +20,12 @@ fate-dvvideo-720p50-frame-threads: RATE = 50
fate-dvvideo-720p60-frame-threads: RATE = 60000/1001
fate-dvvideo-720p50-frame-threads fate-dvvideo-720p60-frame-threads: CMD = framecrc -f lavfi -i testsrc2=size=960x720:rate=$(RATE),format=yuv422p -frames:v 7 -c:v dvvideo -dct int -threads 3 -thread_type frame
+# 720p50 coded profile selection, audio shuffling and a cleared second picture.
+FATE_DVVIDEO_SYNTH-$(call ALLYES, FFMPEG LAVFI_INDEV TESTSRC2_FILTER SINE_FILTER AFORMAT_FILTER ARESAMPLE_FILTER FORMAT_FILTER \
+ WRAPPED_AVFRAME_DECODER PCM_S16$(if $(filter yes,$(HAVE_BIGENDIAN)),BE,LE)_DECODER \
+ DVVIDEO_ENCODER DVVIDEO_DECODER PCM_S16LE_ENCODER DV_MUXER DV_DEMUXER FRAMECRC_MUXER \
+ FILE_PROTOCOL PIPE_PROTOCOL) += fate-dv-720p50-audio
+fate-dv-720p50-audio: CMD = dv_720p_sparse_audio
+
FATE_FFMPEG += $(FATE_DVVIDEO_SYNTH-yes)
fate-dvvideo: $(FATE_DVVIDEO_SYNTH-yes)
diff --git a/tests/ref/fate/dv-720p50-audio b/tests/ref/fate/dv-720p50-audio
new file mode 100644
index 0000000000..d1036c3102
--- /dev/null
+++ b/tests/ref/fate/dv-720p50-audio
@@ -0,0 +1,49 @@
+#tb 0: 1/60000
+#media_type 0: video
+#codec_id 0: dvvideo
+#dimensions 0: 960x720
+#sar 0: 4/3
+#tb 1: 1/14112000
+#media_type 1: audio
+#codec_id 1: pcm_s16le
+#sample_rate 1: 48000
+#channel_layout_name 1: stereo
+#tb 2: 1/14112000
+#media_type 2: audio
+#codec_id 2: pcm_s16le
+#sample_rate 2: 48000
+#channel_layout_name 2: stereo
+#tb 3: 1/14112000
+#media_type 3: audio
+#codec_id 3: pcm_s16le
+#sample_rate 3: 48000
+#channel_layout_name 3: stereo
+#tb 4: 1/14112000
+#media_type 4: audio
+#codec_id 4: pcm_s16le
+#sample_rate 4: 48000
+#channel_layout_name 4: stereo
+0, 0, 0, 1200, 288000, 0xc90ad2ea
+1, 0, 0, 564480, 7680, 0x75c2dc6a
+2, 0, 0, 564480, 7680, 0x044cf3ee
+3, 0, 0, 564480, 7680, 0x607de5c0
+4, 0, 0, 564480, 7680, 0xf3e6e7ac
+0, 1200, 1200, 1200, 288000, 0x951297be
+0, 2400, 2400, 1200, 288000, 0xd8549762
+1, 564480, 564480, 564480, 7680, 0x75c2dc6a
+2, 564480, 564480, 564480, 7680, 0x044cf3ee
+3, 564480, 564480, 564480, 7680, 0x00000000
+4, 564480, 564480, 564480, 7680, 0x00000000
+0, 3600, 3600, 1200, 288000, 0xef868eac
+0, 4800, 4800, 1200, 288000, 0xbdd3c764
+1, 1128960, 1128960, 564480, 7680, 0x00000000
+2, 1128960, 1128960, 564480, 7680, 0x00000000
+3, 1128960, 1128960, 564480, 7680, 0x00000000
+4, 1128960, 1128960, 564480, 7680, 0x00000000
+0, 6000, 6000, 1200, 288000, 0x941e8f24
+0, 7200, 7200, 1200, 288000, 0xb6c3d452
+1, 1693440, 1693440, 564480, 7680, 0x75c2dc6a
+2, 1693440, 1693440, 564480, 7680, 0x044cf3ee
+3, 1693440, 1693440, 564480, 7680, 0x607de5c0
+4, 1693440, 1693440, 564480, 7680, 0xf3e6e7ac
+0, 8400, 8400, 1200, 288000, 0x82cb9926
diff --git a/tests/ref/fate/dvvideo-720p50-frame-threads b/tests/ref/fate/dvvideo-720p50-frame-threads
index d0517985c8..73af741ae3 100644
--- a/tests/ref/fate/dvvideo-720p50-frame-threads
+++ b/tests/ref/fate/dvvideo-720p50-frame-threads
@@ -3,10 +3,10 @@
#codec_id 0: dvvideo
#dimensions 0: 960x720
#sar 0: 1/1
-0, 0, 0, 1, 288000, 0xcc595292
-0, 1, 1, 1, 288000, 0xd7f5ec89
-0, 2, 2, 1, 288000, 0x129815cf
-0, 3, 3, 1, 288000, 0xf3d65d84
-0, 4, 4, 1, 288000, 0xc7972412
-0, 5, 5, 1, 288000, 0x1c371f4b
-0, 6, 6, 1, 288000, 0xc00229a0
+0, 0, 0, 1, 288000, 0x310cc521
+0, 1, 1, 1, 288000, 0x3ca85f27
+0, 2, 2, 1, 288000, 0x773c885e
+0, 3, 3, 1, 288000, 0x5889d013
+0, 4, 4, 1, 288000, 0x2c4a96a1
+0, 5, 5, 1, 288000, 0x80db91da
+0, 6, 6, 1, 288000, 0x24b59c2f
diff --git a/tests/ref/fate/dvvideo-720p60-frame-threads b/tests/ref/fate/dvvideo-720p60-frame-threads
index fdee03d14d..c1a920424e 100644
--- a/tests/ref/fate/dvvideo-720p60-frame-threads
+++ b/tests/ref/fate/dvvideo-720p60-frame-threads
@@ -3,10 +3,10 @@
#codec_id 0: dvvideo
#dimensions 0: 960x720
#sar 0: 1/1
-0, 0, 0, 1, 240000, 0x059a19c3
-0, 1, 1, 1, 240000, 0xb5c72482
-0, 2, 2, 1, 240000, 0x601b7e81
-0, 3, 3, 1, 240000, 0x0f7645e6
-0, 4, 4, 1, 240000, 0x68c611af
-0, 5, 5, 1, 240000, 0x779d661e
-0, 6, 6, 1, 240000, 0xea44860b
+0, 0, 0, 1, 240000, 0x24675b12
+0, 1, 1, 1, 240000, 0xd49465d1
+0, 2, 2, 1, 240000, 0x7ee8bfd0
+0, 3, 3, 1, 240000, 0x2e438735
+0, 4, 4, 1, 240000, 0x879352fe
+0, 5, 5, 1, 240000, 0x966aa76d
+0, 6, 6, 1, 240000, 0x0920c75a
diff --git a/tests/ref/fate/mxf-pcm-anc-cbe b/tests/ref/fate/mxf-pcm-anc-cbe
index 3060d02ec0..44bf29dfed 100644
--- a/tests/ref/fate/mxf-pcm-anc-cbe
+++ b/tests/ref/fate/mxf-pcm-anc-cbe
@@ -1,4 +1,4 @@
-48cd94e1c59f187995ef2d7b0bc6e22d *tests/data/fate/mxf-pcm-anc-cbe.mxf
+b01af2b25a2ac601d06b51215a025f16 *tests/data/fate/mxf-pcm-anc-cbe.mxf
447533 tests/data/fate/mxf-pcm-anc-cbe.mxf
#tb 0: 1001/30000
#media_type 0: video
@@ -13,14 +13,14 @@
#tb 2: 1001/30000
#media_type 2: data
#codec_id 2: smpte_436m_anc
-0, 0, 0, 1, 120000, 0x7fc9c8da
+0, 0, 0, 1, 120000, 0x8a1e6e9d
1, 0, 0, 1602, 24030, 0x00000000
2, 0, 0, 1, 136, 0x9d18224f
-0, 1, 1, 1, 120000, 0x7e5fe0a5
+0, 1, 1, 1, 120000, 0x88b48668
2, 1, 1, 1, 492, 0x49e2e054
1, 1602, 1602, 1601, 24015, 0x00000000
1, 3203, 3203, 1602, 24030, 0x00000000
-0, 2, 2, 1, 120000, 0x3e20d97c
+0, 2, 2, 1, 120000, 0x48757f3f
2, 2, 2, 1, 2, 0x00000000
packet|stream_index=0|size=120000|pos=8192
packet|stream_index=1|size=24030|pos=128512
diff --git a/tests/ref/lavf/dv b/tests/ref/lavf/dv
index d301571411..2a169b8b2c 100644
--- a/tests/ref/lavf/dv
+++ b/tests/ref/lavf/dv
@@ -1,3 +1,3 @@
-343b03a4ae5a95adb7340fc453c7e61e *tests/data/lavf/lavf.dv
+8446a4c970bfc00c9e7f0a05d21f671c *tests/data/lavf/lavf.dv
3600000 tests/data/lavf/lavf.dv
tests/data/lavf/lavf.dv CRC=0x3efa60d5
diff --git a/tests/ref/lavf/dv_ntsc b/tests/ref/lavf/dv_ntsc
index 7b5953461a..5fdae39901 100644
--- a/tests/ref/lavf/dv_ntsc
+++ b/tests/ref/lavf/dv_ntsc
@@ -1,3 +1,3 @@
-947f17de36e17a8f91c844ae84ea1409 *tests/data/lavf/lavf.dv_ntsc
+ff2d86b719b01d9e589105dcde786201 *tests/data/lavf/lavf.dv_ntsc
3480000 tests/data/lavf/lavf.dv_ntsc
tests/data/lavf/lavf.dv_ntsc CRC=0xadfc9598
diff --git a/tests/ref/lavf/dv_pal b/tests/ref/lavf/dv_pal
index b16911f8d1..1a0a2e342a 100644
--- a/tests/ref/lavf/dv_pal
+++ b/tests/ref/lavf/dv_pal
@@ -1,3 +1,3 @@
-7a0264fd1c59908e6c6c3d7557a1ca21 *tests/data/lavf/lavf.dv_pal
+aae522a40597ad549a54bec855779ff8 *tests/data/lavf/lavf.dv_pal
3600000 tests/data/lavf/lavf.dv_pal
tests/data/lavf/lavf.dv_pal CRC=0x5573b571
diff --git a/tests/ref/lavf/mxf_dv25 b/tests/ref/lavf/mxf_dv25
index 33b02319d6..cba48edec8 100644
--- a/tests/ref/lavf/mxf_dv25
+++ b/tests/ref/lavf/mxf_dv25
@@ -1,3 +1,3 @@
-c1c0b76332ab29bb953df28a3af88681 *tests/data/lavf/lavf.mxf_dv25
+8acc520d70634fb4719e54043947196f *tests/data/lavf/lavf.mxf_dv25
3834413 tests/data/lavf/lavf.mxf_dv25
tests/data/lavf/lavf.mxf_dv25 CRC=0x3efa60d5
diff --git a/tests/ref/lavf/mxf_dvcpro100 b/tests/ref/lavf/mxf_dvcpro100
index a1da8b4935..ed7d3c9b50 100644
--- a/tests/ref/lavf/mxf_dvcpro100
+++ b/tests/ref/lavf/mxf_dvcpro100
@@ -1,3 +1,3 @@
-e295922f8f5813c5ccad37947645c99a *tests/data/lavf/lavf.mxf_dvcpro100
+240b08e5ce2e58ee97a186e2ab6c3e53 *tests/data/lavf/lavf.mxf_dvcpro100
14637613 tests/data/lavf/lavf.mxf_dvcpro100
tests/data/lavf/lavf.mxf_dvcpro100 CRC=0x25feb3fd
diff --git a/tests/ref/lavf/mxf_dvcpro50 b/tests/ref/lavf/mxf_dvcpro50
index 09fb7dda4f..66b60aa584 100644
--- a/tests/ref/lavf/mxf_dvcpro50
+++ b/tests/ref/lavf/mxf_dvcpro50
@@ -1,3 +1,3 @@
-7a0dfccb8515e53ab5218ff235b0e0fb *tests/data/lavf/lavf.mxf_dvcpro50
+04a5816f95f7bdbc3b588a9756aadd31 *tests/data/lavf/lavf.mxf_dvcpro50
7431213 tests/data/lavf/lavf.mxf_dvcpro50
tests/data/lavf/lavf.mxf_dvcpro50 CRC=0xfd34a6d9
diff --git a/tests/ref/vsynth/vsynth1-dv b/tests/ref/vsynth/vsynth1-dv
index b381cea89c..e026dadc52 100644
--- a/tests/ref/vsynth/vsynth1-dv
+++ b/tests/ref/vsynth/vsynth1-dv
@@ -1,4 +1,4 @@
-2d6d0aa8d50ad1678080fa9c33e24bc1 *tests/data/fate/vsynth1-dv.dv
+5288f6819c4d9fc23aa243ff02848821 *tests/data/fate/vsynth1-dv.dv
7200000 tests/data/fate/vsynth1-dv.dv
7dcf06a0956c25c407c72140cdcfa078 *tests/data/fate/vsynth1-dv.out.rawvideo
stddev: 6.90 PSNR: 31.34 MAXDIFF: 76 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth1-dv-411 b/tests/ref/vsynth/vsynth1-dv-411
index 86e64cf39d..6ed0e491c5 100644
--- a/tests/ref/vsynth/vsynth1-dv-411
+++ b/tests/ref/vsynth/vsynth1-dv-411
@@ -1,4 +1,4 @@
-a2a0d0c750707a1b8facbe6ebf3cc446 *tests/data/fate/vsynth1-dv-411.dv
+0bd663aafcacb9b154983d2924af1431 *tests/data/fate/vsynth1-dv-411.dv
7200000 tests/data/fate/vsynth1-dv-411.dv
4e294ecbb5ad48ce776fea99ef35d89e *tests/data/fate/vsynth1-dv-411.out.rawvideo
stddev: 9.43 PSNR: 28.63 MAXDIFF: 84 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth1-dv-50 b/tests/ref/vsynth/vsynth1-dv-50
index 920b260709..8d1189a7d5 100644
--- a/tests/ref/vsynth/vsynth1-dv-50
+++ b/tests/ref/vsynth/vsynth1-dv-50
@@ -1,4 +1,4 @@
-f8a602f4b0003576f284a4a69b096707 *tests/data/fate/vsynth1-dv-50.dv
+a187a8d13d1b2dde36a16e046d1e3894 *tests/data/fate/vsynth1-dv-50.dv
14400000 tests/data/fate/vsynth1-dv-50.dv
1e9aeeb0ff36ccd83017cad460384bc3 *tests/data/fate/vsynth1-dv-50.out.rawvideo
stddev: 1.72 PSNR: 43.37 MAXDIFF: 29 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth1-dv-fhd b/tests/ref/vsynth/vsynth1-dv-fhd
index 0027208ab9..20b1a3a48e 100644
--- a/tests/ref/vsynth/vsynth1-dv-fhd
+++ b/tests/ref/vsynth/vsynth1-dv-fhd
@@ -1,4 +1,4 @@
-70b61b2668c657ea8e861cbffc8f417f *tests/data/fate/vsynth1-dv-fhd.dv
+c605566683de0290af59ca156dcd6e2b *tests/data/fate/vsynth1-dv-fhd.dv
28800000 tests/data/fate/vsynth1-dv-fhd.dv
af6efc55053a9b5407dfd0e7722deb90 *tests/data/fate/vsynth1-dv-fhd.out.rawvideo
stddev: 2.54 PSNR: 40.02 MAXDIFF: 35 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth1-dv-hd b/tests/ref/vsynth/vsynth1-dv-hd
index 86644e8b36..1d2b86aa64 100644
--- a/tests/ref/vsynth/vsynth1-dv-hd
+++ b/tests/ref/vsynth/vsynth1-dv-hd
@@ -1,4 +1,4 @@
-4ee275d498d80ea25f07700e1b045768 *tests/data/fate/vsynth1-dv-hd.dv
+d96d43411f3308a4a6677c1a224338c0 *tests/data/fate/vsynth1-dv-hd.dv
14400000 tests/data/fate/vsynth1-dv-hd.dv
20e3ea2d0341a0b323b8fdc223554619 *tests/data/fate/vsynth1-dv-hd.out.rawvideo
stddev: 4.28 PSNR: 35.50 MAXDIFF: 74 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth2-dv b/tests/ref/vsynth/vsynth2-dv
index ee7c6fa4f7..fa83ef16b1 100644
--- a/tests/ref/vsynth/vsynth2-dv
+++ b/tests/ref/vsynth/vsynth2-dv
@@ -1,4 +1,4 @@
-e77f0b747ed8d1492c74a12acb47752e *tests/data/fate/vsynth2-dv.dv
+68227ab2f4191a82c80815989e60af68 *tests/data/fate/vsynth2-dv.dv
7200000 tests/data/fate/vsynth2-dv.dv
f16c6dc6fcf7e2de82460e10985e5d10 *tests/data/fate/vsynth2-dv.out.rawvideo
stddev: 1.99 PSNR: 42.13 MAXDIFF: 38 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth2-dv-411 b/tests/ref/vsynth/vsynth2-dv-411
index c9057ba29a..09c0136204 100644
--- a/tests/ref/vsynth/vsynth2-dv-411
+++ b/tests/ref/vsynth/vsynth2-dv-411
@@ -1,4 +1,4 @@
-89b47e267c6a89f508863b5413df8477 *tests/data/fate/vsynth2-dv-411.dv
+f293fa28db24e768ea673714dccd83d4 *tests/data/fate/vsynth2-dv-411.dv
7200000 tests/data/fate/vsynth2-dv-411.dv
4c73684b84cdab58e99752c9d1e60b6d *tests/data/fate/vsynth2-dv-411.out.rawvideo
stddev: 3.48 PSNR: 37.28 MAXDIFF: 56 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth2-dv-50 b/tests/ref/vsynth/vsynth2-dv-50
index dcd4259eb2..5dde95aed4 100644
--- a/tests/ref/vsynth/vsynth2-dv-50
+++ b/tests/ref/vsynth/vsynth2-dv-50
@@ -1,4 +1,4 @@
-322b2e94e1408a683244b1b347448ad4 *tests/data/fate/vsynth2-dv-50.dv
+cf01b42d85c729498614240884379e89 *tests/data/fate/vsynth2-dv-50.dv
14400000 tests/data/fate/vsynth2-dv-50.dv
ac8fa753f86a1ad0422e7e1bc1334433 *tests/data/fate/vsynth2-dv-50.out.rawvideo
stddev: 0.86 PSNR: 49.43 MAXDIFF: 17 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth2-dv-fhd b/tests/ref/vsynth/vsynth2-dv-fhd
index ec025e6af1..94af3bfd74 100644
--- a/tests/ref/vsynth/vsynth2-dv-fhd
+++ b/tests/ref/vsynth/vsynth2-dv-fhd
@@ -1,4 +1,4 @@
-25cc6c3dc0c29374eb57446c31023313 *tests/data/fate/vsynth2-dv-fhd.dv
+506ba90da3d204e607aff9b7cced7f08 *tests/data/fate/vsynth2-dv-fhd.dv
28800000 tests/data/fate/vsynth2-dv-fhd.dv
247449892bb8dbc5be8147c670981c66 *tests/data/fate/vsynth2-dv-fhd.out.rawvideo
stddev: 1.16 PSNR: 46.83 MAXDIFF: 21 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth2-dv-hd b/tests/ref/vsynth/vsynth2-dv-hd
index 141d5b1cb3..257aa6ba50 100644
--- a/tests/ref/vsynth/vsynth2-dv-hd
+++ b/tests/ref/vsynth/vsynth2-dv-hd
@@ -1,4 +1,4 @@
-60d48e611674a055808d0d892a537468 *tests/data/fate/vsynth2-dv-hd.dv
+026d7cb8e7b57c4f5f52e429b6d4795d *tests/data/fate/vsynth2-dv-hd.dv
14400000 tests/data/fate/vsynth2-dv-hd.dv
fdf957d1e9d70a5e832dbcdfd2d5a27b *tests/data/fate/vsynth2-dv-hd.out.rawvideo
stddev: 1.74 PSNR: 43.28 MAXDIFF: 34 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth3-dv-fhd b/tests/ref/vsynth/vsynth3-dv-fhd
index 3c48d90de7..b115a78814 100644
--- a/tests/ref/vsynth/vsynth3-dv-fhd
+++ b/tests/ref/vsynth/vsynth3-dv-fhd
@@ -1,4 +1,4 @@
-f9d934b86233425aefe65f838e513e54 *tests/data/fate/vsynth3-dv-fhd.dv
+0907484391952e0ec8eea17e2a6902ef *tests/data/fate/vsynth3-dv-fhd.dv
28800000 tests/data/fate/vsynth3-dv-fhd.dv
a038ad7c3c09f776304ef7accdea9c74 *tests/data/fate/vsynth3-dv-fhd.out.rawvideo
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 86700/ 86700
diff --git a/tests/ref/vsynth/vsynth3-dv-hd b/tests/ref/vsynth/vsynth3-dv-hd
index 9ec5341e9d..b069c39819 100644
--- a/tests/ref/vsynth/vsynth3-dv-hd
+++ b/tests/ref/vsynth/vsynth3-dv-hd
@@ -1,4 +1,4 @@
-76680acd86ee4dd16404f49e32cf3f38 *tests/data/fate/vsynth3-dv-hd.dv
+4b8940c92b1f3a948e7d93179a85ef15 *tests/data/fate/vsynth3-dv-hd.dv
14400000 tests/data/fate/vsynth3-dv-hd.dv
a038ad7c3c09f776304ef7accdea9c74 *tests/data/fate/vsynth3-dv-hd.out.rawvideo
stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 86700/ 86700
diff --git a/tests/ref/vsynth/vsynth_lena-dv b/tests/ref/vsynth/vsynth_lena-dv
index f0732cca10..bce6e905c0 100644
--- a/tests/ref/vsynth/vsynth_lena-dv
+++ b/tests/ref/vsynth/vsynth_lena-dv
@@ -1,4 +1,4 @@
-04d844b7ec7b4af546ad082b58912d05 *tests/data/fate/vsynth_lena-dv.dv
+8f14038887a8b3c4deec4b66aeee517b *tests/data/fate/vsynth_lena-dv.dv
7200000 tests/data/fate/vsynth_lena-dv.dv
0c7c574084780daf0e9732cf7a8a8fa5 *tests/data/fate/vsynth_lena-dv.out.rawvideo
stddev: 1.69 PSNR: 43.54 MAXDIFF: 33 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth_lena-dv-411 b/tests/ref/vsynth/vsynth_lena-dv-411
index 09ba97c560..bd6581c3e9 100644
--- a/tests/ref/vsynth/vsynth_lena-dv-411
+++ b/tests/ref/vsynth/vsynth_lena-dv-411
@@ -1,4 +1,4 @@
-d7c8447eb7b5ff54109b6c789f099f55 *tests/data/fate/vsynth_lena-dv-411.dv
+660aa42911f0f9f6f58a18fb7ca40c31 *tests/data/fate/vsynth_lena-dv-411.dv
7200000 tests/data/fate/vsynth_lena-dv-411.dv
a2e4189e19c8b1d1f68c8a75db14041a *tests/data/fate/vsynth_lena-dv-411.out.rawvideo
stddev: 2.87 PSNR: 38.96 MAXDIFF: 45 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth_lena-dv-50 b/tests/ref/vsynth/vsynth_lena-dv-50
index cdda0e401a..7c84e85087 100644
--- a/tests/ref/vsynth/vsynth_lena-dv-50
+++ b/tests/ref/vsynth/vsynth_lena-dv-50
@@ -1,4 +1,4 @@
-68f4c1bb613b3f5d0afd106072b9734c *tests/data/fate/vsynth_lena-dv-50.dv
+ade048949df96f89490376d487ccfa76 *tests/data/fate/vsynth_lena-dv-50.dv
14400000 tests/data/fate/vsynth_lena-dv-50.dv
9313f04ef89da88fbb7157930f3f418e *tests/data/fate/vsynth_lena-dv-50.out.rawvideo
stddev: 0.78 PSNR: 50.28 MAXDIFF: 12 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth_lena-dv-fhd b/tests/ref/vsynth/vsynth_lena-dv-fhd
index b5701423db..60df2bbdc1 100644
--- a/tests/ref/vsynth/vsynth_lena-dv-fhd
+++ b/tests/ref/vsynth/vsynth_lena-dv-fhd
@@ -1,4 +1,4 @@
-a8a1070929f5016c7cdc5074a6d5739d *tests/data/fate/vsynth_lena-dv-fhd.dv
+07ea30a1ee518c2f15ddbc3deafff58e *tests/data/fate/vsynth_lena-dv-fhd.dv
28800000 tests/data/fate/vsynth_lena-dv-fhd.dv
fba140abe1d417f829c3bf20657d220d *tests/data/fate/vsynth_lena-dv-fhd.out.rawvideo
stddev: 1.03 PSNR: 47.80 MAXDIFF: 14 bytes: 7603200/ 7603200
diff --git a/tests/ref/vsynth/vsynth_lena-dv-hd b/tests/ref/vsynth/vsynth_lena-dv-hd
index f92ac2ce1b..65379949cc 100644
--- a/tests/ref/vsynth/vsynth_lena-dv-hd
+++ b/tests/ref/vsynth/vsynth_lena-dv-hd
@@ -1,4 +1,4 @@
-a4583803c9ec843d5ace1228a8d42d4f *tests/data/fate/vsynth_lena-dv-hd.dv
+b4900076f50aee88b7612cd33c0f80b8 *tests/data/fate/vsynth_lena-dv-hd.dv
14400000 tests/data/fate/vsynth_lena-dv-hd.dv
85896fd67284fab17ff60ea04eb2fa9e *tests/data/fate/vsynth_lena-dv-hd.out.rawvideo
stddev: 1.48 PSNR: 44.68 MAXDIFF: 26 bytes: 7603200/ 7603200