python-video-silence-cutter icon indicating copy to clipboard operation
python-video-silence-cutter copied to clipboard

fix PermissionError in Windows

Open moon-jam opened this issue 1 year ago • 1 comments

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:

  1. Prepare Filter Files with delete=False:

    • Changed the creation of temporary files for video and audio filters to include the delete=False parameter. 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")
    
  2. Ensure FFmpeg Completes Execution:

    • Added check=True to the subprocess.run call 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)
    
  3. 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)
    

moon-jam avatar Jul 01 '24 11:07 moon-jam

I didnt forget this, but the merge will take time :( 🙇

DarkTrick avatar Oct 20 '24 23:10 DarkTrick