Audio/video drift problems

Hi, I’m having a problem with the audio and video getting out of sync slowly over time. I am running Shotcut on Ubuntu 16.04, and am having this problem with both version 16.04 and version 16.05 of Shotcut.

I have an mp3 audio track that is about four minutes long and have a number of mp4 videos that are spliced together on a separate track. When I view the whole thing in Shotcut, everything looks good, but when I export to an mp4 then open it again in Shotcut, the video and audio have drifted apart. The drift is small at the beginning (between 10ms and 20ms after about 30 seconds) but it gets progressively worse until it’s over a second at the end of the four minutes. The audio seems fine, but the video gets further and further behind the audio.

I’ve mainly tried libx264 and aac encoding with a variety of options (constant bitrate, quality-based VBR, etc.) but I haven’t found any combination that seems to make a difference.

Any suggestions? Thanks.

What made the source MP4s you are using? Do any of them have variable frame rate? If so, those must be transcoded to constant framerate and replaced. Editing against variable frame-rate is not supported. I am not aware of any editor that supports that without first importing (i.e. transcode).
If not that, try converting the MP3 to WAV and replacing them.

Okay, thanks. The mp4s come from a couple of different sources, so I’ll have check to see if they have variable frame rate, and try using a wav file as well. I won’t have a chance to do that until later today, but I’ll post here whether or not that fixes the problem. Thanks for the quick response!

I thought I would follow up with what I’ve learned since yesterday. I checked and none of the mp4s had variable frame rates, although different files had different rates. The most common appeared to be 29.97 fps, so I did an ffmpeg batch convert of the ones that weren’t using that so that they would all be that frame rate. Unfortunately, that didn’t make a difference, nor did converting the soundtrack to wav. I also tried different interlacing modes, disabling parallel processing, etc., but none of that made a difference.

Eventually, though, I looked at the .mlt file and discovered that some of the properties were wrong, and in particular, that frame_rate_num was 60 and frame_rate_den was 1. I should have realized this earlier because every time I did an export the dialog box defaulted to the wrong values and I had to change them, but I haven’t been using the application for very long so I didn’t know what to expect.

I changed the frame_rate_num value to 29.97 and now the preview at least matches what was exported, with the video lagging the audio by a greater and greater amount during the four minute play time. I haven’t had a chance to do more than that, but I’m guessing that if I adjusted the timing and tried an export again, I would get the correct results. So now I’m trying to decide if I should try to move the clips within Shotcut, edit the .mlt file with a script or with an editor, or try something else such as reverting the frame_rate_num to 60 and trying to export that way.

In any case, I thought I would post an update in case anyone else runs into this problem in the future. Also, if you have suggestions for fixing the timing without re-doing everything by hand, let me know.


I changed the frame_rate_num value to 29.97

This should be an integer value only. frame_rate_num 30000, frame_rate_den 1001.

reverting the frame_rate_num to 60 and trying to export that way

That sounds like a quick and easy test to make.

I have put a large amount of work into A/V sync during the past 12 years of developing MLT - but it is a never-ending battle. I am not sure what is going wrong. At this point, if this were me and this was not my coding project, I would transcode all of the video clips to something more reliable with only I-frames such as DNxHD and replace them in the project.