mirror of https://github.com/jellyfin/jellyfin.git
Use codec to determine image format
This commit is contained in:
parent
f73a7a6ed8
commit
1d729b2b0f
|
@ -721,15 +721,13 @@ namespace MediaBrowser.MediaEncoding.Probing
|
||||||
}
|
}
|
||||||
else if (string.Equals(streamInfo.CodecType, "video", StringComparison.OrdinalIgnoreCase))
|
else if (string.Equals(streamInfo.CodecType, "video", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
stream.Type = isAudio || string.Equals(stream.Codec, "mjpeg", StringComparison.OrdinalIgnoreCase) || string.Equals(stream.Codec, "gif", StringComparison.OrdinalIgnoreCase) || string.Equals(stream.Codec, "png", StringComparison.OrdinalIgnoreCase)
|
|
||||||
? MediaStreamType.EmbeddedImage
|
|
||||||
: MediaStreamType.Video;
|
|
||||||
|
|
||||||
stream.AverageFrameRate = GetFrameRate(streamInfo.AverageFrameRate);
|
stream.AverageFrameRate = GetFrameRate(streamInfo.AverageFrameRate);
|
||||||
stream.RealFrameRate = GetFrameRate(streamInfo.RFrameRate);
|
stream.RealFrameRate = GetFrameRate(streamInfo.RFrameRate);
|
||||||
|
|
||||||
if (isAudio || string.Equals(stream.Codec, "gif", StringComparison.OrdinalIgnoreCase) ||
|
if (isAudio
|
||||||
string.Equals(stream.Codec, "png", StringComparison.OrdinalIgnoreCase))
|
|| string.Equals(stream.Codec, "mjpeg", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| string.Equals(stream.Codec, "gif", StringComparison.OrdinalIgnoreCase)
|
||||||
|
|| string.Equals(stream.Codec, "png", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
stream.Type = MediaStreamType.EmbeddedImage;
|
stream.Type = MediaStreamType.EmbeddedImage;
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,14 @@ namespace MediaBrowser.Providers.MediaInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var format = ImageFormat.Jpg;
|
var format = imageStream.Codec switch
|
||||||
|
{
|
||||||
|
"mjpeg" => ImageFormat.Jpg,
|
||||||
|
"png" => ImageFormat.Png,
|
||||||
|
"gif" => ImageFormat.Gif,
|
||||||
|
_ => ImageFormat.Jpg
|
||||||
|
};
|
||||||
|
|
||||||
string extractedImagePath =
|
string extractedImagePath =
|
||||||
await _mediaEncoder.ExtractVideoImage(item.Path, item.Container, mediaSource, imageStream, imageStream.Index, format, cancellationToken)
|
await _mediaEncoder.ExtractVideoImage(item.Path, item.Container, mediaSource, imageStream, imageStream.Index, format, cancellationToken)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
|
@ -50,7 +50,7 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
||||||
[InlineData("clearlogo.png", null, 1, ImageType.Logo, ImageFormat.Png)] // extract extension from name
|
[InlineData("clearlogo.png", null, 1, ImageType.Logo, ImageFormat.Png)] // extract extension from name
|
||||||
[InlineData("backdrop", "image/bmp", 2, ImageType.Backdrop, ImageFormat.Bmp)] // extract extension from mimetype
|
[InlineData("backdrop", "image/bmp", 2, ImageType.Backdrop, ImageFormat.Bmp)] // extract extension from mimetype
|
||||||
[InlineData("poster", null, 3, ImageType.Primary, ImageFormat.Jpg)] // default extension to jpg
|
[InlineData("poster", null, 3, ImageType.Primary, ImageFormat.Jpg)] // default extension to jpg
|
||||||
public async void GetImage_Attachment_ReturnsCorrectSelection(string filename, string mimetype, int targetIndex, ImageType type, ImageFormat? format)
|
public async void GetImage_Attachment_ReturnsCorrectSelection(string filename, string mimetype, int targetIndex, ImageType type, ImageFormat? expectedFormat)
|
||||||
{
|
{
|
||||||
var attachments = new List<MediaAttachment>();
|
var attachments = new List<MediaAttachment>();
|
||||||
string pathPrefix = "path";
|
string pathPrefix = "path";
|
||||||
|
@ -74,24 +74,27 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
||||||
|
|
||||||
var actual = await embeddedImageProvider.GetImage(input, type, CancellationToken.None);
|
var actual = await embeddedImageProvider.GetImage(input, type, CancellationToken.None);
|
||||||
Assert.NotNull(actual);
|
Assert.NotNull(actual);
|
||||||
if (format == null)
|
if (expectedFormat == null)
|
||||||
{
|
{
|
||||||
Assert.False(actual.HasImage);
|
Assert.False(actual.HasImage);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Assert.True(actual.HasImage);
|
Assert.True(actual.HasImage);
|
||||||
Assert.Equal(pathPrefix + targetIndex + "." + format, actual.Path, StringComparer.OrdinalIgnoreCase);
|
Assert.Equal(pathPrefix + targetIndex + "." + expectedFormat, actual.Path, StringComparer.OrdinalIgnoreCase);
|
||||||
Assert.Equal(format, actual.Format);
|
Assert.Equal(expectedFormat, actual.Format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
[InlineData(null, 1, ImageType.Backdrop, false)] // no label, can only find primary
|
[InlineData(null, null, 1, ImageType.Backdrop, false, ImageFormat.Jpg)] // no label, can only find primary
|
||||||
[InlineData(null, 1, ImageType.Primary, true)] // no label, finds primary
|
[InlineData(null, null, 1, ImageType.Primary, true, ImageFormat.Jpg)] // no label, finds primary
|
||||||
[InlineData("backdrop", 2, ImageType.Backdrop, true)] // uses label to find index 2, not just pulling first stream
|
[InlineData("backdrop", null, 2, ImageType.Backdrop, true, ImageFormat.Jpg)] // uses label to find index 2, not just pulling first stream
|
||||||
[InlineData("cover", 2, ImageType.Primary, true)] // uses label to find index 2, not just pulling first stream
|
[InlineData("cover", null, 2, ImageType.Primary, true, ImageFormat.Jpg)] // uses label to find index 2, not just pulling first stream
|
||||||
public async void GetImage_Embedded_ReturnsCorrectSelection(string label, int targetIndex, ImageType type, bool hasImage)
|
[InlineData(null, "mjpeg", 1, ImageType.Primary, true, ImageFormat.Jpg)]
|
||||||
|
[InlineData(null, "png", 1, ImageType.Primary, true, ImageFormat.Png)]
|
||||||
|
[InlineData(null, "gif", 1, ImageType.Primary, true, ImageFormat.Gif)]
|
||||||
|
public async void GetImage_Embedded_ReturnsCorrectSelection(string label, string? codec, int targetIndex, ImageType type, bool hasImage, ImageFormat expectedFormat)
|
||||||
{
|
{
|
||||||
var streams = new List<MediaStream>();
|
var streams = new List<MediaStream>();
|
||||||
for (int i = 1; i <= targetIndex; i++)
|
for (int i = 1; i <= targetIndex; i++)
|
||||||
|
@ -101,7 +104,8 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
||||||
{
|
{
|
||||||
Type = MediaStreamType.EmbeddedImage,
|
Type = MediaStreamType.EmbeddedImage,
|
||||||
Index = i,
|
Index = i,
|
||||||
Comment = comment
|
Comment = comment,
|
||||||
|
Codec = codec
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,8 +126,8 @@ namespace Jellyfin.Providers.Tests.MediaInfo
|
||||||
Assert.Equal(hasImage, actual.HasImage);
|
Assert.Equal(hasImage, actual.HasImage);
|
||||||
if (hasImage)
|
if (hasImage)
|
||||||
{
|
{
|
||||||
Assert.Equal(pathPrefix + targetIndex + ".jpg", actual.Path, StringComparer.OrdinalIgnoreCase);
|
Assert.Equal(pathPrefix + targetIndex + "." + expectedFormat, actual.Path, StringComparer.OrdinalIgnoreCase);
|
||||||
Assert.Equal(ImageFormat.Jpg, actual.Format);
|
Assert.Equal(expectedFormat, actual.Format);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue