Use codec to determine image format

pull/6831/head
Joe Rogers 3 years ago
parent f73a7a6ed8
commit 1d729b2b0f
No known key found for this signature in database
GPG Key ID: 0074AD57B8FDBBB4

@ -721,15 +721,13 @@ namespace MediaBrowser.MediaEncoding.Probing
}
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.RealFrameRate = GetFrameRate(streamInfo.RFrameRate);
if (isAudio || string.Equals(stream.Codec, "gif", StringComparison.OrdinalIgnoreCase) ||
string.Equals(stream.Codec, "png", StringComparison.OrdinalIgnoreCase))
if (isAudio
|| 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;
}

@ -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 =
await _mediaEncoder.ExtractVideoImage(item.Path, item.Container, mediaSource, imageStream, imageStream.Index, format, cancellationToken)
.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("backdrop", "image/bmp", 2, ImageType.Backdrop, ImageFormat.Bmp)] // extract extension from mimetype
[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>();
string pathPrefix = "path";
@ -74,24 +74,27 @@ namespace Jellyfin.Providers.Tests.MediaInfo
var actual = await embeddedImageProvider.GetImage(input, type, CancellationToken.None);
Assert.NotNull(actual);
if (format == null)
if (expectedFormat == null)
{
Assert.False(actual.HasImage);
}
else
{
Assert.True(actual.HasImage);
Assert.Equal(pathPrefix + targetIndex + "." + format, actual.Path, StringComparer.OrdinalIgnoreCase);
Assert.Equal(format, actual.Format);
Assert.Equal(pathPrefix + targetIndex + "." + expectedFormat, actual.Path, StringComparer.OrdinalIgnoreCase);
Assert.Equal(expectedFormat, actual.Format);
}
}
[Theory]
[InlineData(null, 1, ImageType.Backdrop, false)] // no label, can only find primary
[InlineData(null, 1, ImageType.Primary, true)] // no label, finds primary
[InlineData("backdrop", 2, ImageType.Backdrop, true)] // 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
public async void GetImage_Embedded_ReturnsCorrectSelection(string label, int targetIndex, ImageType type, bool hasImage)
[InlineData(null, null, 1, ImageType.Backdrop, false, ImageFormat.Jpg)] // no label, can only find primary
[InlineData(null, null, 1, ImageType.Primary, true, ImageFormat.Jpg)] // no label, finds primary
[InlineData("backdrop", null, 2, ImageType.Backdrop, true, ImageFormat.Jpg)] // 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
[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>();
for (int i = 1; i <= targetIndex; i++)
@ -101,7 +104,8 @@ namespace Jellyfin.Providers.Tests.MediaInfo
{
Type = MediaStreamType.EmbeddedImage,
Index = i,
Comment = comment
Comment = comment,
Codec = codec
});
}
@ -122,8 +126,8 @@ namespace Jellyfin.Providers.Tests.MediaInfo
Assert.Equal(hasImage, actual.HasImage);
if (hasImage)
{
Assert.Equal(pathPrefix + targetIndex + ".jpg", actual.Path, StringComparer.OrdinalIgnoreCase);
Assert.Equal(ImageFormat.Jpg, actual.Format);
Assert.Equal(pathPrefix + targetIndex + "." + expectedFormat, actual.Path, StringComparer.OrdinalIgnoreCase);
Assert.Equal(expectedFormat, actual.Format);
}
}

Loading…
Cancel
Save