Search code examples
audioffmpeg

ffmpeg modify audio length/size ( stretch or shrink)


I am developing a web app, where people can record videos. I have been able to send chunks of audio n video to server successfully, where I am trying to combine them and return as single proper file.

my problem is if the recording is for one hour, after merging the chunks

video length : 1:00:00 , audio length : 00:59:30,

now, this is not a issue of audio not getting recorded( I have checked that), the problem is, somehow, when i merge the chunks of audio, it shrinks,

I find that it is progressive sync issue where it gets worse and worse as time increases.

I have searched the net for the solution, most places say async, I have tried using it, but to no avail, is the below usage correct?

ffmpeg -i audio.wav -async 1 -i video.webm -y -strict -2 v.mp4

(v.mp4 is the final file that I provide to the users.)


Solution

  • found a solution(or a temp fix, depends of how you look at it),

    it involves combination of ffmpeg and ffprobe ... i have done audio streching( ratio<1)

    ffprobe -i  a.mp3  -show_entries  format=duration  -v quiet  -print_format json
    ffprobe -i  v.mp4  -show_entries  format=duration  -v quiet  -print_format json
    ffmpeg  -i a.mp3 -filter:a atempo="0.9194791304347826" aSync.mp3   // audio is being stretched. 
    ffmpeg  -i aSync.mp3 -i v.mp4 final.mp4