Compare commits

...

6 Commits

23 changed files with 602 additions and 762 deletions

5
audioreactivity.pde Normal file
View File

@@ -0,0 +1,5 @@
AudioIn audioIn;
Amplitude loudness;
float volume;
float volumeRoof = 1.0;

Binary file not shown.

Binary file not shown.

View File

@@ -1,201 +0,0 @@
import * as std from "std";
function usage(msg)
{
if ( msg )
print(msg);
print("usage: ./qjs " + scriptArgs[0] + " [-p] -i <input.json> -s <script.js> -o <output.json>");
return 1;
}
//---------------------------------------------------------------------
// no lf, no space
const pflags_def = [ [ false, false ] ];
function get_pflags(jso)
{
if ( jso === "fcode" || jso === "bcode" )
{
return [
[ true, false ]
];
}
else if ( jso === "forward" || jso === "backward" )
{
return [
[ false, false ],
[ true, false ],
[ true, true ]
];
}
return pflags_def;
}
function print_lf(o_file, level)
{
o_file.puts('\n');
o_file.printf("%*s", level * 2, "");
}
function print_space(o_file)
{
o_file.puts(' ');
}
function output_lf(o_file, pflags, level)
{
const json_pflags_no_lf = pflags[0];
const json_pflags_no_space = pflags[1];
if ( !json_pflags_no_lf )
print_lf(o_file, level);
else if ( !json_pflags_no_space )
print_space(o_file);
}
function json_print_element(o_file, jso, pflags, level)
{
if ( typeof jso === "object" )
{
if ( jso === null )
{
o_file.puts("null");
}
else if ( Array.isArray(jso) )
{
const pflags0 = pflags[0];
const pflags1 = pflags.slice(1);
o_file.puts('[');
for ( let i = 0; i < jso.length; i++ )
{
if ( i != 0 )
o_file.puts(',');
output_lf(o_file, pflags0, level+1);
json_print_element(o_file, jso[i], pflags1, level+1);
}
output_lf(o_file, pflags0, level);
o_file.puts(']');
}
else
{
let i = 0;
o_file.puts('{');
for ( const key in jso )
{
if ( i++ != 0 )
o_file.puts(',');
print_lf(o_file, level+1);
o_file.puts(JSON.stringify(key));
o_file.puts(':');
json_print_element(o_file, jso[key], get_pflags(key), level+1);
}
print_lf(o_file, level);
o_file.puts('}');
}
}
else
{
o_file.puts(JSON.stringify(jso));
}
}
function json_fputs(o_file, jso)
{
json_print_element(o_file, jso, pflags_def, 0);
o_file.puts('\n');
}
///////////////////////////////////////////////////////////////////////
// global variables for the script
var json_stream = null;
var json_frame = null;
function run_script(s_path, i_path, o_path, do_pretty)
{
// load input JSON
print("[+] loading input JSON file '" + i_path + "'")
let i_file = std.open(i_path, "r");
if ( !i_file )
return usage("could not open input file '" + i_path + "'");
let str = i_file.readAsString();
let json_root = JSON.parse(str);
if ( !json_root )
return usage("error parsing input file '" + i_path + "'");
i_file.close();
// will error out on exception
print("[+] running script '" + s_path + "' on JSON data")
std.loadScript(s_path);
// for each stream (normally there is only one stream of interest)
let streams = json_root["streams"];
for ( let i = 0; i < streams.length; i++ )
{
let stream = streams[i];
json_stream = stream;
// for each frame in the stream
let frames = stream["frames"];
for ( let j = 0; j < frames.length; j++ )
{
let frame = frames[j];
json_frame = frame;
glitch_frame(frame);
}
}
// open input JSON
print("[+] writing " + (do_pretty ? "prettified " : "") + "output JSON file '" + o_path + "'")
let o_file = std.open(o_path, "w+");
if ( !o_file )
return usage("could not open output file '" + o_path + "'");
if ( do_pretty )
json_fputs(o_file, json_root);
else
o_file.puts(JSON.stringify(json_root));
o_file.close();
return 0;
}
function main(argc, argv)
{
let i_path = null;
let o_path = null;
let s_path = null;
let do_pretty = false;
for ( let i = 1; i < argc; )
{
let opt = argv[i++];
if ( opt == "-i" )
{
if ( i == argc )
return usage("parameter missing for option '-i'");
i_path = argv[i++];
}
else if ( opt == "-o" )
{
if ( i == argc )
return usage("parameter missing for option '-o'");
o_path = argv[i++];
}
else if ( opt == "-s" )
{
if ( i == argc )
return usage("parameter missing for option '-s'");
s_path = argv[i++];
}
else if ( opt == "-p" )
{
do_pretty = true;
}
else
{
return usage("unknown option '" + opt + "'");
}
}
if ( !s_path || !i_path || !o_path )
return usage();
return run_script(s_path, i_path, o_path, do_pretty);
}
main(scriptArgs.length, scriptArgs, this);

