Skip to content

Commit

Permalink
Merge pull request #160 from ptr727/develop
Browse files Browse the repository at this point in the history
Do not exit on error when counting interlaced frames
  • Loading branch information
ptr727 authored May 23, 2023
2 parents 0a47306 + ce07052 commit bbb3850
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 20 deletions.
10 changes: 5 additions & 5 deletions Docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Images are updated weekly with the latest upstream updates.
### `ptr727/plexcleaner:latest`

```text
PlexCleaner: 3.1.14+11032380cd 02:54:31 [INF] <1> Exit Code : 0
PlexCleaner: 3.1.15+2176c248e3 03:14:46 [INF] <1> Exit Code : 0
dotNET: 7.0.302
HandBrakeCLI: HandBrake 20230223192356-5c2b5d2d0-1.6.x
MediaInfo: MediaInfo Command line, MediaInfoLib - v23.04
Expand All @@ -65,7 +65,7 @@ FfMpeg: ffmpeg version 6.0-0ubuntu1~22.04.sav1.1 Copyright (c) 2000-2023 the FFm
### `ptr727/plexcleaner:savoury`

```text
PlexCleaner: 3.1.14+11032380cd 02:54:31 [INF] <1> Exit Code : 0
PlexCleaner: 3.1.15+2176c248e3 03:14:46 [INF] <1> Exit Code : 0
dotNET: 7.0.302
HandBrakeCLI: HandBrake 20230223192356-5c2b5d2d0-1.6.x
MediaInfo: MediaInfo Command line, MediaInfoLib - v23.04
Expand All @@ -77,7 +77,7 @@ FfMpeg: ffmpeg version 6.0-0ubuntu1~22.04.sav1.1 Copyright (c) 2000-2023 the FFm
### `ptr727/plexcleaner:debian`

```text
PlexCleaner: 3.1.14+11032380cd 02:54:24 [INF] <1> Exit Code : 0
PlexCleaner: 3.1.15+2176c248e3 03:14:36 [INF] <1> Exit Code : 0
dotNET: 7.0.302
HandBrakeCLI: HandBrake 1.6.1
MediaInfo: MediaInfo Command line, MediaInfoLib - v23.04
Expand All @@ -89,7 +89,7 @@ FfMpeg: ffmpeg version 5.1.2-3 Copyright (c) 2000-2022 the FFmpeg developers bui
### `ptr727/plexcleaner:alpine`

```text
PlexCleaner: 3.1.14+11032380cd 02:54:03 [INF] <1> Exit Code : 0
PlexCleaner: 3.1.15+2176c248e3 03:14:19 [INF] <1> Exit Code : 0
dotNET: 7.0.302
HandBrakeCLI: HandBrake 1.6.1
MediaInfo: MediaInfo Command line, MediaInfoLib - v23.04
Expand All @@ -101,7 +101,7 @@ FfMpeg: ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers built w
### `ptr727/plexcleaner:arch`

