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

Get timecode data using AM code

Engaged ,
Mar 28, 2017 Mar 28, 2017

Copy link to clipboard

Copied

I've been trying to find a way to retrieve the timecode data for hours, minutes, seconds and frame for the current position in a Video in Photoshop. The script listener will record when the current active frame is changed. I can't seem to piece together anyway to get the data.

I've spent all day trying to figure this out. Any action manager coding experts out there that know how to do this?

This is the script listener code it gives when changing the current active frame. I figured this info could be used to make function to get the data.

// =======================================================

var idsetd = charIDToTypeID( "setd" );

    var desc405 = new ActionDescriptor();

    var idnull = charIDToTypeID( "null" );

        var ref80 = new ActionReference();

        var idPrpr = charIDToTypeID( "Prpr" );

        var idtime = stringIDToTypeID( "time" );

        ref80.putProperty( idPrpr, idtime );

        var idtimeline = stringIDToTypeID( "timeline" );

        ref80.putClass( idtimeline );

    desc405.putReference( idnull, ref80 );

    var idT = charIDToTypeID( "T   " );

        var desc406 = new ActionDescriptor();

        var idhours = stringIDToTypeID( "hours" );

        desc406.putInteger( idhours, 1 );

        var idminutes = stringIDToTypeID( "minutes" );

        desc406.putInteger( idminutes, 2 );

        var idseconds = stringIDToTypeID( "seconds" );

        desc406.putInteger( idseconds, 57 );

        var idframe = stringIDToTypeID( "frame" );

        desc406.putInteger( idframe, 29 );

        var idframeRate = stringIDToTypeID( "frameRate" );

        desc406.putDouble( idframeRate, 29.970000 );

    var idtimecode = stringIDToTypeID( "timecode" );

    desc405.putObject( idT, idtimecode, desc406 );

executeAction( idsetd, desc405, DialogModes.NO );

Also, the 2 functions below work for getting the total frame count and frame rate. I found an old posting by Mike Hale showing how to get the total frame count and I was able to use the same method to get the frame rate as well. However, using the same method doesn't seem to work for the hours, minutes, seconds and frame. I have tried dozens of ways to patch together AM code to do it. I'm guess that it is possible but I just don't understand action manager code well enough to figure it out.

These functions work for frame count and frame rate...

function getTotalFrameCount(){ 

    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 getFrameRate(){ 

    var ref = new ActionReference(); 

     ref.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "frameRate" ) ); 

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

     var desc = new ActionDescriptor(); 

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

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

      

     return resultDesc.getDouble( stringIDToTypeID( "frameRate" ) ); 

TOPICS
Actions and scripting

Views

915

Translate

Translate

Report

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
Adobe
Enthusiast ,
Mar 30, 2017 Mar 30, 2017

Copy link to clipboard

Copied

Check this tool:

GitHub - jardicc/ps-events-listener: Read very detailed events from Photoshop on the fly in human fr...

You can read same data like in script listener without script listener plugin.

And this will get you nice looking object which you can easily read.

GitHub - JavierAroche/descriptor-info: JSX module to recursively get all the properties in an Action...

Votes

Translate

Translate

Report

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
Engaged ,
Apr 01, 2017 Apr 01, 2017

Copy link to clipboard

Copied

Thanks for the reply. I downloaded and checked it out but it's way to confusing for me to figure out.

All I wanted to do was get the current Hours, Minutes, Seconds and Frame from he timeline into 4 variables. I couldn't figure out how to do that with the code in the download. Anyway, I think I'm just giving up on that now and moving on to something else. I really wish that Adobe would update the DOM and the documentation for it. Piecing together cryptic code to attempt to do simple things is too complex for a simple minded script writer such as myself.

Votes

Translate

Translate

Report

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
Enthusiast ,
Apr 01, 2017 Apr 01, 2017

Copy link to clipboard

Copied

Thing you downloaded can convert action manager code into "DOM like" format.

The problem is that you need to get action descriptor and this you can get through the action manager code.

Anyway there will be much less AM code and basic descriptors e.g. document or current layer usually contains everything you need and usually looks same or similar.

Anyway scripting in Photoshop can be hardcore if you are not lucky.

Votes

Translate

Translate

Report

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
Explorer ,
Jun 05, 2017 Jun 05, 2017

Copy link to clipboard

Copied

LATEST

Silver Back Gorilla?

Is this what you are looking for?

See comments in the code for more information.

function getCurrentTime() { 

    try {

        // placeholder for time values

        var Minutes;

        var Seconds;

        var Frame;

        // placeholder for timecode

        var timecode = new Array();

        // setting up to get property time from the timeline

        var ref = new ActionReference();

        ref.putProperty(charIDToTypeID('Prpr'), stringIDToTypeID('time'));

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

        var desc1 = new ActionDescriptor();

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

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

        // extract time object for furter processing

        desc = desc.getObjectValue(stringIDToTypeID('time'));

        // try to extract minute value or set to zero

        try {

            Minutes = desc.getInteger(stringIDToTypeID('minutes'));

        } catch (e) {

            Minutes = 0

        }

        // try to extract seconds value or set to zero

        try {

            Seconds = desc.getInteger(stringIDToTypeID('seconds'));

        } catch (e) {

            Seconds = 0;

        }

        // try to extract frame value or set to zero

        try {

            Frame = desc.getInteger(stringIDToTypeID('frame'));

        } catch (e) {

            Frame = 0;

        }

        // try to extract Framerate value

        var Framerate = desc.getUnitDoubleValue(stringIDToTypeID('frameRate'));

        // framerate included in single array element

        timecode.push([[Minutes], [Seconds], [Frame], [Framerate]]);

        return timecode;

    } catch (e) {

        // change this to something useful or delete to fail in silence

        return "Failed to get timecode";

    }

}

var currentTimeCode = getCurrentTime();

alert(currentTimeCode);

Votes

Translate

Translate

Report

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