diff options
| author | nicknsy <20588554+nicknsy@users.noreply.github.com> | 2023-02-22 00:08:35 -0800 |
|---|---|---|
| committer | Nick <20588554+nicknsy@users.noreply.github.com> | 2023-06-22 16:19:59 -0700 |
| commit | ca7d1a13000ad948eebbfdeb40542312f3e37d3e (patch) | |
| tree | 6ff31f7f318410c62ba3278aeac71f26e9626603 /MediaBrowser.Controller | |
| parent | a1eb2f6ea8cd78d527f1ae395378419f016208ab (diff) | |
Trickplay generation, manager, storage
Diffstat (limited to 'MediaBrowser.Controller')
4 files changed, 137 insertions, 0 deletions
diff --git a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs index b155d674d..0889a90f4 100644 --- a/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs +++ b/MediaBrowser.Controller/MediaEncoding/EncodingHelper.cs @@ -149,6 +149,36 @@ namespace MediaBrowser.Controller.MediaEncoding return defaultEncoder; } + private string GetMjpegEncoder(EncodingJobInfo state, EncodingOptions encodingOptions) + { + var defaultEncoder = "mjpeg"; + + if (state.VideoType == VideoType.VideoFile) + { + var hwType = encodingOptions.HardwareAccelerationType; + + var codecMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase) + { + { "vaapi", defaultEncoder + "_vaapi" }, + { "qsv", defaultEncoder + "_qsv" } + }; + + if (!string.IsNullOrEmpty(hwType) + && encodingOptions.EnableHardwareEncoding + && codecMap.ContainsKey(hwType)) + { + var preferredEncoder = codecMap[hwType]; + + if (_mediaEncoder.SupportsEncoder(preferredEncoder)) + { + return preferredEncoder; + } + } + } + + return defaultEncoder; + } + private bool IsVaapiSupported(EncodingJobInfo state) { // vaapi will throw an error with this input @@ -277,6 +307,11 @@ namespace MediaBrowser.Controller.MediaEncoding return GetH264Encoder(state, encodingOptions); } + if (string.Equals(codec, "mjpeg", StringComparison.OrdinalIgnoreCase)) + { + return GetMjpegEncoder(state, encodingOptions); + } + if (string.Equals(codec, "vp8", StringComparison.OrdinalIgnoreCase) || string.Equals(codec, "vpx", StringComparison.OrdinalIgnoreCase)) { diff --git a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs index f830b9f29..aa9faa936 100644 --- a/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs +++ b/MediaBrowser.Controller/MediaEncoding/IMediaEncoder.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Dlna; using MediaBrowser.Model.Drawing; using MediaBrowser.Model.Dto; @@ -138,6 +139,32 @@ namespace MediaBrowser.Controller.MediaEncoding Task<string> ExtractVideoImage(string inputFile, string container, MediaSourceInfo mediaSource, MediaStream imageStream, int? imageStreamIndex, ImageFormat? targetFormat, CancellationToken cancellationToken); /// <summary> + /// Extracts the video images on interval. + /// </summary> + /// <param name="inputFile">Input file.</param> + /// <param name="container">Video container type.</param> + /// <param name="mediaSource">Media source information.</param> + /// <param name="imageStream">Media stream information.</param> + /// <param name="interval">The interval.</param> + /// <param name="maxWidth">The maximum width.</param> + /// <param name="allowHwAccel">Allow for hardware acceleration.</param> + /// <param name="allowHwEncode">Allow for hardware encoding. allowHwAccel must also be true.</param> + /// <param name="encodingHelper">EncodingHelper instance.</param> + /// <param name="cancellationToken">The cancellation token.</param> + /// <returns>Directory where images where extracted. A given image made before another will always be named with a lower number.</returns> + Task<string> ExtractVideoImagesOnIntervalAccelerated( + string inputFile, + string container, + MediaSourceInfo mediaSource, + MediaStream imageStream, + TimeSpan interval, + int maxWidth, + bool allowHwAccel, + bool allowHwEncode, + EncodingHelper encodingHelper, + CancellationToken cancellationToken); + + /// <summary> /// Gets the media info. /// </summary> /// <param name="request">The request.</param> diff --git a/MediaBrowser.Controller/Persistence/IItemRepository.cs b/MediaBrowser.Controller/Persistence/IItemRepository.cs index 2c52b2b45..11eb4932c 100644 --- a/MediaBrowser.Controller/Persistence/IItemRepository.cs +++ b/MediaBrowser.Controller/Persistence/IItemRepository.cs @@ -62,6 +62,27 @@ namespace MediaBrowser.Controller.Persistence void SaveChapters(Guid id, IReadOnlyList<ChapterInfo> chapters); /// <summary> + /// Get available trickplay resolutions and corresponding info. + /// </summary> + /// <param name="itemId">The item.</param> + /// <returns>Map of width resolutions to trickplay tiles info.</returns> + Dictionary<int, TrickplayTilesInfo> GetTilesResolutions(Guid itemId); + + /// <summary> + /// Saves trickplay tiles info. + /// </summary> + /// <param name="itemId">The item.</param> + /// <param name="tilesInfo">The trickplay tiles info.</param> + void SaveTilesInfo(Guid itemId, TrickplayTilesInfo tilesInfo); + + /// <summary> + /// Gets trickplay data for an item. + /// </summary> + /// <param name="item">The item.</param> + /// <returns>A map of media source id to a map of tile width to tile info.</returns> + Dictionary<Guid, Dictionary<int, TrickplayTilesInfo>> GetTrickplayManifest(BaseItem item); + + /// <summary> /// Gets the media streams. /// </summary> /// <param name="query">The query.</param> diff --git a/MediaBrowser.Controller/Trickplay/ITrickplayManager.cs b/MediaBrowser.Controller/Trickplay/ITrickplayManager.cs new file mode 100644 index 000000000..bae458f98 --- /dev/null +++ b/MediaBrowser.Controller/Trickplay/ITrickplayManager.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Threading; +using System.Threading.Tasks; +using MediaBrowser.Controller.Entities; +using MediaBrowser.Model.Entities; + +namespace MediaBrowser.Controller.Trickplay +{ + /// <summary> + /// Interface ITrickplayManager. + /// </summary> + public interface ITrickplayManager + { + /// <summary> + /// Generate or replace trickplay data. + /// </summary> + /// <param name="video">The video.</param> + /// <param name="replace">Whether or not existing data should be replaced.</param> + /// <param name="cancellationToken">CancellationToken to use for operation.</param> + /// <returns>Task.</returns> + Task RefreshTrickplayData(Video video, bool replace, CancellationToken cancellationToken); + + /// <summary> + /// Get available trickplay resolutions and corresponding info. + /// </summary> + /// <param name="itemId">The item.</param> + /// <returns>Map of width resolutions to trickplay tiles info.</returns> + Dictionary<int, TrickplayTilesInfo> GetTilesResolutions(Guid itemId); + + /// <summary> + /// Saves trickplay tiles info. + /// </summary> + /// <param name="itemId">The item.</param> + /// <param name="tilesInfo">The trickplay tiles info.</param> + void SaveTilesInfo(Guid itemId, TrickplayTilesInfo tilesInfo); + + /// <summary> + /// Gets the trickplay manifest. + /// </summary> + /// <param name="item">The item.</param> + /// <returns>A map of media source id to a map of tile width to tile info.</returns> + Dictionary<Guid, Dictionary<int, TrickplayTilesInfo>> GetTrickplayManifest(BaseItem item); + + /// <summary> + /// Gets the path to a trickplay tiles image. + /// </summary> + /// <param name="item">The item.</param> + /// <param name="width">The width of a single tile.</param> + /// <param name="index">The tile grid's index.</param> + /// <returns>The absolute path.</returns> + string GetTrickplayTilePath(BaseItem item, int width, int index); + } +} |
