0

This piece of code works fine when run on the Spyder IDE, but crashes when I convert it to exe with auto-py-to-exe. I know it might be because I didn't explicetly include ffmpeg in my pytoexe config and so another user of my program that doesn't have ffmpeg installed might run intro problems, but it doesn't even work for me. When I comment out the try/except block, tt crashes and my way of debugging it has been with Windows events viewer, which doesn't give much details except this code 0xC0000409 (which I got some other time because I accessed indexes on an array that were not there) so I made the script print into a file, giving this error: 'NoneType' object has no attribute 'write'

try:
    ffmpeg_extract_subclip(required_video_file, clipStart , clipEnd)    
except Exception as e:
    with open('DEBUGGING.txt', 'a+') as f:
        f.writelines('\n EXCEPCION:\n'+str(e))
        f.close()

Doesn't make sense because ffmpeg_extract_subclip doesn't even have a write method, and the error is only caused by this lines, cause all the other ones are printed fine into my txt file. As I said, the clips are made successfully when I do it through my IDE, but stops working for some reason when I run the exe.

Edit: placing ffmpeg and ffprobe in the folder didn't solve it. Python version: 3.11

Kevin M.
  • 152
  • 2
  • 14
  • 1
    Try placing `ffmpeg.exe` and `ffprobe.exe` in the same folder of your exe file. In case you want us to try reproducing the problem, please post minimal code sample that is executable. Please also show how to do the conversion to exe using `auto-py-to-exe`. What is the Python version? What the version of MoviePy? What the version of auto-py-to-exe? Does the Python script use arguments (we can't see it from the code above)? `open('DEBUGGING.txt', 'a+')` crashes - make sure you have a write permission to the working folder (use `open('DEBUGGING2.txt', 'w'`) and try executing as Administrator). – Rotem Feb 03 '23 at 09:26

1 Answers1

0

I think I solved the problem, and the answer is related to this other post in stack overflow ffmpeg_extract_subclip function and moviepy string output error. The weird error that I got ('NoneType' object has no attribute 'write') was caused by ffmpeg, moviepy or any other library that writes to the console, and, as my app is windows based, it couldn't output the download procress so it crashed. I figured it out while using moviepy and cx freeze, as this method of converting py to exe also creates a console window and thus the text is shown there and it doesn't crash. I don't mind this console I guess but if you want the solution, it's mentioned in the previous question, either use ffmpeg directly, which didn't work for me, or redirect stdout momentarily, which I think it's the best solution but haven't tried it yet.

Edit: the solution that ultimately worked is this one Moviepy still prints a progress bar even after setting `verbose` to `False`, which is adding this parameters (verbose=False, logger=None) to the method write_videofile, and yes, it is using moviepy. I suspect you can do it using my original code, ffmpeg might have some similar settings, but I switched over to this one which brings the same functionality.

Kevin M.
  • 152
  • 2
  • 14