VideoView does not play Audio in Video properly

梦想与她 提交于 2019-12-25 06:36:28

问题


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.


回答1:


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.




回答2:


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!



来源:https://stackoverflow.com/questions/21399550/videoview-does-not-play-audio-in-video-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!