• fullscreen
  • ControlGui.pde
  • ControlMidi.pde
  • Effects.pde
  • SimpleVideoMixer.pde
  • Video1.pde
  • Video2.pde
  • VideoFilesList.pde
  • VideoRecord.pde
  • ControlP5 controlP5;
    ControlWindow controlWindow;
    Slider crossFadeControl;
    Slider speed1Control, speed2Control;
    DropdownList video1Menu, video2Menu;
    Toggle blendControl;
    
    Textfield sessionTitle;
    Button recordButton;
    
    float crossFade = 50.0;
    float speed1 = 1.0;
    float speed2 = 1.0;
    float maxSpeed = 10.0;
    PFont p = createFont("Arial", 10);
    
    String video1, video2;
    String sessionTitleTxt = timeStamp();
    
    boolean recordSwitch = false;
    
    
    void setupControlP5() {
    
      controlP5 = new ControlP5(this);
      controlP5.setControlFont(p);
      controlWindow = controlP5.addControlWindow("SimpleVideoMixer", controlLocationX, controlLocationY, 320, 200);
      controlWindow.hideCoordinates();
      controlWindow.setBackground(color(40));
    
      crossFadeControl = controlP5.addSlider("crossFade", 0, 100, crossFade, 85, 135, 150, 25);
      crossFadeControl.setWindow(controlWindow);
    
      speed1Control = controlP5.addSlider("speed1", -(maxSpeed), (maxSpeed), speed1, 30, 40, 20, 60);
      speed1Control.moveTo(controlWindow);
      speed2Control = controlP5.addSlider("speed2", -(maxSpeed), (maxSpeed), speed2, 270, 40, 20, 60);
      speed2Control.moveTo(controlWindow);
    
      blendControl = controlP5.addToggle("difference", false, 200, 170, 10, 10);
      blendControl.moveTo(controlWindow);
    
      sessionTitle = controlP5.addTextfield("session", 90, 75, 150, 25);
      sessionTitle.moveTo(controlWindow);
      sessionTitle.setText(timeStamp());
      sessionTitle.setFocus(false);
      sessionTitle.setAutoClear(false);
    
      recordButton = controlP5.addButton("rec", 0, 15, 160, 30, 30);
      recordButton.moveTo(controlWindow);
      recordButton.setSwitch(recordSwitch);
      recordButton.setColorBackground(color(80, 0, 0, 255));
    
      video1Menu = controlP5.addDropdownList("video1", 5, 30, 150, 200);
      video1Menu.moveTo(controlWindow);
      video1Menu.setBarHeight(18);
      video1Menu.setItemHeight(23);
      video1Menu.setValue(videoFileValue1);
    
      video2Menu = controlP5.addDropdownList("video2", 165, 30, 150, 190);
      video2Menu.moveTo(controlWindow);
      video2Menu.setBarHeight(18);
      video2Menu.setItemHeight(23);
      video2Menu.setValue(videoFileValue2);
    
      loadVideoFileList();
      buildVideoMenu1();
      buildVideoMenu2();
    }
    
    
    void buildVideoMenu1() {
    
      for (int i=0; i< videoFileList.length; i++) {
    
        video1Menu.addItem(videoFileList[i], i);
      }
    }
    
    
    void buildVideoMenu2() {
    
      for (int i=0; i< videoFileList.length; i++) {
    
        video2Menu.addItem(videoFileList[i], i);
      }
    }
    
    
    void controlEvent(ControlEvent theEvent) {
    
      if (theEvent.isGroup()) {
    
        if (theEvent.getGroup().equals(video1Menu)) {
          videoFileValue1 = (int)theEvent.getGroup().getValue();
          loadVideoFile1(videoFileList[videoFileValue1]); 
    
          println(videoFileValue1);
        }
    
        if (theEvent.getGroup().equals(video2Menu)) {
          videoFileValue2 = (int)theEvent.getGroup().getValue();
          loadVideoFile2(videoFileList[videoFileValue2]);
        }
      }
    
      else if (theEvent.isController()) {
    
        if (theEvent.controller().equals(recordButton)) {
    
          recordSwitch = !recordSwitch;
    
          if (recordSwitch == true) {
    
            startRecording();
    
            recordButton.setColorBackground(color(255, 0, 0, 255));
          }
    
          if (recordSwitch == false) {
    
            stopRecording();
    
            recordButton.setColorBackground(color(80, 0, 0, 255));
          }
        }
      }
    }
    
    
    MidiBus midiBus;
    
    int midiCcCrossFade = 10;
    int midiCcVideo1Speed = 13;
    int midiCcVideo2Speed = 14;
    int midiCcVideo1Scratch = 25;
    int midiCcVideo2Scratch = 24;
    
    int midiNoteBlendOption = 90;
    int midiNoteRecord = 89;
    
    float scratchSpeed = 7.0;
    
    
    void setupMidiBus() {
      MidiBus.list();
      midiBus = new MidiBus(this, 1, 0);
    }
    
    
      void noteOn(int channel, int pitch, int velocity) {
       //println("Pitch: " + pitch + " | Velocity: " + velocity);
        
         if (pitch == midiNoteBlendOption) {
        blendControl.toggle();
        }
        
             if (pitch == midiNoteRecord) {
    
          recordSwitch = !recordSwitch;
    
          if (recordSwitch == true) {
    
            startRecording();
    
            recordButton.setColorBackground(color(255, 0, 0, 255));
          }
    
          if (recordSwitch == false) {
    
            stopRecording();
    
            recordButton.setColorBackground(color(80, 0, 0, 255));
          }
        }
        
      }
    
    
    
      void controllerChange(int channel, int number, int value) {
        println("Number: " + number + " | Value: " + value);
    
        if (number == midiCcCrossFade) {
            crossFade =  map(value, 0, 127, 0, 100); ;
            crossFadeControl.setValue(crossFade); 
        }
        
         if (number == midiCcVideo1Speed) {
            speed1 =  map(value, 0, 127, -(maxSpeed), (maxSpeed)); ;
            speed1Control.setValue(speed1); 
        }
        
         if (number == midiCcVideo2Speed) {
            speed2 =  map(value, 0, 127, -(maxSpeed), (maxSpeed)); ;
            speed2Control.setValue(speed2); 
        }  
        
            if (number == midiCcVideo1Scratch) {
            speed1 =  map(value, 0, 127, -(scratchSpeed), (scratchSpeed)); ;
            speed1Control.setValue(speed1);  
        }
            
            if (number == midiCcVideo2Scratch) {
            speed2 =  map(value, 0, 127, -(scratchSpeed), (scratchSpeed)); ;
            speed2Control.setValue(speed2);  
        }  
      }
    
    
    
    float videoFrame1, videoFrame2;
    
    void videoMix() { 
    
      video1Speed();
      video2Speed();
    
      background(0);
    
      float video2Alpha = map(crossFade, 0, 100, 0, 255);
      float video1Alpha = 255-video2Alpha; 
    
    
      if (blendControl.getState() == true) {
    
        tint(255, video1Alpha);
        image(videoFiles1[videoFileValue1], 0, 0, width, height);
        blend(videoFiles2[videoFileValue2], 0, 0, width, height, 0, 0, width, height, DIFFERENCE);
    
    
        tint(255, video2Alpha);
        image(videoFiles2[videoFileValue2], 0, 0, width, height);
        blend(videoFiles1[videoFileValue1], 0, 0, width, height, 0, 0, width, height, DIFFERENCE);
      }
    
      else {
    
        tint(255, video1Alpha);
        image(videoFiles1[videoFileValue1], 0, 0, width, height);
    
        tint(255, video2Alpha);
        image(videoFiles2[videoFileValue2], 0, 0, width, height);
      }
    }
    
    
    void video1Speed() {
    
      if (speed1 >= 0 ) {
        if (videoFiles1[videoFileValue1].frame() >= (videoFiles1[videoFileValue1].length()-1)) {
    
          videoFrame1 = 1;
    
          videoFiles1[videoFileValue1].jump(videoFrame1);
          videoFiles1[videoFileValue1].play();
          videoFiles1[videoFileValue1].pause();
        }
    
        videoFrame1 = videoFrame1 + speed1;
        int f1 = (int) videoFrame1;
    
        videoFiles1[videoFileValue1].jump(f1);
        videoFiles1[videoFileValue1].play();
        videoFiles1[videoFileValue1].pause();
      }
    
      if (speed1 < 0 ) {
        if (videoFiles1[videoFileValue1].frame() <= 0) {
    
          videoFrame1 = videoFiles1[videoFileValue1].length()-1;
    
          videoFiles1[videoFileValue1].jump(videoFrame1);
          videoFiles1[videoFileValue1].play(); 
          videoFiles1[videoFileValue1].pause();
        }
    
        videoFrame1 = videoFrame1 + speed1;
        int f1 = (int) videoFrame1;
    
        videoFiles1[videoFileValue1].jump(f1);
        videoFiles1[videoFileValue1].play(); 
        videoFiles1[videoFileValue1].pause();
      }
    }
    
    
    void video2Speed() {
    
      if (speed2 >= 0 ) {
        if (videoFiles2[videoFileValue2].frame() >= (videoFiles2[videoFileValue2].length()-1)) {
    
          videoFrame2 = 1;
    
          videoFiles2[videoFileValue2].jump(videoFrame2);
          videoFiles2[videoFileValue2].play(); 
          videoFiles2[videoFileValue2].pause();
        }
    
        videoFrame2 = videoFrame2 + speed2;
        int f2 = (int) videoFrame2;
    
        videoFiles2[videoFileValue2].jump(f2);
        videoFiles2[videoFileValue2].play();
        videoFiles2[videoFileValue2].pause();
      }
    
      if (speed2 < 0 ) {
        if (videoFiles2[videoFileValue2].frame() <= 0) {
    
          videoFrame2 = videoFiles2[videoFileValue2].length()-1;
          
          videoFiles2[videoFileValue2].jump(videoFrame2);
          videoFiles2[videoFileValue2].play(); 
          videoFiles2[videoFileValue2].pause();
        }
    
        videoFrame2 = videoFrame2 + speed2;
        int f2 = (int) videoFrame2;
    
        videoFiles2[videoFileValue2].jump(f2);
        videoFiles2[videoFileValue2].play(); 
        videoFiles2[videoFileValue2].pause();
      }
    }
    
    
    /*
     *  Simple Video Mixer
     *  by Dread-Eye
     *  http://peace.dreadeye.com/2012/05/simplevideomixer.html
    */
    
    import processing.video.*;
    import codeanticode.gsvideo.*;
    import controlP5.*;
    import themidibus.*;
    
    
    
    //Setup output and control windows
    //Choose basic, fast or projector
    
    //Basic - standard VGA resolution
    int videoWidth = 640;
    int videoHeight = 480;
    int frameLocationX = 50;
    int frameLocationY = 50;
    int frameLocationSet = 0;
    int controlLocationX = 245;
    int controlLocationY = 530;
    int FPS = 30;
    
    
    /*
    //Fast - smaller output for slower systems
     int videoWidth = 320;
     int videoHeight = 240;
     int frameLocationX = 100;
     int frameLocationY = 100;
     int frameLocationSet = 0;
     int controlLocationX = 100;
     int controlLocationY = 340;
     int FPS = 30;
    */
    
    /*
    //Projector - full-screen on second monitor
     //Match frame location and resolution to system display settings
     //Check settings in setup to remove output window border  
     int videoWidth = 640;
     int videoHeight = 480;
     int frameLocationX = -(videoWidth);
     int frameLocationY = 0;
     int frameLocationSet = 0;
     int controlLocationX = 100;
     int controlLocationY = 340;
     int FPS = 30;
     */
    
    int videoFileValue1 = 0;
    int videoFileValue2 = 1; 
    
    String path = "videos/";
    String recordingPath = "data/videos/";
    
    
    
    void setup() {
    
      size(videoWidth, videoHeight); 
      frameRate(FPS);
      frame.setResizable(true);
    
    
      //Projector-friendly settings
      //frame.setUndecorated(true);
      //frame.setAlwaysOnTop(true);
      //noCursor();
    
    
      setupControlP5();
      setupMidiBus();
    
      setupVideoFiles();
    
      video1 = videoFileList[videoFileValue1]; 
      video2 = videoFileList[videoFileValue2]; 
    
      loadVideoFile1(video1);
      loadVideoFile2(video2);
    }
    
    
    void draw() {
    
      if (frameLocationSet < 2) {
        frame.setLocation(frameLocationX, frameLocationY);
        frameLocationSet ++;
      } 
    
      videoMix();
    
      recordFrame();
    }
    
    
    
    public void init() {
      frame.removeNotify();
      super.init();
    } 
    
    
    GSMovie[] videoFiles1 = new GSMovie[0];
    
    
    void loadVideoFile1(String fileName) {
    
      String URL = path+fileName;
      videoFiles1 = (GSMovie[])append(videoFiles1, new GSMovie(this, URL));
      int index = videoFiles1.length-1;
      videoFiles1[index].stop(); 
    
      //println("Video 1 Loaded: "+fileName);
      
    
      if (speed1 < 0 ) {
        if (videoFiles1[videoFileValue1].frame() <= 0) {
    
          videoFiles1[videoFileValue1].play();
          videoFiles1[videoFileValue1].goToEnd();
          videoFiles1[videoFileValue1].pause();
        }
      }
    }
    
    
    
    void movieEvent(GSMovie _videoFile) {
      try {
        _videoFile.read();
      }
      catch(Error e) {
        println(e);
      }
    }
    
    
    
    GSMovie[] videoFiles2 = new GSMovie[0];
    
    
    void loadVideoFile2(String fileName) {
    
      String URL = path+fileName;
      videoFiles2 = (GSMovie[])append(videoFiles2, new GSMovie(this, URL));
      int index = videoFiles2.length-1;
      videoFiles2[index].stop(); 
    
      //println("Video 2 Loaded: "+fileName);
    
    
      if (speed2 < 0 ) {
        if (videoFiles2[videoFileValue2].frame() <= 0) {
    
          videoFiles2[videoFileValue2].play();
          videoFiles2[videoFileValue2].goToEnd();
          videoFiles2[videoFileValue2].pause();
        }
      }
    }
    
    
    String videoFileListTxt = "videoFileList.txt";
    String[] videoFileList = new String[0];
    
    
    void setupVideoFiles() {
    
      int totalFiles = videoFileList.length;
      for (int i=0; i<totalFiles; i++) {
        
        loadVideoFile1(videoFileList[i]);
    
        loadVideoFile2(videoFileList[i]);
      }
    }
    
    
    void loadVideoFileList() {
      videoFileList = loadStrings(recordingPath+videoFileListTxt);
    }
    
    
    void appendVideoFileList(String _recordingFileName) {
      loadVideoFileList();
      videoFileList = append(videoFileList, _recordingFileName);
      saveStrings(recordingPath+videoFileListTxt, videoFileList);
      loadVideoFileList();
    }
    
    
    
    MovieMaker videoRecording;
    Boolean recording = false;
    String recordingFileName;
    
    int sessionFileNumber = 1;
    
    String sessionFile;
      
      
    String timeStamp() {
      String timestamp = year()+"_"+month()+"_"+day()+"_"+hour()+"_"+minute();
      return timestamp;
    }
    
    
    void keyPressed() {
      if (key == ' ') startRecording();
    }
    
    
    void keyReleased() {
      if (key == ' ') stopRecording();
    }
    
    
    void startRecording() {
      
      sessionFile = sessionTitle.getText();
      
      if(!recording) {
        recording = true;
        
        //recordSwitch = true;
        //controlEvent(ControlEvent theEvent);
        
        recordingFileName = sessionFile+"_"+sessionFileNumber+".mov";
        println("Recording: "+recordingFileName);
        //
        String filePath = recordingPath+recordingFileName;
        int codec = MovieMaker.MOTION_JPEG_B;
        int quality = MovieMaker.HIGH;
        int FPS = 30;
        videoRecording = new MovieMaker(
                                        this, 
                                        width, 
                                        height, 
                                        filePath, 
                                        FPS, 
                                        codec, 
                                        quality
                                        );
                                        
        sessionFileNumber ++;
      }
    }
    
    
    void recordFrame() {
      
      if(recording) videoRecording.addFrame();
    }
    
    
    void stopRecording() {
      if(recording) {
        videoRecording.finish();
        println("Stopped Recording");
        recording = false;
        
        recordSwitch = false;
                
        appendVideoFileList(recordingFileName);
       
        loadVideoFile1(recordingFileName);
        loadVideoFile2(recordingFileName);
      
    
      
       video1Menu.clear();
          video2Menu.clear();
          
             loadVideoFileList();
            
       buildVideoMenu1();
       buildVideoMenu2();
        
       //println(videoFileList);
      }
    }
    
    
    
    
    
    
    
    
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Dread-Eye

    SimpleVideoMixer

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    A 2-channel video mixer with MIDI control.

    -Place your video files in the "data/videos/" folder.

    -Create a list of the video file names as a text file named "videoFileList.txt" in the same folder.

    -Hold down the spacebar to record your mix.

    http://peace.dreadeye.com/2012/05/simplevideomixer.html

    -There's a problem with this sketch running as an applet. If you have Processing 1.5.1 with the GSVideo, controlP5 and themidibus external libraries (I had to rename the downloaded MIDI library simply "themidibus" for it to work), then delete the "code" folder and run "SimpleVideoMixer.pde".

    You need to login/register to comment.