Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Stacking video frames

Guest
Jan 03, 2013 Jan 03, 2013

Hi everybody,

I need a bit of help getting started with a script for photoshop CS6.

I've seen that it's possible (Even if not supported) to have a script open individual video frames.  What I need is to take each frame and apply it with lighten blend mode to the frames before it.

The result should be a single image image with a single layer (JPG, PNG, TIFF, whatever...) .

This shouldn't be too complex of a script, right?  I don't remember much about photoshop scripting, so any help would be welcome!

Thanks!

TOPICS
Actions and scripting
3.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Jan 03, 2013 Jan 03, 2013

If I understand what you want this should do all but the final save. Note it could take a long time if there are a lot of frames.

// this requires a document with a video layer be the activeDocument

// and the video layer be the activeLayer. It also requires the timeline panel be visible

var vidDoc = app.activeDocument;

var dupDoc = vidDoc.duplicate();

dupDoc.flatten();

app.activeDocument = vidDoc;

var numerOfFrames = GetFrameCount();

for( var f =0; f< numerOfFrames; f++ ){

    GotoNextFrame();

    vidDoc

...
Translate
Adobe
Community Expert ,
Jan 03, 2013 Jan 03, 2013

I for one find your explanation unclear.

What do you start with, a stack of numbered images or a file with Layers …?

Could you please post a screenshot or mock-up to illustrate what you are trying to achieve?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 03, 2013 Jan 03, 2013

I suppose a run down of the algorithm might help explain what I need.

I start with an .AVI file.

1) Open first frame as base layer (Layer 0)

2) Open second frame as a new layer (layer 1)

3) Change blend mode of layer 1 to Lighten

4) Flatten image (Again, we have only leyer 0)

5) Repeat 2 to 4 untill last frame

6) Save flattened image.

I end up with a JPG or whatever other image file format.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 03, 2013 Jan 03, 2013

Have you tried File > Import > Video Frames to Layers?

Somebody needed help once with digitally simulating film being exposed to a complete movie (so something like a 90-plus-minute exposure) and in that case Layer > Smart Objects > Stack Mode provided a better approach than Blending the Layers directly. This may not at all be what you are after, but I wanted to mention it just in case.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 03, 2013 Jan 03, 2013

I tried importing the video as layers via File > Import > Video frames to layers, but it would only allow me to load up to 500 frames at a time.

That wouldn't be too bad, even if a bit labor intensive, but there's no frame number in the first\last frame selection, only a tiny and a highly inaccurate slider.  That's why I thought maybe a script could be a better option.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 03, 2013 Jan 03, 2013

That's why I thought maybe a script could be a better option.

I admittedly have no experience with import video frames individually via Script.

Have you tried recording it with ScriptingListener.plugin yet?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 03, 2013 Jan 03, 2013

Ummmmm.... nope.  How would I do that?

How do I tell the listener to get one frame at a time?  I've never used the listener before, so that may be a stupid question

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 03, 2013 Jan 03, 2013

One can use ScriptingListener.plugin to record Action Manager code for record-able Photoshop operations.

I thought one could try to figure out which values represent the in and out frames and then use the code in a function.

But it seems to be a bit inconvenient as it uses time and not frames, so it is probably not a valid option …

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 03, 2013 Jan 03, 2013

I've seen that it's possible (Even if not supported) to have a script open individual video frames.

Where have you seen this?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 03, 2013 Jan 03, 2013

Here:

http://forums.adobe.com/thread/726287

It's from 2010, so that would be CS4 or CS5, but I'm hoping it could be done with CS6.

I do have access to CS5 too, if necessary.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 03, 2013 Jan 03, 2013

If I understand what you want this should do all but the final save. Note it could take a long time if there are a lot of frames.

// this requires a document with a video layer be the activeDocument

// and the video layer be the activeLayer. It also requires the timeline panel be visible

var vidDoc = app.activeDocument;

var dupDoc = vidDoc.duplicate();

dupDoc.flatten();

app.activeDocument = vidDoc;

var numerOfFrames = GetFrameCount();

for( var f =0; f< numerOfFrames; f++ ){

    GotoNextFrame();

    vidDoc.selection.selectAll();

    executeAction( charIDToTypeID( "CpTL" ), undefined, DialogModes.NO );// jump frame to new layer

    vidDoc.activeLayer.duplicate(dupDoc);

    vidDoc.activeLayer.remove();

    app.activeDocument = dupDoc;

    dupDoc.activeLayer.blendMode = BlendMode.LIGHTEN;

    dupDoc.flatten();

    app.activeDocument = vidDoc;

}

function GetFrameCount(){

    var ref = new ActionReference();

     ref.putProperty( charIDToTypeID( 'Prpr' ), stringIDToTypeID( "frameCount" ) );

     ref.putClass( stringIDToTypeID( "timeline" ) );

     var desc = new ActionDescriptor();

     desc.putReference( charIDToTypeID( 'null' ), ref );

     var resultDesc = executeAction( charIDToTypeID( 'getd' ), desc, DialogModes.NO );

    

     return resultDesc.getInteger( stringIDToTypeID( "frameCount" ) );

};

