System.UnauthorizedAccessException: Access to the path is denied even with admin's right
MickaelBNeron opened this issue · 4 comments
When launched from my repos' /bin/debug/ folder, my application is able to create videos properly using FFMpegCore.
However, when launched from an a version of my app created via an installer, I get the following error even if the app is launched with administrator's rights:
_System.UnauthorizedAccessException: Access to the path 'C:\Users\Mickael\Videos\PATIENT_M_60y_90kg_175cm_2023_08_02 13.mp4' is denied.
at System.IO._Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalDelete(String path, Boolean checkHost)
at System.IO.File.Delete(String path)
at Redacted.Common.Gui.Wpf.ViewModels.ReplayExportViewModel.d__117.MoveNext()
To be clear, mu program doesn't call File.Delete. It looks like FFMpegCore calls it after producing the final frame. Here's basically what I have, where CreateVideoFrames uses deferred execution to produce IVideoFrame using yield return new BitmapVideoFrameWrapper(bitmap); (and these bitmaps only exists in memory. They are not saved on disk).
var videoFrames = CreateVideoFrames();
var pipeSource = new RawVideoPipeSource(videoFrames) {
FrameRate = FPS,
};
FFMpegArguments
.FromPipeInput(pipeSource)
.OutputToFile(VideoFileName, true, options => options
.WithVideoCodec("libxvid")
.WithCustomArgument("-an") // No audio
.WithCustomArgument("-q:v 0")) // -q:v sets the quality of the video stream. Lower values gives higher quality.
.NotifyOnError(Log.Info) // It appears that NotifyOnError gets triggered for things that aren't errors. For instance, NotifyOnError gets triggered every three frames with a content that looks like normal information as opposed to an error.
.NotifyOnOutput(Log.Info)
.ProcessSynchronously();
Been awhile since I really dug into the internals, but I think ffmpeg needs to create a temporary directory in order to perform at least some transformations/actions. I can see that being an issue if the executing user doesn't have delete permissions for the executing directory (which propagates to any created directories, if memory serves), or if ffmpeg has to abort and can't do so cleanly - you'll get this error if a directory or one of it's file is still open when trying to delete it.
Kinda looks like you're using Serilog? Is that logging an error of any sort?
I assume you know most of this, but seemed worth mentioning.
Yeah, it's a error (I think it's FFMpegCore that logs it, since I specified .NotifyOnError(Log.Info).
Thanks for your input. Looks like I'll have to navigate permissions somehow if it's not possible to have FFMpegCore call ffmpeg.exe with admin rights or something (not sure that's even possible. I don't know much how perms work).
Yeah, it's a error (I think it's FFMpegCore that logs it, since I specified .NotifyOnError(Log.Info).
Thanks for your input. Looks like I'll have to navigate permissions somehow if it's not possible to have FFMpegCore call ffmpeg.exe with admin rights or something (not sure that's even possible. I don't know much how perms work).
It's 100% possible that I'm completely wrong, but it seems like its a folder/directory permissions issue, given that running it from a debug folder (for which your user has full control) works.
Does installing the app as Administrator work (not too familiar with ClickOnce, but I imagine if you're using that then you're installing it as an administrator)?
I'll have to check that. I've been tasked with something else (on tablets, which is the target device for the app, the issue doesn't come up, so it's sadly given a low priority), but when I can get to it, I'll check to modify the installer (written with WIX Toolset for what it's worth) to install as admin.
However, I'm not sure it'll actually fix the issue, since I can save to C:\Users\Mickael, but I can't to C:\Users\Mickael\Videos, while these paths aren't related to the installation folder... But then again, who knows... There could be things going on under the hood (when installing as admin) that would fix it, so still worth trying.