Selur's Little Message Board

Full Version: Audio is ahead of video for half a second
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm using the latest Hybrid 2023.01.22.1 on Windows 64-bit. I am converting AVI files to MP4 with deinterlacing, but the video lags behind the audio for approximately half a second. I select input and output and set Audio to auto-add (first). I apply a x264 profile (https://we.tl/t-CiYd4YoF11), set Crop/resize settings, deinterlace with QTGMC (VapourSynth) with input scan type to top field first, preset Faster and Bob enabled, apple an Audio profile (https://we.tl/t-VE1vtzijFa) and dispatch the job.

Input file: https://we.tl/t-K6Xzsy2GHi
Output file: https://we.tl/t-vW9OS0aQJ9
Debug output: https://we.tl/t-QZDvWfAwnR

I think it might be the same problem as this guy: https://forum.selur.net/thread-2980.html Though if it is the same issue, he is incorrect in that the video is delayed, not the audio.

Do you have any idea what I might be doing wrong? Or is it a bug? I have used this workflow many times before, with these exact profiles, and I've never had this issue.

Thanks for the wonderful software! :) Any help is greatly appreciated.Please, read the 'Infos needed to fix&reproduce bugs,..'-sticky before you post about a problem.
Don't see any errors in the processing.
Time codes in the input indicate cfr.
No clue.
Not even sure there is a delay.
Looking at the files you provided with VirtualDub2:
[Image: grafik.png]
[Image: grafik.png]
those file seem to be sync.

Could it be a decoding issue on your end?

Cu Selur
A single freeze frame would create a 40ms delay not half a second (500ms).
Loading the input file in Hybrid, overwriting the scantype to tff, using QTGMC-Bob I see a small issue with frame 42.
Loading the output file in Hybrid, disabling the overwriting of the scantype to tff I too see a small issue with frame 42.
(Happens with both LWLibAVSource and FFMPEGSource2. And can be somewhat compensated using 'StabilizeIT'.)
In case you have a 64bit vfw decoder for the HuffYUV in your system, you can enable 'Filtering->Vapoursynth->Misc->Source->Prefer AviSource for .avi input' which will tell Hybrid to use AviSource if it finds a 64bit vfw decoder for the content. This was you can test whether it's an issue with the decoder.

I did a quick encode using:
Code:
# Imports
import vapoursynth as vs
import os
import ctypes
# Loading Support Files
Dllref = ctypes.windll.LoadLibrary("i:/Hybrid/64bit/vsfilters/Support/libfftw3-3.dll")
Dllref = ctypes.windll.LoadLibrary("i:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
import sys
# getting Vapoursynth core
core = vs.core
# Import scripts folder
scriptPath = 'i:/Hybrid/64bit/vsscripts'
sys.path.insert(0, os.path.abspath(scriptPath))
# Loading Plugins
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DebandFilter/Flash3kDeband/flash3kyuu_deband.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/SharpenFilter/AWarpSharp2/libawarpsharp2.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/TCanny.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/vcm.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/libtemporalmedian.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/FFT3DFilter/fft3dfilter.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/EEDI3m_opencl.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")
# Import scripts
import mvsfunc
import muvsfunc
import G41Fun
import fromDoom9
import SpotLess
import autowhite
import havsfunc
# source: 'C:\Users\Selur\Desktop\sync\Sample.avi'
# current color space: YUV422P8, bit depth: 8, resolution: 720x576, fps: 25, color matrix: 470bg, yuv luminance scale: limited, scanorder: top field first
# Loading C:\Users\Selur\Desktop\sync\Sample.avi using LWLibavSource
clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/sync/Sample.avi", format="YUV422P8", stream_index=0, cache=0, prefer_hw=0)
# Setting detected color matrix (470bg).
clip = core.std.SetFrameProps(clip, _Matrix=5)
# Setting color transfer info, when it is not set
clip = clip if not core.text.FrameProps(clip,'_Transfer') else core.std.SetFrameProps(clip, _Transfer=5)
# Setting color primaries info, when it is not set
clip = clip if not core.text.FrameProps(clip,'_Primaries') else core.std.SetFrameProps(clip, _Primaries=5)
# Setting color range to TV (limited) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
# making sure frame rate is set to 25
clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2)
# setting field order to what QTGMC should assume (top field first)
clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=2)
# Deinterlacing using QTGMC
clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=True, opencl=True) # new fps: 50
# make sure content is preceived as frame based
clip = core.std.SetFieldBased(clip, 0)
# adjusting color space from YUV422P8 to RGB24 for vsAutoWhite
clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, matrix_in_s="470bg", range_s="limited")
# Color Adjustment
clip = autowhite.AutoWhite(clip=clip)
# adjusting color space from RGB24 to YUV444P8 for vsSpotLess
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P8, matrix_s="470bg", range_s="limited")
clip = SpotLess.SpotLess(clip=clip, radT=1)
# stabilizing using StabilizeIT
clip = fromDoom9.StabilizeIT(clip=clip,thSCD2=140)
# cropping the video to 694x556
clip = core.std.CropRel(clip=clip, left=10, right=16, top=12, bottom=8)
# denoising using FFT3DFilter
clip = core.fft3dfilter.FFT3DFilter(clip=clip, sigma=8.00, planes=[1,2])
# denoising using mClean
clip = G41Fun.mClean(clip=clip)
# Resizing using 10 - bicubic spline
clip = core.fmtc.resample(clip=clip, kernel="spline16", w=704, h=568, interlaced=False, interlacedd=False) # resolution 704x568
# adjusting output color from: YUV444P16 to YUV422P10 for x264Model
clip = core.resize.Bicubic(clip=clip, dither_type="error_diffusion", format=vs.YUV422P10, range_s="limited")
# set output frame rate to 50fps
clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
# Output
clip.set_output()
and attached the result. (using QTGMC, AutoWhite, SpotLess, StabilizeIT, FFT3DFilter, mClean)