```text
PlexCleaner: 3.1.14+11032380cd 02:54:20 [INF] <1> Exit Code : 0
PlexCleaner: 3.1.15+2176c248e3 03:14:50 [INF] <1> Exit Code : 0
dotNET: 7.0.103
HandBrakeCLI: HandBrake 1.6.1
MediaInfo: MediaInfo Command line, MediaInfoLib - v23.04
Expand Down
15 changes: 13 additions & 2 deletions PlexCleaner/FfMpegTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public bool VerifyMedia(string filename, out string error)
StringBuilder commandline = new();
CreateDefaultArgs(filename, commandline);

// Null muxer and exit on error
// Null muxer and exit immediately on error (-xerror)
commandline.Append("-hide_banner -nostats -loglevel error -xerror -f null -");

// Execute and limit captured output to last 5 lines
Expand Down Expand Up @@ -434,8 +434,19 @@ private bool GetIdetInfoText(string inputName, out string text)
StringBuilder commandline = new();
CreateDefaultArgs(inputName, commandline);

// Counting can report a failure if there are any stream errors
// Do not exit on error (-xerror)
// [h264 @ 0x55ec750529c0] Invalid NAL unit size (106673 > 27162).
// [h264 @ 0x55ec750529c0] Error splitting the input into NAL units.
// Error while decoding stream #0:0: Invalid data found when processing input
// frame=44164 fps=409 q=-0.0 Lsize=119242800kB time=00:30:41.96 bitrate=530323.3kbits/s dup=1 drop=0 speed=17.1x
// video:119242800kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%
// [Parsed_idet_0 @ 0x55ec7698bd00] Repeated Fields: Neither: 44163 Top: 0 Bottom: 0
// [Parsed_idet_0 @ 0x55ec7698bd00] Single frame detection: TFF: 34 BFF: 33 Progressive: 29439 Undetermined: 14657
// [Parsed_idet_0 @ 0x55ec7698bd00] Multi frame detection: TFF: 41 BFF: 99 Progressive: 43999 Undetermined: 24

// Run idet filter
commandline.Append($"-hide_banner -nostats -xerror -filter:v idet -an -f rawvideo {nullOut}");
commandline.Append($"-hide_banner -nostats -filter:v idet -an -f rawvideo {nullOut}");

// Execute and limit captured output to 5 lines to just get stats
var exitCode = Command(commandline.ToString(), 5, out _, out text);
Expand Down
4 changes: 4 additions & 0 deletions PlexCleaner/Language.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using InsaneGenius.Utilities;
Expand Down Expand Up @@ -155,6 +156,7 @@ public static CultureInfo CreateCultureInfo(string language)
var cultureInfo = CultureInfo.GetCultureInfo(language, true);

// Make sure the culture was not custom created
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
if (cultureInfo == null ||
cultureInfo.ThreeLetterWindowsLanguageName.Equals(Missing, StringComparison.OrdinalIgnoreCase) ||
(cultureInfo.CultureTypes & CultureTypes.UserCustomCulture) == CultureTypes.UserCustomCulture)
Expand All @@ -177,6 +179,8 @@ public static bool IsUndefined(string language)

public bool IsMatch(string prefix, string language)
{
Debug.Assert(!string.IsNullOrEmpty(prefix));
Debug.Assert(!string.IsNullOrEmpty(language));
while (true)
{
// https://r12a.github.io/app-subtags/
Expand Down
2 changes: 2 additions & 0 deletions PlexCleaner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,14 @@ private static Program Create(CommandLineOptions options, bool verifyTools)
}

// Log app and runtime version
// ReSharper disable once RedundantAssignment
bool debugBuild = false;
#if DEBUG
debugBuild = true;
#endif
string appVersion = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
string runtimeVersion = Environment.Version.ToString();
// ReSharper disable once ConditionIsAlwaysTrueOrFalse
Log.Logger.Information("Application Version : {AppVersion}, Runtime Version : {RuntimeVersion}, Debug Build: {DebugBuild}", appVersion, runtimeVersion, debugBuild);

// Parallel processing config
Expand Down
26 changes: 14 additions & 12 deletions PlexCleaner/TrackInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected TrackInfo() { }

internal TrackInfo(MkvToolJsonSchema.Track trackJson)
{
const string parser = "MkvToolJsonSchema";
Format = trackJson.Codec;
Codec = trackJson.Properties.CodecId;
Title = trackJson.Properties.TrackName;
Expand Down Expand Up @@ -99,7 +100,7 @@ internal TrackInfo(MkvToolJsonSchema.Track trackJson)
State = StateType.ReMux;

// Failed to lookup ISO tag from IETF tag
Log.Logger.Error("MkvToolJsonSchema : Failed to lookup ISO639 tag from IETF tag : ISO639: {Language}, IETF: {LanguageIetf}, State: {State}", Language, LanguageIetf, State);
Log.Logger.Error("{Parser} : Failed to lookup ISO639 tag from IETF tag : ISO639: {Language}, IETF: {LanguageIetf}, State: {State}", parser, Language, LanguageIetf, State);
}
else if (!Language.Equals(isoLookup, StringComparison.OrdinalIgnoreCase))
{
Expand All @@ -108,7 +109,7 @@ internal TrackInfo(MkvToolJsonSchema.Track trackJson)
State = StateType.ReMux;

// Lookup ISO from IETF is good, but ISO lookup does not match set ISO language
Log.Logger.Error("MkvToolJsonSchema : Failed to match ISO639 tag with ISO639 from IETF tag : ISO639: {Language}, IETF: {LanguageIetf}, ISO639 from IETF: {Lookup}, State: {State}", Language, LanguageIetf, isoLookup, State);
Log.Logger.Error("{Parser} : Failed to match ISO639 tag with ISO639 from IETF tag : ISO639: {Language}, IETF: {LanguageIetf}, ISO639 from IETF: {Lookup}, State: {State}", parser, Language, LanguageIetf, isoLookup, State);
}
// Lookup good and matches
}
Expand All @@ -126,7 +127,7 @@ internal TrackInfo(MkvToolJsonSchema.Track trackJson)
State = StateType.ReMux;

// Failed to lookup IETF tag from ISO tag
Log.Logger.Error("MkvToolJsonSchema : Failed to lookup IETF tag from ISO639 tag : ISO639: {Language}, State: {State}", Language, State);
Log.Logger.Error("{Parser} : Failed to lookup IETF tag from ISO639 tag : ISO639: {Language}, State: {State}", parser, Language, State);
}
else
{
Expand All @@ -137,7 +138,7 @@ internal TrackInfo(MkvToolJsonSchema.Track trackJson)

// Set IETF tag from lookup tag
LanguageIetf = ietfLookup;
Log.Logger.Information("MkvToolJsonSchema : Setting IETF tag from ISO639 tag : ISO639: {Language}, IETF: {LanguageIetf}, State: {State}", Language, LanguageIetf, State);
Log.Logger.Information("{Parser} : Setting IETF tag from ISO639 tag : ISO639: {Language}, IETF: {LanguageIetf}, State: {State}", parser, Language, LanguageIetf, State);
}
}

Expand All @@ -156,13 +157,13 @@ internal TrackInfo(MkvToolJsonSchema.Track trackJson)
if (string.IsNullOrEmpty(isoLookup))
{
// Failed to lookup ISO from IETF
Log.Logger.Error("MkvToolJsonSchema : Failed to lookup ISO639 tag from IETF tag : IETF: {LanguageIetf}, State: {State}", LanguageIetf, State);
Log.Logger.Error("{Parser} : Failed to lookup ISO639 tag from IETF tag : IETF: {LanguageIetf}, State: {State}", parser, LanguageIetf, State);
}
else
{
// Set ISO from lookup
Language = isoLookup;
Log.Logger.Warning("MkvToolJsonSchema : Setting ISO639 tag from IETF tag : ISO639: {Language}, IETF: {LanguageIetf}, State: {State}", Language, LanguageIetf, State);
Log.Logger.Warning("{Parser} : Setting ISO639 tag from IETF tag : ISO639: {Language}, IETF: {LanguageIetf}, State: {State}", parser, Language, LanguageIetf, State);
}
}

Expand All @@ -175,7 +176,7 @@ internal TrackInfo(MkvToolJsonSchema.Track trackJson)
// Set track error and recommend remux
HasErrors = true;
State = StateType.ReMux;
Log.Logger.Warning("MkvToolJsonSchema : TagLanguage does not match Language : TagLanguage: {TagLanguage}, Language: {Language}, State: {State}", trackJson.Properties.TagLanguage, trackJson.Properties.Language, State);
Log.Logger.Warning("{Parser} : TagLanguage does not match Language : TagLanguage: {TagLanguage}, Language: {Language}, State: {State}", parser, trackJson.Properties.TagLanguage, trackJson.Properties.Language, State);
}

// Take care to use id and number correctly in MkvMerge and MkvPropEdit
Expand All @@ -189,7 +190,7 @@ internal TrackInfo(MkvToolJsonSchema.Track trackJson)
HasTags = NotTrackTitleFlag();

// Set flags from title
SetFlagsFromTitle("MkvToolJsonSchema");
SetFlagsFromTitle(parser);

// Verify required info
Debug.Assert(!string.IsNullOrEmpty(Format));
Expand All @@ -198,6 +199,7 @@ internal TrackInfo(MkvToolJsonSchema.Track trackJson)

internal TrackInfo(FfMpegToolJsonSchema.Stream trackJson)
{
const string parser = "FfMpegToolJsonSchema";
Format = trackJson.CodecName;
Codec = trackJson.CodecLongName;

Expand Down Expand Up @@ -244,7 +246,7 @@ internal TrackInfo(FfMpegToolJsonSchema.Stream trackJson)
// Set track error and recommend remux
HasErrors = true;
State = StateType.ReMux;
Log.Logger.Warning("FfMpegToolJsonSchema : Invalid Language : {Language} : {State}", Language, State);
Log.Logger.Warning("{Parser} : Invalid Language : {Language} : {State}", parser, Language, State);
}

// Leave the Language as is, no need to verify
Expand Down Expand Up @@ -358,14 +360,14 @@ public virtual void WriteLine(string prefix)

public bool NotTrackTitleFlag()
{
// NOT logic, i.e. title is not a flag
// Not logic, i.e. title is not a flag
if (string.IsNullOrEmpty(Title))
{
// Empty is NOT a flag
// Empty is not a flag
return false;
}

// NOT a flag is NOT a flag
// Not a flag is not a flag
return !TitleFlags.Any(tuple => Title.Contains(tuple.Item1, StringComparison.OrdinalIgnoreCase));
}

Expand Down
2 changes: 1 addition & 1 deletion PlexCleanerTests/PlexCleanerTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down

0 comments on commit bbb3850

Please sign in to comment.