Skip to content

Commit

Permalink
Implemented the movie recording feature (incl. in the example).
Browse files Browse the repository at this point in the history
  • Loading branch information
smallfly committed Jun 19, 2014
1 parent eb3d93e commit 3713cf7
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 7 deletions.
17 changes: 17 additions & 0 deletions example/src/testApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
void testApp::setup() {
ofSetVerticalSync(true);
ofSetLogLevel(OF_LOG_VERBOSE);

bIsRecordingMovie = false;
camera.setup();
}

Expand All @@ -11,11 +13,16 @@ void testApp::update() {
if(camera.isFrameNew()) {
// process the live view with camera.getLivePixels()
}

if(camera.isPhotoNew()) {
// process the photo with camera.getPhotoPixels()
// or just save the photo to disk (jpg only):
camera.savePhoto(ofToString(ofGetFrameNum()) + ".jpg");
}

if(camera.isMovieNew()) {
camera.savePhoto(ofToString(ofGetFrameNum()) + ".mov");
}
}

void testApp::draw() {
Expand All @@ -35,4 +42,14 @@ void testApp::keyPressed(int key) {
if(key == ' ') {
camera.takePhoto();
}

else if(key == 'v') {
bIsRecordingMovie ^= true;
if (bIsRecordingMovie) {
camera.beginMovieRecording();
} else {
camera.endMovieRecording();
}
}

}
2 changes: 2 additions & 0 deletions example/src/testApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ class testApp : public ofBaseApp {
void keyPressed(int key);

ofxEdsdk::Camera camera;

bool bIsRecordingMovie;
};
4 changes: 3 additions & 1 deletion src/EdsWrapper/EdsExamples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Eds {

// from EDSDK API sample 6.3.6
void DownloadImage(EdsDirectoryItemRef directoryItem, ofBuffer& imageBuffer, bool deleteAfterDownload) {
EdsDirectoryItemInfo DownloadImage(EdsDirectoryItemRef directoryItem, ofBuffer& imageBuffer, bool deleteAfterDownload) {
EdsStreamRef stream = NULL;
EdsDirectoryItemInfo dirItemInfo;
Eds::GetDirectoryItemInfo(directoryItem, &dirItemInfo);
Expand All @@ -17,6 +17,8 @@ namespace Eds {
Eds::DeleteDirectoryItem(directoryItem);
}
Eds::SafeRelease(stream);

return dirItemInfo;
}

// from EDSDK API sample 6.3.10
Expand Down
2 changes: 1 addition & 1 deletion src/EdsWrapper/EdsExamples.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/

namespace Eds {
void DownloadImage(EdsDirectoryItemRef directoryItem, ofBuffer& imageBuffer, bool deleteAfterDownload = true);
EdsDirectoryItemInfo DownloadImage(EdsDirectoryItemRef directoryItem, ofBuffer& imageBuffer, bool deleteAfterDownload = true);
void StartLiveview(EdsCameraRef camera);
bool DownloadEvfData(EdsCameraRef camera, ofBuffer& imageBuffer);
void EndLiveview(EdsCameraRef camera);
Expand Down
71 changes: 67 additions & 4 deletions src/ofxEdsdk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
*/
#define OFX_EDSDK_BUFFER_SIZE 4
#define OFX_EDSDK_LIVE_DELAY 100

#define OFX_EDSDK_JPG_FORMAT 14337
#define OFX_EDSDK_MOV_FORMAT 45316

#ifdef TARGET_OSX
#include <Cocoa/Cocoa.h>
#elif defined(TARGET_WIN32)
Expand Down Expand Up @@ -59,6 +63,9 @@ namespace ofxEdsdk {
frameNew(false),
needToTakePhoto(false),
photoNew(false),
needToStartRecording(false),
needToStopRecording(false),
movieNew(false),
needToDecodePhoto(false),
needToUpdatePhoto(false),
photoDataReady(false),
Expand Down Expand Up @@ -177,6 +184,15 @@ namespace ofxEdsdk {
return false;
}
}

bool Camera::isMovieNew() {
if(movieNew) {
movieNew = false;
return true;
} else {
return false;
}
}

float Camera::getFrameRate() {
float frameRate;
Expand All @@ -196,6 +212,20 @@ namespace ofxEdsdk {
}
}
}

void Camera::beginMovieRecording()
{
lock();
needToStartRecording = true;
unlock();
}

void Camera::endMovieRecording()
{
lock();
needToStopRecording = true;
unlock();
}

ofPixels& Camera::getLivePixels() {
return livePixels;
Expand Down Expand Up @@ -342,6 +372,33 @@ namespace ofxEdsdk {
ofLogError() << "Error while taking a picture: " << e.what();
}
}

if(needToStartRecording) {
try {
EdsUInt32 saveTo = kEdsSaveTo_Camera;
EdsSetPropertyData(camera, kEdsPropID_SaveTo, 0, sizeof(saveTo) , &saveTo);

EdsUInt32 record_start = 4; // Begin movie shooting
EdsSetPropertyData(camera, kEdsPropID_Record, 0, sizeof(record_start), &record_start);
lock();
needToStartRecording = false;
unlock();
} catch (Eds::Exception& e) {
ofLogError() << "Error while beginning to record: " << e.what();
}
}

if(needToStopRecording) {
try {
EdsUInt32 record_stop = 0; // End movie shooting
EdsSetPropertyData(camera, kEdsPropID_Record, 0, sizeof(record_stop), &record_stop);
lock();
needToStopRecording = false;
unlock();
} catch (Eds::Exception& e) {
ofLogError() << "Error while stopping to record: " << e.what();
}
}

if(needToSendKeepAlive) {
try {
Expand All @@ -358,17 +415,23 @@ namespace ofxEdsdk {

if(needToDownloadImage) {
try {
Eds::DownloadImage(directoryItem, photoBuffer);
ofLogVerbose() << "Downloaded image: " << (int) (photoBuffer.size() / 1024) << " KB";
EdsDirectoryItemInfo dirItemInfo = Eds::DownloadImage(directoryItem, photoBuffer);
ofLogVerbose() << "Downloaded item: " << (int) (photoBuffer.size() / 1024) << " KB";
lock();
photoDataReady = true;
photoNew = true;
needToDecodePhoto = true;
needToUpdatePhoto = true;
needToDownloadImage = false;

if (dirItemInfo.format == OFX_EDSDK_JPG_FORMAT) {
photoNew = true;
} else if (dirItemInfo.format == OFX_EDSDK_MOV_FORMAT) {
movieNew = true;
}

unlock();
} catch (Eds::Exception& e) {
ofLogError() << "Error while downloading image: " << e.what();
ofLogError() << "Error while downloading item: " << e.what();
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/ofxEdsdk.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ namespace ofxEdsdk {
bool savePhoto(string filename); // .jpg only
ofPixels& getPhotoPixels();
ofTexture& getPhotoTexture();

void beginMovieRecording();
void endMovieRecording();
bool isMovieNew();

protected:
EdsCameraRef camera;
Expand Down Expand Up @@ -80,9 +84,13 @@ namespace ofxEdsdk {
bool photoDataReady; // Photo data has been downloaded at least once.
bool needToSendKeepAlive; // Send keepalive next chance we get.
bool needToDownloadImage; // Download image next chance we get.

bool movieNew;
bool needToStartRecording; // threadedFunction() should start recording next chance it gets.
bool needToStopRecording; // threadedFunction() should start recording next chance it gets.

void threadedFunction();

// the liveview needs to be reset every so often to avoid the camera turning off
float resetIntervalMinutes;
float lastResetTime;
Expand Down

0 comments on commit 3713cf7

Please sign in to comment.