Skip to content

Commit

Permalink
Fix audio does not play for audio only file
Browse files Browse the repository at this point in the history
This specific file was a WMA file with DTS coded audio. The first
packet of audio does not have a PTS of zero. Since there is no
video in the file, MLT tries to seek to position 0 for the first
audio frame and attempts to sync audio frames as if they started
at 0. This patch finds a first_pts value if there is no video in
the file to look for.
  • Loading branch information
bmatherly authored and ddennedy committed Sep 7, 2024
1 parent 278e9a0 commit 8e1367d
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/modules/avformat/producer_avformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,25 @@ static void find_first_pts(producer_avformat self, int video_index)
int64_t prev_pkt_duration = AV_NOPTS_VALUE;

av_init_packet(&pkt);

if (video_index == -1 && self->audio_index >= 0) {
// Special case for audio only files.
while (ret >= 0 && pkt_countdown-- > 0 && (self->first_pts == AV_NOPTS_VALUE)) {
ret = av_read_frame(context, &pkt);
if (ret >= 0 && pkt.stream_index == self->audio_index) {
mlt_log_verbose(MLT_PRODUCER_SERVICE(self->parent),
"first_pts %" PRId64 " dts %" PRId64 " pts_dts_delta %d\n",
pkt.pts,
pkt.dts,
(int) (pkt.pts - pkt.dts));
self->first_pts = best_pts(self, pkt.pts, pkt.dts);
}
av_packet_unref(&pkt);
}
av_seek_frame(context, -1, 0, AVSEEK_FLAG_BACKWARD);
return;
}

while (ret >= 0 && pkt_countdown-- > 0
&& (self->first_pts == AV_NOPTS_VALUE
|| (vfr_counter < VFR_THRESHOLD && vfr_countdown > 0))) {
Expand Down Expand Up @@ -3125,7 +3144,7 @@ static int seek_audio(producer_avformat self, mlt_position position, double time
int video_index = self->video_index;
if (video_index == -1)
video_index = first_video_index(self);
if (self->first_pts == AV_NOPTS_VALUE && video_index >= 0)
if (self->first_pts == AV_NOPTS_VALUE)
find_first_pts(self, video_index);
}

Expand Down

0 comments on commit 8e1367d

Please sign in to comment.