zackmawaldi / YouTube-shorts-generator

Automatically download Reddit videos, edit them, and upload them to YouTube.
MIT License
323 stars 62 forks source link

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

Closed VectrorX closed 1 year ago

VectrorX commented 2 years ago

Traceback (most recent call last): File "X:\YouTube-shorts-generator\main.py", line 36, in r.render(directory, "main_clip.mp4", "output.mp4", config.video['dimensions']) File "X:\YouTube-shorts-generator\render.py", line 27, in render os.rename(directory + "main_clip.mp4", directory + "output.mp4") PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'temp_clips/main_clip.mp4' -> 'temp_clips/output.mp4'

zackmawaldi commented 2 years ago

Hmm, looks to be a permission error. It's saying that main_clip.mp4 is being used somewhere else on PC.

Obvious question is that is the file open somewhere? Less obvious, it might be some sort of error involving windows. I wrote the this on Mac.

Check out: https://github.com/Belval/pdf2image/issues/151 https://stackoverflow.com/questions/27215462/permissionerror-winerror-32-the-process-cannot-access-the-file-because-it-is

If you're coding inclined, try modifying your local script to do the following: The point of os.rename(directory + "main_clip.mp4", directory + "output.mp4") (line 27) in render.py is to rename the main_clip.mp4 to output.mp4 so that it can be picked up by last line in main.py (the line that uploads to YT). You can try to replacing line 27 in render to nothing, so...

render.py (line 27 is removed)

    if 0.56 < ratio < 0.565:
        print(f"clip is very close to 9:16!\n"
              f"exact: {ratio}\n"
              f"theoretical: 0.5625")
        return 1

main.py (last lines)

render_result = r.render(directory, "main_clip.mp4", "output.mp4", config.video['dimensions'])

if render_result == 1:
    yt.upload2YT(directory + "main_clip.mp4", config.youtube)
elif render_result == 0:
    yt.upload2YT(directory + "output.mp4", config.youtube)

Kinda jank, but I think it should work.

Let me know if you found a fix! Zack.

VectrorX commented 2 years ago

Wait, render use is to upload to yt? I tried to detach the upload to yt feature so i can do it manually, feels better for me this way.

Also there seems to be problem with deleting temp files, program don't have permissions to delete them, even with admin cmd, folder read-only off and permission changed.

zackmawaldi commented 2 years ago

Yup. So in render.py, it first checks if raw video from reddit is 9:16 (vertical phone format). If yes, then it only renames the raw clip from reddit to output.mp4 to indicate it's ready for uploading. If not, it renders a new clip by reformatting the size to 9:16 format (or the size given in config.py file).

I know comments and documentation is little lacking. Kinda wrote this and moved on, so sorry if it's a little hard to understand.

If you want to just get an output video file, then remove yt.uplaod line from main.py (should be last lines).

In terms of permissions, try to googling it. It seems like a common issue with windows and python scripts.

Good luck!!

xEPIx commented 1 year ago

easier solution is running the script using IDLE shell as administrator, solved.