View File

@@ -1,131 +0,0 @@
#!/usr/bin/env python
# run script on frames from input file:
# ffglitch -i <file> -f <features> -s <script> -o <file>
import argparse
import os
import subprocess
import sys
import tempfile
import hashlib
# Load json library (try first with fastest one)
try:
import orjson
_json = orjson
_dumps_ftype = 'wb'
except:
import json
_json = json
_dumps_ftype = 'w'
parser = argparse.ArgumentParser()
parser.add_argument('-i', metavar="<file>", dest='input', required=True, help='input media file')
parser.add_argument('-f', metavar="<feature>", dest='feature', required=True, help='select feature to glitch')
parser.add_argument('-s', metavar="<file>", dest='script', required=True, help='script to glitch frames')
parser.add_argument('-o', metavar="<file>", dest='output', required=True, help='output media file')
parser.add_argument('-v', action="store_true", dest='verbose', required=False, help='verbose output')
parser.add_argument('-k', action="store_true", dest='keep', required=False, help='do not delete temporary JSON file')
args = parser.parse_args()
# Handle verbosity
if args.verbose:
stderr = sys.stdout
else:
stderr = open(os.devnull, 'w')
# Generate input json file name
json_in = os.path.splitext(args.input)[0] + ".json"
# Check that input file name does not end in .json
if json_in == args.input:
raise ValueError('Input file name must not end in .json')
# Function to get sha1sum of file
def calc_sha1sum(filename):
h = hashlib.sha1()
b = bytearray(128*1024)
mv = memoryview(b)
with open(filename, 'rb', buffering=0) as f:
for n in iter(lambda : f.readinto(mv), 0):
h.update(mv[:n])
return h.hexdigest()
# Try to read input json file
json_root = None
try:
with open(json_in, 'r') as f:
print("[+] checking existing JSON file '%s'" % json_in)
json_root = _json.loads(f.read())
# check features
features = json_root["features"]
if len(features) != 1 or features[0] != args.feature:
json_root = None
print("[-] feature '%s' not found in '%s'" % (args.feature, json_in))
# check sha1sum
sha1sum = json_root["sha1sum"]
if len(sha1sum) != 40 or sha1sum != calc_sha1sum(args.input):
json_root = None
print("[-] sha1sum mismatch for '%s' in '%s'" % (args.input, json_in))
if json_root is not None:
print("[+] OK")
except IOError:
pass
ffedit_path = None
def run_ffedit(cmd):
global ffedit_path
if ffedit_path == None:
dir_path = os.path.dirname(os.path.realpath(__file__))
ffedit_path = [os.path.join(dir_path, "ffedit")]
cmd = ffedit_path + cmd
if args.verbose:
print("[v] $ %s" % ' '.join(cmd))
return subprocess.check_output(cmd, stderr=stderr)
# First pass (export data)
if json_root is None:
print("[+] exporting feature '%s' to '%s'" % (args.feature, json_in))
run_ffedit([args.input, "-f", args.feature, "-e", json_in])
with open(json_in, 'r') as f:
json_root = _json.loads(f.read())
# Run script on JSON data.
print("[+] running script '%s' on JSON data" % args.script)
with open(args.script) as infile:
exec(infile.read())
json_stream = None
json_frame = None
# for each stream (normally there is only one stream of interest)
for stream in json_root["streams"]:
json_stream = stream
# for each frame in the stream
for frame in stream["frames"]:
json_frame = frame
# if ffedit exported motion vectors
if args.feature in frame:
glitch_frame(frame[args.feature])
# Dump modified JSON data to temporary file.
json_fd, json_out = tempfile.mkstemp(prefix='ffglitch_', suffix='.json')
json_fp = os.fdopen(json_fd, _dumps_ftype)
print("[+] dumping modified data to '%s'" % json_out)
json_fp.write(_json.dumps(json_root))
json_fp.close()
# Second pass (apply data).
print("[+] applying modified data to '%s'" % args.output)
ok = False
try:
run_ffedit([args.input, "-f", args.feature, "-a", json_out, args.output])
ok = True
except subprocess.CalledProcessError as grepexc:
vstr = " (rerun FFglitch with '-v')" if not args.verbose else ""
print("[-] something went wrong%s" % vstr)
# Remove temporary JSON file.
if ok and not args.keep:
os.unlink(json_out)
else:
print("[+] not deleting temporary file '%s'" % json_out)

