0

I want to extract an aligned audio stream from a video. The goal is to obtain an audio sequence that is precisely aligned with the video.

Issue: The video and audio sequences are not aligned. The output audio duration is shorter than the video input.

Script to reproduce:

fn=TV-20200617-2242-4900.websm.h264
url=https://download.media.tagesschau.de/video/2020/0617/$fn.mp4
wget -nc $url

ffmpeg -y -i "$fn.mp4" -vsync 1 -async 1 -map 0:a "$fn.wav" -map 0:v "$fn.flv"

ffprobe -i $fn.mp4  # Duration: 00:01:51.68
ffprobe -i $fn.flv  # Duration: 00:01:51.68
ffprobe -i $fn.wav  # Duration: 00:01:49.61

What I have tried (without success):

  • Adding -async 1 as suggested in this answer.
  • Adding -acodec copy and exporting the video at the same time (link).
  • Opening the mp4 in Audacity. The duration there is 00:01:49.61.
  • Opening the mp4 in VLC. Duration: 00:01:51.68.
  • Explicitly setting the framerate.
  • Other video files.

ffmpeg version 4.2.4-1ubuntu0.1

I would appreciate any hint on how to make this work. Thank you.

mcb
  • 398
  • 2
  • 12

1 Answers1

0

ffmpeg is doing nothing wrong. The input video and audio have slightly different durations:

$ ffprobe -v error -show_entries stream=codec_type,duration,start_pts,start_time -sexagesimal TV-20200617-2242-4900.websm.h264.mp4 
[STREAM]
codec_type=video
start_pts=3780
start_time=0:00:00.042000
duration=0:01:51.680000
[/STREAM]
[STREAM]
codec_type=audio
start_pts=0
start_time=0:00:00.000000
duration=0:01:49.610667
[/STREAM]

This does not mean the audio and video are out of sync.

llogan
  • 121,796
  • 28
  • 232
  • 243
  • Thank you for the hint, I did not think of this explanation. I am confused about the meaning of `start_time`. I have another file where `ffprobe` outputs a negative start time for audio: `start_pts=-2048 start_time=0:00:-0.042667`. How can this be? – mcb Oct 17 '20 at 18:14
  • @mcb I don't know your audio format and container, but it seems like *priming*, which is normal. See [ffmpeg wrong audio file duration after conversion in AAC](https://stackoverflow.com/questions/42410479/ffmpeg-wrong-audio-file-after-conversion-in-aac). – llogan Oct 17 '20 at 19:00