enabled autochoosing opengl pixel format from source

This commit is contained in:
itsmattkc
2018-12-22 15:20:39 +11:00
parent e08df8df4d
commit 81f6b5d549
8 changed files with 58 additions and 16 deletions
+19
View File
@@ -0,0 +1,19 @@
#include "avtogl.h"
extern "C" {
#include <libavutil/avutil.h>
}
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;
}
+9
View File
@@ -0,0 +1,9 @@
#ifndef AVTOGL_H
#define AVTOGL_H
#include <QOpenGLTexture>
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
+1
View File
@@ -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();
+4 -2
View File
@@ -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 \
+16 -9
View File
@@ -24,6 +24,7 @@ extern "C" {
#include <libavfilter/buffersrc.h>
#include <libavfilter/buffersink.h>
#include <libavutil/opt.h>
#include <libavutil/pixdesc.h>
}
#include <QOpenGLFramebufferObject>
@@ -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<AVPixelFormat>(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<enum AVPixelFormat>(clip->stream->codecpar->format), 1, NULL);
const char* chosen_format = av_get_pix_fmt_name(static_cast<enum AVPixelFormat>(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);
+5 -3
View File
@@ -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 <libavformat/avformat.h>
#include <libavutil/pixdesc.h>
#include <libavcodec/avcodec.h>
#include <libswscale/swscale.h>
#include <libswresample/swresample.h>
@@ -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<enum AVPixelFormat>(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;
+1
View File
@@ -100,6 +100,7 @@ struct Clip
bool finished_opening;
bool replaced;
bool ignore_reverse;
int pix_fmt;
// caching functions
bool use_existing_frame;
+3 -2
View File
@@ -20,6 +20,7 @@
#include "project/undo.h"
#include "project/media.h"
#include "ui/viewercontainer.h"
#include "io/avtogl.h"
#include <QPainter>
#include <QAudioOutput>
@@ -511,10 +512,10 @@ GLuint ViewerWidget::compose_sequence(QVector<Clip*>& 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();