samiamwork / Movist

Movie Player for Mac OS X based on QuickTime & FFmpeg. (Fork of original project on Google Code as it seems to have died)
GNU General Public License v3.0
206 stars 54 forks source link

Audio delay playing back mp4 files #46

Closed gradha closed 10 years ago

gradha commented 10 years ago

Recently I upgraded to handbrake 6240 from 5853 for encoding and noticed that movist doesn't sync the audio properly. However, movies produced by handbrake play fine in quicktime or vlc. Here are two small fragments (17s) from a video, each encoded with a different version:

Something in the stream has to be different for movist to have this audio delay effect. On the 6240 the incorrect lip sync is very noticeable.

samiamwork commented 10 years ago

I'll take a look.

samiamwork commented 10 years ago

I've looked into this a little and I can confirm the issue.

I inspected the videos to see what was different about them and I think I see where the problem might be. In the r5853 video the audio and video both start at 0. In the r6240 the video starts at 0.322589 and the audio starts at 0.161000. A difference of about 0.16, which feels like it matches the lag in the video.

[streams.stream.0]
index=0
codec_name=h264
codec_long_name=H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
codec_type=video
codec_time_base=1/180000
codec_tag_string=avc1
codec_tag=0x31637661
profile=Main
width=1024
height=576
has_b_frames=2
sample_aspect_ratio=1\:1
display_aspect_ratio=16\:9
pix_fmt=yuv420p
level=31
avg_frame_rate=6480000/219727
bit_rate=3308282.000000
time_base=1/90000
start_time=0.322589
duration=17.089878
nb_frames=504

...
[streams.stream.1]
index=1
codec_name=aac
codec_long_name=AAC (Advanced Audio Coding)
codec_type=audio
codec_time_base=1/48000
codec_tag_string=mp4a
codec_tag=0x6134706d
sample_rate=48000.000000
channels=2
bits_per_sample=0
avg_frame_rate=0/0
bit_rate=160978.000000
time_base=1/48000
start_time=0.161000
duration=17.024000
nb_frames=799

After looking around it appears that Movist should be adjusting pts times by the start time so they start at zero.

I've checked in a fix with 41ded956d45. Let me know if you find any others like this.