From 276151d415cf507311cc3f7478032725724562ae Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Mon, 25 Mar 2019 01:42:01 +1100 Subject: [PATCH] fixed bug causing larger than necessary exported files --- rendering/exportthread.cpp | 41 ++++++++++++++++++++++------------- rendering/renderfunctions.cpp | 2 +- 2 files changed, 27 insertions(+), 16 deletions(-) diff --git a/rendering/exportthread.cpp b/rendering/exportthread.cpp index 6e389c607..9ccf3c79f 100644 --- a/rendering/exportthread.cpp +++ b/rendering/exportthread.cpp @@ -20,17 +20,6 @@ #include "exportthread.h" -#include "global/global.h" -#include "timeline/sequence.h" -#include "panels/panels.h" - -#include "ui/viewerwidget.h" -#include "rendering/renderthread.h" -#include "rendering/renderfunctions.h" -#include "rendering/audio.h" -#include "ui/mainwindow.h" -#include "global/debug.h" - extern "C" { #include #include @@ -43,6 +32,17 @@ extern "C" { #include #include #include +#include + +#include "global/global.h" +#include "timeline/sequence.h" +#include "panels/panels.h" +#include "ui/viewerwidget.h" +#include "rendering/renderthread.h" +#include "rendering/renderfunctions.h" +#include "rendering/audio.h" +#include "ui/mainwindow.h" +#include "global/debug.h" ExportThread::ExportThread(const ExportParams ¶ms, const VideoCodecParams& vparams, @@ -92,7 +92,18 @@ bool ExportThread::Encode(AVFormatContext* ofmt_ctx, AVCodecContext* codec_ctx, } packet->stream_index = stream->index; - if (rescale) av_packet_rescale_ts(packet, codec_ctx->time_base, stream->time_base); + if (rescale) { + if (packet->pts != AV_NOPTS_VALUE) { + packet->pts = qRound(packet->pts * av_q2d(codec_ctx->time_base) / av_q2d(stream->time_base)); + } + if (packet->dts != AV_NOPTS_VALUE) { + packet->dts = qRound(packet->dts * av_q2d(codec_ctx->time_base) / av_q2d(stream->time_base)); + } + if (packet->duration > 0) { + packet->duration = qRound(packet->duration * av_q2d(codec_ctx->time_base) / av_q2d(stream->time_base)); + } + //av_packet_rescale_ts(packet, codec_ctx->time_base, stream->time_base); + } av_interleaved_write_frame(ofmt_ctx, packet); av_packet_unref(packet); } @@ -469,10 +480,10 @@ void ExportThread::Export() // Convert raw RGBA buffer to format expected by the encoder sws_scale(sws_ctx, video_frame->data, video_frame->linesize, 0, video_frame->height, sws_frame->data, sws_frame->linesize); - sws_frame->pts = qRound(timecode_secs/av_q2d(video_stream->time_base)); + sws_frame->pts = qRound(timecode_secs/av_q2d(vcodec_ctx->time_base)); // Send frame to encoder - if (!Encode(fmt_ctx, vcodec_ctx, sws_frame, &video_pkt, video_stream, false)) { + if (!Encode(fmt_ctx, vcodec_ctx, sws_frame, &video_pkt, video_stream, true)) { return; } @@ -578,7 +589,7 @@ void ExportThread::Export() // Flush remaining packets out of video and audio encoders while (continueVideo && continueAudio) { if (continueVideo) { - continueVideo = Encode(fmt_ctx, vcodec_ctx, nullptr, &video_pkt, video_stream, false); + continueVideo = Encode(fmt_ctx, vcodec_ctx, nullptr, &video_pkt, video_stream, true); } if (continueAudio) { continueAudio = Encode(fmt_ctx, acodec_ctx, nullptr, &audio_pkt, audio_stream, true); diff --git a/rendering/renderfunctions.cpp b/rendering/renderfunctions.cpp index 8c27b954f..48cfc1a84 100644 --- a/rendering/renderfunctions.cpp +++ b/rendering/renderfunctions.cpp @@ -407,10 +407,10 @@ GLuint olive::rendering::compose_sequence(ComposeSequenceParams ¶ms) { // run through all of the clip's effects for (int j=0;jeffects.size();j++) { + Effect* e = c->effects.at(j).get(); process_effect(c, e, timecode, coords, textureID, fbo_switcher, params.texture_failed, kTransitionNone); - } // if the clip has an opening transition, process that now