Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 20th December 2017, 23:30   #1  |  Link
darkelf5
Registered User
 
Join Date: Aug 2009
Posts: 17
Audio sync help

I've been wrestling with this the whole day.
I have a video that's perfectly synced when being played with MPC-HC
which i'm trying to trim and encode and it's always out of sync no matter
what i've tried. I've indexed it with ffms, lsmash, used fpsnum and fpsden, audiodelay without succes.

The only thing that trims and encodes it with audio synced is xvid4psp but i wanna add some filters that it doesn't support so i wanna do it on my own.

Can anyone try and help me with this? Here's the MediaInfo output:
Code:
Video
Count                                    : 338
Count of stream of this kind             : 1
Kind of stream                           : Video
Kind of stream                           : Video
Stream identifier                        : 0
StreamOrder                              : 0
Inform                                   : 15.0 Mb/s, 3840*2160 (16:9), at 23.844 FPS, AVC (Main@L5.1) (CABAC / 3 Ref Frames)
ID                                       : 1
ID                                       : 1
Unique ID                                : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format/Url                               : http://developers.videolan.org/x264.html
Commercial name                          : AVC
Format profile                           : Main@L5.1
Format settings                          : CABAC / 3 Ref Frames
Format settings, CABAC                   : Yes
Format settings, CABAC                   : Yes
Format settings, RefFrames               : 3
Format settings, RefFrames               : 3 frames
Internet media type                      : video/H264
Codec ID                                 : V_MPEG4/ISO/AVC
Codec ID/Url                             : http://ffdshow-tryout.sourceforge.net/
Codec                                    : V_MPEG4/ISO/AVC
Codec                                    : AVC
Codec/Family                             : AVC
Codec/Info                               : Advanced Video Codec
Codec/Url                                : http://ffdshow-tryout.sourceforge.net/
Codec profile                            : Main@L5.1
Codec settings                           : CABAC / 3 Ref Frames
Codec settings, CABAC                    : Yes
Codec_Settings_RefFrames                 : 3
Duration                                 : 4545534.000000
Duration                                 : 1 h 15 min
Duration                                 : 1 h 15 min 45 s 534 ms
Duration                                 : 1 h 15 min
Duration                                 : 01:15:45.534
Duration                                 : 01:15:15:23
Duration                                 : 01:15:45.534 (01:15:15:23)
Bit rate mode                            : CBR
Bit rate mode                            : Constant
Bit rate                                 : 14999552
Bit rate                                 : 15.0 Mb/s
Width                                    : 3840
Width                                    : 3 840 pixels
Height                                   : 2160
Height                                   : 2 160 pixels
Sampled_Width                            : 3840
Sampled_Height                           : 2160
Pixel aspect ratio                       : 1.000
Display aspect ratio                     : 1.778
Display aspect ratio                     : 16:9
Frame rate mode                          : VFR
Frame rate mode                          : Variable
Frame rate                               : 23.844
Frame rate                               : 23.844 FPS
Original frame rate                      : 23.976
Original frame rate                      : 23.976 (24000/1001) FPS
FrameRate_Original_Num                   : 24000
FrameRate_Original_Den                   : 1001
Frame count                              : 108383
Resolution                               : 8
Resolution                               : 8 bits
Colorimetry                              : 4:2:0
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Chroma subsampling                       : 4:2:0
Bit depth                                : 8
Bit depth                                : 8 bits
Scan type                                : Progressive
Scan type                                : Progressive
Interlacement                            : PPF
Interlacement                            : Progressive
Bits/(Pixel*Frame)                       : 0.076
Delay                                    : 291
Delay                                    : 291 ms
Delay                                    : 291 ms
Delay                                    : 291 ms
Delay                                    : 00:00:00.291
Delay, origin                            : Container
Delay, origin                            : Container
Stream size                              : 8479208897
Stream size                              : 7.90 GiB (99%)
Stream size                              : 8 GiB
Stream size                              : 7.9 GiB
Stream size                              : 7.90 GiB
Stream size                              : 7.897 GiB
Stream size                              : 7.90 GiB (99%)
Proportion of this stream                : 0.98694
Default                                  : Yes
Default                                  : Yes
Forced                                   : No
Forced                                   : No
Buffer size                              : 30000000

