View Full Version : Cant return the correct clip from a script. Help !


madhatter300871
21st October 2010, 13:09
Hi all

I have a very, very simple script that whilst processing video grabs evey 20th frame.

This script here works :-

-------------------------------------------------
cl=DirectShowSource("Z:\VM_shared\Outputs\testclip\Track 1-VC1 video.mkv")
Scriptclip(cl, "current_frame%20==0 ? Screengrab(cl) : cl")

function ScreenGrab(clip cl)
{
ImageWriter(cl, "D:\", Type = "ebmp")
}
--------------------------------------------------

.... and procudes 00000.ebmp (etc) files in the D drive every 20th frame ....

However, this does NOT work :-

-------------------------------------------------
cl=DirectShowSource("Z:\VM_shared\Outputs\testclip\Track 1-VC1 video.mkv")
Scriptclip(cl, "current_frame%20==0 ? Screengrab(cl) : cl")

function ScreenGrab(clip cl)
{
ImageWriter(cl.converttorgb(), "D:\", Type = "jpg")
}
--------------------------------------------------

.... I get the error "ScriptClip: Function does not return a video clip of the same colorspace as the source clip!"

I don't want ".ebmp" images, I want ".jpg" images.

If I then add "return cl" to the end of the function, no error is generated but also no image is written by imagewriter.

I can do what I want as follows :-
-----------------------------------------
video=DirectShowSource("Z:\VM_shared\Outputs\testclip\Track 1-VC1 video.mkv")
Image = ImageWriter(video.ConvertToRGB(), File = "D:\", Type = "jpg")
ConditionalFIlter(video, Image, video.ConvertToRGB(), "current_frame%50", "equals", "0")
------------------------------------------

...but it's soooo slow, my processing takes about a 40% speed hit because (I presume) i'm making an imagewriter for everyframe, just choosing whether to return the source frame or the imagewriter frame each time.

H E L P !!

How do I get my function to A) write an image using imagewriter and B) return a clip of the right colorspace back to the main script. I'm sure I am being very dumb and missing something here !

Many thanks in advance for any help offered.

madhatter300871
21st October 2010, 13:57
I've answered my own question !!

Because ImageWriter returns the clip ASWELL as writing the frame out to disc, I just needed to add ConvertToYV12() at the end of the function. So the script is now :-

-------------------------------------------------
cl=DirectShowSource("Z:\VM_shared\Outputs\testclip\Track 1-VC1 video.mkv")
Scriptclip(cl, "current_frame%20==0 ? Screengrab(cl) : cl")

function ScreenGrab(clip cl)
{
ImageWriter(cl.converttorgb(), "D:\", Type = "jpg")
ConvertToYV12()
}
--------------------------------------------------

Which leads me onto my next question, I now have every 20th frame converted to RGB and then converted back to YV12, not exactly ideal. Is there no way to have my function return the original clip AND write a convertedtoRGB clip out to disc.

Thanks.

Gavino
21st October 2010, 16:10
Is there no way to have my function return the original clip AND write a convertedtoRGB clip out to disc.
I don't think so. Since ImageWriter
a) only writes out frames that contribute to the final output, and
b) only accepts RGB input when writing to .jpg,
the final output has to include frames that have passed through ConvertToRGB.
If you want the script to output the original unprocessed frames, you will need to run it again without the ImageWriter part.

Also, in principle a more efficient way of writing your script would be
cl=DirectShowSource("Z:\VM_shared\Outputs\testclip\Track 1-VC1 video.mkv")
Image = Screengrab(cl)
ConditionalFilter(cl, Image, cl, "current_frame%20", "equals", "0")

function ScreenGrab(clip cl) {
ImageWriter(cl.converttorgb(), "D:\", Type = "jpg")
ConvertToYV12()
}
as ImageWriter is only instantiated once.

madhatter300871
1st November 2010, 16:53
Gavino, thanks. I didn't think there was a way, unfortunately !

Incidently, I used the conditional filter originally, before I started to play with scriptclip, and it slows down the whole process a lot, like at least half as slow. Having said that I didn't use "image=screengrab(cl)", I just included an imagewriter in the conditionalfilter so infact imagewriter was being instantiated every frame I presume.

I'll try your method to see if it's any faster.

Gavino
7th November 2010, 14:26
Is there no way to have my function return the original clip AND write a convertedtoRGB clip out to disc.
I don't think so.
I obviously wasn't thinking hard enough, as I've realised there is a way to do this.
The trick is to use a run-time function to force the required frames to be got from the ImageWriter clip, even though they are then discarded.
cl=DirectShowSource("Z:\VM_shared\Outputs\testclip\Track 1-VC1 video.mkv")
Image = ImageWriter(cl.converttorgb(), "D:\", Type = "jpg").Crop(0, 0, 16, 1)
Blank = BlankClip(Image)
ScriptClip(cl, "
dummy = current_frame%20 == 0 ? RGBDifference(Image, Blank) : 0
return last
")