Log in

View Full Version : H264/avc (.ts) Outsync When Using Avisynth Script


lurk
18th March 2008, 00:29
Hello!

Lets start. I recorded DVB-T (H264/AVC) stream using AltDVB to a .TS file. Then, as we all know we will have to use some script to open it in VirtualDub, so I asked a friend of mine about that, and he gave me following line

DirectShowSource("FILE.TS")

so I made .avs file with that line and opened it with VirtualDub, everything went fine. I have K-Lite Codec Pack 3.80 (full) installed so 2x Haali Media Splitters opened (why 2? maybe because input and output video boxes in VirtualDub) and also ffdshow video decoder and ffdshow audio decoder.
Well I get previews and such just fine, but now, when I click play in VirtualDub, audio/video goes out of sync! Well, thats not that strange, but lets say it happens randomly! What Im trying to say is that when I click play at one place, it is out of sync, when I click play at another place on timeline, its normal, when I change place on timeline again its outsync again, and when I change once more, its still out of sync. As I said, outsync appears just really really randomly!
Well, when I save the time, output file is most of the time out of sync, but sometimes its just fine. And again, as I said, this outsync appears REALLY REALLY randomly.
Well one more thing, everything is just excellent in Media Player Classic.
Also, Im on XP, and one more thing, Ive tried it on another machine (AMD Athlon 1.4 ghz ; 32 MB GPU) and outsync is there too. Current machine is Intel Celeron 1.3 ghz ; 64 MB GPU ; 512 MB RAM. Oh and Ive tried VirtualDub 1.7.18 and 1.8.0

Any help is appreciated!

Atak_Snajpera
18th March 2008, 01:47
Also, Im on XP, and one more thing, Ive tried it on another machine (AMD Athlon 1.4 ghz ; 32 MB GPU) and outsync is there too. Current machine is Intel Celeron 1.3 ghz ; 64 MB GPU ; 512 MB RAM. Oh and Ive tried VirtualDub 1.7.18 and 1.8.0

1.4ghz is not enough to decode h.264 therefore audio is not in sync. CPU is not able to decode frames in real time. If your source is 1080p you should have Core2Duo@3Ghz.

lurk
18th March 2008, 02:22
The video is 720x576
well, but is there any way for me to edit this video in VDub? (Cut adverts out and use filters)

Guest
18th March 2008, 02:47
If you want to scroll around on the timeline and set cut points in VirtualDub, you'll need a solution that supports random access. DirectShowSource() does not. The only solution I am aware of that supports random access is DGAVCDec.

lurk
18th March 2008, 03:01
If you want to scroll around on the timeline and set cut points in VirtualDub, you'll need a solution that supports random access. DirectShowSource() does not. The only solution I am aware of that supports random access is DGAVCDec.

Do you mean that I will have to use DGAVCDec before I can use VDub? Well Ive tried, but DGAVCDec doesnt seem to be support my AAC audio.

Guest
18th March 2008, 03:17
Do you mean that I will have to use DGAVCDec before I can use VDub? As I said, if you want random access, you have to use a solution that supports that. Is there something unclear about that?

Well Ive tried, but DGAVCDec doesnt seem to be support my AAC audio. Post a link to a chunk of your transport stream so I can see what you are talking about. Did DGAVCIndex demux the audio properly? Does your script dub that audio back in as it should?

lurk
18th March 2008, 03:27
There you go (its not the one Im doing things on, but I couldnt upload the 1 GB one Im working on)
http://x92.org/20080225_1217_ETV.TS

And well I think yes, after demuxing with DGAVCIndex I got these files:
yes.TS
yes.log
yes PID 2da L2 2ch 48 256.mp2
yes.demuxed.avc
yes.dga

Then I made script yes.avs and opened in VDub, but I didnt get sound.

Guest
18th March 2008, 04:27
I don't see any AAC audio.

This works just fine for me:

vid=AVCSource("E:\tmp\20080225_1217_ETV.dga")
aud=NicMPASource("20080225_1217_ETV PID 2da L2 2ch 48 256.mp2")
audiodub(vid,aud)

NicMPASource() is part of nicaudio.dll:

http://nic.dnsalias.com/NicAudio.zip

You'll have to sync it manually as I have not yet decided on the final approach I want use for AV sync. Use DelayAudio() as needed:

vid=AVCSource("E:\tmp\20080225_1217_ETV.dga")
aud=NicMPASource("20080225_1217_ETV PID 2da L2 2ch 48 256.mp2").DelayAudio(...as needed...)
audiodub(vid,aud)

lurk
18th March 2008, 13:31
I noticed that when I use DGAVCIndex, and then open .dga in VDub, I only get like 1/3 of the video.
My video was 50 minutes, now I get 22 minutes.

Heres the script I used
LoadPlugin("DGAVCDecode.dll")
LoadPlugin("NicAudio.dll")
vid=AVCSource("yes.dga")
aud=NicMPASource("yes PID 2da L2 2ch 48 256.mp2")
audiodub(vid,aud)

: edit :

Okay this one was recorded with AltDVB, now I tried DVBDream and then used DGAVCIndex,
everything went fine.