Audio
Count                                    : 275
Count of stream of this kind             : 1
Kind of stream                           : Audio
Kind of stream                           : Audio
Stream identifier                        : 0
StreamOrder                              : 1
Inform                                   : 192 kb/s, 44.1 kHz, 2 channels, AAC (LC)
ID                                       : 2
ID                                       : 2
Unique ID                                : 2
Format                                   : AAC
Format/Info                              : Advanced Audio Codec
Commercial name                          : AAC
Format profile                           : LC
Codec ID                                 : A_AAC-2
Codec                                    : AAC LC
Codec                                    : AAC LC
Codec/Family                             : AAC
Duration                                 : 4545676.000000
Duration                                 : 1 h 15 min
Duration                                 : 1 h 15 min 45 s 676 ms
Duration                                 : 1 h 15 min
Duration                                 : 01:15:45.676
Duration                                 : 01:15:44:17
Duration                                 : 01:15:45.676 (01:15:44:17)
Bit rate                                 : 192000
Bit rate                                 : 192 kb/s
Channel(s)                               : 2
Channel(s)                               : 2 channels
Channel positions                        : Front: L R
Channel positions                        : 2/0/0
ChannelLayout                            : L R
Samples per frame                        : 1024
Sampling rate                            : 44100
Sampling rate                            : 44.1 kHz
Samples count                            : 200464304
Frame rate                               : 43.066
Frame rate                               : 43.066 FPS (1024 SPF)
Frame count                              : 195409
Compression mode                         : Lossy
Compression mode                         : Lossy
Delay                                    : 0
Delay                                    : 00:00:00.000
Delay, origin                            : Container
Delay, origin                            : Container
Delay relative to video                  : -291
Delay relative to video                  : -291 ms
Delay relative to video                  : -291 ms
Delay relative to video                  : -291 ms
Delay relative to video                  : -00:00:00.291
Video0 delay                             : -291
Video0 delay                             : -291 ms
Video0 delay                             : -291 ms
Video0 delay                             : -291 ms
Video0 delay                             : -00:00:00.291
Stream size                              : 110799774
Stream size                              : 106 MiB (1%)
Stream size                              : 106 MiB
Stream size                              : 106 MiB
Stream size                              : 106 MiB
Stream size                              : 105.7 MiB
Stream size                              : 106 MiB (1%)
Proportion of this stream                : 0.01290
Default                                  : Yes
Default                                  : Yes
Forced                                   : No
Forced                                   : No
darkelf5 is offline   Reply With Quote
Old 20th December 2017, 23:40   #2  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 1,822
Not my strong suit, but I'm guessing that this:

Code:
Frame rate mode                          : Variable
is going to be a problem. Avisynth doesn't do variable frame rates.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 21st December 2017, 00:04   #3  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 506
I think of the following, extract the audio and convert it to WAV, then join it to the video and do the trim, the audio that is going to be left should be synchronized. These problems happen when working with variable audio.
__________________
By law and justice!

Flea Market
GMJCZP is offline   Reply With Quote
Old 21st December 2017, 00:51   #4  |  Link
darkelf5
Registered User
 
Join Date: Aug 2009
Posts: 17
Nope, still the same issue.
darkelf5 is offline   Reply With Quote
Old 21st December 2017, 03:07   #5  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 506
Try with DSS2 Mod for index the video, convert it to a lossless format, the audio in wav attach it and check if it is synchronized.
__________________
By law and justice!

Flea Market
GMJCZP is offline   Reply With Quote
Old 21st December 2017, 05:13   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,197
You could try below BAT file

Code:
setlocal

REM Where to Find ffmpeg
set FFMPEG="C:\BIN\ffmpeg.exe"

REM Where to get input file, No terminating Backslash, "." = current directory
set INDIR="."


REM Where to place output file, No terminating Backslash.
set OUTDIR="D:"


FOR %%A IN (*.wmv *.mpg *.avi *.flv *.mov *.mp4 *.m4v *.RAM *.RM *.mkv *.TS *.ogv) DO (
  %FFMPEG% -i "%INDIR%\%%A" -vcodec utvideo -acodec pcm_s16le "%OUTDIR%\%%~nxA.AVI"

)

Pause
It dont like Spaces in filenames.
REM lines are comments
Output UT_Video video and PCM audio.

