Why is my export different (lagging video) from what I see in preview?

Sorry in advance if this question will be fairly high level but I’m extremely new to both video editing and Shotcut. Basically, I’m pretty happy with the timing of my production when I’m playing it through the preview window. To my surprise, I the resulting timing of the content in the exported .mp4 is just a bit “off”. The video seems to lag just a touch against the audio. Obviously, I don’t understand why this would be and I’m a bit surprised as I’d expect preview to lag (if anything) rather than the export. It’s not a tremendous lag but enough frames to make it noticeable and just feel “off”.

Just looking for general feedback or possibly even a list of things I might want to check in terms of having what I see in preview match what export spits out.

Thanks in advance

Trying to help it occurs to me to ask:
-Shotcut version and operating system.
-Export configuration, do you use a certain preset?
-Do you use hardware encoding for export?
-What is the configuration of your project?

In any case, I detected in one of my latest projects a desynchronization between audio and video, when I export using a hardware encoder (in my case h264_nvec) so I tried disabling the hardware encoder (it is disabled by default) and I exported (libX264 ) and that desynchronization disappeared.
I did this in the Youtube export preset without modifying any additional parameters.

If you are using Hardware Encoding, try switching it off.

Member @jonray had this tip for another member with a similar problem to yours:

This has happened to me before. I found a workaround was to advance the audio track forwards by 7 frames (I presume your audio is on a separate track). It seems out of synch in the preview but synched in the export.
You can test just a portion of your video by using the “timeline to source” feature.

See also this thread:

Thank you. I’ve been able to see improved results by disabling the hardware encoding as you’ve suggested. Much appreciated.

Continuing this thread as disabling hardware encoding has gotten me only so far. Using the Youtube preset with the default quality allowed me to export a file with audio and video that is in sync and represents the work I’ve done in my timeline. FYI, my audio is on its own track and I’ve got 2 other tracks of various video clips that weave in and out with various transitions and filters. The export mentioned above is 72mb in size. Here’s the file’s meta information as reported by smplayer

General
File: /data/mtf8/Cavity/video/shotcut/export/Cavity2.mp4
Size: 74181 KB (72 MB)
Length: 00:04:26
Demuxer: lavfpref
Initial Video Stream
Resolution: 1920 x 1080
Aspect ratio: 1.7778
Format: H264
Bitrate: 1887 kbps
Frames per second: 60.000
Selected codec: ffh264
Video Streams
Track 0
ID: 0
Initial Audio Stream
Format: MP4A
Bitrate: 381 kbps
Rate: 48000 Hz
Channels: 2
Selected codec: ffaac

Using the same Youtube export, I ran another export job but with a modified quality value of 75 (up from the default of 55). This resulted in a file size of 312mb and I was able to somewhat notice the video lag as the resulting file was played from start to finish. In other words, it seemed to be in sync in the beginning but became out of sync as it progressed. Again, it was “somewhat noticeable”.

Then I ran another job with the Youtube quality bumped to 85. File size doubled but the lag was most definitely noticeable. My take on all this is that there is most definitely a direct relationship between the quality and the resulting sync issue. I don’t understand this and could use some help in deciding what to do. Shifting the audio by 6 or 7 frames as suggested in other threads doesn’t feel like the right move as I have no point of reference and it just feels like I’d be flying blind.

Also, what is this “ProRef” export preset I’ve been reading about in this forum? I’m running 20.06.28 and I don’t see that preset?

What other information should I be providing here in order to help nail this down?

Thanks in advance

I have seen players that struggle to cope with throughput and seemingly do not handle frame-dropping well to keep up. I noticed various problems when testing 4K60 playback of AVC and HEVC on a strong PC in Windows player, VLC, MPC-HT, and PotPlayer. Sometimes video was stalled, garbled digital noise, or the audio and playhead would end while the video continues playing. In fact, in this test I found Shotcut player to be better than most (must use Automatic Video Mode). I see you are using 1080p60; so not as stressful, but perhaps there is a relationship between quality level and reading+decoding throughput. Try more than one player.

I found the prores codec. Tried to run a small sample export job with it but the job failed right away. I have no idea why

Some additional results from various tests of a small 30 second export

Preset: Youtube
Quality: 55%
Codec: hw-nvenc
Result: No video, blank white screen

Preset: Youtube
Quality: 55%
Codec: hw-vaapi
Result: Looks and sounds good. File size of 8.1Mb

Preset Youtube
Quality: 100%
Codec: hw-vaapi
Result: Looks and sounds good. File size of 11.7MB

Preset: Youtube
Quality: 100%
Codec: libx264
Result: A/V out of sync. File size of 178MB

From the above, I’ve got a few questions:

  1. What exactly is hw-vaapi? I mean, I know it’s hardware related and I gather that hw-nvenc didn’t work because I’m probably not using the non-free Nvidia bits on my system. I’m not sure what vaapi is though or why it even works for me to begin with?

  2. Why would using the libx264 (software) codec produce a file so much larger than when using a hardware codec?

  3. Regarding the export dialog (advanced), it seems there are 2 ways to select hardware encoding. There’s the “Use hardware encoding” checkbox with the “configure” button next to it. Then there’s the Codec dropdown menu. I assume these are acting in tandem and essentially producing the same outcome regardless of which is used?

Thanks in advance

100% means lossless. There is no compression and quite a few video players will probably have difficulties playing the resulting file properly. If you want “Visually Lossless” (i.e. the human eye can’t see the difference) don’t go above 67%. From the ffmpeg website:

Lossless H.264

You can use -crf 0 to create a lossless video. Two useful presets for this are ultrafast or veryslow since either a fast encoding speed or best compression are usually the most important factors.

Fast encoding example:

ffmpeg -i input -c:v libx264 -preset ultrafast -crf 0 output.mkv

Best compression example:

ffmpeg -i input -c:v libx264 -preset veryslow -crf 0 output.mkv

Note that lossless output files will likely be huge, and most non-FFmpeg based players will not be able to decode lossless. Therefore, if compatibility or file size are an issue, you should not use lossless.

Tip: If you’re looking for an output that is roughly “visually lossless” but not technically lossless, use a -crf value of around 17 or 18 (you’ll have to experiment to see which value is acceptable for you). It will likely be indistinguishable from the source and not result in a huge, possibly incompatible file like true lossless mode.

2 Likes

Thank you so much for this information. Looking forward to putting it to use later tonight! Happy 4th!

I can confirm this with VLC playing a 1920 X 1080 XDCAM (50Mb/s) file.
The computer is a MacPro with Xeon CPU and loads of RAM, yet the audio
progressively gets out of sync and lots of clicking noises on the audio.

Seeking is extremely slow too.

Also happens with the higher ProRes codecs and probably DNxHD but have not tried that.

This topic was automatically closed after 90 days. New replies are no longer allowed.