python-video-silence-cutter
python-video-silence-cutter copied to clipboard
fix PermissionError in Windows
Related Issues: #6 #7
- [x] Run properly on Windows 11
- [x] Run properly on Ubuntu 22.04 (on WSL2)
I encountered an issue while running the script where temporary filter files were not being properly cleaned up, leading to a PermissionError. To resolve this, I made the following changes:
-
Prepare Filter Files with
delete=False:- Changed the creation of temporary files for video and audio filters to include the
delete=Falseparameter. This ensures that the files are not deleted immediately upon closure, allowing FFmpeg to access them properly.
vFile = tempfile.NamedTemporaryFile (mode="w", encoding="UTF-8", delete=False, prefix="silence_video") aFile = tempfile.NamedTemporaryFile (mode="w", encoding="UTF-8", delete=False, prefix="silence_audio") - Changed the creation of temporary files for video and audio filters to include the
-
Ensure FFmpeg Completes Execution:
- Added
check=Trueto thesubprocess.runcall to ensure that FFmpeg completes execution before the script proceeds. This helps in catching errors early and ensuring that the resources are properly released.
subprocess.run (command, check=True) - Added
-
Properly Remove Temporary Files:
- Explicitly removed the temporary files after FFmpeg completes execution to ensure proper cleanup of resources and avoid any
PermissionError.
os.remove(videoFilter_file) os.remove(audioFilter_file) - Explicitly removed the temporary files after FFmpeg completes execution to ensure proper cleanup of resources and avoid any
I didnt forget this, but the merge will take time :( 🙇