Perhaps something like this afterwards in avs Script
Code:
AssumeFPS(24000,1001,True)
ReSampleAudio(44100)    # or 48000
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 21st December 2017, 20:02   #7  |  Link
darkelf5
Registered User
 
Join Date: Aug 2009
Posts: 17
Indexing the original video with DSS2 i get an Wait for FrameReady error.

Converting the video to utvideo with ffmpeg and loading it with DSS2 (which shows frame rate as 23.000) with the wav attached works but it's also out of sync when i try to trim it even with manually setting the fps either in DSS2 or via AssumeFPS.

It doesn't matter, thanks for your help guys.
darkelf5 is offline   Reply With Quote
Old 21st December 2017, 21:27   #8  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 7,197
Did you try with AviSource (always good idea to try first with AVI lossless), followed by the given script ?

EDIT: I thought ffmpeg as in given bat, converts to constant framerate (inserting frames as needed).

EDIT: Might also be worth trying VirtualDubFilterMod, and save as AVI with UT_Video and PCM audio (with Fast Recompress).
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 21st December 2017 at 21:33.
StainlessS is offline   Reply With Quote
Old 21st December 2017, 21:52   #9  |  Link
GMJCZP
Registered User
 
GMJCZP's Avatar
 
Join Date: Apr 2010
Location: I have a statue in Hakodate, Japan
Posts: 506
darkelf5, try what TinMan tells you, in the past I solved problems of desynchronization with AVI with audio in MP3 VBR.

EDIT: did you use DDS2 or DSS2 Mod as I suggested?
__________________
By law and justice!

Flea Market

Last edited by GMJCZP; 21st December 2017 at 23:31.
GMJCZP is offline   Reply With Quote
Old 22nd December 2017, 00:19   #10  |  Link
darkelf5
Registered User
 
Join Date: Aug 2009
Posts: 17
@StainlessS
Well it converts it to constant 23.000 fps. Just tried AviSource - same problem.

@GMJCZP
DSS2Mod

Gonna try VirtualDubFilterMod.
darkelf5 is offline   Reply With Quote
Old 22nd December 2017, 01:16   #11  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,155
Is your video vfr?
lansing is offline   Reply With Quote
Old 22nd December 2017, 01:55   #12  |  Link
darkelf5
Registered User
 
Join Date: Aug 2009
Posts: 17
MediaInfo says it is.

Quote:
Originally Posted by darkelf5 View Post
Code:
Frame rate mode                          : VFR
Frame rate mode                          : Variable
Frame rate                               : 23.844
Original frame rate                      : 23.976
darkelf5 is offline   Reply With Quote
Old 22nd December 2017, 02:22   #13  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,976
You would need to convert to CFR before editing. This is true for almost everything (other video editing applications), not just avisynth

I'm guessing you already did that with xvid4psp, the only thing that "worked" for you
Quote:
Originally Posted by darkelf5 View Post
The only thing that trims and encodes it with audio synced is xvid4psp but i wanna add some filters that it doesn't support so i wanna do it on my own.

Have a look at the script it used . Look at the log files. I bet it was something like DirectShowSource("video.ext" , fps=23.976, convertfps=true)

But it's not "safe" to use temporal filters with directshow . So if you were planning on those types of filters, I would use that to encode an intermediate first
poisondeathray is offline   Reply With Quote
Old 22nd December 2017, 02:33   #14  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,155
Quote:
Originally Posted by darkelf5 View Post
MediaInfo says it is.
That mediainfo you posted looks very confusing to me. By VFR it usually means that the video change frame rate something like 30fps to 24fps on playback, 23.844 to 23.976 is probably some false alarm.

You'll have to play the original file and check it yourself. For example, play it with media player classic, turn on view->statistics, jump around in the video and look at the playback rate.
lansing is offline   Reply With Quote
Old 22nd December 2017, 03:07   #15  |  Link
darkelf5
Registered User
 
Join Date: Aug 2009
Posts: 17
MPC statistics shows that frame rate is about 23 ,so it must be the audio issue, right?
xvid4psp converts it to 23.976 but i don't think that the new versions use AviSynth so there's no script to inspect.
darkelf5 is offline   Reply With Quote
Old 22nd December 2017, 03:55   #16  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,976
Quote:
Originally Posted by darkelf5 View Post
MPC statistics shows that frame rate is about 23 ,so it must be the audio issue, right?
Not necessarily

