From 54606c76f977b77109805e21eeaf6dde65931075 Mon Sep 17 00:00:00 2001
From: Jason Dove <1695733+jasongdove@users.noreply.github.com>
Date: Tue, 2 Dec 2025 12:20:09 -0600
Subject: [PATCH] framerate improvements (#2692)
* framerate improvements
* fixes
---
CHANGELOG.md | 7 ++
.../Channels/Queries/GetChannelFramerate.cs | 6 +-
.../Queries/GetChannelFramerateHandler.cs | 83 +++++++------------
.../Commands/StartFFmpegSessionHandler.cs | 5 +-
.../Streaming/HlsSessionWorker.cs | 5 +-
.../GetPlayoutItemProcessByChannelNumber.cs | 3 +-
...layoutItemProcessByChannelNumberHandler.cs | 4 -
.../PrepareTroubleshootingPlaybackHandler.cs | 4 +-
.../FFmpeg/FFmpegLibraryProcessService.cs | 11 ++-
.../FFmpeg/FFmpegPlaybackSettings.cs | 3 +-
.../FFmpegPlaybackSettingsCalculator.cs | 4 +-
ErsatzTV.Core/FFmpeg/FFmpegProcessService.cs | 2 +-
.../FFmpeg/IFFmpegProcessService.cs | 2 +-
.../Streaming/GraphicsEngineContext.cs | 3 +-
.../Metadata/FFmpegProfileTemplateDataKey.cs | 2 +
ErsatzTV.FFmpeg.Tests/MediaStreamTests.cs | 10 +--
.../PipelineBuilderBaseTests.cs | 18 ++--
ErsatzTV.FFmpeg/Filter/FrameRateFilter.cs | 6 +-
ErsatzTV.FFmpeg/Filter/ResetPtsFilter.cs | 6 +-
ErsatzTV.FFmpeg/FrameRate.cs | 30 +++++++
ErsatzTV.FFmpeg/FrameState.cs | 2 +-
ErsatzTV.FFmpeg/InputFile.cs | 2 +-
.../InputOption/RawVideoInputOption.cs | 4 +-
ErsatzTV.FFmpeg/MediaStream.cs | 2 +-
.../OutputFormat/OutputFormatHls.cs | 39 ++-------
.../OutputOption/FrameRateOutputOption.cs | 22 ++---
.../Pipeline/PipelineBuilderBase.cs | 21 +++--
.../Pipeline/QsvPipelineBuilder.cs | 12 ++-
.../Graphics/GraphicsElementLoader.cs | 2 +
.../Streaming/Graphics/GraphicsEngine.cs | 4 +-
.../Graphics/Motion/MotionElement.cs | 2 +-
ErsatzTV/Controllers/InternalController.cs | 3 +-
ErsatzTV/Controllers/IptvController.cs | 3 +-
33 files changed, 164 insertions(+), 168 deletions(-)
create mode 100644 ErsatzTV.FFmpeg/FrameRate.cs
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d1f23b2b8..c10b92528 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Remote stream definitions (yaml files) can now contain `title`, `plot`, `year` and `content_rating` fields
- Remote streams can now have thumbnails (same name as yaml file but with image extension)
- This metadata will be used in generated XMLTV entries, using a template that can be customized like other media kinds
+- Add framerate template data to graphics engine
+ - `RFrameRate` - the real content framerate (or channel normalized framerate) as reported by ffmpeg, e.g. `30000/1001`
+ - `FrameRate` - the decimal representation of `RFrameRate`, e.g. `29.97002997`
### Fixed
- Fix startup on systems unsupported by NvEncSharp
@@ -29,6 +32,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- A warning will be logged when this scenario is detected
- AMD VAAPI: work around buggy ffmpeg behavior where hevc_vaapi encoder with RadeonSI driver incorrectly outputs height of 1088 instead of 1080
- Optimize graphics engine to generate element frames in parallel and to eliminate redundant frame copies
+- Match graphics engine framerate with source content (or channel normalized) framerate
+
+### Changed
+- No longer round framerate to nearest integer when normalizing framerate
## [25.9.0] - 2025-11-29
### Added
diff --git a/ErsatzTV.Application/Channels/Queries/GetChannelFramerate.cs b/ErsatzTV.Application/Channels/Queries/GetChannelFramerate.cs
index 7d907e277..331c5f7bf 100644
--- a/ErsatzTV.Application/Channels/Queries/GetChannelFramerate.cs
+++ b/ErsatzTV.Application/Channels/Queries/GetChannelFramerate.cs
@@ -1,3 +1,5 @@
-namespace ErsatzTV.Application.Channels;
+using ErsatzTV.FFmpeg;
-public record GetChannelFramerate(string ChannelNumber) : IRequest