ptr727 / PlexCleaner

Utility to optimize media files for Direct Play in Plex, Emby, Jellyfin
MIT License
268 stars 13 forks source link

Crash on no audio stream #81

Closed Migushthe2nd closed 2 years ago

Migushthe2nd commented 2 years ago

Some of my video files don't have an audio channel. This causes PlexCleaner to crash. I've noticed this with the MJPEG codec (AVI, wmv). Not sure about other codecs.

The First() call throws an error: https://github.com/ptr727/PlexCleaner/blob/eb592ee4f892d50cb3b0ceb7a17588bd459590c0/PlexCleaner/ProcessFile.cs#L1013-L1016

Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at PlexCleaner.ProcessFile.GetBitrateInfo(BitrateInfo& bitrateInfo) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\ProcessFile.cs:line 1013
   at PlexCleaner.ProcessFile.VerifyBitrate() in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\ProcessFile.cs:line 623
   at PlexCleaner.ProcessFile.Verify(Boolean conditional, Boolean& modified) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\ProcessFile.cs:line 542
   at PlexCleaner.Process.ProcessFile(FileInfo fileinfo, Boolean& modified, States& state, FileInfo& processInfo) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\Process.cs:line 268
   at PlexCleaner.Process.<>c__DisplayClass3_0.<ProcessFiles>b__0(FileInfo fileInfo) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\Process.cs:line 114
   at PlexCleaner.Process.ProcessFilesDriver(List`1 fileList, String taskName, Func`2 taskFunc) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\Process.cs:line 542
   at PlexCleaner.Process.ProcessFiles(List`1 fileList) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\Process.cs:line 111
   at PlexCleaner.Program.ProcessCommand(CommandLineOptions options) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\Program.cs:line 109
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at System.CommandLine.NamingConventionBinder.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass26_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass24_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__23_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass21_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__8_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__7_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseExceptionHandler>b__0>d.MoveNext()
ptr727 commented 2 years ago

There is a test for audio and video track counts before calling the bitrate calculation: https://github.com/ptr727/PlexCleaner/blob/eb592ee4f892d50cb3b0ceb7a17588bd459590c0/PlexCleaner/ProcessFile.cs#L477-L485

I wonder if there is a difference in track counts between what ffprobe and mediainfo reports. Could you possibly share a sample file that exhibits the problem?

Migushthe2nd commented 2 years ago

Hmm this actually happens with files that do have an audio track as well. These are family videos so I'd rather not share these here publicly.

Migushthe2nd commented 2 years ago

This is an example wmv file

image
PS D:\Temp\PlexCleaner\win-x64> .\PlexCleaner.exe --settingsfile "PlexCleaner.json" --logfile "PlexCleaner.log" --logappend process --mediafiles "L:\2012"
[18:10:24 INF] Loading settings from : "PlexCleaner.json"
[18:10:24 INF] Logging output to : "PlexCleaner.log"
[18:10:24 INF] Application Version : "2.3.5+Branch.main.Sha.eb592ee4f892d50cb3b0ceb7a17588bd459590c0.eb592ee4f892d50cb3b0ceb7a17588bd459590c0", Runtime Version : "6.0.1"
[18:10:24 INF] Executing FfMpeg : "-version"
[18:10:24 INF] FfMpeg : Version: "4.4.1", Path: "D:\\Temp\\PlexCleaner\\win-x64\\Tools\\FfMpeg\\bin\\ffmpeg.exe"
[18:10:24 INF] Executing FfProbe : "-version"
[18:10:24 INF] FfProbe : Version: "4.4.1", Path: "D:\\Temp\\PlexCleaner\\win-x64\\Tools\\FfMpeg\\bin\\ffprobe.exe"
[18:10:24 INF] Executing MkvMerge : "--version"
[18:10:24 INF] MkvMerge : Version: "64.0.0", Path: "D:\\Temp\\PlexCleaner\\win-x64\\Tools\\MkvToolNix\\mkvmerge.exe"
[18:10:24 INF] Executing MkvPropEdit : "--version"
[18:10:24 INF] MkvPropEdit : Version: "64.0.0", Path: "D:\\Temp\\PlexCleaner\\win-x64\\Tools\\MkvToolNix\\mkvpropedit.exe"
[18:10:24 INF] Executing MediaInfo : "--version"
[18:10:24 INF] MediaInfo : Version: "21.09", Path: "D:\\Temp\\PlexCleaner\\win-x64\\Tools\\MediaInfo\\mediainfo.exe"
[18:10:24 INF] Executing HandBrake : "--version"
[18:10:25] Compile-time hardening features are enabled
[18:10:25] hb_init: starting libhb thread
[18:10:25] thread 1 started ("libhb")
HandBrake has exited.
[18:10:26 INF] HandBrake : Version: "1.4.2", Path: "D:\\Temp\\PlexCleaner\\win-x64\\Tools\\HandBrake\\HandBrakeCLI.exe"
[18:10:26 INF] Executing SevenZip : ""
[18:10:26 INF] SevenZip : Version: "19.00", Path: "D:\\Temp\\PlexCleaner\\win-x64\\Tools\\SevenZip\\x64\\7za.exe"
[18:10:26 INF] Creating file and folder list ...
[18:10:26 INF] Getting files and folders from "L:\\2012" ...
[18:10:26 INF] Discovered 2 directories and 182 files
[18:10:26 INF] Starting "Process", processing 182 files ...
[18:10:26 INF] "Process" (46.15 %) : "L:\\2012\\Video.wmv"
[18:10:26 INF] ReMux file matched by extension : "Video.wmv"
[18:10:26 INF] Executing MkvMerge : "--disable-track-statistics-tags --no-global-tags --no-track-tags --flush-on-close  --output \"L:\\2012\\Video.tmp\" \"L:\\2012\\Video.wmv\""
mkvmerge v64.0.0 ('Willows') 64-bit
Error: The file 'L:\2012\Video.wmv' is a non-supported file type (Windows Media (ASF/WMV)).
[18:10:26 WRN] Executing MkvMerge : ExitCode: 2
[18:10:26 INF] Executing FfMpeg : "-i \"L:\\2012\\Video.wmv\"  -map 0 -codec copy -f matroska \"L:\\2012\\Video.tmp\""
ffmpeg version 4.4.1-full_build-www.gyan.dev Copyright (c) 2000-2021 the FFmpeg developers
  built with gcc 11.2.0 (Rev1, Built by MSYS2 project)
  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libdav1d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxvid --enable-libaom --enable-libopenjpeg --enable-libvpx --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-libglslang --enable-vulkan --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint
  libavutil      56. 70.100 / 56. 70.100
  libavcodec     58.134.100 / 58.134.100
  libavformat    58. 76.100 / 58. 76.100
  libavdevice    58. 13.100 / 58. 13.100
  libavfilter     7.110.100 /  7.110.100
  libswscale      5.  9.100 /  5.  9.100
  libswresample   3.  9.100 /  3.  9.100
  libpostproc    55.  9.100 / 55.  9.100
[wmv3 @ 000001db277e6140] Extra data: 8 bits left, value: 0
Guessed Channel Layout for Input Stream #0.1 : stereo
Input #0, asf, from 'L:\2012\Video.wmv':
  Metadata:
    WMFSDKNeeded    : 0.0.0.0000
    DeviceConformanceTemplate: MP@ML
    WMFSDKVersion   : 12.0.7601.17514
    IsVBR           : 0
  Duration: 00:00:59.44, start: 0.000000, bitrate: 1567 kb/s
  Stream #0:0: Video: mjpeg (Baseline), yuvj420p(pc, bt470bg/unknown/unknown), 426x240, 90k tbr, 90k tbn, 90k tbc (attached pic)
    Metadata:
      comment         : Movie/video screen capture
  Stream #0:1(eng): Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, stereo, fltp, 48 kb/s
  Stream #0:2(eng): Video: wmv3 (Main) (WMV3 / 0x33564D57), yuv420p, 426x240, 1500 kb/s, 29.97 fps, 29.97 tbr, 1k tbn, 1k tbc
Output #0, matroska, to 'L:\2012\Video.tmp':
  Metadata:
    WMFSDKNeeded    : 0.0.0.0000
    DeviceConformanceTemplate: MP@ML
    WMFSDKVersion   : 12.0.7601.17514
    IsVBR           : 0
    encoder         : Lavf58.76.100
  Stream #0:0: Video: mjpeg (Baseline) (MJPG / 0x47504A4D), yuvj420p(pc, bt470bg/unknown/unknown), 426x240, q=2-31, 90k tbr, 1k tbn, 90k tbc (attached pic)
    Metadata:
      comment         : Movie/video screen capture
  Stream #0:1(eng): Audio: wmav2 (a[1][0][0] / 0x0161), 44100 Hz, stereo, fltp, 48 kb/s
  Stream #0:2(eng): Video: wmv3 (Main) (WMV3 / 0x33564D57), yuv420p, 426x240, q=2-31, 1500 kb/s, 29.97 fps, 29.97 tbr, 1k tbn, 1k tbc
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:1 -> #0:1 (copy)
  Stream #0:2 -> #0:2 (copy)
Press [q] to stop, [?] for help
frame=    1 fps=0.0 q=-1.0 Lq=-1.0 size=   11293kB time=00:00:59.39 bitrate=1557.6kbits/s speed= 156x
video:10915kB audio:362kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.144380%
[18:10:26 INF] Waiting for IO to flush : 5s : "Video.mkv"
[18:10:31 INF] Reading media info from tools : "Video.mkv"
[18:10:31 INF] Executing MediaInfo : "--Output=XML \"L:\\2012\\Video.mkv\""
[18:10:32 INF] Executing MkvMerge : "--identify \"L:\\2012\\Video.mkv\" --identification-format json"
[18:10:32 INF] Executing FfProbe : "-loglevel quiet -show_streams -print_format json \"L:\\2012\\Video.mkv\""
[18:10:32 INF] "MediaInfo" : Type: "VideoInfo", Format: "V_MJPEG", HDR: "", Codec: "V_MJPEG", Language: "und", Id: 1, Number: 0, State: None, Title: "", Default: True, HasErrors: False, Profile: "", Interlaced: False
[18:10:32 INF] "MediaInfo" : Type: "VideoInfo", Format: "VC-1", HDR: "", Codec: "V_MS/VFW/FOURCC / WMV3", Language: "eng", Id: 3, Number: 2, State: None, Title: "", Default: False, HasErrors: False, Profile: "", Interlaced: False
[18:10:32 INF] "MediaInfo" : Type: "AudioInfo", Format: "WMA", Codec: "A_MS/ACM / 161", Language: "eng", Id: 2, Number: 1, State: None, Title: "", Default: True, HasErrors: False
[18:10:32 INF] "MKVMerge" : Type: "VideoInfo", Format: "V_MJPEG", HDR: "", Codec: "V_MJPEG", Language: "und", Id: 0, Number: 1, State: None, Title: "", Default: True, HasErrors: False, Profile: "", Interlaced: False
[18:10:32 INF] "MKVMerge" : Type: "VideoInfo", Format: "0x574d5633 \"WMV3\"", HDR: "", Codec: "V_MS/VFW/FOURCC", Language: "eng", Id: 2, Number: 3, State: None, Title: "", Default: False, HasErrors: False, Profile: "", Interlaced: False
[18:10:32 INF] "MKVMerge" : Type: "AudioInfo", Format: "unknown, format tag 0x0161", Codec: "A_MS/ACM", Language: "eng", Id: 1, Number: 2, State: None, Title: "", Default: True, HasErrors: False
[18:10:32 INF] "FFprobe" : Type: "VideoInfo", Format: "wmv3", HDR: "", Codec: "WMV3", Language: "eng", Id: 2, Number: 2, State: None, Title: "", Default: False, HasErrors: False, Profile: "Main@-99", Interlaced: False
[18:10:32 INF] "FFprobe" : Type: "AudioInfo", Format: "wmav2", Codec: "Windows Media Audio 2", Language: "eng", Id: 1, Number: 1, State: None, Title: "", Default: True, HasErrors: False
[18:10:32 INF] Sidecar created : State: None : "Video.PlexCleaner"
[18:10:32 INF] Sidecar updated : State: ReMuxed, ReNamed : "Video.PlexCleaner"
[18:10:32 INF] Setting unknown language tracks to "eng" : "Video.mkv"
[18:10:32 INF] "Known" : Type: "VideoInfo", Format: "0x574d5633 \"WMV3\"", HDR: "", Codec: "V_MS/VFW/FOURCC", Language: "eng", Id: 2, Number: 3, State: None, Title: "", Default: False, HasErrors: False, Profile: "", Interlaced: False
[18:10:32 INF] "Known" : Type: "AudioInfo", Format: "unknown, format tag 0x0161", Codec: "A_MS/ACM", Language: "eng", Id: 1, Number: 2, State: None, Title: "", Default: True, HasErrors: False
[18:10:32 INF] "Unknown" : Type: "VideoInfo", Format: "V_MJPEG", HDR: "", Codec: "V_MJPEG", Language: "und", Id: 0, Number: 1, State: None, Title: "", Default: True, HasErrors: False, Profile: "", Interlaced: False
[18:10:32 INF] Executing MkvPropEdit : "\"L:\\2012\\Video.mkv\" --flush-on-close --edit track:@1 --set language=eng"
The file is being analyzed.
The changes are written to the file.
Done.
[18:10:32 INF] Waiting for IO to flush : 5s : "Video.mkv"
[18:10:37 INF] Reading media info from tools : "Video.mkv"
[18:10:37 INF] Executing MediaInfo : "--Output=XML \"L:\\2012\\Video.mkv\""
[18:10:38 INF] Executing MkvMerge : "--identify \"L:\\2012\\Video.mkv\" --identification-format json"
[18:10:38 INF] Executing FfProbe : "-loglevel quiet -show_streams -print_format json \"L:\\2012\\Video.mkv\""
[18:10:38 INF] "MediaInfo" : Type: "VideoInfo", Format: "V_MJPEG", HDR: "", Codec: "V_MJPEG", Language: "eng", Id: 1, Number: 0, State: None, Title: "", Default: True, HasErrors: False, Profile: "", Interlaced: False
[18:10:38 INF] "MediaInfo" : Type: "VideoInfo", Format: "VC-1", HDR: "", Codec: "V_MS/VFW/FOURCC / WMV3", Language: "eng", Id: 3, Number: 2, State: None, Title: "", Default: False, HasErrors: False, Profile: "", Interlaced: False
[18:10:38 INF] "MediaInfo" : Type: "AudioInfo", Format: "WMA", Codec: "A_MS/ACM / 161", Language: "eng", Id: 2, Number: 1, State: None, Title: "", Default: True, HasErrors: False
[18:10:38 INF] "MKVMerge" : Type: "VideoInfo", Format: "V_MJPEG", HDR: "", Codec: "V_MJPEG", Language: "eng", Id: 0, Number: 1, State: None, Title: "", Default: True, HasErrors: False, Profile: "", Interlaced: False
[18:10:38 INF] "MKVMerge" : Type: "VideoInfo", Format: "0x574d5633 \"WMV3\"", HDR: "", Codec: "V_MS/VFW/FOURCC", Language: "eng", Id: 2, Number: 3, State: None, Title: "", Default: False, HasErrors: False, Profile: "", Interlaced: False
[18:10:38 INF] "MKVMerge" : Type: "AudioInfo", Format: "unknown, format tag 0x0161", Codec: "A_MS/ACM", Language: "eng", Id: 1, Number: 2, State: None, Title: "", Default: True, HasErrors: False
[18:10:38 INF] "FFprobe" : Type: "VideoInfo", Format: "wmv3", HDR: "", Codec: "WMV3", Language: "eng", Id: 2, Number: 2, State: None, Title: "", Default: False, HasErrors: False, Profile: "Main@-99", Interlaced: False
[18:10:38 INF] "FFprobe" : Type: "AudioInfo", Format: "wmav2", Codec: "Windows Media Audio 2", Language: "eng", Id: 1, Number: 1, State: None, Title: "", Default: True, HasErrors: False
[18:10:38 INF] Sidecar updated : State: SetLanguage, ReMuxed, ReNamed : "Video.PlexCleaner"
[18:10:38 INF] Removing duplicate tracks : "Video.mkv"
[18:10:38 INF] "Keep" : Type: "VideoInfo", Format: "V_MJPEG", HDR: "", Codec: "V_MJPEG", Language: "eng", Id: 0, Number: 1, State: Keep, Title: "", Default: True, HasErrors: False, Profile: "", Interlaced: False
[18:10:38 INF] "Keep" : Type: "AudioInfo", Format: "unknown, format tag 0x0161", Codec: "A_MS/ACM", Language: "eng", Id: 1, Number: 2, State: Keep, Title: "", Default: True, HasErrors: False
[18:10:38 INF] "Remove" : Type: "VideoInfo", Format: "0x574d5633 \"WMV3\"", HDR: "", Codec: "V_MS/VFW/FOURCC", Language: "eng", Id: 2, Number: 3, State: Remove, Title: "", Default: False, HasErrors: False, Profile: "", Interlaced: False
[18:10:38 INF] Re-muxing union of tracks : "Video.mkv"
[18:10:38 INF] "Keep" : Type: "VideoInfo", Format: "V_MJPEG", HDR: "", Codec: "V_MJPEG", Language: "eng", Id: 0, Number: 1, State: Keep, Title: "", Default: True, HasErrors: False, Profile: "", Interlaced: False
[18:10:38 INF] "Keep" : Type: "AudioInfo", Format: "unknown, format tag 0x0161", Codec: "A_MS/ACM", Language: "eng", Id: 1, Number: 2, State: Keep, Title: "", Default: True, HasErrors: False
[18:10:38 INF] "Remove" : Type: "VideoInfo", Format: "0x574d5633 \"WMV3\"", HDR: "", Codec: "V_MS/VFW/FOURCC", Language: "eng", Id: 2, Number: 3, State: Remove, Title: "", Default: False, HasErrors: False, Profile: "", Interlaced: False
[18:10:38 INF] Executing MkvMerge : "--disable-track-statistics-tags --no-global-tags --no-track-tags --flush-on-close  --output \"L:\\2012\\Video.tmp\" --video-tracks 0 --audio-tracks 1 --no-subtitles  \"L:\\2012\\Video.mkv\""
mkvmerge v64.0.0 ('Willows') 64-bit
'L:\2012\Video.mkv': Using the demultiplexer for the format 'Matroska'.
'L:\2012\Video.mkv' track 0: Using the output module for the format 'generic video'.
'L:\2012\Video.mkv' track 1: Using the generic output module for track type 'audio'.
The file 'L:\2012\Video.tmp' has been opened for writing.
Progress: 100%
The cue entries (the index) are being written...
Multiplexing took 0 seconds.
[18:10:38 INF] Waiting for IO to flush : 5s : "Video.mkv"
[18:10:43 INF] Reading media info from tools : "Video.mkv"
[18:10:43 INF] Executing MediaInfo : "--Output=XML \"L:\\2012\\Video.mkv\""
[18:10:43 INF] Executing MkvMerge : "--identify \"L:\\2012\\Video.mkv\" --identification-format json"
[18:10:43 INF] Executing FfProbe : "-loglevel quiet -show_streams -print_format json \"L:\\2012\\Video.mkv\""
[18:10:43 INF] "MediaInfo" : Type: "VideoInfo", Format: "V_MJPEG", HDR: "", Codec: "V_MJPEG", Language: "eng", Id: 1, Number: 0, State: None, Title: "", Default: True, HasErrors: False, Profile: "", Interlaced: False
[18:10:43 INF] "MediaInfo" : Type: "AudioInfo", Format: "WMA", Codec: "A_MS/ACM / 161", Language: "eng", Id: 2, Number: 1, State: None, Title: "", Default: True, HasErrors: False
[18:10:43 INF] "MKVMerge" : Type: "VideoInfo", Format: "V_MJPEG", HDR: "", Codec: "V_MJPEG", Language: "eng", Id: 0, Number: 1, State: None, Title: "", Default: True, HasErrors: False, Profile: "", Interlaced: False
[18:10:43 INF] "MKVMerge" : Type: "AudioInfo", Format: "unknown, format tag 0x0161", Codec: "A_MS/ACM", Language: "eng", Id: 1, Number: 2, State: None, Title: "", Default: True, HasErrors: False
[18:10:43 INF] "FFprobe" : Type: "AudioInfo", Format: "wmav2", Codec: "Windows Media Audio 2", Language: "eng", Id: 1, Number: 1, State: None, Title: "", Default: True, HasErrors: False
[18:10:43 INF] Sidecar updated : State: SetLanguage, ReMuxed, ReNamed : "Video.PlexCleaner"
[18:10:43 INF] Verifying media streams : "Video.mkv"
[18:10:43 INF] Executing FfMpeg : "-i \"L:\\2012\\Video.mkv\" -max_muxing_queue_size 1024 -nostats -loglevel error -xerror  -f null -"
[18:10:43 INF] Calculating bitrate info : "Video.mkv"
[18:10:43 INF] Executing FfProbe : "-loglevel error -show_packets -show_entries packet=codec_type,stream_index,pts_time,dts_time,duration_time,size -print_format json \"L:\\2012\\Video.mkv\""
Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.InvalidOperationException: Sequence contains no elements
   at System.Linq.ThrowHelper.ThrowNoElementsException()
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at PlexCleaner.ProcessFile.GetBitrateInfo(BitrateInfo& bitrateInfo) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\ProcessFile.cs:line 1013
   at PlexCleaner.ProcessFile.VerifyBitrate() in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\ProcessFile.cs:line 623
   at PlexCleaner.ProcessFile.Verify(Boolean conditional, Boolean& modified) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\ProcessFile.cs:line 542
   at PlexCleaner.Process.ProcessFile(FileInfo fileinfo, Boolean& modified, States& state, FileInfo& processInfo) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\Process.cs:line 268
   at PlexCleaner.Process.<>c__DisplayClass3_0.<ProcessFiles>b__0(FileInfo fileInfo) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\Process.cs:line 114
   at PlexCleaner.Process.ProcessFilesDriver(List`1 fileList, String taskName, Func`2 taskFunc) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\Process.cs:line 542
   at PlexCleaner.Process.ProcessFiles(List`1 fileList) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\Process.cs:line 111
   at PlexCleaner.Program.ProcessCommand(CommandLineOptions options) in D:\a\PlexCleaner\PlexCleaner\PlexCleaner\Program.cs:line 109
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Span`1& arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at System.CommandLine.NamingConventionBinder.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass26_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass24_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__23_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass21_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__8_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__7_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseExceptionHandler>b__0>d.MoveNext()
ptr727 commented 2 years ago

I can see form the log what happens, the file is remuxed from WMV to MKV, and in the process the video track is removed.

I do have a WMV sample, but it does not exhibit this problem. Could you possibly create a test file using the same format, just a few seconds will do, and I'll try to get it to convert to MKV H265 AC3 without the errors?

ptr727 commented 2 years ago

Thx, let me try it, else we can telegram share (wondering how to exchange contact info with github removing dm feature?)

ptr727 commented 2 years ago

Ah shoot;

// Media file must be at least 2 * the hash window length
Debug.Assert(MediaFileInfo.Length >= 2 * HashWindowLength);

Could you make it longer than 128KB, or telegram, how do we share contact info?

ptr727 commented 2 years ago

Unfortunately that file does not have the mjpeg cover art track. Let's try telegram, how do we exchange contact info without the world seeing it here?

Migushthe2nd commented 2 years ago

Oh I think my username will work. Try searching for @migush on telegram Edit: https://t.me/Migushthe2nd

ptr727 commented 2 years ago

Should be fixed now, please let me know. Remember to add the codec types to the JSON config if you want the wma2 audio and wmv3 video to be converted to ac3 and h265.

Migushthe2nd commented 2 years ago

It's working! I have a few more files with weird audio channels though. I've sent a file via Telegram

[14:26:06 INF] "Process" (23.53 %) : "L:\\2004\\Augustus 2004 038.avi"
[14:26:06 INF] ReMux file matched by extension : "Augustus 2004 038.avi"
[14:26:06 INF] Executing MkvMerge : "--disable-track-statistics-tags --no-global-tags --no-track-tags --flush-on-close  --output \"L:\\2004\\Augustus 2004 038.tmp\" \"L:\\2004\\Augustus 2004 038.avi\""
mkvmerge v64.0.0 ('Willows') 64-bit
'L:\2004\Augustus 2004 038.avi': Using the demultiplexer for the format 'AVI'.
'L:\2004\Augustus 2004 038.avi' track 0: Using the output module for the format 'VfW compatible video'.
'L:\2004\Augustus 2004 038.avi' track 1: Using the output module for the format 'PCM'.
The file 'L:\2004\Augustus 2004 038.tmp' has been opened for writing.
Progress: 100%
The cue entries (the index) are being written...
Multiplexing took 0 seconds.
[14:26:07 INF] Waiting for IO to flush : 5s : "Augustus 2004 038.mkv"
[14:26:12 INF] Reading media info from tools : "Augustus 2004 038.mkv"
[14:26:12 INF] Executing MediaInfo : "--Output=XML \"L:\\2004\\Augustus 2004 038.mkv\""
[14:26:12 INF] Executing MkvMerge : "--identify \"L:\\2004\\Augustus 2004 038.mkv\" --identification-format json"
[14:26:12 INF] Executing FfProbe : "-loglevel quiet -show_streams -print_format json \"L:\\2004\\Augustus 2004 038.mkv\""
[14:26:12 INF] "MediaInfo" : Type: "VideoInfo", Format: "JPEG", HDR: "", Codec: "V_MS/VFW/FOURCC / MJPG", Language: "und", Id: 1, Number: 0, State: None, Title: "", Default: True, HasErrors: False, Profile: "", Interlaced: False
[14:26:12 INF] "MediaInfo" : Type: "AudioInfo", Format: "PCM", Codec: "A_PCM/INT/LIT", Language: "und", Id: 2, Number: 1, State: None, Title: "", Default: True, HasErrors: False
[14:26:12 INF] "MKVMerge" : Type: "VideoInfo", Format: "0x4d4a5047 \"MJPG\"", HDR: "", Codec: "V_MS/VFW/FOURCC", Language: "und", Id: 0, Number: 1, State: None, Title: "", Default: True, HasErrors: False, Profile: "", Interlaced: False
[14:26:12 INF] "MKVMerge" : Type: "AudioInfo", Format: "PCM", Codec: "A_PCM/INT/LIT", Language: "und", Id: 1, Number: 2, State: None, Title: "", Default: True, HasErrors: False
[14:26:12 INF] "FFprobe" : Type: "AudioInfo", Format: "pcm_u8", Codec: "PCM unsigned 8-bit", Language: "und", Id: 1, Number: 1, State: None, Title: "", Default: True, HasErrors: False
[14:26:12 INF] Sidecar created : State: None : "Augustus 2004 038.PlexCleaner"
[14:26:12 INF] Sidecar updated : State: ReMuxed, ReNamed : "Augustus 2004 038.PlexCleaner"
[14:26:12 ERR] Tool track count discrepency : "Augustus 2004 038.mkv"
[14:26:12 ERR] "Process" Error : "L:\\2004\\Augustus 2004 038.avi"
ptr727 commented 2 years ago

I can't get the AVI you sent to convert to H265 and AC3, the MJPEG video converts, but the PCM audio is not recognized after converting to AC3 or AAC.

Do try the develop branch I just pushed, you can build locally, I made some enhancements to try and help. Also add the codecs you want to reencode to the JSON config file if not already added.

I may not get it working 100% with AVI and all the many funky codecs.

ptr727 commented 2 years ago

Merged to main branch.