Add test data and unit test for mp4 metadata probe

This commit is contained in:
Joe Rogers 2021-10-01 21:47:42 +02:00
parent 531efc345a
commit 4c2adc39c7
No known key found for this signature in database
GPG Key ID: 0074AD57B8FDBBB4
2 changed files with 328 additions and 0 deletions

View File

@ -5,8 +5,10 @@ using System.Text.Json;
using Jellyfin.Extensions.Json;
using MediaBrowser.MediaEncoding.Probing;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.MediaInfo;
using Microsoft.Extensions.Logging.Abstractions;
using Moq;
using Xunit;
namespace Jellyfin.MediaEncoding.Tests.Probing
@ -55,6 +57,72 @@ namespace Jellyfin.MediaEncoding.Tests.Probing
Assert.Equal("Just color bars", res.Overview);
}
[Fact]
public void GetMediaInfo_Mp4MetaData_Success()
{
var bytes = File.ReadAllBytes("Test Data/Probing/video_mp4_metadata.json");
var internalMediaInfoResult = JsonSerializer.Deserialize<InternalMediaInfoResult>(bytes, _jsonOptions);
// subtitle handling requires a localization object, set a mock to return the input string
var mockLocalization = new Mock<ILocalizationManager>();
mockLocalization.Setup(x => x.GetLocalizedString(It.IsAny<string>())).Returns<string>(x => x);
ProbeResultNormalizer localizedProbeResultNormalizer = new ProbeResultNormalizer(new NullLogger<EncoderValidatorTests>(), mockLocalization.Object);
MediaInfo res = localizedProbeResultNormalizer.GetMediaInfo(internalMediaInfoResult, VideoType.VideoFile, false, "Test Data/Probing/video_mp4_metadata.mkv", MediaProtocol.File);
// [Video, Audio (Main), Audio (Commentary), Subtitle (Main, Spanish), Subtitle (Main, English), Subtitle (Commentary)
Assert.Equal(6, res.MediaStreams.Count);
Assert.NotNull(res.VideoStream);
Assert.Equal(res.MediaStreams[0], res.VideoStream);
Assert.Equal(0, res.VideoStream.Index);
Assert.Equal("h264", res.VideoStream.Codec);
Assert.Equal("High", res.VideoStream.Profile);
Assert.Equal(MediaStreamType.Video, res.VideoStream.Type);
Assert.Equal(358, res.VideoStream.Height);
Assert.Equal(720, res.VideoStream.Width);
Assert.Equal("2.40:1", res.VideoStream.AspectRatio);
Assert.Equal("yuv420p", res.VideoStream.PixelFormat);
Assert.Equal(31d, res.VideoStream.Level);
Assert.Equal(1, res.VideoStream.RefFrames);
Assert.True(res.VideoStream.IsAVC);
Assert.Equal(120f, res.VideoStream.RealFrameRate);
Assert.Equal("1/90000", res.VideoStream.TimeBase);
Assert.Equal(1147365, res.VideoStream.BitRate);
Assert.Equal(8, res.VideoStream.BitDepth);
Assert.True(res.VideoStream.IsDefault);
Assert.Equal("und", res.VideoStream.Language);
Assert.Equal(MediaStreamType.Audio, res.MediaStreams[1].Type);
Assert.Equal("aac", res.MediaStreams[1].Codec);
Assert.Equal(7, res.MediaStreams[1].Channels);
Assert.True(res.MediaStreams[1].IsDefault);
Assert.Equal("eng", res.MediaStreams[1].Language);
Assert.Equal("Surround 6.1", res.MediaStreams[1].Title);
Assert.Equal(MediaStreamType.Audio, res.MediaStreams[2].Type);
Assert.Equal("aac", res.MediaStreams[2].Codec);
Assert.Equal(2, res.MediaStreams[2].Channels);
Assert.False(res.MediaStreams[2].IsDefault);
Assert.Equal("eng", res.MediaStreams[2].Language);
Assert.Equal("Commentary", res.MediaStreams[2].Title);
Assert.Equal("spa", res.MediaStreams[3].Language);
Assert.Equal(MediaStreamType.Subtitle, res.MediaStreams[3].Type);
Assert.Equal("DVDSUB", res.MediaStreams[3].Codec);
Assert.Null(res.MediaStreams[3].Title);
Assert.Equal("eng", res.MediaStreams[4].Language);
Assert.Equal(MediaStreamType.Subtitle, res.MediaStreams[4].Type);
Assert.Equal("mov_text", res.MediaStreams[4].Codec);
Assert.Null(res.MediaStreams[4].Title);
Assert.Equal("eng", res.MediaStreams[5].Language);
Assert.Equal(MediaStreamType.Subtitle, res.MediaStreams[5].Type);
Assert.Equal("mov_text", res.MediaStreams[5].Codec);
Assert.Equal("Commentary", res.MediaStreams[5].Title);
}
[Fact]
public void GetMediaInfo_MusicVideo_Success()
{

View File

@ -0,0 +1,260 @@
{
"streams": [
{
"index": 0,
"codec_name": "h264",
"codec_long_name": "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10",
"profile": "High",
"codec_type": "video",
"codec_tag_string": "avc1",
"codec_tag": "0x31637661",
"width": 720,
"height": 358,
"coded_width": 720,
"coded_height": 358,
"closed_captions": 0,
"has_b_frames": 2,
"sample_aspect_ratio": "32:27",
"display_aspect_ratio": "1280:537",
"pix_fmt": "yuv420p",
"level": 31,
"color_range": "tv",
"color_space": "smpte170m",
"color_transfer": "bt709",
"color_primaries": "smpte170m",
"chroma_location": "left",
"refs": 1,
"is_avc": "true",
"nal_length_size": "4",
"r_frame_rate": "120/1",
"avg_frame_rate": "1704753000/71073479",
"time_base": "1/90000",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 1421469580,
"duration": "15794.106444",
"bit_rate": "1147365",
"bits_per_raw_sample": "8",
"nb_frames": "378834",
"disposition": {
"default": 1,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
},
"tags": {
"creation_time": "2021-09-13T22:42:42.000000Z",
"language": "und",
"handler_name": "VideoHandler",
"vendor_id": "[0][0][0][0]"
}
},
{
"index": 1,
"codec_name": "aac",
"codec_long_name": "AAC (Advanced Audio Coding)",
"profile": "LC",
"codec_type": "audio",
"codec_tag_string": "mp4a",
"codec_tag": "0x6134706d",
"sample_fmt": "fltp",
"sample_rate": "48000",
"channels": 7,
"bits_per_sample": 0,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/48000",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 758115312,
"duration": "15794.069000",
"bit_rate": "224197",
"nb_frames": "740348",
"disposition": {
"default": 1,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
},
"tags": {
"creation_time": "2021-09-13T22:42:42.000000Z",
"language": "eng",
"handler_name": "Surround 6.1",
"vendor_id": "[0][0][0][0]"
}
},
{
"index": 2,
"codec_name": "aac",
"codec_long_name": "AAC (Advanced Audio Coding)",
"profile": "LC",
"codec_type": "audio",
"codec_tag_string": "mp4a",
"codec_tag": "0x6134706d",
"sample_fmt": "fltp",
"sample_rate": "48000",
"channels": 2,
"channel_layout": "stereo",
"bits_per_sample": 0,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/48000",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 758114304,
"duration": "15794.048000",
"bit_rate": "160519",
"nb_frames": "740347",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
},
"tags": {
"creation_time": "2021-09-13T22:42:42.000000Z",
"language": "eng",
"handler_name": "Commentary",
"vendor_id": "[0][0][0][0]"
}
},
{
"index": 3,
"codec_name": "dvd_subtitle",
"codec_long_name": "DVD subtitles",
"codec_type": "subtitle",
"codec_tag_string": "mp4s",
"codec_tag": "0x7334706d",
"width": 720,
"height": 480,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/90000",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 1300301588,
"duration": "14447.795422",
"bit_rate": "2653",
"nb_frames": "3545",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
},
"tags": {
"creation_time": "2021-09-13T22:42:42.000000Z",
"language": "spa",
"handler_name": "SubtitleHandler"
}
},
{
"index": 4,
"codec_name": "mov_text",
"codec_long_name": "MOV text",
"codec_type": "subtitle",
"codec_tag_string": "tx3g",
"codec_tag": "0x67337874",
"width": 853,
"height": 51,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/90000",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 1401339330,
"duration": "15570.437000",
"bit_rate": "88",
"nb_frames": "5079",
"disposition": {
"default": 1,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
},
"tags": {
"creation_time": "2021-09-13T22:42:42.000000Z",
"language": "eng",
"handler_name": "SubtitleHandler"
}
},
{
"index": 5,
"codec_name": "mov_text",
"codec_long_name": "MOV text",
"codec_type": "subtitle",
"codec_tag_string": "tx3g",
"codec_tag": "0x67337874",
"width": 853,
"height": 51,
"r_frame_rate": "0/0",
"avg_frame_rate": "0/0",
"time_base": "1/90000",
"start_pts": 0,
"start_time": "0.000000",
"duration_ts": 1370580300,
"duration": "15228.670000",
"bit_rate": "18",
"nb_frames": "1563",
"disposition": {
"default": 0,
"dub": 0,
"original": 0,
"comment": 0,
"lyrics": 0,
"karaoke": 0,
"forced": 0,
"hearing_impaired": 0,
"visual_impaired": 0,
"clean_effects": 0,
"attached_pic": 0,
"timed_thumbnails": 0
},
"tags": {
"creation_time": "2021-09-13T22:42:42.000000Z",
"language": "eng",
"handler_name": "Commentary"
}
}
]
}