mirror of
https://github.com/Akascape/Datamosher-Pro.git
synced 2025-12-11 18:59:58 +01:00
added new UI for python version
Now python users can also enjoy the easy UI
This commit is contained in:
71
Python Version/DatamoshLib/FFG_effects/jscripts/Delay.js
Normal file
71
Python Version/DatamoshLib/FFG_effects/jscripts/Delay.js
Normal file
@@ -0,0 +1,71 @@
|
||||
// dd_delay.js
|
||||
// works kinda like an audio delay
|
||||
// stacks the previous n frames into a buffer
|
||||
|
||||
// global variable holding forward motion vectors from previous frames
|
||||
var prev_fwd_mvs = [ ];
|
||||
|
||||
// change these values to use a smaller or greater number of frames to
|
||||
// perform the average of motion vectors
|
||||
|
||||
// try making the delay long enough to overlap an edit in the content ...
|
||||
var delay = 20;
|
||||
|
||||
function glitch_frame(frame)
|
||||
{
|
||||
// bail out if we have no motion vectors
|
||||
let mvs = frame["mv"];
|
||||
if ( !mvs )
|
||||
return;
|
||||
// bail out if we have no forward motion vectors
|
||||
let fwd_mvs = mvs["forward"];
|
||||
if ( !fwd_mvs )
|
||||
return;
|
||||
|
||||
// update variable holding forward motion vectors from previous
|
||||
// frames. note that we perform a deep copy of the clean motion
|
||||
// vector values before modifying them.
|
||||
let json_str = JSON.stringify(fwd_mvs);
|
||||
let deep_copy = JSON.parse(json_str);
|
||||
// push to the end of array
|
||||
prev_fwd_mvs.push(deep_copy);
|
||||
// drop values from earliest frames to always keep the same tail
|
||||
// length
|
||||
if ( prev_fwd_mvs.length > delay )
|
||||
prev_fwd_mvs = prev_fwd_mvs.slice(1);
|
||||
|
||||
// bail out if we still don't have enough frames
|
||||
if ( prev_fwd_mvs.length != delay )
|
||||
return;
|
||||
|
||||
// replace all motion vectors of current frame with an average
|
||||
// of the motion vectors from the previous 10 frames
|
||||
for ( let i = 0; i < fwd_mvs.length; i++ )
|
||||
{
|
||||
// loop through all rows
|
||||
let row = fwd_mvs[i];
|
||||
let delay_row = prev_fwd_mvs[0][i];
|
||||
let insert_row = prev_fwd_mvs[delay-1][i];
|
||||
|
||||
for ( let j = 0; j < row.length; j++ )
|
||||
{
|
||||
// loop through all macroblocks
|
||||
let mv = row[j];
|
||||
let dmv = delay_row[j];
|
||||
let imv = insert_row[j];
|
||||
// THIS IS WHERE THE MAGIC HAPPENS
|
||||
|
||||
// temp copy of the incoming vectors
|
||||
let x = mv[0];
|
||||
let y = mv[1];
|
||||
// pull their replacements out of the buffer
|
||||
mv[0] = dmv[0];
|
||||
mv[1] = dmv[1];
|
||||
// feedback the 'old' with the 'new' for next time
|
||||
imv[0] = x;
|
||||
imv[1] = y;
|
||||
// rinse and repeat
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user