diff --git a/io/avtogl.cpp b/io/avtogl.cpp new file mode 100644 index 000000000..895612c6b --- /dev/null +++ b/io/avtogl.cpp @@ -0,0 +1,19 @@ +#include "avtogl.h" + +extern "C" { + #include +} + +enum QOpenGLTexture::PixelFormat get_gl_pix_fmt_from_av(int format) { + switch (format) { + case AV_PIX_FMT_RGB24: return QOpenGLTexture::RGB; + } + return QOpenGLTexture::RGBA; +} + +enum QOpenGLTexture::TextureFormat get_gl_tex_fmt_from_av(int format) { + switch (format) { + case AV_PIX_FMT_RGB24: return QOpenGLTexture::RGB8_UNorm; + } + return QOpenGLTexture::RGBA8_UNorm; +} diff --git a/io/avtogl.h b/io/avtogl.h new file mode 100644 index 000000000..b2bfd1e34 --- /dev/null +++ b/io/avtogl.h @@ -0,0 +1,9 @@ +#ifndef AVTOGL_H +#define AVTOGL_H + +#include + +enum QOpenGLTexture::PixelFormat get_gl_pix_fmt_from_av(int format); +enum QOpenGLTexture::TextureFormat get_gl_tex_fmt_from_av(int format); + +#endif // AVTOGL_H diff --git a/mainwindow.cpp b/mainwindow.cpp index c4a4441b1..6cf750313 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -227,6 +227,7 @@ MainWindow::MainWindow(QWidget *parent) : } MainWindow::~MainWindow() { + panel_effect_controls->clear_effects(true); panel_sequence_viewer->viewer_widget->delete_function(); panel_footage_viewer->viewer_widget->delete_function(); diff --git a/olive.pro b/olive.pro index 56f3bfe89..000bc854d 100644 --- a/olive.pro +++ b/olive.pro @@ -95,7 +95,8 @@ SOURCES += \ effects/internal/cubetransition.cpp \ project/effectgizmo.cpp \ io/clipboard.cpp \ - dialogs/stabilizerdialog.cpp + dialogs/stabilizerdialog.cpp \ + io/avtogl.cpp HEADERS += \ mainwindow.h \ @@ -170,7 +171,8 @@ HEADERS += \ effects/internal/cubetransition.h \ project/effectgizmo.h \ io/clipboard.h \ - dialogs/stabilizerdialog.h + dialogs/stabilizerdialog.h \ + io/avtogl.h FORMS += \ mainwindow.ui \ diff --git a/playback/cacher.cpp b/playback/cacher.cpp index ff6fd9fd3..ae3ecc683 100644 --- a/playback/cacher.cpp +++ b/playback/cacher.cpp @@ -24,6 +24,7 @@ extern "C" { #include #include #include + #include } #include @@ -34,7 +35,7 @@ extern "C" { // temp debug shit //#define AUDIOWARNINGS -int dest_format = AV_PIX_FMT_RGBA; +//int dest_format = AV_PIX_FMT_RGBA; double bytes_to_seconds(int nb_bytes, int nb_channels, int sample_rate) { return ((double) (nb_bytes >> 1) / nb_channels / sample_rate); @@ -712,11 +713,6 @@ void open_clip_worker(Clip* clip) { avfilter_graph_create_filter(&clip->buffersrc_ctx, avfilter_get_by_name("buffer"), "in", filter_args, NULL, clip->filter_graph); avfilter_graph_create_filter(&clip->buffersink_ctx, avfilter_get_by_name("buffersink"), "out", NULL, NULL, clip->filter_graph); - /*enum AVPixelFormat sinkpix_fmts[] = { static_cast(dest_format), AV_PIX_FMT_NONE }; - if (av_opt_set_int_list(clip->buffersink_ctx, "pix_fmts", sinkpix_fmts, AV_PIX_FMT_NONE, AV_OPT_SEARCH_CHILDREN) < 0) { - dout << "[ERROR] Could not set output pixel format"; - }*/ - AVFilterContext* last_filter = clip->buffersrc_ctx; if (ms->video_interlacing != VIDEO_PROGRESSIVE) { @@ -729,7 +725,7 @@ void open_clip_worker(Clip* clip) { last_filter = yadif_filter; } - /* stabilization code one day */ + /* stabilization code */ bool stabilize = false; if (stabilize) { AVFilterContext* stab_filter; @@ -741,10 +737,21 @@ void open_clip_worker(Clip* clip) { avfilter_link(last_filter, 0, stab_filter, 0); last_filter = stab_filter; } - } + } + + enum AVPixelFormat valid_pix_fmts[] = { + AV_PIX_FMT_RGB24, + AV_PIX_FMT_RGBA, + AV_PIX_FMT_NONE + }; + + clip->pix_fmt = avcodec_find_best_pix_fmt_of_list(valid_pix_fmts, static_cast(clip->stream->codecpar->format), 1, NULL); + const char* chosen_format = av_get_pix_fmt_name(static_cast(clip->pix_fmt)); + char format_args[100]; + snprintf(format_args, sizeof(format_args), "pix_fmts=%s", chosen_format); AVFilterContext* format_conv; - avfilter_graph_create_filter(&format_conv, avfilter_get_by_name("format"), "fmt", "pix_fmts=rgba", NULL, clip->filter_graph); + avfilter_graph_create_filter(&format_conv, avfilter_get_by_name("format"), "fmt", format_args, NULL, clip->filter_graph); avfilter_link(last_filter, 0, format_conv, 0); avfilter_link(format_conv, 0, clip->buffersink_ctx, 0); diff --git a/playback/playback.cpp b/playback/playback.cpp index 12361233d..13e71bac7 100644 --- a/playback/playback.cpp +++ b/playback/playback.cpp @@ -12,10 +12,12 @@ #include "panels/effectcontrols.h" #include "project/media.h" #include "io/config.h" +#include "io/avtogl.h" #include "debug.h" extern "C" { #include + #include #include #include #include @@ -220,8 +222,8 @@ void get_clip_frame(Clip* c, long playhead) { } if (target_frame != NULL) { - // add gate if this is the same frame - glPixelStorei(GL_UNPACK_ROW_LENGTH, target_frame->linesize[0]/4); + int nb_components = av_pix_fmt_desc_get(static_cast(c->pix_fmt))->nb_components; + glPixelStorei(GL_UNPACK_ROW_LENGTH, target_frame->linesize[0]/nb_components); bool copied = false; uint8_t* data = target_frame->data[0]; @@ -240,7 +242,7 @@ void get_clip_frame(Clip* c, long playhead) { } } - c->texture->setData(0, QOpenGLTexture::RGBA, QOpenGLTexture::UInt8, data); + c->texture->setData(0, get_gl_pix_fmt_from_av(c->pix_fmt), QOpenGLTexture::UInt8, data); if (copied) delete [] data; diff --git a/project/clip.h b/project/clip.h index 6e2ffc75a..69e757d5f 100644 --- a/project/clip.h +++ b/project/clip.h @@ -100,6 +100,7 @@ struct Clip bool finished_opening; bool replaced; bool ignore_reverse; + int pix_fmt; // caching functions bool use_existing_frame; diff --git a/ui/viewerwidget.cpp b/ui/viewerwidget.cpp index f044afc24..0c80622cd 100644 --- a/ui/viewerwidget.cpp +++ b/ui/viewerwidget.cpp @@ -20,6 +20,7 @@ #include "project/undo.h" #include "project/media.h" #include "ui/viewercontainer.h" +#include "io/avtogl.h" #include #include @@ -511,10 +512,10 @@ GLuint ViewerWidget::compose_sequence(QVector& nests, bool render_audio) if (c->texture == NULL) { c->texture = new QOpenGLTexture(QOpenGLTexture::Target2D); c->texture->setSize(c->stream->codecpar->width, c->stream->codecpar->height); - c->texture->setFormat(QOpenGLTexture::RGBA8_UNorm); + c->texture->setFormat(get_gl_tex_fmt_from_av(c->pix_fmt)); c->texture->setMipLevels(c->texture->maximumMipLevels()); c->texture->setMinMagFilters(QOpenGLTexture::Linear, QOpenGLTexture::Linear); - c->texture->allocateStorage(QOpenGLTexture::RGBA, QOpenGLTexture::UInt8); + c->texture->allocateStorage(get_gl_pix_fmt_from_av(c->pix_fmt), QOpenGLTexture::UInt8); } get_clip_frame(c, playhead); textureID = c->texture->textureId();