various: allow setting footage aspect ratios
We had support for detecting aspect ratios and respecting them in the render, but this allows people to not only see the aspect ratio in use, but also override it with their own.
This commit is contained in:
@@ -242,38 +242,53 @@ QIcon Footage::icon()
|
||||
|
||||
QString Footage::duration()
|
||||
{
|
||||
if (streams_.isEmpty()) {
|
||||
return QString();
|
||||
// Find longest stream duration
|
||||
|
||||
StreamPtr longest_stream = nullptr;
|
||||
rational longest;
|
||||
|
||||
foreach (StreamPtr stream, streams_) {
|
||||
if (stream->type() == Stream::kVideo || stream->type() == Stream::kAudio) {
|
||||
rational this_stream_dur = Timecode::timestamp_to_time(stream->duration(),
|
||||
stream->timebase());
|
||||
|
||||
if (this_stream_dur > longest) {
|
||||
longest_stream = stream;
|
||||
longest = this_stream_dur;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (streams_.first()->type() == Stream::kVideo) {
|
||||
VideoStreamPtr video_stream = std::static_pointer_cast<VideoStream>(streams_.first());
|
||||
if (longest_stream) {
|
||||
if (longest_stream->type() == Stream::kVideo) {
|
||||
VideoStreamPtr video_stream = std::static_pointer_cast<VideoStream>(longest_stream);
|
||||
|
||||
int64_t duration = video_stream->duration();
|
||||
rational frame_rate_timebase = video_stream->frame_rate().flipped();
|
||||
int64_t duration = video_stream->duration();
|
||||
rational frame_rate_timebase = video_stream->frame_rate().flipped();
|
||||
|
||||
if (video_stream->timebase() != frame_rate_timebase) {
|
||||
// Convert from timebase to frame rate
|
||||
rational duration_time = Timecode::timestamp_to_time(duration, video_stream->timebase());
|
||||
duration = Timecode::time_to_timestamp(duration_time, frame_rate_timebase);
|
||||
if (video_stream->timebase() != frame_rate_timebase) {
|
||||
// Convert from timebase to frame rate
|
||||
rational duration_time = Timecode::timestamp_to_time(duration, video_stream->timebase());
|
||||
duration = Timecode::time_to_timestamp(duration_time, frame_rate_timebase);
|
||||
}
|
||||
|
||||
return Timecode::timestamp_to_timecode(duration,
|
||||
frame_rate_timebase,
|
||||
Core::instance()->GetTimecodeDisplay());
|
||||
} else if (longest_stream->type() == Stream::kAudio) {
|
||||
AudioStreamPtr audio_stream = std::static_pointer_cast<AudioStream>(longest_stream);
|
||||
|
||||
// If we're showing in a timecode, we prefer showing audio in seconds instead
|
||||
Timecode::Display display = Core::instance()->GetTimecodeDisplay();
|
||||
if (display == Timecode::kTimecodeDropFrame
|
||||
|| display == Timecode::kTimecodeNonDropFrame) {
|
||||
display = Timecode::kTimecodeSeconds;
|
||||
}
|
||||
|
||||
return Timecode::timestamp_to_timecode(longest_stream->duration(),
|
||||
longest_stream->timebase(),
|
||||
display);
|
||||
}
|
||||
|
||||
return Timecode::timestamp_to_timecode(duration,
|
||||
frame_rate_timebase,
|
||||
Core::instance()->GetTimecodeDisplay());
|
||||
} else if (streams_.first()->type() == Stream::kAudio) {
|
||||
AudioStreamPtr audio_stream = std::static_pointer_cast<AudioStream>(streams_.first());
|
||||
|
||||
// If we're showing in a timecode, we prefer showing audio in seconds instead
|
||||
Timecode::Display display = Core::instance()->GetTimecodeDisplay();
|
||||
if (display == Timecode::kTimecodeDropFrame
|
||||
|| display == Timecode::kTimecodeNonDropFrame) {
|
||||
display = Timecode::kTimecodeSeconds;
|
||||
}
|
||||
|
||||
return Timecode::timestamp_to_timecode(streams_.first()->duration(),
|
||||
streams_.first()->timebase(),
|
||||
display);
|
||||
}
|
||||
|
||||
return QString();
|
||||
@@ -285,15 +300,13 @@ QString Footage::rate()
|
||||
return QString();
|
||||
}
|
||||
|
||||
if (streams_.first()->type() == Stream::kVideo) {
|
||||
// Return the timebase as a frame rate
|
||||
VideoStreamPtr video_stream = std::static_pointer_cast<VideoStream>(streams_.first());
|
||||
|
||||
if (HasStreamsOfType(Stream::kVideo)) {
|
||||
// This is a video editor, prioritize video streams
|
||||
VideoStreamPtr video_stream = std::static_pointer_cast<VideoStream>(get_first_stream_of_type(Stream::kVideo));
|
||||
return QCoreApplication::translate("Footage", "%1 FPS").arg(video_stream->frame_rate().toDouble());
|
||||
} else if (streams_.first()->type() == Stream::kAudio) {
|
||||
// Return the sample rate
|
||||
} else if (HasStreamsOfType(Stream::kAudio)) {
|
||||
// No video streams, return audio
|
||||
AudioStreamPtr audio_stream = std::static_pointer_cast<AudioStream>(streams_.first());
|
||||
|
||||
return QCoreApplication::translate("Footage", "%1 Hz").arg(audio_stream->sample_rate());
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,8 @@ OLIVE_NAMESPACE_ENTER
|
||||
|
||||
ImageStream::ImageStream() :
|
||||
premultiplied_alpha_(false),
|
||||
interlacing_(kInterlaceNone)
|
||||
interlacing_(kInterlaceNone),
|
||||
pixel_aspect_ratio_(1)
|
||||
{
|
||||
set_type(kImage);
|
||||
}
|
||||
|
||||
@@ -93,6 +93,23 @@ public:
|
||||
emit ParametersChanged();
|
||||
}
|
||||
|
||||
const rational& pixel_aspect_ratio() const
|
||||
{
|
||||
return pixel_aspect_ratio_;
|
||||
}
|
||||
|
||||
void set_pixel_aspect_ratio(const rational& r)
|
||||
{
|
||||
// Auto-correct null aspect ratio to 1:1
|
||||
if (r.isNull()) {
|
||||
pixel_aspect_ratio_ = 1;
|
||||
} else {
|
||||
pixel_aspect_ratio_ = r;
|
||||
}
|
||||
|
||||
emit ParametersChanged();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void FootageSetEvent(Footage*) override;
|
||||
|
||||
@@ -109,6 +126,8 @@ private:
|
||||
|
||||
PixelFormat::Format format_;
|
||||
|
||||
rational pixel_aspect_ratio_;
|
||||
|
||||
private slots:
|
||||
void ColorConfigChanged();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user