From d51ce537aeb066c247bfcd3ec84bb3ea4183bef9 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 8 Jan 2019 09:10:09 +1100 Subject: [PATCH] scroll to item and export improvements --- dialogs/actionsearch.cpp | 8 +++---- io/exportthread.cpp | 48 +++++++++++++++++++++++++++++----------- io/exportthread.h | 10 ++++++--- panels/project.cpp | 2 +- ui/viewerwidget.cpp | 2 +- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/dialogs/actionsearch.cpp b/dialogs/actionsearch.cpp index c1eafd6c2..5bf7461d8 100644 --- a/dialogs/actionsearch.cpp +++ b/dialogs/actionsearch.cpp @@ -88,9 +88,9 @@ void ActionSearch::perform_action() { void ActionSearch::move_selection_up() { int lim = list_widget->count(); for (int i=1;iitem(i)->isSelected()) { -// list_widget->item(i)->setSelected(false); + if (list_widget->item(i)->isSelected()) { list_widget->item(i-1)->setSelected(true); + list_widget->scrollToItem(list_widget->item(i-1)); break; } } @@ -99,9 +99,9 @@ void ActionSearch::move_selection_up() { void ActionSearch::move_selection_down() { int lim = list_widget->count()-1; for (int i=0;iitem(i)->isSelected()) { -// list_widget->item(i)->setSelected(false); + if (list_widget->item(i)->isSelected()) { list_widget->item(i+1)->setSelected(true); + list_widget->scrollToItem(list_widget->item(i+1)); break; } } diff --git a/io/exportthread.cpp b/io/exportthread.cpp index a2eeb5962..a3e7cf965 100644 --- a/io/exportthread.cpp +++ b/io/exportthread.cpp @@ -26,6 +26,23 @@ extern "C" { ExportThread::ExportThread() : continueEncode(true) { surface.create(); + + fmt_ctx = NULL; + video_stream = NULL; + vcodec = NULL; + vcodec_ctx = NULL; + video_frame = NULL; + sws_frame = NULL; + sws_ctx = NULL; + audio_stream = NULL; + acodec = NULL; + audio_frame = NULL; + swr_frame = NULL; + acodec_ctx = NULL; + swr_ctx = NULL; + + vpkt_alloc = false; + apkt_alloc = false; } bool ExportThread::encode(AVFormatContext* ofmt_ctx, AVCodecContext* codec_ctx, AVFrame* frame, AVPacket* packet, AVStream* stream, bool rescale) { @@ -390,12 +407,17 @@ void ExportThread::run() { frame_count++; } + if (continueEncode) { + if (video_enabled) vpkt_alloc = true; + if (audio_enabled) apkt_alloc = true; + } + panel_sequence_viewer->viewer_widget->default_fbo = NULL; rendering = false; fbo.release(); - if (audio_enabled) { + if (audio_enabled && continueEncode) { // flush swresample do { swr_convert_frame(swr_ctx, swr_frame, NULL); @@ -427,19 +449,19 @@ void ExportThread::run() { avio_closep(&fmt_ctx->pb); - if (video_enabled) { - avcodec_close(vcodec_ctx); - av_packet_unref(&video_pkt); - av_frame_free(&video_frame); - avcodec_free_context(&vcodec_ctx); - } + if (vpkt_alloc) av_packet_unref(&video_pkt); + if (video_frame != NULL) av_frame_free(&video_frame); + if (vcodec_ctx != NULL) { + avcodec_close(vcodec_ctx); + avcodec_free_context(&vcodec_ctx); + } - if (audio_enabled) { - avcodec_close(acodec_ctx); - av_packet_unref(&audio_pkt); - av_frame_free(&audio_frame); - avcodec_free_context(&acodec_ctx); - } + if (apkt_alloc) av_packet_unref(&audio_pkt); + if (audio_frame != NULL) av_frame_free(&audio_frame); + if (acodec_ctx != NULL) { + avcodec_close(acodec_ctx); + avcodec_free_context(&acodec_ctx); + } avformat_free_context(fmt_ctx); diff --git a/io/exportthread.h b/io/exportthread.h index 0eb74b952..0710343db 100644 --- a/io/exportthread.h +++ b/io/exportthread.h @@ -58,13 +58,13 @@ private: bool setupAudio(); bool setupContainer(); - AVFormatContext* fmt_ctx = NULL; + AVFormatContext* fmt_ctx; AVStream* video_stream; AVCodec* vcodec; AVCodecContext* vcodec_ctx; AVFrame* video_frame; AVFrame* sws_frame; - SwsContext* sws_ctx = NULL; + SwsContext* sws_ctx; AVStream* audio_stream; AVCodec* acodec; AVFrame* audio_frame; @@ -72,7 +72,11 @@ private: AVCodecContext* acodec_ctx; AVPacket video_pkt; AVPacket audio_pkt; - SwrContext* swr_ctx = NULL; + SwrContext* swr_ctx; + + bool vpkt_alloc; + bool apkt_alloc; + int aframe_bytes; int ret; char* c_filename; diff --git a/panels/project.cpp b/panels/project.cpp index 0c245f316..faf05daf6 100644 --- a/panels/project.cpp +++ b/panels/project.cpp @@ -527,7 +527,7 @@ void Project::delete_selected_media() { // remove if (remove) { panel_effect_controls->clear_effects(true); - sequence->selections.clear(); + if (sequence != NULL) sequence->selections.clear(); // remove media and parents for (int m=0;mthread() == this->thread()) { makeCurrent(); QOpenGLWidget::paintEvent(e); }