function GotoNextFrame() {

     var thatWorked = undefined;

     try {

          var desc = new ActionDescriptor();

          var ref = new ActionReference();

          ref.putEnumerated( charIDToTypeID( "Mn  " ), charIDToTypeID( "MnIt" ), stringIDToTypeID( "timelineGoToNextFrame" ) );

          desc.putReference( charIDToTypeID( "null" ), ref );

          executeAction( charIDToTypeID( "slct" ), desc, DialogModes.NO );

          thatWorked = true;

     }

     catch(e) {

          thatWorked = false;

          alert('All frames are processed.');

     }

     return thatWorked;

};

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 04, 2013 Jan 04, 2013

Wow, thanks for the script

I have good news and bad news though...

Good news, it goes frame by frame, like it should, and seems to extract each frame at a time.  Also, in the end it creates a new image.

Bad news, the resulting image is identical to first frame of the video....

Also, I don't know if it's a bug in the script or a Photoshop "feature", but after running the script once, if I try to run it again, it takes the first frame and says 'All frames are processed', then goes to the next frame, and says 'All frames are processed', then the next frame and so on.  Only shutting Photoshop down and loading it again makes it re-run the script as it should.

I really appreciate all the help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2013 Jan 04, 2013

By temporarily marking out the line

dupDoc.flatten();

it seems that the duplicated Layers maintain their position in the timeline.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 04, 2013 Jan 04, 2013

c,pfaffenbichler, I'd try it yself, but now photoshop won't lemme open video files (DynamicLink media server unavailable)...

When you look at the duplicate layers, do they all look the same, or does each layer has a different frame in it?

Thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2013 Jan 04, 2013

The Layers are fine, they are just further down the timeline; so before flattening one might have to select the last frame.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2013 Jan 04, 2013

Inserting this code

var idslct = charIDToTypeID( "slct" );

var desc154 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );

var ref135 = new ActionReference();

var idMn = charIDToTypeID( "Mn " );

var idMnIt = charIDToTypeID( "MnIt" );

var idtimelineGoToLastFrame = stringIDToTypeID( "timelineGoToLastFrame" );

ref135.putEnumerated( idMn, idMnIt, idtimelineGoToLastFrame );

desc154.putReference( idnull, ref135 );

executeAction( idslct, desc154, DialogModes.NO );

before the flattening line might help.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 04, 2013 Jan 04, 2013

And

var idslct = charIDToTypeID( "slct" );

var desc153 = new ActionDescriptor();

var idnull = charIDToTypeID( "null" );

var ref134 = new ActionReference();

var idMn = charIDToTypeID( "Mn  " );

var idMnIt = charIDToTypeID( "MnIt" );

var idtimelineGoToFirstFrame = stringIDToTypeID( "timelineGoToFirstFrame" );

ref134.putEnumerated( idMn, idMnIt, idtimelineGoToFirstFrame );

desc153.putReference( idnull, ref134 );

executeAction( idslct, desc153, DialogModes.NO );

before the for-clause might address the alert-issue.

Edit: It seems I was wrong …

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jan 04, 2013 Jan 04, 2013

The script does make some assumptions and I didn't add any error checking. I should have added a check for last frame in the loop to avoid multiple 'all frames processed' alerts.

The Animation(Timeline) panel must be open and visible. If it is not the Action Manager functions will not work. That may be why it stays on the same frame when you use it.

It also assumes the current frame is the one you want to start with. It doesn't reset the position when it's done. So if you run it once you will have to reset the start position yourself( or use c.pfaffenbichler's function to goto first frame ) or it will start with the last frame and can't advance when run a second time.

I don't have CS6 but it works for me in CS5. There is one thing I would like you to check for me. With any frame selected in the movie press ctrl-a to select all then ctrl-j to copy to a new layer. IN CS5 the new layer is a normal art layer( not a video layer ) of the current frame. If it's a video layer in CS6 that would be the reason for all the layers being the first frame.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 04, 2013 Jan 04, 2013

I really appreciate all the help guys!

I'll try it on CS5 as soon as I get the chance, and I'll add c.pfaffenbichler's function.

I'm sure that with just a little messing around with the script I'll get exactly what I need.

You guys are the best!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 05, 2013 Jan 05, 2013

The layers are normal artLayers, but they seem to maintain Timeline properties when duplicated to the other image in CS6.

(Foe the screenshot I commented out the flatten-step.)

animationFramesScriptTest.jpg

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 08, 2013 Jan 08, 2013

Indeed.  Seems that CS6 keeps each layer as a video layer.

Still, with the flatten-step running, the resulting image is exactly what I need.

Thanks again for all the help!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jan 13, 2013 Jan 13, 2013
LATEST

Bahhh!   I just found out my algorithm was wrong

I tried modifying the script that you guys made, but got totally lost and made a mess.

I just modified the script you guys made, although it's far from elegant...

A couple of questions that may help me make the script a bit more tidy and readable:

1) Is there a way to "debug" what I'm doing, Like stepping line by line?

2) Is there a list of all the script commands I can use?  I noticed that some things (like flattening an image) can be written in one line, but the scripting listener makes you write 8 lines and have 17 vars for the same task.

Thanks!

Message was edited by: Morgantao

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines