summaryrefslogtreecommitdiff
path: root/libavformat
diff options
context:
space:
mode:
authorMarton Balint <cus@passwd.hu>2020-10-31 17:51:34 +0100
committerMarton Balint <cus@passwd.hu>2020-12-06 18:09:24 +0100
commit76fbb0052df471075858c1cb82b04c8be7adba8d (patch)
treecec3039da55ebb38f65a8ef15165ed2849664e05 /libavformat
parent7a170bd6c14b17c7972d11deb9fbd6cfa2131256 (diff)
avformat/dv: fix timestamps of audio packets in case of dropped corrupt audio frames
By using the frame counter (and the video time base) for audio pts we lose some timestamp precision but we ensure that video and audio coming from the same DV frame are always in sync. This patch also makes timestamps after seek consistent and it should also fix the timestamps when the audio clock is unlocked and have a completely indpendent clock source. (E.g. runs on fixed 48009 Hz which should have been exact 48000 Hz) Fixes out of sync timestamps in ticket #8762. Signed-off-by: Marton Balint <cus@passwd.hu>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/dv.c16
1 files changed, 2 insertions, 14 deletions
diff --git a/libavformat/dv.c b/libavformat/dv.c
index 3e0d12c0e3..26a78139f5 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -49,7 +49,6 @@ struct DVDemuxContext {
uint8_t audio_buf[4][8192];
int ach;
int frames;
- uint64_t abytes;
};
static inline uint16_t dv_audio_12to16(uint16_t sample)
@@ -258,7 +257,7 @@ static int dv_extract_audio_info(DVDemuxContext *c, const uint8_t *frame)
c->ast[i] = avformat_new_stream(c->fctx, NULL);
if (!c->ast[i])
break;
- avpriv_set_pts_info(c->ast[i], 64, 1, 30000);
+ avpriv_set_pts_info(c->ast[i], 64, c->sys->time_base.num, c->sys->time_base.den);
c->ast[i]->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
c->ast[i]->codecpar->codec_id = AV_CODEC_ID_PCM_S16LE;
@@ -387,8 +386,7 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
for (i = 0; i < c->ach; i++) {
c->audio_pkt[i].pos = pos;
c->audio_pkt[i].size = size;
- c->audio_pkt[i].pts = c->abytes * 30000 * 8 /
- c->ast[i]->codecpar->bit_rate;
+ c->audio_pkt[i].pts = (c->sys->height == 720) ? (c->frames & ~1) : c->frames;
ppcm[i] = c->audio_buf[i];
}
if (c->ach)
@@ -401,10 +399,7 @@ int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt,
c->audio_pkt[2].size = c->audio_pkt[3].size = 0;
} else {
c->audio_pkt[0].size = c->audio_pkt[1].size = 0;
- c->abytes += size;
}
- } else {
- c->abytes += size;
}
/* Now it's time to return video packet */
@@ -444,13 +439,6 @@ static int64_t dv_frame_offset(AVFormatContext *s, DVDemuxContext *c,
void ff_dv_offset_reset(DVDemuxContext *c, int64_t frame_offset)
{
c->frames = frame_offset;
- if (c->ach) {
- if (c->sys) {
- c->abytes = av_rescale_q(c->frames, c->sys->time_base,
- (AVRational) { 8, c->ast[0]->codecpar->bit_rate });
- } else
- av_log(c->fctx, AV_LOG_ERROR, "cannot adjust audio bytes\n");
- }
c->audio_pkt[0].size = c->audio_pkt[1].size = 0;
c->audio_pkt[2].size = c->audio_pkt[3].size = 0;
}