Binary file not shown.

View File

@@ -1,44 +0,0 @@
<Technical info about this build>:
FFglitch 0.9.4
macOS
64-bit
You can get the source code here:
http://ffglitch.org/pub/src/ffglitch-0.9.4.tar.xz
FFglitch also includes the following libraries:
quickjs 2021-03-27 <https://bellard.org/quickjs>
zlib 1.2.11 <http://zlib.net>
Xvid 1.3.6 <https://labs.xvid.com>
<What?>
FFglitch is a multimedia bitstream editor, based on the open-source
project FFmpeg <http://ffmpeg.org>.
For more information, go to <http://ffglitch.org>.
<Who?>
Hi, I’m Ramiro Polla <https://github.com/ramiropolla>.
On my free time I like to work on useless projects.
<GPL boilerplate>:
Copyright (C) 2018-2021 Ramiro Polla
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 102 KiB

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 MiB

File diff suppressed because one or more lines are too long

View File

@@ -1,2 +1,2 @@
//globals
uptime = 117464831
uptime = 119045247

BIN
data/sox-0.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 754 B

BIN
data/sox-149.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 10 MiB

After

Width:  |  Height:  |  Size: 981 KiB

Binary file not shown.

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -1,14 +1,15 @@
/* todo:
- implement all sox effects
- don't rerender on change of blend-mode
- add blending option everywhere
- add blend-effect to blend a selected layer
- add png corruption
- add png, jpg, gif and fractal compression artifact effects
*/
- implement all sox effects
- don't rerender on change of blend-mode
- add blending option everywhere
- add blend-effect to blend a selected layer
- add png corruption
- add png, jpg, gif and fractal compression artifact effects
*/
import drop.*;
import controlP5.*;
import processing.sound.*;
import java.util.*;
//import processing.net.*;
@@ -22,6 +23,11 @@ import java.util.Arrays;
Class<?> sketchClass;
VideoExport videoExport;
AudioIn audioIn;
Amplitude loudness;
float volume;
float volumeRoof = 1.0;
int maxFx = 15; //possible amount of effect layers
SDrop drop;
PImage source;
@@ -40,16 +46,31 @@ int w, h;
boolean spawnPlaying = false;
boolean autoPlay = false;
boolean videoRecord = false;
boolean webcamMode = false;
//boolean webcamMode = false;
int micChannel = 0; //which microphone?
//Capture[] cams;
//ArrayList<Capture> cams = new ArrayList<Capture>();
Capture cam;
Capture cam2;
String[] cameras;
int currentCam;
String[] params;
PImage droppedImage;
void dropEvent(DropEvent theDropEvent) {
sourceManager.importURI(theDropEvent.filePath());
}
SecondApplet gui;
PApplet mainApplet;
void setup() {
@@ -77,7 +98,29 @@ void setup() {
}
fallbackImage = loadImage(dataPath("0.png"));
bin = loadImage(dataPath("bin.png"));
cam = new Capture(this, 1280, 768);
audioIn = new AudioIn(this, micChannel);
audioIn.start();
loudness = new Amplitude(this);
loudness.input(audioIn);
cameras = Capture.list();
/*
for (int i = 0; i < cameras.length-1; i++) {
try {
cams.add(new Capture(this, 1920, 1080, cameras[i]));
}
catch(Exception e) {
println(e);
}
}
*/
//cam = new Capture(this, 1920,1080, "pipeline:autovideosrc");
//cam = new Capture(this, 1920,1080, "Video Assist 5\" 3G");
cam = new Capture(this, 1920, 1080, "OBS Virtual Camera", 60);
cam2 = new Capture(this, 1920, 1080, "Kamera von „Victors iPhone“", 60);
OS = getOS();
String[] args = {"SecondFrame"};
@@ -85,6 +128,7 @@ void setup() {
gui = new SecondApplet();
PApplet.runSketch(args, gui);
renderer = createGraphics(width, height);
renderer.noSmooth();
viewport = createImage(renderer.width, renderer.height, ARGB);
@@ -92,11 +136,38 @@ void setup() {
//sourceManager.importURI("/home/giers/.local/bin/fast-style-transfer/data/train2014");
}
PImage webcamImg;
PImage iPhoneImg;
void captureEvent(Capture c) {
c.read();
//webcamImg = cam.get();
if (c == cam) {
webcamImg = cam.get();
}
if (c == cam2) {
iPhoneImg = cam2.get();
}
}
void draw() {
uptime+=1;
renderFrameRate = frameRate;
volume = map(loudness.analyze(),0,1,0,volumeRoof);
if(volume > 1) volumeRoof -= 0.008;
//if(webcamRunning){
//webcamImg =
// }
background(255);
sourceManager.update(); //will write some image to the renderer
sourceManager.setSource();
if (autoPlay) gui.robot();
@@ -126,6 +197,7 @@ void draw() {
}
if (recording) {
snapshot();
fill(#ff0000);

View File

@@ -24,7 +24,8 @@ public class SecondApplet extends PApplet {
public void settings() {
size(275, 120);
}
Toggle webcam, auto;
//Toggle webcam, auto;
Toggle auto;
public void setup() {
surface.setLocation(285, 240);
//List l = Arrays.asList(availableFx);
@@ -62,12 +63,12 @@ public class SecondApplet extends PApplet {
webcam = cp5.addToggle("webcam")
.setPosition(100, height-65)
.setSize(12, 12)
.setValue(false)
.plugTo(this, "CP5_webcamAction");
webcam.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20);
/* webcam = cp5.addToggle("webcam")
.setPosition(100, height-65)
.setSize(12, 12)
.setValue(false)
.plugTo(this, "CP5_webcamAction");
webcam.getCaptionLabel().getStyle().setMargin(-17, 0, 0, 20);*/
Toggle robot = cp5.addToggle("autoPlay")
.setPosition(100, height-50)
@@ -101,16 +102,16 @@ public class SecondApplet extends PApplet {
startRobot = true;
autoPlay = !autoPlay;
}
/*
void CP5_webcamAction()  {
webcamMode = !webcamMode;
if (webcamMode) sourceManager.startWebcam();
else {
sourceManager.stopWebcam();
source = null;
}
}
webcamMode = !webcamMode;
if (webcamMode) sourceManager.startWebcam();
else {
sourceManager.stopWebcam();
source = null; //to trigger auto-fallback next frame
}
}
*/
void CP5_nativeResoAction() {
renderSize = max(nativeResoX, nativeResoY);
//renderer.setSize(nativeResoX, nativeResoY);
@@ -179,6 +180,12 @@ public class SecondApplet extends PApplet {
noStroke();
rect(mouseX, mouseY, 35, 15);
}
//audioindicator
fill(map(volume,0,0.5,0,255));
noStroke();
ellipse(260,height-105,15,15);
}
boolean heightOverLimit;
@@ -381,7 +388,11 @@ public class SecondApplet extends PApplet {
for (int i = 0; i < slider.size(); i++) {
if (slider.get(i).hovering || slider.get(i).hovering_anim_btn) sliderHover = true;
if (paused && slider.get(i).animated) paused = false;
params.get(i).audioMulti = slider.get(i).audioVal * volume * 2;
}
if (mouseX > 10 && mouseX < 22 && mouseY > 4+totalBrickHeight+scrollAmount && mouseY < 4+totalBrickHeight+13+scrollAmount) {
hoverActiveButton = true;
@@ -413,8 +424,12 @@ public class SecondApplet extends PApplet {
}
for (int i = 0; i < slider.size(); i++) {
slider.get(i).update();
//params.get(i).value = slider.get(i).value;
//* map(volume,0,1,0.8,1.2);
//slider.get(i).value = map(volume,0,1,0.8,1.2) * slider.get(i).value;
params.get(i).value = slider.get(i).value;
slider.get(i).update();
}
brickBGcol = color(85, 85, 85);
}
@@ -476,8 +491,8 @@ public class SecondApplet extends PApplet {
class Slider {
int x, y, w, h, mode;
int[] osciModes;
float minVal, maxVal, value; //should be private but doesnt work lol
boolean hovering, hovering_anim_btn, animated;
float minVal, maxVal, value, audioVal; //should be private but doesnt work lol
boolean hovering, hovering_anim_btn,hovering_audio_slider, animated;
String label;
Oscillator osci;
@@ -495,7 +510,8 @@ public class SecondApplet extends PApplet {
osci = new Oscillator(int(random(2, 5)), osciModes);
osci.amplitude(minVal, maxVal);
osci.update();
setValue(osci.value);
//setValue(osci.value);
setValue((minVal+maxVal)/2);
animated = true;
@@ -538,14 +554,17 @@ public class SecondApplet extends PApplet {
void update() {
//float audioImpact = (audioVal * volume) + 1;
//setValue(value*(1+audioVal));
osci.update();
// osci.update();
if (animated) {
osci.update();
setValue(osci.value);
}
if (mouseX >= x && mouseX <= x+w && mouseY >= y+scrollAmount && mouseY <= y+h+scrollAmount) {
hovering = true;
@@ -558,6 +577,12 @@ public class SecondApplet extends PApplet {
} else {
hovering_anim_btn = false;
}
if (mouseX >= x+w+20 && mouseX <= x+w+35 && mouseY >= y+scrollAmount && mouseY <= y+h+scrollAmount) {
hovering_audio_slider = true;
} else {
hovering_audio_slider = false;
}
}
void display() {
@@ -577,6 +602,11 @@ public class SecondApplet extends PApplet {
fill(100+(40*int(hovering_anim_btn)));
}
rect(x+w+5, y, h, h);
stroke(255);
line(x+w+5+h+10,y, x+w+5+h+10, y+h);
line(x+w+5+h+5, y+h-(audioVal*h), x+w+5+h+15, y+h-(audioVal*h));
}
}
@@ -610,10 +640,13 @@ public class SecondApplet extends PApplet {
if (random(1)<0.01) {
int removeMe = int(random(shaderList.size()-1));
println("removing" + removeMe);
bricks.get(removeMe).press();
shaderManager.removeShader(removeMe);
pressedBrick = -1;
if ((removeMe == 0 && bricks.get(removeMe).name.equals("Webcam")) == false) {
println(bricks.get(removeMe).name);
println("removing" + removeMe);
bricks.get(removeMe).press();
shaderManager.removeShader(removeMe);
pressedBrick = -1;
}
}
}
@@ -639,6 +672,9 @@ public class SecondApplet extends PApplet {
Slider s = slider.get(i);
if (s.hovering) s.press(i);
if (s.hovering_anim_btn) s.animated = !s.animated;
if (s.hovering_audio_slider){
s.audioVal = map(mouseY-(s.y+scrollAmount),0,12,1,0);
}
}
for (int i = bricks.size()-1; i >= 0; i--) {
if (bricks.get(i).hovering) {
@@ -717,6 +753,12 @@ public class SecondApplet extends PApplet {
}
}
textSize(10);
if (mouseX > 245 && mouseY < height-90 && mouseY > height-120) {
volumeRoof -= float(event.getCount())/100;
if(volumeRoof > 100) volumeRoof = 100;
if(volumeRoof <= 0.01) volumeRoof = 0.01;
}
}
int numberTypedFrame;
boolean typingNumber;

View File

@@ -3,6 +3,7 @@ class Param {
int type;
float minValue, maxValue;
float value;
float audioMulti;
int[] osciModes;
Param(String name_, int type_, float minValue_, float maxValue_, int[] osciModes_) {
name = name_;
@@ -11,6 +12,9 @@ class Param {
maxValue = maxValue_;
osciModes = osciModes_;
}
float getValue(){
return(value + ((maxValue-minValue) * audioMulti)); //wenn man so auch die automation-values handhabt, kann man mit automatisierten slidern besser spielen .. mayb
}
}
class Shader {
@@ -59,6 +63,8 @@ class Shader {
paramChanged = true;
}
previousPos = pos;
if(volume > 0) paramChanged = true;
try{
if (previousActive != gui.bricks.get(pos).active) { //fails if brick has not yet been loaded but shader has
@@ -86,7 +92,7 @@ class Shader {
gui.bricks.get(pos).exchangeSlider(paramNo, newParam);
paramChanged = true;
}
void shade() {
if (renderSizeChanged || paramChanged) {
this.setupCanvas();

View File

@@ -1,4 +1,4 @@
Capture cam;
Movie movie;
boolean moviePlaying, imageChanged;
PImage fallbackImage;
@@ -38,7 +38,8 @@ class SourceManager { //no constructor
void setImage(PImage img) { //set image to source
imageChanged = true;
source = img.get();
if(!webcamMode)fallbackImage = source;
//if(!webcamMode) fallbackImage = source;
fallbackImage = source;
nativeResoX = source.width;
nativeResoY = source.height;
//println(nativeResoX);
@@ -48,7 +49,7 @@ class SourceManager { //no constructor
println("Fallback");
setImage(fallbackImage); //fallbackImage should always be a copy of the last image that worked
}
/*
void startWebcam() {
String[] cameras = Capture.list();
println(cameras);
@@ -58,15 +59,17 @@ class SourceManager { //no constructor
void stopWebcam() {
cam.stop();
webcamMode = false;
}
}*/
void update() {
/*
if (webcamMode) {
if (cam.available()) {
cam.read();
setImage(cam);
}
}
*/
if (source == null) {
fallback();
@@ -123,7 +126,7 @@ class SourceManager { //no constructor
if (isImage(path) || isVideo(path)) {
println("Importing file " + path);
if (moviePlaying) movie.stop();
if (webcamMode) gui.webcam.setValue(false);
//if (webcamMode) gui.webcam.setValue(false);
if (isImage(path)) {
moviePlaying = false;
setImage(loadImage(path));

View File

@@ -1,4 +1,7 @@
String FX[] = {
"WEBCAM",
"MASK",
"IPHONE",
"ASDFPIXELSORT",
"DISTORTER",
"FM",
@@ -17,7 +20,6 @@ String FX[] = {
"COPYZOOM",
"SUBTLESORT",
"SCANKER",
"MASK",
"DRAWSTROKES",
"DRAWGENERATIVE",
"PIXELDRIFTER",
@@ -31,7 +33,8 @@ String FX[] = {
"SEGMENTER",
"COLORCRUSHER",
"JPGCORRUPTION",
"WEBPCORRUPTION",
"WEBPCORRUPTION"
/*,
"SOXALLPASS",
"SOXBAND",
"SOXBANDPASS",
@@ -95,7 +98,7 @@ String FX[] = {
"SOXTRIM",
"SOXUPSAMPLE",
"SOXVAD",
"SOXVOL"
"SOXVOL"*/
};