PDA

View Full Version : Add black frames in front of video (Shift video x milliseconds)


twazerty
8th December 2009, 18:56
When I record something with my DVB-S2 card I get a ts file where the audio starts sooner than the video.
So the audiodelay is negative.
timecode 0ms: first video frame
timecode -1070ms: first audioframe

When I convert the video to a different stream and then remux it with tsMuxer I get an out of sync file. tsMuxer doesn't handle negative audiodelay's well. So my idea was to add black frames before the video. If I could add 1070ms of black video the problem is solved. But I can't figure out how to do it.

DirectShowsource("c:\Recs\ZDF.ts",fps=50.000,audio=false)

How to add black frames in front of the video?

thetoof
8th December 2009, 19:04
s=directshowsource...
b=blackness(s).killaudio().trim(0,53) #1000/50fps = 20ms/frame 54*20=1080
b+s

poisondeathray
8th December 2009, 19:05
use blankclip()

e.g.
a=blankclip(100,1920,1080,"YV12",fps=50).killaudio()
b=directshowsource()
a++b

In this example, the blankclip is 100 frames long, fps 50, 1920x1080. You have to adjust the math for your specific case of 1070ms

whoops, thetoof beat me to the punch :)

Gavino
8th December 2009, 19:12
Note that doing this in Avisynth will require the entire video to be re-encoded. You might be better to just create the blank part and then do the appending in an editor that supports smart rendering. (unless you're processing the video anyway for some other reason)

thetoof
8th December 2009, 19:14
yeah, I prefer blackness since you are sure to get no compatibility issue between the clips

Gavino
8th December 2009, 19:21
I prefer blackness since you are sure to get no compatibility issue between the clips
I guess you mean using the form blackness(s) instead of blankclip(100, ...).
You can also use blankclip(s) - Blackness() is just an alias for BlankClip().

twazerty
8th December 2009, 19:36
They already need to be reencoded. And adding frames is easier then cutting audio. I'll go for poisondeathray's way. That is the easiest one for me.

thetoof
8th December 2009, 19:50
I guess you mean using the form blackness(s) instead of blankclip(100, ...)..Yes exactly; no need to specify anything like resolution, colorspace, etc etc

twazerty, you don't cut any audio with the script I posted. You simply say "create a black clip using the same specs as the source, disable audio in it, select 54 frames of that clip". Only a different way to do the exact same thing.

IanB
8th December 2009, 22:12
When cloning a Blank/Black clip you don't want the KillAudio() as the cloned clip will have identical properties including audio or the lack thereof. And you can do all the maths for the frame count as well. And if you had the audio in the script you could get it absolutely exact.Duration = 1070 # Milliseconds

Src=DirectShowSource(...

NFrames=Ceil(FrameRate(Src) * Duration / 1000.0)

Blackness(Src, Length=NFrames) ++ Src

# DelayAudio(Duration/1000.0 - NFrames/FrameRate()) # Residual delay
...

poisondeathray
8th December 2009, 22:26
Nice...That's a better way of doing it .

Good to know

Thanks

stickboy
9th December 2009, 07:15
Yes exactly; no need to specify anything like resolution, colorspace, etc etcYou don't need to do that for BlankClip either. As Gavino said, Blackness is an alias to BlankClip.

thetoof
9th December 2009, 07:23
Oh, my bad. I somehow thought that the argument clip was exclusive to blackness.