Skip to content

Commit b1e6fdc

Browse files
committed
first commit
0 parents  commit b1e6fdc

File tree

6 files changed

+516
-0
lines changed

6 files changed

+516
-0
lines changed

example/bin/data/audio.wav

14.6 MB
Binary file not shown.

example/src/main.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "ofMain.h"
2+
#include "testApp.h"
3+
#include "ofAppGlutWindow.h"
4+
5+
//========================================================================
6+
int main( ){
7+
8+
ofAppGlutWindow window;
9+
ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context
10+
11+
// this kicks off the running of my app
12+
// can be OF_WINDOW or OF_FULLSCREEN
13+
// pass in width and height too:
14+
ofRunApp( new testApp());
15+
16+
}

example/src/testApp.cpp

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#include "testApp.h"
2+
#include "ofxAVFVideoRecorder.h"
3+
4+
//--------------------------------------------------------------
5+
void testApp::setup(){
6+
// Test code to generate video
7+
int width = 640;
8+
int height = 480;
9+
int framerate = 30;
10+
int num_frames = 120;
11+
12+
ofxAVFVideoRecorder recorder;
13+
recorder.setup(ofToDataPath("test.mov"), width, height, framerate); // must end in .mov extension
14+
recorder.setAudioFile(ofToDataPath("audio.wav"));
15+
16+
int arr_size = width*height*4;
17+
unsigned char *data = (unsigned char *)malloc(arr_size*sizeof(unsigned char));
18+
19+
// make test pattern
20+
int base_q = 10;
21+
int q_amp = 600;
22+
int period = 60;
23+
for (int frame=0; frame < num_frames; frame++)
24+
{
25+
int q = base_q + 2 * q_amp * (fabs(frame % (period *2) - period))/ ((float) period);
26+
int x_shift, y_shift, val;
27+
for(int y=0;y<height;y++) {
28+
for(int x=0;x<width;x++) {
29+
30+
x_shift = x - width / 2 + frame;
31+
y_shift = y - height /2 + frame ;
32+
val = fabs(((x_shift * y_shift + frame) % q) * 255.0/(float)q);
33+
int linesize = width * 4;
34+
data[y * linesize + x*4] = val ; //r
35+
data[y * linesize + x*4+1] = val ; //g
36+
data[y * linesize + x*4+2] = val ; //b
37+
}
38+
}
39+
40+
recorder.writeRGBA(data); // write frame to video
41+
}
42+
43+
free(data);
44+
45+
recorder.finishMovie(); // save movie and add audio
46+
}
47+
48+
//--------------------------------------------------------------
49+
void testApp::update(){
50+
51+
}
52+
53+
//--------------------------------------------------------------
54+
void testApp::draw(){
55+
56+
}
57+
58+
//--------------------------------------------------------------
59+
void testApp::keyPressed(int key){
60+
61+
}
62+
63+
//--------------------------------------------------------------
64+
void testApp::keyReleased(int key){
65+
66+
}
67+
68+
//--------------------------------------------------------------
69+
void testApp::mouseMoved(int x, int y ){
70+
71+
}
72+
73+
//--------------------------------------------------------------
74+
void testApp::mouseDragged(int x, int y, int button){
75+
76+
}
77+
78+
//--------------------------------------------------------------
79+
void testApp::mousePressed(int x, int y, int button){
80+
81+
}
82+
83+
//--------------------------------------------------------------
84+
void testApp::mouseReleased(int x, int y, int button){
85+
86+
}
87+
88+
//--------------------------------------------------------------
89+
void testApp::windowResized(int w, int h){
90+
91+
}
92+
93+
//--------------------------------------------------------------
94+
void testApp::gotMessage(ofMessage msg){
95+
96+
}
97+
98+
//--------------------------------------------------------------
99+
void testApp::dragEvent(ofDragInfo dragInfo){
100+
101+
}

example/src/testApp.h

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#pragma once
2+
3+
#include "ofMain.h"
4+
5+
class testApp : public ofBaseApp{
6+
7+
public:
8+
void setup();
9+
void update();
10+
void draw();
11+
12+
void keyPressed (int key);
13+
void keyReleased(int key);
14+
void mouseMoved(int x, int y );
15+
void mouseDragged(int x, int y, int button);
16+
void mousePressed(int x, int y, int button);
17+
void mouseReleased(int x, int y, int button);
18+
void windowResized(int w, int h);
19+
void dragEvent(ofDragInfo dragInfo);
20+
void gotMessage(ofMessage msg);
21+
22+
};

src/ofxAVFVideoRecorder.h

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#pragma once
2+
#ifndef _AVF_VIDEO_RECORDER_H
3+
#define _AVF_VIDEO_RECORDER_H
4+
5+
6+
#include <string>
7+
8+
9+
using namespace std;
10+
11+
class ofxAVFVideoRecorder {
12+
public:
13+
ofxAVFVideoRecorder();
14+
~ofxAVFVideoRecorder();
15+
bool isRecording();
16+
void setup(string $filename, int $width, int $height, int $framerate); // TODO type, quality
17+
void writeRGBA(unsigned char *data); // TODO other data types?
18+
int setAudioFile(string filename);
19+
void finishMovie();
20+
private:
21+
// CGImageRef getCGImageFromData(unsigned char *data);
22+
// CVPixelBufferRef pixelBufferFromCGImage(CGImageRef image);
23+
void addAudioToFileAtPath(string srcPath, string destPath);
24+
25+
bool recording;
26+
string audioFile;
27+
int width;
28+
int height;
29+
int framerate;
30+
int frames;
31+
string filename;
32+
string tmp_filename;
33+
34+
// AVAssetWriterInput * writerInput;
35+
// AVAssetWriter * videoWriter;
36+
// AVAssetWriterInputPixelBufferAdaptor * pixelBufferAdaptor;
37+
// dispatch_queue_t dispatchQueue;
38+
39+
void * recorderData;
40+
};
41+
42+
#endif

0 commit comments

Comments
 (0)