Skip to content

Commit

Permalink
Fixing color format for opencv conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
jonoomph committed Oct 30, 2020
1 parent b74b3ea commit df154c3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/Frame.cpp
Expand Up @@ -968,14 +968,14 @@ cv::Mat Frame::GetImageCV()

std::shared_ptr<QImage> Frame::Mat2Qimage(cv::Mat img){
cv::cvtColor(img, img, cv::COLOR_BGR2RGB);
QImage qimg((uchar*) img.data, img.cols, img.rows, img.step, QImage::Format_RGBA8888_Premultiplied);
QImage qimg((uchar*) img.data, img.cols, img.rows, img.step, QImage::Format_RGB888);

std::shared_ptr<QImage> imgIn = std::make_shared<QImage>(qimg.copy());

// Always convert to RGBA8888 (if different)
if (imgIn->format() != QImage::Format_RGBA8888_Premultiplied)
*imgIn = imgIn->convertToFormat(QImage::Format_RGBA8888_Premultiplied);

return imgIn;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Qt/PlayerPrivate.cpp
Expand Up @@ -195,10 +195,10 @@ namespace openshot
// Stop video/audio playback
void PlayerPrivate::stopPlayback(int timeOutMilliseconds)
{
if (isThreadRunning()) stopThread(timeOutMilliseconds);
if (audioPlayback->isThreadRunning() && reader->info.has_audio) audioPlayback->stopThread(timeOutMilliseconds);
if (videoCache->isThreadRunning() && reader->info.has_video) videoCache->stopThread(timeOutMilliseconds);
if (videoPlayback->isThreadRunning() && reader->info.has_video) videoPlayback->stopThread(timeOutMilliseconds);
if (isThreadRunning()) stopThread(timeOutMilliseconds);
}

}
60 changes: 30 additions & 30 deletions src/Qt/VideoCacheThread.cpp
Expand Up @@ -93,43 +93,43 @@ namespace openshot

while (!threadShouldExit() && is_playing) {

// Cache frames before the other threads need them
// Cache frames up to the max frames. Reset to current position
// if cache gets too far away from display frame. Cache frames
// even when player is paused (i.e. speed 0).
while ((position - current_display_frame) < max_frames)
{
// Only cache up till the max_frames amount... then sleep
try
// Cache frames before the other threads need them
// Cache frames up to the max frames. Reset to current position
// if cache gets too far away from display frame. Cache frames
// even when player is paused (i.e. speed 0).
while (((position - current_display_frame) < max_frames) && is_playing)
{
if (reader) {
ZmqLogger::Instance()->AppendDebugMethod("VideoCacheThread::run (cache frame)", "position", position, "current_display_frame", current_display_frame, "max_frames", max_frames, "needed_frames", (position - current_display_frame));

// Force the frame to be generated
if (reader->GetCache()->GetSmallestFrame()) {
int64_t smallest_cached_frame = reader->GetCache()->GetSmallestFrame()->number;
if (smallest_cached_frame > current_display_frame) {
// Cache position has gotten too far away from current display frame.
// Reset the position to the current display frame.
position = current_display_frame;
// Only cache up till the max_frames amount... then sleep
try
{
if (reader) {
ZmqLogger::Instance()->AppendDebugMethod("VideoCacheThread::run (cache frame)", "position", position, "current_display_frame", current_display_frame, "max_frames", max_frames, "needed_frames", (position - current_display_frame));

// Force the frame to be generated
if (reader->GetCache()->GetSmallestFrame()) {
int64_t smallest_cached_frame = reader->GetCache()->GetSmallestFrame()->number;
if (smallest_cached_frame > current_display_frame) {
// Cache position has gotten too far away from current display frame.
// Reset the position to the current display frame.
position = current_display_frame;
}
}
reader->GetFrame(position);
}
reader->GetFrame(position);

}
catch (const OutOfBoundsFrame & e)
{
// Ignore out of bounds frame exceptions
}

// Increment frame number
position++;
}
catch (const OutOfBoundsFrame & e)
{
// Ignore out of bounds frame exceptions
}

// Increment frame number
position++;
}

// Sleep for 1 frame length
std::this_thread::sleep_for(frame_duration);
}
// Sleep for 1 frame length
std::this_thread::sleep_for(frame_duration);
}

return;
}
Expand Down

0 comments on commit df154c3

Please sign in to comment.