Now, Im having outsync problem again, I tried .DelayAudio(...as needed...) but I think
it didnt worked as I got no audio in VDub (I tried -7450 because this tool gave this value http://www.h264tscutter.de/show_artikel.php?id=4 ), so I tried interleaving inside VDub, didnt worked either.
Any ideas?

: edit :

Okay I tried opening the first AviSynth script ( DirectShowSource("pn.ts") ) in Media Player Classic, and what I saw, audio/video went out of sync. Well I was amazed because when I opened .TS directly in MPC, there was no outsync. There has to be problem with AviSynth. Also using DirectShowSource() opened 2 Haali media splitters http://i26.tinypic.com/x1yijm.jpg , while opening directly with MPC opened only 1 Haali http://i27.tinypic.com/2dcidg2.jpg

Comatose
8th April 2008, 11:00
1.4ghz is not enough to decode h.264 therefore audio is not in sync. CPU is not able to decode frames in real time. If your source is 1080p you should have Core2Duo@3Ghz.

My C2D @ 2.13ghz decodes 1080p realtime
Now, Im having outsync problem again
As said before, it's probably because you can't decode at realtime, so the audio is going out of sync.

Southstorm
8th April 2008, 12:29
I doubt it's a problem with AVISynth, but most likely a problem in using Directshowsource(). Render the file in Graphedit and see what filters are being used. Your problem probably lies in there.

lurk
8th April 2008, 14:48
Hello again!

There you have it

http://i124.photobucket.com/albums/p25/x92Heiko/grapheditforrapanija.jpg

Also when I played the file in GraphEdit everything was fine

Edit: One more thing. Is is possible to force AviSynth script to use VMR7/9 instead of Overlay Mixer?
Well right now I disabled ffdshow and enabled CoreAVC for video (audio is still using ffdshow)
and when Im playing the video inside VDub, theres no outsync right now, but I need VMR7 or 9
because Overlay Mixer makes the picture brighter

Overlay Mixer http://i124.photobucket.com/albums/p25/x92Heiko/VMR_Overlay.jpg
VMR7 http://i124.photobucket.com/albums/p25/x92Heiko/VMR_VMR7.jpg

Okay I think I managed to fix the last thing, I opened up CoreAVC's config window and changed these from Autodetect to PC (TV worked for me also) but you must change both of them.

http://i124.photobucket.com/albums/p25/x92Heiko/CoreAVCConfig.jpg

Edit2: Hello again

I think Ive finally managed to fix the outsync problem, I just used CoreAVC instead of ffdshow and audio was perfectly in sync in 4 videos, while before at least 1 wasnt using ffdshow.

If you have the same problem that I did, do the following:

1) Install CoreAVC (if you havent already)
2) Disable H264/AVC in ffdshow
http://i124.photobucket.com/albums/p25/x92Heiko/ffdshow_h264-disabled.jpg
Now you should have CoreAVC as default codec

TIP I had to (HAD TO) disable CoreAVC's deinterlacing (select None under Deinterlacing), otherwise I just got blue screen in VirtualDub when using DirectShowSource

lurk
13th April 2008, 03:36
Sorry for making new post but I wanted to post new results

I tried but.. its out of sync again.. when I select small range, about 30 seconds everything is fine, but when I select like 50 minutes then audio/video is out of sync very randomly, its out of sync, then its back in sync, then out again.. Im gonna set CoreAVC to "Skip when safe" and see what happens
Also, I think I havent mentioned I have a 5400rpm HDD, maybe this is the problem?


EDIT
Okay more updates, Im now pretty much sure that AltDVB caused the outsync. Okay heres the story...
I recorded 3 videos with altDVB, I opened them in DGAVCIndex and checked for audio, 2 had 32b and 1 had 322
Now when I encoded them all, those 2 with 32b were out of sync, and the one with 322 was perfectly fine.
Now Im using DVBDream and so far all videos have audio PID 322, I will encode some tonight.


...EDIT... and its final!
Hello again, I think I just solved all my problems!
First I make a AviSynth script with cutting info inside it.
Then I open it in VDub (cutting is already done) so I just add filters, select codecs for audio and video and process the file.
Ive encoded 7 files so far and all of them have been in sync!

Heres my script in case anyone needs it
DirectShowSource("the simpsons.ts",fps=25,convertfps=true)
clipOne = Trim(3266, 26193)
clipTwo = Trim(28081, 36885)
AlignedSplice(clipOne, clipTwo)

It takes some more time for me to learn how to deinterlace, crop and resize :P

xer0z
17th April 2008, 22:54
Hi! i have a similar problem, is DVBDream still the solution after
you found out about the trim() "fix" in the avs? or can you capture with altdvb and still get it in sync if you use the trim function?
and are you still using ffdshow for audio? and which version of coreavc are you running?

thanks for reporting your progress!
and thanks in advance! =)

lurk
18th April 2008, 00:08
Hello xer0z :)

Ive completely managed to fix my problem using Trim() function, whatever DVB software I use, well its logical because software just dumps the stream into a file, it doesn't re-encode it. Right now Im using AltDVB again because I guess I dont have enough RAM to run DVBDream, it gets laggy after a while. AltDVB works fine.

And yes Im using ffdshow for audio. My CoreAVC is 1.6.5.

Right now I have found that doing Trim() in script and doing deinterlacing, cropping and resizing in VirtualDub works the best, well for me at least.

xer0z
5th May 2008, 20:21
oh thanks lurk, works great!

do you know if it's possible to demux the AC3 track somehow?
instead of re-encoding it? and still keep it in sync? and ofc, still using the trim() script.

thanks in advance =))

lurk
5th May 2008, 20:27
Hello again xer0z!

Sorry but I have no experience about that.

lurk
26th May 2008, 23:43
Hello folks,

here's an update which will make all my current theories fall apart. Everything gets out of sync when dumping the stream to my HDD, but since my HDD is too slow for that (5400 rpm) it dumps with errors. All I need is a 7200rpm HDD and everything should be totally fine. Also, when I closed all other applications, and opened only DVBDream and dumped the stream, I got 0 stream errors, so when I encode, everything will be in sync.

Also heres the script Im using right now.
DirectShowSource("FINAL.ts",convertfps=true,fps=25)
Trim(355,294933)
Crop( 4, 44, -4, -42)
LanczosResize(720, 480)
Could be useful for someome. I must do some research about deinterlacing.