WyattBlue / auto-editor

Auto-Editor: Efficient media analysis and rendering
https://auto-editor.com
The Unlicense
2.81k stars 411 forks source link

Add check to not crash while opening and processing cache file #397

Closed sam-astro closed 9 months ago

sam-astro commented 10 months ago

Bug description

This has happened multiple times to me, where the process may have stopped or another problem occurred, and the cache file was written to with no content. Then, the next time the auto-editor is run, it obviously failed to decode it as json, because the file is blank. So the only way to fix it is by deleting the cache file manually in the /tmp/ directory. A very simple check could fix this, just seeing if the contents of the file is valid json (which in this case could be done by seeing if the file length is > 0)

What's your platform?

Python Version: 3.8.10 64-bit
Platform: Linux 5.15.90.1-microsoft-standard-WSL2 x86_64
FFmpeg Version: 4.2.7-0ubuntu0.1
FFmpeg Path: ffmpeg
Auto-Editor Version: 22w39a

What command did you use

auto-editor <any video>

What properties does your input video have?

(This does not apply, as it breaks for all videos, due to the nature of this bug)

Comments

No response

sam-astro commented 9 months ago

More specifically, this is the error it gives:

Debug: Temp Directory: /tmp/tmp2lryxod5
Traceback (most recent call last):
  File "/home/sam/.local/bin/auto-editor", line 8, in <module>
    sys.exit(main())
  File "/home/sam/.local/lib/python3.8/site-packages/auto_editor/__main__.py", line 391, in main
    edit_media(paths, ffmpeg, args, temp, log)
  File "/home/sam/.local/lib/python3.8/site-packages/auto_editor/edit.py", line 242, in edit_media
    timeline = make_timeline(
  File "/home/sam/.local/lib/python3.8/site-packages/auto_editor/timeline.py", line 99, in make_timeline
    chunks, vclips, aclips = make_layers(
  File "/home/sam/.local/lib/python3.8/site-packages/auto_editor/make_layers.py", line 144, in make_layers
    has_loud = get_has_loud(method, src, ensure, strict, tb, bar, temp, log)
  File "/home/sam/.local/lib/python3.8/site-packages/auto_editor/method.py", line 156, in get_has_loud
    audio_levels(ensure, inp, s, tb, bar, strict, temp, log),
  File "/home/sam/.local/lib/python3.8/site-packages/auto_editor/analyze.py", line 166, in audio_levels
    if (arr := read_cache(src, tb, "audio", {"stream": s}, temp)) is not None:
  File "/home/sam/.local/lib/python3.8/site-packages/auto_editor/analyze.py", line 103, in read_cache
    cache = json.load(file)
  File "/usr/lib/python3.8/json/__init__.py", line 293, in load
    return loads(fp.read(),
  File "/usr/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python3.8/json/decoder.py", line 340, in decode
    raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 19463006 (char 19463005)

And the solution to fix this issue is to delete the file /tmp/ae-22w39a/ for this version with the command:

sudo rm -r /tmp/ae-22w39a/
WyattBlue commented 9 months ago

You're using a release that's almost a year old. We don't even support Python 3.9 or ffmpeg 4 anymore.