Quote:
xvid4psp converts it to 23.976 but i don't think that the new versions use AviSynth so there's no script to inspect.

It doesn't matter. It's still the right answer and source filter if you want to edit and use avisynth . The other methods are slightly less accurate and can have slight problems with frame placement. But this assumes your directshow system is configured correctly.


In fact, you can just check it really quickly in MPCHC , jump around a bit. If it's in sync there (assuming you can playback UHD in realtime), then it's almost 100% guarenteed to work if you encode an intermediate first before editing / other filters


What lansing is probably suggesting by "false alarm" , is that there is a small chance you can just assume a CFR framerate by overwriting timecodes, e.g. with mp4fpsmod. Because it looks like it's minimally variable if you assume mediainfo is correct. You would have to extract the timecodes and examine it to be sure. The benefit would be no large intermediate file, and you could use "normal" source filter like lsmashvideosource)
poisondeathray is offline   Reply With Quote
Old 22nd December 2017, 03:56   #17  |  Link
lansing
Registered User
 
Join Date: Sep 2006
Posts: 1,155
Quote:
Originally Posted by darkelf5 View Post
MPC statistics shows that frame rate is about 23 ,so it must be the audio issue, right?
xvid4psp converts it to 23.976 but i don't think that the new versions use AviSynth so there's no script to inspect.
To check where the problem came from, convert your audio to WAV and then open it with the original video, the audio should be out of sync by some milliseconds, just adjust it with the + and - key in number pad if you're playing with mpc, and then remember that delay.

Then did a quick convert of the video to create a test video, like encode it with ultrafast mode in x264 and resolution 640x360, and then play that test video with the wav, use the same delay you found before. If they're in sync and the whole time, then the problem should be just the audio delay. If they're out of sync, the problem is the video.
lansing is offline   Reply With Quote
Old 22nd December 2017, 11:44   #18  |  Link
tebasuna51
Moderator
 
tebasuna51's Avatar
 
Join Date: Feb 2005
Location: Spain
Posts: 5,642
I can try other approach to preserve A/V sync. For that I need:

1) I don't know your source container from the initial MediaInfo.
Please obtain a Source.mkv from it, renaming or converting with MkvToolNix.

2) Extract the timestamps from video and audio tracks of Source.mkv:
..."mkvextract.exe" "Source.mkv" timestamps_v2 0:"Source.mkv_ 0.txt" 1:"Source.mkv_ 1.txt"

zip "Source.mkv_ 0.txt" and "Source.mkv_ 1.txt" and upload here (Attach)

3) Put here your avs, at least with Trim's an any other function than change fps.
__________________
BeHappy, AviSynth audio transcoder, in Doom9 forums. NicAudio, BassAudio, audio decoders.
tebasuna51 is offline   Reply With Quote
Old 22nd December 2017, 13:02   #19  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,495
Quote:
Originally Posted by darkelf5 View Post
what i've tried. I've indexed it with ffms, lsmash, used fpsnum and fpsden, audiodelay without succes.
Are you running both video and audio through the script or just video, but audio separately?

E.g.:
Code:
a=ffaudiosource("source.mkv")
v=ffvideosource("source.mkv", fpsnum=24000, fpsden=1001)
AudioDub(v, a)
If you are running both through the script and it async (but playing the original file in e.g. MPC-HC is sync) then its an ffms bug and should be reported on their bug tracker (along with the file).
sneaker_ger is offline   Reply With Quote
Old 22nd December 2017, 13:07   #20  |  Link
darkelf5
Registered User
 
Join Date: Aug 2009
Posts: 17
Manually adjusting the sync works although it gets desynced near the end.

Code:
v = LWLibavVideoSource("video.mkv", fpsnum=24000, fpsden=1001)
a = WAVSource("audio.wav")
AudioDub(v, a)
Dissolve(Trim(0, 19478), Trim(25962, 55793), 18)
FadeIO(1)
Can't attach the timecodes as they exceed the 300kb limit
Code:
http://www12.zippyshare.com/v/d7CYgXUP/file.html
@sneaker_ger
I've tried importing both external wav and internal audio. The results are the same.

Last edited by darkelf5; 22nd December 2017 at 13:14.
darkelf5 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 01:52.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.