diff --git a/src/audiosource.cpp b/src/audiosource.cpp index 8032d98..cc35295 100644 --- a/src/audiosource.cpp +++ b/src/audiosource.cpp @@ -195,7 +195,7 @@ void LWAudioDecoder::SetFrameNumber(int64_t N, int64_t SampleNumber) { CurrentSample = SampleNumber; } -void LWAudioDecoder::GetAudioProperties(AudioProperties &AP) { +void LWAudioDecoder::GetAudioProperties(BSAudioProperties &AP) { assert(CurrentFrame == 0); AP = {}; AVFrame *PropFrame = GetNextFrame(); @@ -272,7 +272,7 @@ bool LWAudioDecoder::HasSeeked() const { return Seeked; } -void AudioFormat::Set(int Format, int BitsPerRawSample) { +void BSAudioFormat::Set(int Format, int BitsPerRawSample) { Float = (Format == AV_SAMPLE_FMT_FLTP || Format == AV_SAMPLE_FMT_FLT || Format == AV_SAMPLE_FMT_DBLP || Format == AV_SAMPLE_FMT_DBL); BytesPerSample = av_get_bytes_per_sample(static_cast(Format)); Bits = BitsPerRawSample ? BitsPerRawSample : (BytesPerSample * 8); @@ -467,7 +467,7 @@ double BestAudioSource::GetRelativeStartTime(int Track) const { if (Track < 0) { try { std::unique_ptr Dec(new LWVideoDecoder(Source, "", 0, Track, true, 0, LAVFOptions)); - VideoProperties VP; + BSVideoProperties VP; Dec->GetVideoProperties(VP); return AP.StartTime - VP.StartTime; } catch (BestSourceException &) { @@ -476,13 +476,13 @@ double BestAudioSource::GetRelativeStartTime(int Track) const { } else { try { std::unique_ptr Dec(new LWVideoDecoder(Source, "", 0, Track, true, 0, LAVFOptions)); - VideoProperties VP; + BSVideoProperties VP; Dec->GetVideoProperties(VP); return AP.StartTime - VP.StartTime; } catch (BestSourceException &) { try { std::unique_ptr Dec(new LWAudioDecoder(Source, false, Track, Threads, LAVFOptions, 0)); - AudioProperties AP2; + BSAudioProperties AP2; Dec->GetAudioProperties(AP2); return AP.StartTime - AP2.StartTime; } catch (BestSourceException &) { @@ -492,7 +492,7 @@ double BestAudioSource::GetRelativeStartTime(int Track) const { } } -const AudioProperties &BestAudioSource::GetAudioProperties() const { +const BSAudioProperties &BestAudioSource::GetAudioProperties() const { return AP; } diff --git a/src/audiosource.h b/src/audiosource.h index 6ef0316..1fc7980 100644 --- a/src/audiosource.h +++ b/src/audiosource.h @@ -37,7 +37,7 @@ struct AVBufferRef; struct AVFrame; struct AVPacket; -struct AudioFormat { +struct BSAudioFormat { bool Float; int Bits; int BytesPerSample; // FIXME, kinda odd to have it exposed here but very useful to store internally @@ -45,8 +45,8 @@ struct AudioFormat { void Set(int Format, int BitsPerRawSample); }; -struct AudioProperties { - AudioFormat AF; +struct BSAudioProperties { + BSAudioFormat AF; int SampleRate; int Channels; uint64_t ChannelLayout; @@ -80,7 +80,7 @@ struct LWAudioDecoder { [[nodiscard]] int64_t GetFrameNumber() const; // The frame you will get when calling GetNextFrame() [[nodiscard]] int64_t GetSamplePos() const; // The frame you will get when calling GetNextFrame() void SetFrameNumber(int64_t N, int64_t SampleNumber); // Use after seeking to update internal frame number - void GetAudioProperties(AudioProperties &VP); // Decodes one frame and advances the position to retrieve the full properties, only call directly after creation + void GetAudioProperties(BSAudioProperties &VP); // Decodes one frame and advances the position to retrieve the full properties, only call directly after creation [[nodiscard]] AVFrame *GetNextFrame(); bool SkipFrames(int64_t Count); [[nodiscard]] bool HasMoreFrames() const; @@ -96,7 +96,7 @@ class BestAudioFrame { BestAudioFrame(AVFrame *Frame); ~BestAudioFrame(); [[nodiscard]] const AVFrame *GetAVFrame() const; - AudioFormat AF; + BSAudioFormat AF; int NumChannels; int64_t Pts; @@ -147,7 +147,7 @@ class BestAudioSource { static constexpr int MaxVideoSources = 4; std::map LAVFOptions; double DrcScale; - AudioProperties AP = {}; + BSAudioProperties AP = {}; std::filesystem::path Source; int AudioTrack; bool VariableFormat; @@ -185,7 +185,7 @@ class BestAudioSource { void SetMaxCacheSize(size_t Bytes); /* default max size is 1GB */ void SetSeekPreRoll(int64_t Frames); /* the number of frames to cache before the position being fast forwarded to */ double GetRelativeStartTime(int Track) const; - [[nodiscard]] const AudioProperties &GetAudioProperties() const; + [[nodiscard]] const BSAudioProperties &GetAudioProperties() const; [[nodiscard]] BestAudioFrame *GetFrame(int64_t N, bool Linear = false); [[nodiscard]] FrameRange GetFrameRangeBySamples(int64_t Start, int64_t Count) const; void GetPackedAudio(uint8_t *Data, int64_t Start, int64_t Count); diff --git a/src/avisynth.cpp b/src/avisynth.cpp index 809827e..a779ae9 100644 --- a/src/avisynth.cpp +++ b/src/avisynth.cpp @@ -94,7 +94,7 @@ class AvisynthVideoSource : public IClip { V.reset(new BestVideoSource(CreateProbablyUTF8Path(Source), HWDevice ? HWDevice : "", ExtraHWFrames, Track, false, Threads, CacheMode, CachePath, &Opts)); - const VideoProperties &VP = V->GetVideoProperties(); + const BSVideoProperties &VP = V->GetVideoProperties(); if (VP.VF.ColorFamily == cfGray) { VI.pixel_type = VideoInfo::CS_GENERIC_Y; } else if (VP.VF.ColorFamily == cfYUV && VP.VF.Alpha) { @@ -246,7 +246,7 @@ class AvisynthVideoSource : public IClip { Env->ThrowError("BestVideoSource: %s", e.what()); } - const VideoProperties &VP = V->GetVideoProperties(); + const BSVideoProperties &VP = V->GetVideoProperties(); AVSMap *Props = Env->getFramePropsRW(Dst); SetSynthFrameProperties(Src, VP, RFF, V->GetFrameIsTFF(n, RFF), @@ -300,7 +300,7 @@ class AvisynthAudioSource : public IClip { try { A.reset(new BestAudioSource(CreateProbablyUTF8Path(Source), Track, AdjustDelay, false, Threads, CacheMode, CachePath ? CachePath : "", &Opts, DrcScale)); - const AudioProperties &AP = A->GetAudioProperties(); + const BSAudioProperties &AP = A->GetAudioProperties(); if (AP.AF.Float && AP.AF.Bits == 32) { VI.sample_type = SAMPLE_FLOAT; } else if (!AP.AF.Float && AP.AF.Bits <= 8) { diff --git a/src/synthshared.cpp b/src/synthshared.cpp index c4b9a66..852d92a 100644 --- a/src/synthshared.cpp +++ b/src/synthshared.cpp @@ -21,7 +21,7 @@ #include "synthshared.h" #include "VSHelper4.h" -void SetSynthFrameProperties(const std::unique_ptr &Src, const VideoProperties &VP, bool RFF, bool TFF, const std::function &mapSetInt, const std::function &mapSetFloat, const std::function &mapSetData) { +void SetSynthFrameProperties(const std::unique_ptr &Src, const BSVideoProperties &VP, bool RFF, bool TFF, const std::function &mapSetInt, const std::function &mapSetFloat, const std::function &mapSetData) { // Set AR variables if (VP.SAR.Num > 0 && VP.SAR.Den > 0) { mapSetInt("_SARNum", VP.SAR.Num); diff --git a/src/synthshared.h b/src/synthshared.h index 45ca017..15ac94b 100644 --- a/src/synthshared.h +++ b/src/synthshared.h @@ -26,6 +26,6 @@ #include #include -void SetSynthFrameProperties(const std::unique_ptr &Src, const VideoProperties &VP, bool RFF, bool TFF, const std::function &mapSetInt, const std::function &mapSetFloat, const std::function &mapSetData); +void SetSynthFrameProperties(const std::unique_ptr &Src, const BSVideoProperties &VP, bool RFF, bool TFF, const std::function &mapSetInt, const std::function &mapSetFloat, const std::function &mapSetData); #endif \ No newline at end of file diff --git a/src/vapoursynth.cpp b/src/vapoursynth.cpp index 230d8ae..f7eeb89 100644 --- a/src/vapoursynth.cpp +++ b/src/vapoursynth.cpp @@ -108,7 +108,7 @@ static const VSFrame *VS_CC BestVideoSourceGetFrame(int n, int ActivationReason, return nullptr; } - const VideoProperties &VP = D->V->GetVideoProperties(); + const BSVideoProperties &VP = D->V->GetVideoProperties(); VSMap *Props = vsapi->getFramePropertiesRW(Dst); if (AlphaDst) vsapi->mapConsumeFrame(Props, "_Alpha", AlphaDst, maAppend); @@ -201,7 +201,7 @@ static void VS_CC CreateBestVideoSource(const VSMap *In, VSMap *Out, void *, VSC D->V.reset(new BestVideoSource(Source, HWDevice ? HWDevice : "", ExtraHWFrames, Track, VariableFormat, Threads, CacheMode, CachePath ? CachePath : "", &Opts)); } - const VideoProperties &VP = D->V->GetVideoProperties(); + const BSVideoProperties &VP = D->V->GetVideoProperties(); if (VP.VF.ColorFamily == 0 || !vsapi->queryVideoFormat(&D->VI.format, VP.VF.ColorFamily, VP.VF.Float, VP.VF.Bits, VP.VF.SubSamplingW, VP.VF.SubSamplingH, Core)) throw BestSourceException("Unsupported video format from decoder (probably less than 8 bit or palette)"); D->VI.width = VP.SSModWidth; @@ -338,7 +338,7 @@ static void VS_CC CreateBestAudioSource(const VSMap *In, VSMap *Out, void *, VSC D->A.reset(new BestAudioSource(Source, Track, AdjustDelay, false, Threads, CacheMode, CachePath ? CachePath : "", &Opts, DrcScale)); } - const AudioProperties &AP = D->A->GetAudioProperties(); + const BSAudioProperties &AP = D->A->GetAudioProperties(); D->Is8Bit = (AP.AF.Bits <= 8); if (!vsapi->queryAudioFormat(&D->AI.format, AP.AF.Float, D->Is8Bit ? 16 : AP.AF.Bits, AP.ChannelLayout, Core)) throw BestSourceException("Unsupported audio format from decoder (probably 8-bit)"); diff --git a/src/version.h b/src/version.h index 6b687c6..78b6472 100644 --- a/src/version.h +++ b/src/version.h @@ -21,7 +21,7 @@ #ifndef VERSION_H #define VERSION_H -#define BEST_SOURCE_VERSION_MAJOR 4 +#define BEST_SOURCE_VERSION_MAJOR 6 #define BEST_SOURCE_VERSION_MINOR 0 #endif \ No newline at end of file diff --git a/src/videosource.cpp b/src/videosource.cpp index 8e2ba45..d64f6b6 100644 --- a/src/videosource.cpp +++ b/src/videosource.cpp @@ -283,7 +283,7 @@ void LWVideoDecoder::SetFrameNumber(int64_t N) { CurrentFrame = N; } -void LWVideoDecoder::GetVideoProperties(VideoProperties &VP) { +void LWVideoDecoder::GetVideoProperties(BSVideoProperties &VP) { assert(CurrentFrame == 0); VP = {}; AVFrame *PropFrame = GetNextFrame(); @@ -458,7 +458,7 @@ bool LWVideoDecoder::HasSeeked() const { return Seeked; } -void VideoFormat::Set(const AVPixFmtDescriptor *Desc) { +void BSVideoFormat::Set(const AVPixFmtDescriptor *Desc) { Alpha = HasAlpha(Desc); Float = GetSampleTypeIsFloat(Desc); ColorFamily = GetColorFamily(Desc); @@ -1057,7 +1057,7 @@ bool BestVideoSource::IndexTrack(const ProgressFunction &Progress) { return !TrackIndex.Frames.empty(); } -const VideoProperties &BestVideoSource::GetVideoProperties() const { +const BSVideoProperties &BestVideoSource::GetVideoProperties() const { return VP; } @@ -1456,7 +1456,7 @@ BestVideoFrame *BestVideoSource::GetFrameWithRFF(int64_t N, bool Linear) { } BestVideoFrame *BestVideoSource::GetFrameByTime(double Time, bool Linear) { - int64_t PTS = static_cast(((Time * 1000 * VP.TimeBase.Den) / VP.TimeBase.Num) + .001); + int64_t PTS = static_cast(((Time * VP.TimeBase.Den) / VP.TimeBase.Num) + .001); FrameInfo F{ PTS }; auto Pos = std::lower_bound(TrackIndex.Frames.begin(), TrackIndex.Frames.end(), F, [](const FrameInfo &FI1, const FrameInfo &FI2) { return FI1.PTS < FI2.PTS; }); diff --git a/src/videosource.h b/src/videosource.h index d331c26..f08baf3 100644 --- a/src/videosource.h +++ b/src/videosource.h @@ -38,7 +38,7 @@ struct AVFrame; struct AVPacket; struct AVPixFmtDescriptor; -struct VideoFormat { +struct BSVideoFormat { int ColorFamily; /* Unknown = 0, Gray = 1, RGB = 2, YUV = 3 */ bool Alpha; bool Float; @@ -49,7 +49,7 @@ struct VideoFormat { void Set(const AVPixFmtDescriptor *Desc); }; -struct VideoProperties { +struct BSVideoProperties { BSRational TimeBase; double StartTime; // in seconds int64_t Duration; @@ -59,7 +59,7 @@ struct VideoProperties { BSRational FPS; BSRational SAR; - VideoFormat VF; + BSVideoFormat VF; int Width; int Height; @@ -121,7 +121,7 @@ struct LWVideoDecoder { [[nodiscard]] int GetTrack() const; // Useful when opening nth video track to get the actual number [[nodiscard]] int64_t GetFrameNumber() const; // The frame you will get when calling GetNextFrame() void SetFrameNumber(int64_t N); // Use after seeking to update internal frame number - void GetVideoProperties(VideoProperties &VP); // Decodes one frame and advances the position to retrieve the full properties, only call directly after creation + void GetVideoProperties(BSVideoProperties &VP); // Decodes one frame and advances the position to retrieve the full properties, only call directly after creation [[nodiscard]] AVFrame *GetNextFrame(); bool SkipFrames(int64_t Count); [[nodiscard]] bool HasMoreFrames() const; @@ -140,7 +140,7 @@ class BestVideoFrame { void MergeField(bool Top, const BestVideoFrame *FieldSrc); // Useful for RFF and other such things where fields from multiple decoded frames need to be combined, retains original frame's properties bool ExportAsPlanar(uint8_t *const *const Dsts1, const ptrdiff_t *const Stride, uint8_t *AlphaDst = nullptr, ptrdiff_t AlphaStride = 0) const; - VideoFormat VF; + BSVideoFormat VF; int Width; int Height; @@ -242,7 +242,7 @@ class BestVideoSource { static constexpr int MaxVideoSources = 4; std::map LAVFOptions; - VideoProperties VP = {}; + BSVideoProperties VP = {}; std::filesystem::path Source; std::string HWDevice; int ExtraHWFrames; @@ -268,12 +268,12 @@ class BestVideoSource { public: BestVideoSource(const std::filesystem::path &SourceFile, const std::string &HWDeviceName, int ExtraHWFrames, int Track, bool VariableFormat, int Threads, int CacheMode, const std::filesystem::path &CachePath, const std::map *LAVFOpts, const ProgressFunction &Progress = nullptr); [[nodiscard]] int GetTrack() const; // Useful when opening nth video track to get the actual number - void SetMaxCacheSize(size_t Bytes); /* default max size is 1GB */ - void SetSeekPreRoll(int64_t Frames); /* the number of frames to cache before the position being fast forwarded to */ - [[nodiscard]] const VideoProperties &GetVideoProperties() const; + void SetMaxCacheSize(size_t Bytes); /* Default max size is 1GB */ + void SetSeekPreRoll(int64_t Frames); /* The number of frames to cache before the position being fast forwarded to */ + [[nodiscard]] const BSVideoProperties &GetVideoProperties() const; [[nodiscard]] BestVideoFrame *GetFrame(int64_t N, bool Linear = false); [[nodiscard]] BestVideoFrame *GetFrameWithRFF(int64_t N, bool Linear = false); - [[nodiscard]] BestVideoFrame *GetFrameByTime(double Time, bool Linear = false); + [[nodiscard]] BestVideoFrame *GetFrameByTime(double Time, bool Linear = false); /* Time is in seconds */ [[nodiscard]] bool GetFrameIsTFF(int64_t N, bool RFF = false); void WriteTimecodes(const std::filesystem::path &TimecodeFile) const; [[nodiscard]] const FrameInfo &GetFrameInfo(int64_t N) const;