From 58736bd243b0653e867852fab1ffaf1dadf159f3 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Fri, 22 Jun 2018 18:07:03 -0700 Subject: [PATCH] added #88 --- io/previewgenerator.cpp | 19 +++++++++++-------- olive.pro.user | 2 +- ui/timelineheader.cpp | 2 ++ ui/timelinewidget.cpp | 13 +++++++++++-- 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/io/previewgenerator.cpp b/io/previewgenerator.cpp index 333e952d4..ea7772e3c 100644 --- a/io/previewgenerator.cpp +++ b/io/previewgenerator.cpp @@ -37,13 +37,16 @@ void PreviewGenerator::run() { AVFrame* temp_frame = av_frame_alloc(); AVCodecContext** codec_ctx = new AVCodecContext* [fmt_ctx->nb_streams]; for (unsigned int i=0;inb_streams;i++) { - AVCodec* codec = avcodec_find_decoder(fmt_ctx->streams[i]->codecpar->codec_id); - codec_ctx[i] = avcodec_alloc_context3(codec); - avcodec_parameters_to_context(codec_ctx[i], fmt_ctx->streams[i]->codecpar); - avcodec_open2(codec_ctx[i], codec, NULL); + codec_ctx[i] = NULL; + if (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO || fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO) { + AVCodec* codec = avcodec_find_decoder(fmt_ctx->streams[i]->codecpar->codec_id); + codec_ctx[i] = avcodec_alloc_context3(codec); + avcodec_parameters_to_context(codec_ctx[i], fmt_ctx->streams[i]->codecpar); + avcodec_open2(codec_ctx[i], codec, NULL); - if (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && codec_ctx[i]->channel_layout == 0) { - codec_ctx[i]->channel_layout = guess_layout_from_channels(fmt_ctx->streams[i]->codecpar->channels); + if (fmt_ctx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_AUDIO && codec_ctx[i]->channel_layout == 0) { + codec_ctx[i]->channel_layout = guess_layout_from_channels(fmt_ctx->streams[i]->codecpar->channels); + } } } AVPacket packet; @@ -56,14 +59,14 @@ void PreviewGenerator::run() { avcodec_send_packet(codec_ctx[packet.stream_index], &packet); while (!end_of_file) { - while (avcodec_receive_frame(codec_ctx[packet.stream_index], temp_frame) == AVERROR(EAGAIN)) { + while (codec_ctx[packet.stream_index] == NULL || avcodec_receive_frame(codec_ctx[packet.stream_index], temp_frame) == AVERROR(EAGAIN)) { av_packet_unref(&packet); int read_ret = av_read_frame(fmt_ctx, &packet); if (read_ret < 0) { end_of_file = true; if (read_ret != AVERROR_EOF) qDebug() << "[ERROR] Failed to read packet for preview generation"; break; - } else { + } else if (codec_ctx[packet.stream_index] != NULL) { avcodec_send_packet(codec_ctx[packet.stream_index], &packet); } } diff --git a/olive.pro.user b/olive.pro.user index 372d7ad90..593fd1514 100644 --- a/olive.pro.user +++ b/olive.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/ui/timelineheader.cpp b/ui/timelineheader.cpp index 7385cf2e3..4a8ab5cb3 100644 --- a/ui/timelineheader.cpp +++ b/ui/timelineheader.cpp @@ -33,6 +33,8 @@ void TimelineHeader::mouseMoveEvent(QMouseEvent* event) { void TimelineHeader::mouseReleaseEvent(QMouseEvent *) { dragging = false; + panel_timeline->snapped = false; + panel_timeline->repaint_timeline(); } void TimelineHeader::paintEvent(QPaintEvent*) { diff --git a/ui/timelinewidget.cpp b/ui/timelinewidget.cpp index 35f563711..5ae406411 100644 --- a/ui/timelinewidget.cpp +++ b/ui/timelinewidget.cpp @@ -53,7 +53,6 @@ int TimelineWidget::calculate_track_height(int track) { while (track_heights.size() < index+1) { track_heights.append(TRACK_DEFAULT_HEIGHT); } - qDebug() << track_heights.at(index); return track_heights.at(index); } @@ -175,7 +174,15 @@ void TimelineWidget::dropEvent(QDropEvent* event) { } void TimelineWidget::mouseDoubleClickEvent(QMouseEvent *event) { - + if (panel_timeline->tool == TIMELINE_TOOL_EDIT) { + int clip_index = getClipIndexFromCoords(panel_timeline->cursor_frame, panel_timeline->cursor_track); + if (clip_index >= 0) { + Clip* clip = sequence->get_clip(clip_index); + if (!(event->modifiers() & Qt::ShiftModifier)) panel_timeline->selections.clear(); + panel_timeline->selections.append({clip->timeline_in, clip->timeline_out, clip->track}); + panel_timeline->repaint_timeline(); + } + } } void TimelineWidget::mousePressEvent(QMouseEvent *event) { @@ -343,6 +350,8 @@ void TimelineWidget::mouseReleaseEvent(QMouseEvent *event) { pre_clips.clear(); post_clips.clear(); +// panel_timeline->repaint_timeline(); + // find out how many clips are selected bool single_select = false; int selected_clip = 0;