better support for various bit rates
This commit is contained in:
+12
-3
@@ -79,7 +79,9 @@ Config::Config()
|
||||
default_sequence_height(1080),
|
||||
default_sequence_framerate(29.97),
|
||||
default_sequence_audio_frequency(48000),
|
||||
default_sequence_audio_channel_layout(3)
|
||||
default_sequence_audio_channel_layout(3),
|
||||
playback_bit_depth(olive::rendering::PIX_FMT_RGBA16F),
|
||||
export_bit_depth(olive::rendering::PIX_FMT_RGBA32F)
|
||||
{}
|
||||
|
||||
void Config::load(QString path) {
|
||||
@@ -246,6 +248,12 @@ void Config::load(QString path) {
|
||||
} else if (stream.name() == "DefaultSequenceAudioLayout") {
|
||||
stream.readNext();
|
||||
default_sequence_audio_channel_layout = stream.text().toInt();
|
||||
} else if (stream.name() == "PlaybackBitDepth") {
|
||||
stream.readNext();
|
||||
playback_bit_depth = stream.text().toInt();
|
||||
} else if (stream.name() == "ExportBitDepth") {
|
||||
stream.readNext();
|
||||
export_bit_depth = stream.text().toInt();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -322,6 +330,8 @@ void Config::save(QString path) {
|
||||
stream.writeTextElement("DefaultSequenceFrameRate", QString::number(default_sequence_framerate));
|
||||
stream.writeTextElement("DefaultSequenceAudioFrequency", QString::number(default_sequence_audio_frequency));
|
||||
stream.writeTextElement("DefaultSequenceAudioLayout", QString::number(default_sequence_audio_channel_layout));
|
||||
stream.writeTextElement("PlaybackBitDepth", QString::number(playback_bit_depth));
|
||||
stream.writeTextElement("ExportBitDepth", QString::number(export_bit_depth));
|
||||
|
||||
stream.writeEndElement(); // configuration
|
||||
stream.writeEndDocument(); // doc
|
||||
@@ -329,6 +339,5 @@ void Config::save(QString path) {
|
||||
}
|
||||
|
||||
RuntimeConfig::RuntimeConfig() :
|
||||
shaders_are_enabled(true),
|
||||
ocio_config_date(QDateTime::currentMSecsSinceEpoch())
|
||||
shaders_are_enabled(true)
|
||||
{}
|
||||
|
||||
+10
-7
@@ -593,6 +593,16 @@ struct Config {
|
||||
*/
|
||||
int default_sequence_audio_channel_layout;
|
||||
|
||||
/**
|
||||
* @brief Playback bit depth (an index of olive::rendering::bit_depths)
|
||||
*/
|
||||
int playback_bit_depth;
|
||||
|
||||
/**
|
||||
* @brief Export bit depth (an index of olive::rendering::bit_depths)
|
||||
*/
|
||||
int export_bit_depth;
|
||||
|
||||
/**
|
||||
* @brief Load config from file
|
||||
*
|
||||
@@ -644,13 +654,6 @@ struct RuntimeConfig {
|
||||
*/
|
||||
QString external_translation_file;
|
||||
|
||||
/**
|
||||
* @brief OpenColorIO Configuration Time
|
||||
*
|
||||
* A crude but quick way of determining whether the OCIO config has changed and if the rendering threads need to
|
||||
* re-create their OCIO shaders. Not intended to be saved - could be moved
|
||||
*/
|
||||
qint64 ocio_config_date;
|
||||
};
|
||||
|
||||
namespace olive {
|
||||
|
||||
+9
-3
@@ -52,7 +52,8 @@ QString olive::ActiveProjectFilename;
|
||||
QString olive::AppName;
|
||||
|
||||
OliveGlobal::OliveGlobal() :
|
||||
changed_since_last_autorecovery(false)
|
||||
changed_since_last_autorecovery(false),
|
||||
rendering_(false)
|
||||
{
|
||||
// sets current app name
|
||||
QString version_id;
|
||||
@@ -108,8 +109,13 @@ void OliveGlobal::check_for_autorecovery_file() {
|
||||
}
|
||||
}
|
||||
|
||||
void OliveGlobal::set_rendering_state(bool rendering) {
|
||||
audio_rendering = rendering;
|
||||
bool OliveGlobal::is_exporting()
|
||||
{
|
||||
return rendering_;
|
||||
}
|
||||
|
||||
void OliveGlobal::set_export_state(bool rendering) {
|
||||
rendering_ = rendering;
|
||||
if (rendering) {
|
||||
autorecovery_timer.stop();
|
||||
} else {
|
||||
|
||||
+16
-1
@@ -74,6 +74,16 @@ public:
|
||||
*/
|
||||
void check_for_autorecovery_file();
|
||||
|
||||
/**
|
||||
* @brief Get whether the project is currently being rendered or not. Useful for determining whether to treat the
|
||||
* render as online or offline.
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* TRUE if the project is being exported, FALSE if not.
|
||||
*/
|
||||
bool is_exporting();
|
||||
|
||||
/**
|
||||
* @brief Set the application state depending on if the user is exporting a video
|
||||
*
|
||||
@@ -90,7 +100,7 @@ public:
|
||||
*
|
||||
* **TRUE** if Olive is about to export a video. **FALSE** if Olive has finished exporting.
|
||||
*/
|
||||
void set_rendering_state(bool rendering);
|
||||
void set_export_state(bool rendering);
|
||||
|
||||
/**
|
||||
* @brief Set the application's "modified" state
|
||||
@@ -423,6 +433,11 @@ private:
|
||||
*/
|
||||
bool changed_since_last_autorecovery;
|
||||
|
||||
/**
|
||||
* @brief Internal variable for rendering state (set by set_rendering_state() and accessed by is_rendering() ).
|
||||
*/
|
||||
bool rendering_;
|
||||
|
||||
private slots:
|
||||
|
||||
};
|
||||
|
||||
@@ -0,0 +1,169 @@
|
||||
#include "timing.h"
|
||||
|
||||
#include "timeline/sequence.h"
|
||||
#include "timeline/clip.h"
|
||||
#include "global/config.h"
|
||||
|
||||
double get_timecode(Clip* c, long playhead) {
|
||||
return double(playhead_to_clip_frame(c, playhead))/c->sequence->frame_rate;
|
||||
}
|
||||
|
||||
long rescale_frame_number(long framenumber, double source_frame_rate, double target_frame_rate) {
|
||||
return qRound((double(framenumber)/source_frame_rate)*target_frame_rate);
|
||||
}
|
||||
|
||||
long playhead_to_clip_frame(Clip* c, long playhead) {
|
||||
return (qMax(0L, playhead - c->timeline_in(true)) + c->clip_in(true));
|
||||
}
|
||||
|
||||
double playhead_to_clip_seconds(Clip* c, long playhead) {
|
||||
// returns time in seconds
|
||||
long clip_frame = playhead_to_clip_frame(c, playhead);
|
||||
|
||||
if (c->reversed()) {
|
||||
clip_frame = c->media_length() - clip_frame - 1;
|
||||
}
|
||||
|
||||
double secs = (double(clip_frame)/c->sequence->frame_rate)*c->speed().value;
|
||||
if (c->media() != nullptr && c->media()->get_type() == MEDIA_TYPE_FOOTAGE) {
|
||||
secs *= c->media()->to_footage()->speed;
|
||||
}
|
||||
|
||||
return secs;
|
||||
}
|
||||
|
||||
int64_t seconds_to_timestamp(Clip *c, double seconds) {
|
||||
return qRound64(seconds * av_q2d(av_inv_q(c->time_base())));
|
||||
}
|
||||
|
||||
int64_t playhead_to_timestamp(Clip* c, long playhead) {
|
||||
return seconds_to_timestamp(c, playhead_to_clip_seconds(c, playhead));
|
||||
}
|
||||
|
||||
bool frame_rate_is_droppable(double rate) {
|
||||
return (qFuzzyCompare(rate, 23.976)
|
||||
|| qFuzzyCompare(rate, 29.97)
|
||||
|| qFuzzyCompare(rate, 59.94));
|
||||
}
|
||||
|
||||
long timecode_to_frame(const QString& s, int view, double frame_rate) {
|
||||
QList<QString> list = s.split(QRegExp("[:;]"));
|
||||
|
||||
if (view == olive::kTimecodeFrames || (list.size() == 1 && view != olive::kTimecodeMilliseconds)) {
|
||||
return s.toLong();
|
||||
}
|
||||
|
||||
int frRound = qRound(frame_rate);
|
||||
int hours, minutes, seconds, frames;
|
||||
|
||||
if (view == olive::kTimecodeMilliseconds) {
|
||||
long milliseconds = s.toLong();
|
||||
|
||||
hours = milliseconds/3600000;
|
||||
milliseconds -= (hours*3600000);
|
||||
minutes = milliseconds/60000;
|
||||
milliseconds -= (minutes*60000);
|
||||
seconds = milliseconds/1000;
|
||||
milliseconds -= (seconds*1000);
|
||||
frames = qRound64((milliseconds*0.001)*frame_rate);
|
||||
|
||||
seconds = qRound64(seconds * frame_rate);
|
||||
minutes = qRound64(minutes * frame_rate * 60);
|
||||
hours = qRound64(hours * frame_rate * 3600);
|
||||
} else {
|
||||
hours = ((list.size() > 0) ? list.at(0).toInt() : 0) * frRound * 3600;
|
||||
minutes = ((list.size() > 1) ? list.at(1).toInt() : 0) * frRound * 60;
|
||||
seconds = ((list.size() > 2) ? list.at(2).toInt() : 0) * frRound;
|
||||
frames = (list.size() > 3) ? list.at(3).toInt() : 0;
|
||||
}
|
||||
|
||||
int f = (frames + seconds + minutes + hours);
|
||||
|
||||
if ((view == olive::kTimecodeDrop || view == olive::kTimecodeMilliseconds) && frame_rate_is_droppable(frame_rate)) {
|
||||
// return drop
|
||||
int d;
|
||||
int m;
|
||||
|
||||
int dropFrames = qRound(frame_rate * .066666); //Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate
|
||||
int framesPer10Minutes = qRound(frame_rate * 60 * 10); //Number of frames per ten minutes
|
||||
int framesPerMinute = (qRound(frame_rate)*60)- dropFrames; //Number of frames per minute is the round of the framerate * 60 minus the number of dropped frames
|
||||
|
||||
d = f / framesPer10Minutes;
|
||||
f -= dropFrames*9*d;
|
||||
|
||||
m = f % framesPer10Minutes;
|
||||
|
||||
if (m > dropFrames) {
|
||||
f -= (dropFrames * ((m - dropFrames) / framesPerMinute));
|
||||
}
|
||||
}
|
||||
|
||||
// return non-drop
|
||||
return f;
|
||||
}
|
||||
|
||||
QString frame_to_timecode(long f, int view, double frame_rate) {
|
||||
if (view == olive::kTimecodeFrames) {
|
||||
return QString::number(f);
|
||||
}
|
||||
|
||||
// return timecode
|
||||
int hours = 0;
|
||||
int mins = 0;
|
||||
int secs = 0;
|
||||
int frames = 0;
|
||||
QString token = ":";
|
||||
|
||||
if ((view == olive::kTimecodeDrop || view == olive::kTimecodeMilliseconds) && frame_rate_is_droppable(frame_rate)) {
|
||||
//CONVERT A FRAME NUMBER TO DROP FRAME TIMECODE
|
||||
//Code by David Heidelberger, adapted from Andrew Duncan, further adapted for Olive by Olive Team
|
||||
//Given an int called framenumber and a double called framerate
|
||||
//Framerate should be 29.97, 59.94, or 23.976, otherwise the calculations will be off.
|
||||
|
||||
int d;
|
||||
int m;
|
||||
|
||||
int dropFrames = qRound(frame_rate * .066666); //Number of frames to drop on the minute marks is the nearest integer to 6% of the framerate
|
||||
int framesPerHour = qRound(frame_rate*60*60); //Number of frqRound64ames in an hour
|
||||
int framesPer24Hours = framesPerHour*24; //Number of frames in a day - timecode rolls over after 24 hours
|
||||
int framesPer10Minutes = qRound(frame_rate * 60 * 10); //Number of frames per ten minutes
|
||||
int framesPerMinute = (qRound(frame_rate)*60)- dropFrames; //Number of frames per minute is the round of the framerate * 60 minus the number of dropped frames
|
||||
|
||||
//If framenumber is greater than 24 hrs, next operation will rollover clock
|
||||
f = f % framesPer24Hours; // % is the modulus operator, which returns a remainder. a % b = the remainder of a/b
|
||||
|
||||
d = f / framesPer10Minutes; // \ means integer division, which is a/b without a remainder. Some languages you could use floor(a/b)
|
||||
m = f % framesPer10Minutes;
|
||||
|
||||
//In the original post, the next line read m>1, which only worked for 29.97. Jean-Baptiste Mardelle correctly pointed out that m should be compared to dropFrames.
|
||||
if (m > dropFrames) {
|
||||
f = f + (dropFrames*9*d) + dropFrames * ((m - dropFrames) / framesPerMinute);
|
||||
} else {
|
||||
f = f + dropFrames*9*d;
|
||||
}
|
||||
|
||||
int frRound = qRound(frame_rate);
|
||||
frames = f % frRound;
|
||||
secs = (f / frRound) % 60;
|
||||
mins = ((f / frRound) / 60) % 60;
|
||||
hours = (((f / frRound) / 60) / 60);
|
||||
|
||||
token = ";";
|
||||
} else {
|
||||
// non-drop timecode
|
||||
|
||||
int int_fps = qRound(frame_rate);
|
||||
hours = f / (3600 * int_fps);
|
||||
mins = f / (60*int_fps) % 60;
|
||||
secs = f/int_fps % 60;
|
||||
frames = f%int_fps;
|
||||
}
|
||||
if (view == olive::kTimecodeMilliseconds) {
|
||||
return QString::number((hours*3600000)+(mins*60000)+(secs*1000)+qCeil(frames*1000/frame_rate));
|
||||
}
|
||||
return QString(QString::number(hours).rightJustified(2, '0') +
|
||||
":" + QString::number(mins).rightJustified(2, '0') +
|
||||
":" + QString::number(secs).rightJustified(2, '0') +
|
||||
token + QString::number(frames).rightJustified(2, '0')
|
||||
);
|
||||
}
|
||||
+137
@@ -0,0 +1,137 @@
|
||||
#ifndef TIMING_H
|
||||
#define TIMING_H
|
||||
|
||||
#include <QString>
|
||||
#include <QtMath>
|
||||
|
||||
class Clip;
|
||||
|
||||
/**
|
||||
* @brief Get timecode
|
||||
*
|
||||
* Get the current clip/media time from the Timeline playhead in seconds. For instance if the playhead was at the start
|
||||
* of a clip (whose in point wasn't trimmed), this would be 0.0 as it's the start of the clip/media;
|
||||
*
|
||||
* @param c
|
||||
*
|
||||
* Clip to get the timecode of
|
||||
*
|
||||
* @param playhead
|
||||
*
|
||||
* Sequence playhead to convert to a clip/media timecode
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* Timecode in seconds
|
||||
*/
|
||||
double get_timecode(Clip *c, long playhead);
|
||||
|
||||
/**
|
||||
* @brief Rescale a frame number between two frame rates
|
||||
*
|
||||
* Converts a frame number from one frame rate to its equivalent in another frame rate
|
||||
*
|
||||
* @param framenumber
|
||||
*
|
||||
* The frame number to convert
|
||||
*
|
||||
* @param source_frame_rate
|
||||
*
|
||||
* Frame rate that the frame number is currently in
|
||||
*
|
||||
* @param target_frame_rate
|
||||
*
|
||||
* Frame rate to convert to
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* Rescaled frame number
|
||||
*/
|
||||
long rescale_frame_number(long framenumber, double source_frame_rate, double target_frame_rate);
|
||||
|
||||
/**
|
||||
* @brief Convert playhead frame number to a clip frame number
|
||||
*
|
||||
* Converts a Timeline playhead to a the current clip's frame. Equivalent to
|
||||
* `PLAYHEAD - CLIP_TIMELINE_IN + CLIP_MEDIA_IN`. All keyframes are in clip frames.
|
||||
*
|
||||
* @param c
|
||||
*
|
||||
* The clip to get the current frame number of
|
||||
*
|
||||
* @param playhead
|
||||
*
|
||||
* The current Timeline frame number
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* The curren frame number of the clip at `playhead`
|
||||
*/
|
||||
long playhead_to_clip_frame(Clip* c, long playhead);
|
||||
|
||||
/**
|
||||
* @brief Converts the playhead to clip seconds
|
||||
*
|
||||
* Get the current timecode at the playhead in terms of clip seconds.
|
||||
*
|
||||
* FIXME: Possible duplicate of get_timecode()? Will need to research this more.
|
||||
*
|
||||
* @param c
|
||||
*
|
||||
* Clip to return clip seconds of.
|
||||
*
|
||||
* @param playhead
|
||||
*
|
||||
* Current Timeline playhead to convert to clip seconds
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* Clip time in seconds
|
||||
*/
|
||||
double playhead_to_clip_seconds(Clip *c, long playhead);
|
||||
|
||||
/**
|
||||
* @brief Convert seconds to FFmpeg timestamp
|
||||
*
|
||||
* Used for interaction with FFmpeg, converts seconds in a floating-point value to a timestamp in AVStream->time_base
|
||||
* units.
|
||||
*
|
||||
* @param c
|
||||
*
|
||||
* Clip to get timestamp of
|
||||
*
|
||||
* @param seconds
|
||||
*
|
||||
* Clip time in seconds
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* An FFmpeg-compatible timestamp in AVStream->time_base units.
|
||||
*/
|
||||
int64_t seconds_to_timestamp(Clip* c, double seconds);
|
||||
|
||||
/**
|
||||
* @brief Convert Timeline playhead to FFmpeg timestamp
|
||||
*
|
||||
* Used for interaction with FFmpeg, converts the Timeline playhead to a timestamp in AVStream->time_base
|
||||
* units.
|
||||
*
|
||||
* @param c
|
||||
*
|
||||
* Clip to get timestamp of
|
||||
*
|
||||
* @param playhead
|
||||
*
|
||||
* Timeline playhead to convert to a timestamp
|
||||
*
|
||||
* @return
|
||||
*
|
||||
* An FFmpeg-compatible timestamp in AVStream->time_base units.
|
||||
*/
|
||||
int64_t playhead_to_timestamp(Clip *c, long playhead);
|
||||
|
||||
bool frame_rate_is_droppable(double rate);
|
||||
long timecode_to_frame(const QString& s, int view, double frame_rate);
|
||||
QString frame_to_timecode(long f, int view, double frame_rate);
|
||||
|
||||
#endif // TIMING_H
|
||||
Reference in New Issue
Block a user