Skip to content

Commit 89714b6

Browse files
committed
Small refactor to ensure that audio files have no image data - and allow videos below them to show through...
1 parent b21a686 commit 89714b6

File tree

5 files changed

+23
-15
lines changed

5 files changed

+23
-15
lines changed

src/Clip.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ std::shared_ptr<Frame> Clip::GetFrame(std::shared_ptr<openshot::Frame> backgroun
438438
apply_timemapping(frame);
439439

440440
// Apply waveform image (if any)
441-
apply_waveform(frame, background_frame->GetImage());
441+
apply_waveform(frame, background_frame);
442442

443443
// Apply local effects to the frame (if any)
444444
apply_effects(frame);
@@ -453,7 +453,7 @@ std::shared_ptr<Frame> Clip::GetFrame(std::shared_ptr<openshot::Frame> backgroun
453453
}
454454

455455
// Apply keyframe / transforms
456-
apply_keyframes(frame, background_frame->GetImage());
456+
apply_keyframes(frame, background_frame);
457457

458458
// Add final frame to cache
459459
final_cache.Add(frame);
@@ -1224,7 +1224,7 @@ bool Clip::isEqual(double a, double b)
12241224
}
12251225

12261226
// Apply keyframes to the source frame (if any)
1227-
void Clip::apply_keyframes(std::shared_ptr<Frame> frame, std::shared_ptr<QImage> background_canvas) {
1227+
void Clip::apply_keyframes(std::shared_ptr<Frame> frame, std::shared_ptr<Frame> background_frame) {
12281228
// Skip out if video was disabled or only an audio frame (no visualisation in use)
12291229
if (!frame->has_image_data) {
12301230
// Skip the rest of the image processing for performance reasons
@@ -1233,6 +1233,7 @@ void Clip::apply_keyframes(std::shared_ptr<Frame> frame, std::shared_ptr<QImage>
12331233

12341234
// Get image from clip
12351235
std::shared_ptr<QImage> source_image = frame->GetImage();
1236+
std::shared_ptr<QImage> background_canvas = background_frame->GetImage();
12361237

12371238
// Get transform from clip's keyframes
12381239
QTransform transform = get_transform(frame, background_canvas->width(), background_canvas->height());
@@ -1291,7 +1292,7 @@ void Clip::apply_keyframes(std::shared_ptr<Frame> frame, std::shared_ptr<QImage>
12911292
}
12921293

12931294
// Apply apply_waveform image to the source frame (if any)
1294-
void Clip::apply_waveform(std::shared_ptr<Frame> frame, std::shared_ptr<QImage> background_canvas) {
1295+
void Clip::apply_waveform(std::shared_ptr<Frame> frame, std::shared_ptr<Frame> background_frame) {
12951296

12961297
if (!Waveform()) {
12971298
// Exit if no waveform is needed
@@ -1300,6 +1301,7 @@ void Clip::apply_waveform(std::shared_ptr<Frame> frame, std::shared_ptr<QImage>
13001301

13011302
// Get image from clip
13021303
std::shared_ptr<QImage> source_image = frame->GetImage();
1304+
std::shared_ptr<QImage> background_canvas = background_frame->GetImage();
13031305

13041306
// Debug output
13051307
ZmqLogger::Instance()->AppendDebugMethod(

src/Clip.h

+4-6
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,6 @@
3737
#include "KeyFrame.h"
3838
#include "TrackedObjectBase.h"
3939

40-
#include <QImage>
41-
4240
namespace openshot {
4341
class AudioResampler;
4442
class EffectInfo;
@@ -132,11 +130,11 @@ namespace openshot {
132130
/// Apply effects to the source frame (if any)
133131
void apply_effects(std::shared_ptr<openshot::Frame> frame);
134132

135-
/// Apply keyframes to an openshot::Frame and use an existing QImage as a background image (if any)
136-
void apply_keyframes(std::shared_ptr<Frame> frame, std::shared_ptr<QImage> background_canvas);
133+
/// Apply keyframes to an openshot::Frame and use an existing background frame (if any)
134+
void apply_keyframes(std::shared_ptr<Frame> frame, std::shared_ptr<Frame> background_frame);
137135

138-
/// Apply waveform image to an openshot::Frame and use an existing QImage as a background image (if any)
139-
void apply_waveform(std::shared_ptr<Frame> frame, std::shared_ptr<QImage> background_canvas);
136+
/// Apply waveform image to an openshot::Frame and use an existing background frame (if any)
137+
void apply_waveform(std::shared_ptr<Frame> frame, std::shared_ptr<Frame> background_frame);
140138

141139
/// Adjust frame number for Clip position and start (which can result in a different number)
142140
int64_t adjust_timeline_framenumber(int64_t clip_frame_number);

src/FrameMapper.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,13 @@ std::shared_ptr<Frame> FrameMapper::GetFrame(int64_t requested_frame)
513513
// Copy the image from the odd field
514514
std::shared_ptr<Frame> odd_frame = mapped_frame;
515515

516-
if (odd_frame)
516+
if (odd_frame && odd_frame->has_image_data)
517517
frame->AddImage(std::make_shared<QImage>(*odd_frame->GetImage()), true);
518518
if (mapped.Odd.Frame != mapped.Even.Frame) {
519519
// Add even lines (if different than the previous image)
520520
std::shared_ptr<Frame> even_frame;
521521
even_frame = GetOrCreateFrame(mapped.Even.Frame);
522-
if (even_frame)
522+
if (even_frame && even_frame->has_image_data)
523523
frame->AddImage(std::make_shared<QImage>(*even_frame->GetImage()), false);
524524
}
525525

src/Timeline.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -706,8 +706,8 @@ void Timeline::add_layer(std::shared_ptr<Frame> new_frame, Clip* source_clip, in
706706
ZmqLogger::Instance()->AppendDebugMethod(
707707
"Timeline::add_layer (Transform: Composite Image Layer: Completed)",
708708
"source_frame->number", source_frame->number,
709-
"new_frame->GetImage()->width()", new_frame->GetImage()->width(),
710-
"new_frame->GetImage()->height()", new_frame->GetImage()->height());
709+
"new_frame->GetImage()->width()", new_frame->GetWidth(),
710+
"new_frame->GetImage()->height()", new_frame->GetHeight());
711711
}
712712

713713
// Update the list of 'opened' clips

src/effects/Caption.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ std::shared_ptr<openshot::Frame> Caption::GetFrame(std::shared_ptr<openshot::Fra
114114
Clip* clip = (Clip*) ParentClip();
115115
Timeline* timeline = NULL;
116116
Fraction fps;
117+
QSize image_size(1, 1);
117118

118119
if (clip && clip->ParentTimeline() != NULL) {
119120
timeline = (Timeline*) clip->ParentTimeline();
@@ -124,16 +125,23 @@ std::shared_ptr<openshot::Frame> Caption::GetFrame(std::shared_ptr<openshot::Fra
124125
// Get the FPS from the parent object (Timeline or Clip's Reader)
125126
if (timeline != NULL) {
126127
fps = timeline->info.fps;
128+
image_size = QSize(timeline->info.width, timeline->info.height);
127129
} else if (clip != NULL && clip->Reader() != NULL) {
128130
fps = clip->Reader()->info.fps;
131+
image_size = QSize(clip->Reader()->info.width, clip->Reader()->info.height);
132+
}
133+
134+
if (!frame->has_image_data) {
135+
// Give audio-only files a full frame image of solid color
136+
frame->AddColor(image_size.width(), image_size.height(), "#000000");
129137
}
130138

131139
// Get the frame's image
132140
std::shared_ptr<QImage> frame_image = frame->GetImage();
133141

134142
// Calculate scale factor, to keep different resolutions from
135143
// having dramatically different font sizes
136-
double timeline_scale_factor = frame->GetImage()->width() / 600.0;
144+
double timeline_scale_factor = frame_image->width() / 600.0;
137145

138146
// Load timeline's new frame image into a QPainter
139147
QPainter painter(frame_image.get());

0 commit comments

Comments
 (0)