ArdenButterfield / stammer

Recreate any audio track by rearranging the frames of another video
MIT License
443 stars 31 forks source link

The process cannot access the file because it is being used by another process #89

Closed PatoFlamejanteTV closed 1 month ago

PatoFlamejanteTV commented 2 months ago

Hi, I recently tried to use this tool, but all I get is this error: "The process cannot access the file because it is being used by another process". I had used it more than once before, and it had worked, but for some reason, it is no longer working.

C:\Users\mcmco\stammer>python stammer.py "C:\Users\mcmco\stammer\To The Bone.mp4" C:\Users\mcmco\stammer\PapyBass.mp3 papbass.mp4
Calculating video length
Separating video frames
frame= 6981 fps= 43 q=-0.0 Lsize=N/A time=00:04:50.87 bitrate=N/A dup=0 drop=114 speed= 1.8x
reading audio
analyzing audio
creating output audio
building output video
Traceback (most recent call last):
  File "C:\Users\mcmco\stammer\stammer.py", line 303, in main
    process(**vars(args))
  File "C:\Users\mcmco\stammer\stammer.py", line 263, in process
    build_output_video(handler, matcher)
  File "C:\Users\mcmco\stammer\stammer.py", line 144, in build_output_video
    video_handler.write_frame(video_frame_i,video_handler.get_frame(carrier_video_frame))
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mcmco\stammer\video_out.py", line 122, in get_frame
    return open(self.frames_dir / f"frame{idx:06d}.png", 'rb')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\mcmco\\AppData\\Local\\Temp\\tmpj2c17ldl\\frames\\frame007044.png'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python312\Lib\shutil.py", line 633, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\mcmco\\AppData\\Local\\Temp\\tmpj2c17ldl\\out.wav'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\mcmco\stammer\stammer.py", line 307, in <module>
    main()
  File "C:\Users\mcmco\stammer\stammer.py", line 300, in main
    with tempfile.TemporaryDirectory() as tempdir:
  File "C:\Python312\Lib\tempfile.py", line 946, in __exit__
    self.cleanup()
  File "C:\Python312\Lib\tempfile.py", line 950, in cleanup
    self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)
  File "C:\Python312\Lib\tempfile.py", line 930, in _rmtree
    _shutil.rmtree(name, onexc=onexc)
  File "C:\Python312\Lib\shutil.py", line 781, in rmtree
    return _rmtree_unsafe(path, onexc)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\shutil.py", line 635, in _rmtree_unsafe
    onexc(os.unlink, fullname, err)
  File "C:\Python312\Lib\tempfile.py", line 905, in onexc
    _os.unlink(path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\mcmco\\AppData\\Local\\Temp\\tmpj2c17ldl\\out.wav'
PatoFlamejanteTV commented 2 months ago

Same issue, but now, all the files are in the same folder:

C:\Users\mcmco\Downloads\stammer-main>python stammer.py bone.mp4 PapyBass.mp3 papbass.mp4
Calculating video length
Separating video frames
frame= 6981 fps= 37 q=-0.0 Lsize=N/A time=00:04:50.87 bitrate=N/A dup=0 drop=114 speed=1.54x
reading audio
analyzing audio
creating output audio
building output video
Traceback (most recent call last):
  File "C:\Users\mcmco\Downloads\stammer-main\stammer.py", line 303, in main
    process(**vars(args))
  File "C:\Users\mcmco\Downloads\stammer-main\stammer.py", line 263, in process
    build_output_video(handler, matcher)
  File "C:\Users\mcmco\Downloads\stammer-main\stammer.py", line 144, in build_output_video
    video_handler.write_frame(video_frame_i,video_handler.get_frame(carrier_video_frame))
                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mcmco\Downloads\stammer-main\video_out.py", line 122, in get_frame
    return open(self.frames_dir / f"frame{idx:06d}.png", 'rb')
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\mcmco\\AppData\\Local\\Temp\\tmp0ia7tnc_\\frames\\frame007044.png'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python312\Lib\shutil.py", line 633, in _rmtree_unsafe
    os.unlink(fullname)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\mcmco\\AppData\\Local\\Temp\\tmp0ia7tnc_\\out.wav'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\mcmco\Downloads\stammer-main\stammer.py", line 307, in <module>
    main()
  File "C:\Users\mcmco\Downloads\stammer-main\stammer.py", line 300, in main
    with tempfile.TemporaryDirectory() as tempdir:
  File "C:\Python312\Lib\tempfile.py", line 946, in __exit__
    self.cleanup()
  File "C:\Python312\Lib\tempfile.py", line 950, in cleanup
    self._rmtree(self.name, ignore_errors=self._ignore_cleanup_errors)
  File "C:\Python312\Lib\tempfile.py", line 930, in _rmtree
    _shutil.rmtree(name, onexc=onexc)
  File "C:\Python312\Lib\shutil.py", line 781, in rmtree
    return _rmtree_unsafe(path, onexc)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Python312\Lib\shutil.py", line 635, in _rmtree_unsafe
    onexc(os.unlink, fullname, err)
  File "C:\Python312\Lib\tempfile.py", line 905, in onexc
    _os.unlink(path)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'C:\\Users\\mcmco\\AppData\\Local\\Temp\\tmp0ia7tnc_\\out.wav'
Firepal commented 1 month ago

That's new, never seen that before I believe.

Idea 1: Perhaps some kind of antivirus is looking at temporary folders? In the Resource Monitor under Disk, you can see what programs are using what file.

Idea 2: This is a long shot, but it sounds like you've ran out of space trying to use stammer; stammer extracts all frames of the video to disk by default. If you have the RAM to spare, try using stammer in mem_decay mode with -vm mem_decay -mcf 5. That will make stammer read the video on-demand as frames are needed and will only use your disk space for audio, which is not too big.

Also, tell me your Python version python --version.

PatoFlamejanteTV commented 1 month ago

That's new, never seen that before I believe.

Idea 1: Perhaps some kind of antivirus is looking at temporary folders? In the Resource Monitor under Disk, you can see what programs are using what file.

Idea 2: This is a long shot, but it sounds like you've ran out of space trying to use stammer; stammer extracts all frames of the video to disk by default. If you have the RAM to spare, try using stammer in mem_decay mode with -vm mem_decay -mcf 5. That will make stammer read the video on-demand as frames are needed and will only use your disk space for audio, which is not too big.

Also, tell me your Python version python --version.

I accidentally ended up "fixing" this, probably the video was too big and caused this problem, for some reason only that video was causing this problem.

My current python version is: 3.12.5

I was not using an Antivirus, i was just using Windows Defender, NextDNS, UBOrigin, but NextDNS is just an DNS-over-HTTP thing and just "filters" HTTP requests, and UBO is just for browsers.

Firepal commented 1 month ago

Yeah. I recommend you use mem_decay when the carrier is high-quality/very long