Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 17 additions & 11 deletions Sofa/GL/src/sofa/gl/VideoRecorderFFMPEG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ bool VideoRecorderFFMPEG::init(const std::string& ffmpeg_exec_filepath, const st
extension = ".exe";
#endif
m_ffmpegExecPath = helper::Utils::getExecutablePath() + "/ffmpeg" + extension;
if(!FileSystem::isFile(m_ffmpegExecPath))
if(!FileSystem::isFile(m_ffmpegExecPath, true))
{
msg_warning("VideoRecorderFFMPEG")<< "ffmpeg hasn't been found automatically. Falling back to simply calling ffmpeg"<< extension <<" and hope that the OS finds it on its own. " ;
// Fallback to a relative FFMPEG (may be in system or exposed in PATH)
m_ffmpegExecPath = "ffmpeg" + extension;
}
Expand Down Expand Up @@ -138,31 +139,38 @@ void VideoRecorderFFMPEG::addFrame()
{
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);

if ((viewport[2] != m_viewportWidth) || (viewport[3] != m_viewportHeight))
{
std::cout << "WARNING viewport changed during video capture from " << m_viewportWidth << "x" << m_viewportHeight << " to " << viewport[2] << "x" << viewport[3] << std::endl;
}

glReadPixels(viewport[0], viewport[1], m_viewportWidth, m_viewportHeight, GL_RGBA, GL_UNSIGNED_BYTE, (void*)m_viewportBuffer);

addFrame(m_viewportBuffer, m_viewportWidth, m_viewportHeight);
}


glReadPixels(0, 0, m_viewportWidth, m_viewportHeight, GL_RGBA, GL_UNSIGNED_BYTE, (void*)m_viewportBuffer);

// set ffmpeg buffer: initialize to 0 (black)
void VideoRecorderFFMPEG::addFrame(unsigned char* rgbData, int fbWidth, int fbHeight)
{

// set ffmpeg buffer: initialize to 0 (black)
memset(m_ffmpegBuffer, 0, m_ffmpegBufferSize);

if (m_viewportWidth == m_ffmpegWidth)
if (fbWidth == m_ffmpegWidth)
{
memcpy(m_ffmpegBuffer, m_viewportBuffer, m_viewportBufferSize);
memcpy(m_ffmpegBuffer, rgbData, fbHeight * fbWidth * m_pixelFormatSize);
}
else
{
const unsigned char* viewportBufferIter = m_viewportBuffer;
const size_t viewportRowSizeInBytes = m_pixelFormatSize * m_viewportWidth;
const unsigned char* viewportBufferIter = rgbData;
const size_t viewportRowSizeInBytes = m_pixelFormatSize * fbWidth;

unsigned char* ffmpegBufferIter = m_ffmpegBuffer;
const size_t ffmpegRowSizeInBytes = m_pixelFormatSize * m_ffmpegWidth;

int row = m_viewportHeight;
int row = fbHeight;
while ( row-- > 0 )
{
memcpy( ffmpegBufferIter, viewportBufferIter, viewportRowSizeInBytes);
Expand All @@ -174,8 +182,6 @@ void VideoRecorderFFMPEG::addFrame()


fwrite(m_ffmpegBuffer, m_ffmpegBufferSize, 1, m_ffmpeg);

return;
}

void VideoRecorderFFMPEG::finishVideo()
Expand Down
5 changes: 5 additions & 0 deletions Sofa/GL/src/sofa/gl/VideoRecorderFFMPEG.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ class SOFA_GL_API VideoRecorderFFMPEG
bool init(const std::string& ffmpeg_exec_filepath, const std::string& filename, int width, int height, unsigned int framerate, unsigned int bitrate, const std::string& codec="");

void addFrame();
void addFrame(unsigned char* rgbData, int fbWidth, int fbHeight);
void saveVideo();
void finishVideo();

int getPixelFormatSize()
{
return m_pixelFormatSize;
};

void setPrefix(const std::string v) { m_prefix = v; }

Expand Down
Loading