You've already forked libopenshot
mirror of
https://github.com/OpenShot/libopenshot.git
synced 2026-03-02 08:53:52 -08:00
Merge pull request #166 from OpenShot/master
Merging master back into develop
This commit is contained in:
@@ -36,8 +36,8 @@
|
||||
|
||||
#define OPENSHOT_VERSION_MAJOR 0; /// Major version number is incremented when huge features are added or improved.
|
||||
#define OPENSHOT_VERSION_MINOR 2; /// Minor version is incremented when smaller (but still very important) improvements are added.
|
||||
#define OPENSHOT_VERSION_BUILD 0; /// Build number is incremented when minor bug fixes and less important improvements are added.
|
||||
#define OPENSHOT_VERSION_SO 15; /// Shared object version number. This increments any time the API and ABI changes (so old apps will no longer link)
|
||||
#define OPENSHOT_VERSION_BUILD 1; /// Build number is incremented when minor bug fixes and less important improvements are added.
|
||||
#define OPENSHOT_VERSION_SO 16; /// Shared object version number. This increments any time the API and ABI changes (so old apps will no longer link)
|
||||
#define OPENSHOT_VERSION_MAJOR_MINOR STRINGIZE(OPENSHOT_VERSION_MAJOR) "." STRINGIZE(OPENSHOT_VERSION_MINOR); /// A string of the "Major.Minor" version
|
||||
#define OPENSHOT_VERSION_ALL STRINGIZE(OPENSHOT_VERSION_MAJOR) "." STRINGIZE(OPENSHOT_VERSION_MINOR) "." STRINGIZE(OPENSHOT_VERSION_BUILD); /// A string of the entire version "Major.Minor.Build"
|
||||
|
||||
|
||||
@@ -333,6 +333,11 @@ void FFmpegReader::UpdateAudioInfo()
|
||||
info.height = 480;
|
||||
}
|
||||
|
||||
// Fix invalid video lengths for certain types of files (MP3 for example)
|
||||
if (info.has_video && ((info.duration * info.fps.ToDouble()) - info.video_length > 60)) {
|
||||
info.video_length = info.duration * info.fps.ToDouble();
|
||||
}
|
||||
|
||||
// Add audio metadata (if any found)
|
||||
AVDictionaryEntry *tag = NULL;
|
||||
while ((tag = av_dict_get(aStream->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) {
|
||||
@@ -422,7 +427,7 @@ void FFmpegReader::UpdateVideoInfo()
|
||||
}
|
||||
|
||||
// Override an invalid framerate
|
||||
if (info.fps.ToFloat() > 240.0f || (info.fps.num == 0 || info.fps.den == 0)) {
|
||||
if (info.fps.ToFloat() > 240.0f || (info.fps.num <= 0 || info.fps.den <= 0) || info.video_length <= 0) {
|
||||
// Calculate FPS, duration, video bit rate, and video length manually
|
||||
// by scanning through all the video stream packets
|
||||
CheckFPS();
|
||||
@@ -1864,7 +1869,6 @@ void FFmpegReader::CheckWorkingFrames(bool end_of_stream, int64_t requested_fram
|
||||
void FFmpegReader::CheckFPS()
|
||||
{
|
||||
check_fps = true;
|
||||
AV_ALLOCATE_IMAGE(pFrame, AV_GET_CODEC_PIXEL_FORMAT(pStream, pCodecCtx), info.width, info.height);
|
||||
|
||||
int first_second_counter = 0;
|
||||
int second_second_counter = 0;
|
||||
@@ -1872,6 +1876,7 @@ void FFmpegReader::CheckFPS()
|
||||
int forth_second_counter = 0;
|
||||
int fifth_second_counter = 0;
|
||||
int frames_detected = 0;
|
||||
int64_t pts = 0;
|
||||
|
||||
// Loop through the stream
|
||||
while (true)
|
||||
@@ -1891,7 +1896,7 @@ void FFmpegReader::CheckFPS()
|
||||
UpdatePTSOffset(true);
|
||||
|
||||
// Get PTS of this packet
|
||||
int64_t pts = GetVideoPTS();
|
||||
pts = GetVideoPTS();
|
||||
|
||||
// Remove pFrame
|
||||
RemoveAVFrame(pFrame);
|
||||
@@ -1922,7 +1927,7 @@ void FFmpegReader::CheckFPS()
|
||||
|
||||
// Double check that all counters have greater than zero (or give up)
|
||||
if (second_second_counter != 0 && third_second_counter != 0 && forth_second_counter != 0 && fifth_second_counter != 0) {
|
||||
// Calculate average FPS
|
||||
// Calculate average FPS (average of first few seconds)
|
||||
int sum_fps = second_second_counter + third_second_counter + forth_second_counter + fifth_second_counter;
|
||||
int avg_fps = round(sum_fps / 4.0f);
|
||||
|
||||
@@ -1931,22 +1936,32 @@ void FFmpegReader::CheckFPS()
|
||||
|
||||
// Update Duration and Length
|
||||
info.video_length = frames_detected;
|
||||
info.duration = frames_detected / round(sum_fps / 4.0f);
|
||||
info.duration = frames_detected / (sum_fps / 4.0f);
|
||||
|
||||
// Update video bit rate
|
||||
info.video_bit_rate = info.file_size / info.duration;
|
||||
} else if (second_second_counter != 0 && third_second_counter != 0) {
|
||||
// Calculate average FPS (only on second 2)
|
||||
int sum_fps = second_second_counter;
|
||||
|
||||
// Update FPS
|
||||
info.fps = Fraction(sum_fps, 1);
|
||||
|
||||
// Update Duration and Length
|
||||
info.video_length = frames_detected;
|
||||
info.duration = frames_detected / float(sum_fps);
|
||||
|
||||
// Update video bit rate
|
||||
info.video_bit_rate = info.file_size / info.duration;
|
||||
} else {
|
||||
|
||||
// Too short to determine framerate, just default FPS
|
||||
// Set a few important default video settings (so audio can be divided into frames)
|
||||
info.fps.num = 30;
|
||||
info.fps.den = 1;
|
||||
info.video_timebase.num = info.fps.den;
|
||||
info.video_timebase.den = info.fps.num;
|
||||
|
||||
// Calculate number of frames
|
||||
info.video_length = frames_detected;
|
||||
info.duration = frames_detected / info.video_timebase.ToFloat();
|
||||
info.duration = frames_detected / info.fps.ToFloat();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -512,6 +512,8 @@ int Frame::GetSamplesPerFrame(int64_t number, Fraction fps, int sample_rate, int
|
||||
// Subtract the previous frame's total samples with this frame's total samples. Not all sample rates can
|
||||
// be evenly divided into frames, so each frame can have have different # of samples.
|
||||
int samples_per_frame = round(total_samples - previous_samples);
|
||||
if (samples_per_frame < 0)
|
||||
samples_per_frame = 0;
|
||||
return samples_per_frame;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user