Closed GeertvanHorrik closed 4 years ago
I installed / purchased the correct extensions in the store.
Please share the OS version, command line, and exception details.
I tried catching the exception, but the whole powershell host crashes (so not sure how to get the exception message since the host console disappears).
Command line:
.\ConvertTo-jpg.ps1 "c:\users\some path with spaces\some file\something.heic"
This script tries to catch and display any managed-code exceptions that occur while running. If something is bypassing that and/or crashing PowerShell, maybe there’s an issue with the codec or Windows configuration. Have you tried opening that image in Windows Photo viewer? Or converting it on another machine?
I can open it fine in the Photos app. Maybe I will investigate this by converting it to a C# (UWP) console app tomorrow to see why it crashes.
Great idea!
On my laptop with vs 2019, it works (as UWP). Testing script alone on this laptop.
Says "unsupported", let me check if I need the codec on this laptop as well (not only the photo viewer extension).
Also installing HEVC Video Extensions from the store.
Here are the exception details in powershell:
System.Management.Automation.MethodInvocationException: Exception calling "Wait" with "0" argument(s): "One or more errors occurred." ---> System.AggregateException: One or more errors occurred. ---> System.ArgumentException: Value does not fall within the expected range.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at CallSite.Target(Closure , CallSite , Object )
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
Looks like a completely different error on this laptop, this is the code:
try
{
# Get SoftwareBitmap from input file
Write-Host 1
$inputFile = AwaitOperation ([Windows.Storage.StorageFile]::GetFileFromPathAsync($file)) ([Windows.Storage.StorageFile])
Write-Host 2
$inputFolder = AwaitOperation ($inputFile.GetParentAsync()) ([Windows.Storage.StorageFolder])
Write-Host 3
$inputStream = AwaitOperation ($inputFile.OpenReadAsync()) ([Windows.Storage.Streams.IRandomAccessStreamWithContentType])
Write-Host 4
$decoder = AwaitOperation ([Windows.Graphics.Imaging.BitmapDecoder]::CreateAsync($inputStream)) ([Windows.Graphics.Imaging.BitmapDecoder])
Write-Host 5
}
catch
{
# Ignore non-image files
Write-Host " [Unsupported]"
Write-Host $_.Exception
continue
}
Output is:
1
[Unsupported]
System.Management.Automation.MethodInvocationException: Exception calling "Wait" with "0" argument(s): "One or more errors occurred." ---> System.AggregateException: One or more errors occurred. ---> System.ArgumentException: Value does not fall within the expected range.
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at CallSite.Target(Closure , CallSite , Object )
--- End of inner exception stack trace ---
at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
at System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
On my other machine it gets to 4...
Failing after 1 above is weird - StorageFile is built-in and has nothing to do with the extra codecs. Maybe this is a Windows 1903 problem? (I know of other .NET scenarios they broke from similar reports.) If so, I’ll find out after I upgrade because I use this script every week. Until then, sorry for the trouble! Nobody else has reported this issue so far.
No problem at all, just wanted to report this. I am using CopyTrans HEIC for Windows at the moment, which you can also call as command line.
I needed it because I was working on a video / photo diary (see https://github.com/GeertvanHorrik/DiaryGenerator). Maybe in the future, if this script works again, I will replace it again. Would save another dependency users will have to install at the moment.
The issue of failing after step 1 should be fixed by https://github.com/DavidAnson/ConvertTo-Jpeg/commit/db8f7d0fd6b448c85ca6098ce2fff341bfc0e17e.
Been trying this out, but it crashes. Been debugging a bit, looks like this part is the culprit:
Will try to investigate further.