Skip to main content
Participant
May 20, 2023
Answered

Batch editing the nth frame delay of gifs

  • May 20, 2023
  • 1 reply
  • 233 views

How can I batch edit gifs in Photoshop to use an alternating frame delay of 2-2-1?

Frame 1 0.02 secs
Frame 2 0.02 secs
Frame 3 0.01 secs
Frame 4 0.02 secs
Frame 5 0.02 secs
Frame 6 0.01...

Is there already a script for this?

 

 

Ideally I'd want it to

1) Open Gif

2) Loop through timeline and set 0.01 secs for every 3rd frame

3) Save for Web export

4) Batch the next gif

 

Just need some help with the second step

This topic has been closed for replies.
Correct answer c.pfaffenbichler

Kind of dirty, but you can give this a try: 

// select frame and set to certain duration;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    var theCheck = true;
    var theFrame = 1;
    while (theCheck == true) {
    var theCheck = setFrameDuration (theFrame, 0.5);
    theFrame++;
    var theCheck = setFrameDuration (theFrame, 0.5);
    theFrame++;
    var theCheck = setFrameDuration (theFrame, 0.05);
    theFrame++;
    }
};
////// set delay of frame //////
function setFrameDuration (theFrame, theDelay) {
try {
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
// select frame
    var desc2 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putIndex( idanimationFrameClass, theFrame );
    desc2.putReference( charIDToTypeID( "null" ), ref1 );
executeAction( charIDToTypeID( "slct" ), desc2, DialogModes.NO );
// set frame’s duration;
    var desc3 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putEnumerated( idanimationFrameClass, charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
    desc3.putReference(  charIDToTypeID( "null" ), ref2 );
        var desc4 = new ActionDescriptor();
        desc4.putDouble( stringIDToTypeID( "animationFrameDelay" ), theDelay );
    desc3.putObject( charIDToTypeID( "T   " ), idanimationFrameClass, desc4 );
executeAction( charIDToTypeID( "setd" ), desc3, DialogModes.NO );
return true
} catch (e) {return false};
};
////// by michael l hale //////
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" ) );
};

1 reply

c.pfaffenbichler
Community Expert
c.pfaffenbichlerCommunity ExpertCorrect answer
Community Expert
May 20, 2023

Kind of dirty, but you can give this a try: 

// select frame and set to certain duration;
// 2023, use it at your own risk;
if (app.documents.length > 0) {
    var myDocument = app.activeDocument;
    var theCheck = true;
    var theFrame = 1;
    while (theCheck == true) {
    var theCheck = setFrameDuration (theFrame, 0.5);
    theFrame++;
    var theCheck = setFrameDuration (theFrame, 0.5);
    theFrame++;
    var theCheck = setFrameDuration (theFrame, 0.05);
    theFrame++;
    }
};
////// set delay of frame //////
function setFrameDuration (theFrame, theDelay) {
try {
var idanimationFrameClass = stringIDToTypeID( "animationFrameClass" );
// select frame
    var desc2 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putIndex( idanimationFrameClass, theFrame );
    desc2.putReference( charIDToTypeID( "null" ), ref1 );
executeAction( charIDToTypeID( "slct" ), desc2, DialogModes.NO );
// set frame’s duration;
    var desc3 = new ActionDescriptor();
        var ref2 = new ActionReference();
        ref2.putEnumerated( idanimationFrameClass, charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ) );
    desc3.putReference(  charIDToTypeID( "null" ), ref2 );
        var desc4 = new ActionDescriptor();
        desc4.putDouble( stringIDToTypeID( "animationFrameDelay" ), theDelay );
    desc3.putObject( charIDToTypeID( "T   " ), idanimationFrameClass, desc4 );
executeAction( charIDToTypeID( "setd" ), desc3, DialogModes.NO );
return true
} catch (e) {return false};
};
////// by michael l hale //////
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" ) );
};