Categories
User Help

Video scaling in ffmpeg causes audio gaps

I am trying to scale down a video (mp4 format) by using the following process :

  1. Segment the video
ffmpeg -v quiet -i <input-file> -map 0 -c copy -f segment -segment_time <segment_length> -reset_timestamps 1 -avoid_negative_ts make_non_negative output_%03d.mp4 
  1. Scale down each segment parallelly
ls output_*.mp4 |  parallel ffmpeg -v quiet -i {} -vf scale=-2:<output-resolution> temp_{#}.mp4
  1. Join segments to get back whole video
for i in temp_*.mp4; do echo file "$i"; done > concat.txt
ffmpeg -v quiet -f concat -i concat.txt -codec copy <output-file>

However, the final output contains small audio gaps. Consider segment length of 15s, then at roughly 15.28s there is a gap in the audio stream as shown in the waveform of audio below.

Audacity waveform

The green part highlights the waveform of the audio generated by scaling down the video using this command :

ffmpeg -v quiet -i <input-file> -vf scale=-2:<output-resolution> <output-file>

The yellow part highlights the waveform of the audio scaled down using the segmenting process described earlier.

One approach I could think of is to work on the video stream only while segmenting and copy the audio stream from the input file directly to the output file. But again it might lead to audio sync issues. How do I solve this ?

I am using ffmpeg version git-2020-03-03-60b1f85 in Windows 10.

Please note that I don’t want to re-encode the video because this will defeat the purpose of segmenting in the first place (in terms of time taken).

Leave a Reply

Your email address will not be published. Required fields are marked *