Question

I have an *.mp4 file which is duration of 2 min. Now it has audio track starting from 30 seconds upto 1.10 min. The rest before 30s and after 1.10min is blank.

Now the problem is when I try to play it in videoview or mediaplayer then, it plays audio right from beginning of the video rather from its actual position. I tried this on multiple phones with same result.

When I play the same video in MXPlayer or in Windows(VLC); it plays properly.

What is the solution to this problem ?

Edit

I have used -itsoffset command of Ffmpeg for achieving above video.

ffmpeg -y -i a.mp4 -itsoffset 00:00:30 sng.m4a -map 0:0 -map 1:0 -c:v copy -preset ultrafast out.mp4

Thanks in advance.

Was it helpful?

Solution

Ok finally I solved the problem by adding just 1 option -async

ffmpeg -y -i a.mp4 -itsoffset 00:00:30 sng.m4a -map 0:0 -map 1:0 -c:v copy -preset ultrafast -async 1 out.mp4

By default audio/video timestamps are stretched to match each other; which was my problem of audio starting from intial even after giving itsoffset.

As per Ffmpeg Doc using async 1 corrects the initial timestamp of audio only. I know that this option is deprecated; but anyhow it solved my case.

OTHER TIPS

There must be a simpler way to do it but the following works just fine for me:

ffmpeg -y -i a.mp4 -itsoffset 00:00:30 sng.m4a -f lavfi -i "aevalsrc=0" -filter_complex "[1:a][2:a]amix=inputs=2:duration=first:dropout_transition=0, apad[out]" -map 0:v -map '[out]' -c:v copy -preset ultrafast -shortest out.mp4

It does the following:

  • Create a silent sound
  • Mix it with the shifted audio until the end of your m4a file
  • Pad with silence indefinitely
  • Map this and the input video
  • Select the shortest duration (the video duration as the audio duration is infinite because of the pad filter)

Give it a try ;)

Edit: Jay's solution, using "-async 1", is a lot easier, check it!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top