It still sounds a bit like it might be a playback issue.
AVC 4:2:2 is often not supported by Hardware decoders.

-> I also attached a YUV420 version, does the YUV420 version work better for you?
Do you see the duplicate frame if you open your reencode in Hybrid and check the Vapoursynth preview? (if yes, which frame?)

Cu Selur

Ps.: Your system isn't overclocked, is it?
Thanks for all your help! It's all going a bit over my head to be honest. What I established is that my output file plays fine on another computer. However, other MP4 output files that I compressed using an older version of Hybrid play fine on my regular PC as well, and if I compress the AVI with an old version of Hybrid (version 2021.07.18.1) now, it also plays fine. In other words, there has been some change in Hybrid since then that causes output that has this playback issue on my regular PC. And now that you mention it, my system is probably overclocked (which I think I did way back in 2016, so I'm not entirely sure, but almost sure).

Both your encodes play back fine. I will check for the duplicate frame tomorrow, as I just dispatched a bunch of jobs in Hybrid.

And "freezeframe" was a misnomer; the video freezes for approximately half a second (or 42 frames maybe?) at the start is what I meant.
I think I will stick to version 2021.07.18.1 for the time being; that one works Smile
Quote:What I established is that my output file plays fine on another computer.
Okay, so the file itself it fine, it might just be a decoder issue.
What player do you use? (if you use VLC try updating to the latest version, vlc 4 nightly build)

Quote: However, other MP4 output files that I compressed using an older version of Hybrid play fine on my regular PC as well, and if I compress the AVI with an old version of Hybrid (version 2021.07.18.1) now, it also plays fine. In other words, there has been some change in Hybrid since then that causes output that has this playback issue on my regular PC. And now that you mention it, my system is probably overclocked (which I think I did way back in 2016, so I'm not entirely sure, but almost sure).
Basically all tools Hybrid uses have been updated since 2021.07.18.1, so it's hard to tell what changed.

Quote:Both your encodes play back fine. I will check for the duplicate frame tomorrow, as I just dispatched a bunch of jobs in Hybrid.
Please also check whether it works if you use another aac encoder.

Quote:And "freezeframe" was a misnomer; the video freezes for approximately half a second (or 42 frames maybe?) at the start is what I meant.
I think I will stick to version 2021.07.18.1 for the time being; that one works Smile
half a second = 500ms = 12.5 frames (1 frame @ 25fps = 1000/24 = 40ms)

I suspect it is either an aac audio or mp4 container issue.
You can also try whether it works with the current version if you enable 'Config->Containers->Mp4 Settings->FFmpeg instead of MP4Box' and thus tell Hybrid to use ffmpeg instead of MP4Box for muxing.

Cu Selur

Ps.: going to bed now, but I'm curious to know what's causing the issue.