added noise effect and drawing nested sequences to texture
This commit is contained in:
+125
-112
@@ -28,8 +28,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
|
||||
multithreaded(true),
|
||||
force_audio(false),
|
||||
enable_paint(true),
|
||||
flip(false),
|
||||
fbo(NULL)
|
||||
flip(false)
|
||||
{
|
||||
QSurfaceFormat format;
|
||||
format.setDepthBufferSize(24);
|
||||
@@ -82,11 +81,11 @@ void ViewerWidget::paintEvent(QPaintEvent *e) {
|
||||
if (enable_paint) QOpenGLWidget::paintEvent(e);
|
||||
}
|
||||
|
||||
GLuint ViewerWidget::draw_clip(GLuint texture) {
|
||||
GLuint ViewerWidget::draw_clip(Clip* clip, GLuint texture) {
|
||||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glOrtho(0, 1, 0, 1, -1, 1);
|
||||
fbo->bind();
|
||||
clip->fbo->bind();
|
||||
glBindTexture(GL_TEXTURE_2D, texture);
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(0, 0); // top left
|
||||
@@ -99,22 +98,20 @@ GLuint ViewerWidget::draw_clip(GLuint texture) {
|
||||
glVertex2f(0, 1); // bottom left
|
||||
glEnd();
|
||||
glBindTexture(GL_TEXTURE_2D, NULL);
|
||||
fbo->release();
|
||||
clip->fbo->release();
|
||||
glPopMatrix();
|
||||
return fbo->takeTexture();
|
||||
return clip->fbo->takeTexture();
|
||||
}
|
||||
|
||||
void ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio) {
|
||||
Sequence* s = sequence;
|
||||
GLuint ViewerWidget::compose_sequence(Clip* nest, bool render_audio) {
|
||||
Sequence* s = sequence;
|
||||
long playhead = panel_timeline->playhead;
|
||||
|
||||
Clip* nest = NULL;
|
||||
if (nests.size() > 0) {
|
||||
nest = nests.last();
|
||||
if (nest != NULL) {
|
||||
s = static_cast<Sequence*>(nest->media);
|
||||
playhead += nest->clip_in - nest->timeline_in;
|
||||
playhead = refactor_frame_number(playhead, sequence->frame_rate, s->frame_rate);
|
||||
}
|
||||
playhead += nest->clip_in - nest->timeline_in;
|
||||
playhead = refactor_frame_number(playhead, nest->sequence->frame_rate, s->frame_rate);
|
||||
}
|
||||
|
||||
QVector<Clip*> current_clips;
|
||||
|
||||
@@ -175,105 +172,122 @@ void ViewerWidget::compose_sequence(QVector<Clip*>& nests, bool render_audio) {
|
||||
qDebug() << "[WARNING] Tried to display clip" << i << "but it's closed";
|
||||
texture_failed = true;
|
||||
} else {
|
||||
switch (c->media_type) {
|
||||
case MEDIA_TYPE_FOOTAGE:
|
||||
if (c->stream->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
|
||||
// start preparing cache
|
||||
get_clip_frame(c, playhead);
|
||||
if (c->track < 0) {
|
||||
GLuint textureID = 0;
|
||||
int video_width, video_height;
|
||||
|
||||
if (c->texture == NULL) {
|
||||
qDebug() << "[WARNING] Texture hasn't been created yet";
|
||||
texture_failed = true;
|
||||
} else if (playhead >= c->timeline_in) {
|
||||
MediaStream* ms = static_cast<Media*>(c->media)->get_stream_from_file_index(c->track < 0, c->media_stream);
|
||||
|
||||
int half_width = sequence->width/2;
|
||||
int half_height = sequence->height/2;
|
||||
if (flip) half_height = -half_height;
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor4f(1.0, 1.0, 1.0, 1.0);
|
||||
glLoadIdentity();
|
||||
glOrtho(-half_width, half_width, half_height, -half_height, -1, 1);
|
||||
glViewport(0, 0, ms->video_width, ms->video_height);
|
||||
|
||||
// TEMP DEBUG CODE
|
||||
if (fbo != NULL) delete fbo;
|
||||
fbo = new QOpenGLFramebufferObject(ms->video_width, ms->video_height);
|
||||
GLuint composite_texture = draw_clip(c->texture->textureId());
|
||||
// END
|
||||
|
||||
GLTextureCoords coords;
|
||||
coords.vertexTopLeftX = coords.vertexBottomLeftX = -ms->video_width/2;
|
||||
coords.vertexTopLeftY = coords.vertexTopRightY = -ms->video_height/2;
|
||||
coords.vertexTopRightX = coords.vertexBottomRightX = ms->video_width/2;
|
||||
coords.vertexBottomLeftY = coords.vertexBottomRightY = ms->video_height/2;
|
||||
coords.textureTopLeftY = coords.textureTopRightY = coords.textureTopLeftX = coords.textureBottomLeftX = 0;
|
||||
coords.textureBottomLeftY = coords.textureBottomRightY = coords.textureTopRightX = coords.textureBottomRightX = 1.0;
|
||||
|
||||
// EFFECT CODE START
|
||||
for (int j=0;j<c->effects.size();j++) {
|
||||
if (c->effects.at(j)->enable_opengl && c->effects.at(j)->is_enabled()) {
|
||||
c->effects.at(j)->process_gl(((double)(panel_timeline->playhead-c->timeline_in+c->clip_in)/(double)sequence->frame_rate), coords);
|
||||
composite_texture = draw_clip(composite_texture);
|
||||
}
|
||||
}
|
||||
|
||||
if (c->opening_transition != NULL) {
|
||||
int transition_progress = playhead - c->timeline_in;
|
||||
if (transition_progress < c->opening_transition->length) {
|
||||
c->opening_transition->process_transition((double)transition_progress/(double)c->opening_transition->length);
|
||||
}
|
||||
}
|
||||
|
||||
if (c->closing_transition != NULL) {
|
||||
int transition_progress = c->closing_transition->length - (playhead - c->timeline_in - c->getLength() + c->closing_transition->length);
|
||||
if (transition_progress < c->closing_transition->length) {
|
||||
c->closing_transition->process_transition((double)transition_progress/(double)c->closing_transition->length);
|
||||
}
|
||||
}
|
||||
// EFFECT CODE END
|
||||
|
||||
for (int j=0;j<c->effects.size();j++) {
|
||||
if (c->effects.at(j)->enable_opengl && c->effects.at(j)->is_enabled()) {
|
||||
c->effects.at(j)->clean_gl();
|
||||
}
|
||||
}
|
||||
|
||||
glViewport(0, 0, width(), height());
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, composite_texture);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(coords.textureTopLeftX, coords.textureTopLeftY); // top left
|
||||
glVertex2f(coords.vertexTopLeftX, coords.vertexTopLeftY); // top left
|
||||
glTexCoord2f(coords.textureTopRightX, coords.textureTopRightY); // top right
|
||||
glVertex2f(coords.vertexTopRightX, coords.vertexTopRightY); // top right
|
||||
glTexCoord2f(coords.textureBottomRightX, coords.textureBottomRightY); // bottom right
|
||||
glVertex2f(coords.vertexBottomRightX, coords.vertexBottomRightY); // bottom right
|
||||
glTexCoord2f(coords.textureBottomLeftX, coords.textureBottomLeftY); // bottom left
|
||||
glVertex2f(coords.vertexBottomLeftX, coords.vertexBottomLeftY); // bottom left
|
||||
glEnd();
|
||||
|
||||
glDeleteTextures(1, &composite_texture);
|
||||
}
|
||||
} else if (render_audio &&
|
||||
c->stream->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
|
||||
c->lock.tryLock()) {
|
||||
// clip is not caching, start caching audio
|
||||
cache_clip(c, playhead, false, false, c->audio_reset, nest);
|
||||
c->lock.unlock();
|
||||
if (c->media_type == MEDIA_TYPE_FOOTAGE) {
|
||||
get_clip_frame(c, playhead);
|
||||
MediaStream* ms = static_cast<Media*>(c->media)->get_stream_from_file_index(c->track < 0, c->media_stream);
|
||||
video_width = ms->video_width;
|
||||
video_height = ms->video_height;
|
||||
if (c->texture != NULL) textureID = c->texture->textureId();
|
||||
} else if (c->media_type == MEDIA_TYPE_SEQUENCE) {
|
||||
video_width = s->width;
|
||||
video_height = s->height;
|
||||
textureID = compose_sequence(c, render_audio);
|
||||
}
|
||||
break;
|
||||
case MEDIA_TYPE_SEQUENCE:
|
||||
nests.append(c);
|
||||
compose_sequence(nests, render_audio);
|
||||
break;
|
||||
}
|
||||
|
||||
if (textureID == 0) {
|
||||
qDebug() << "[WARNING] Texture hasn't been created yet";
|
||||
texture_failed = true;
|
||||
} else if (playhead >= c->timeline_in) {
|
||||
// start preparing cache
|
||||
if (c->fbo == NULL) c->fbo = new QOpenGLFramebufferObject(video_width, video_height);
|
||||
|
||||
int half_width = c->sequence->width/2;
|
||||
int half_height = c->sequence->height/2;
|
||||
if (flip || nest != NULL) half_height = -half_height;
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
glColor4f(1.0, 1.0, 1.0, 1.0);
|
||||
glLoadIdentity();
|
||||
glOrtho(-half_width, half_width, half_height, -half_height, -1, 1);
|
||||
glViewport(0, 0, video_width, video_height);
|
||||
|
||||
GLuint composite_texture = draw_clip(c, textureID);
|
||||
|
||||
GLTextureCoords coords;
|
||||
coords.vertexTopLeftX = coords.vertexBottomLeftX = -video_width/2;
|
||||
coords.vertexTopLeftY = coords.vertexTopRightY = -video_height/2;
|
||||
coords.vertexTopRightX = coords.vertexBottomRightX = video_width/2;
|
||||
coords.vertexBottomLeftY = coords.vertexBottomRightY = video_height/2;
|
||||
coords.textureTopLeftY = coords.textureTopRightY = coords.textureTopLeftX = coords.textureBottomLeftX = 0;
|
||||
coords.textureBottomLeftY = coords.textureBottomRightY = coords.textureTopRightX = coords.textureBottomRightX = 1.0;
|
||||
|
||||
// EFFECT CODE START
|
||||
for (int j=0;j<c->effects.size();j++) {
|
||||
if (c->effects.at(j)->enable_opengl && c->effects.at(j)->is_enabled()) {
|
||||
c->effects.at(j)->process_gl(((double)(panel_timeline->playhead-c->timeline_in+c->clip_in)/(double)sequence->frame_rate), coords);
|
||||
composite_texture = draw_clip(c, composite_texture);
|
||||
}
|
||||
}
|
||||
|
||||
if (c->opening_transition != NULL) {
|
||||
int transition_progress = playhead - c->timeline_in;
|
||||
if (transition_progress < c->opening_transition->length) {
|
||||
c->opening_transition->process_transition((double)transition_progress/(double)c->opening_transition->length);
|
||||
}
|
||||
}
|
||||
|
||||
if (c->closing_transition != NULL) {
|
||||
int transition_progress = c->closing_transition->length - (playhead - c->timeline_in - c->getLength() + c->closing_transition->length);
|
||||
if (transition_progress < c->closing_transition->length) {
|
||||
c->closing_transition->process_transition((double)transition_progress/(double)c->closing_transition->length);
|
||||
}
|
||||
}
|
||||
// EFFECT CODE END
|
||||
|
||||
for (int j=0;j<c->effects.size();j++) {
|
||||
if (c->effects.at(j)->enable_opengl && c->effects.at(j)->is_enabled()) {
|
||||
c->effects.at(j)->clean_gl();
|
||||
}
|
||||
}
|
||||
|
||||
if (nest != NULL) {
|
||||
if (nest->fbo == NULL) nest->fbo = new QOpenGLFramebufferObject(s->width, s->height);
|
||||
nest->fbo->bind();
|
||||
glViewport(0, 0, s->width, s->height);
|
||||
} else {
|
||||
glViewport(0, 0, width(), height());
|
||||
}
|
||||
|
||||
glBindTexture(GL_TEXTURE_2D, composite_texture);
|
||||
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glTexCoord2f(coords.textureTopLeftX, coords.textureTopLeftY); // top left
|
||||
glVertex2f(coords.vertexTopLeftX, coords.vertexTopLeftY); // top left
|
||||
glTexCoord2f(coords.textureTopRightX, coords.textureTopRightY); // top right
|
||||
glVertex2f(coords.vertexTopRightX, coords.vertexTopRightY); // top right
|
||||
glTexCoord2f(coords.textureBottomRightX, coords.textureBottomRightY); // bottom right
|
||||
glVertex2f(coords.vertexBottomRightX, coords.vertexBottomRightY); // bottom right
|
||||
glTexCoord2f(coords.textureBottomLeftX, coords.textureBottomLeftY); // bottom left
|
||||
glVertex2f(coords.vertexBottomLeftX, coords.vertexBottomLeftY); // bottom left
|
||||
glEnd();
|
||||
|
||||
glDeleteTextures(1, &composite_texture);
|
||||
|
||||
if (nest != NULL) {
|
||||
nest->fbo->release();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (c->media_type == MEDIA_TYPE_FOOTAGE
|
||||
&& render_audio
|
||||
&& c->lock.tryLock()) {
|
||||
// clip is not caching, start caching audio
|
||||
cache_clip(c, playhead, false, false, c->audio_reset, nest);
|
||||
c->lock.unlock();
|
||||
} else if (c->media_type == MEDIA_TYPE_SEQUENCE) {
|
||||
compose_sequence(c, render_audio);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (nest != NULL && nest->fbo != NULL) ? nest->fbo->takeTexture() : 0;
|
||||
}
|
||||
|
||||
void ViewerWidget::paintGL() {
|
||||
@@ -291,9 +305,8 @@ void ViewerWidget::paintGL() {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// compose video preview
|
||||
QVector<Clip*> nests;
|
||||
compose_sequence(nests, (panel_timeline->playing || force_audio));
|
||||
// compose video preview
|
||||
compose_sequence(NULL, (panel_timeline->playing || force_audio));
|
||||
|
||||
if (texture_failed) {
|
||||
if (multithreaded) {
|
||||
|
||||
Reference in New Issue
Block a user