Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeroDivisionError when percentage completion is zero #6

Open
rpanderson opened this issue Aug 9, 2020 · 1 comment
Open

ZeroDivisionError when percentage completion is zero #6

rpanderson opened this issue Aug 9, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@rpanderson
Copy link
Collaborator

ffmpeg:silencedetect and ffmpeg:filter_complex_script are both prone to raising ZeroDivisionError when computing time_remaining. This occurs because percentage can be zero when hhmmssd_to_seconds returns zero.

Example:

C:\Users\rpanderson\Videos> autoscrub autoprocess input.mp4 output.mp4
[autoscrub:info] Processing systems3.mp4
[ffprobe] Getting audio sample rate...
[ffmpeg:ebur128] Checking loudness of file...
[autoscrub:info] Measured loudness = -16.3 dBLUFS; Silence threshold = -16.3 dB; Gain to apply = -1.7 dB
[ffmpeg:silencedetect] Searching for silence...
[ffmpeg:silencedetect] Completed in 00:00:25
[autoscrub:info] Found 119 silences of average duration 3.7 seconds.
[autoscrub:info] Generating ffmpeg filter_complex script...
[autoscrub:info] autoscrubbing video
Traceback (most recent call last):
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.8_3.8.1520.0_x64__qbz5n2kfra8p0\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "C:\Users\rpanderson\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\Scripts\autoscrub.exe\__main__.py", line 7, in <module>
  File "C:\Users\rpanderson\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\click\core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "C:\Users\rpanderson\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\click\core.py", line 717, in main
    rv = self.invoke(ctx)
  File "C:\Users\rpanderson\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\click\core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Users\rpanderson\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\click\core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Users\rpanderson\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\click\core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "C:\Users\rpanderson\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\autoscrub\scripts\cli.py", line 276, in autoprocess
    result = autoscrub.ffmpegComplexFilter(input, filter_graph_path, output, run_command=True, overwrite=True, stderr_callback=callback)
  File "C:\Users\rpanderson\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\autoscrub\__init__.py", line 1107, in ffmpegComplexFilter
    stdout, stderr = _agnostic_communicate(p, new_line_callback=stderr_callback)
  File "C:\Users\rpanderson\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\autoscrub\__init__.py", line 185, in _agnostic_communicate
    new_line_callback(local_buffer)
  File "C:\Users\rpanderson\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\autoscrub\scripts\cli.py", line 100, in new_line_callback
    time_remaining = (time.time()-self.start_time)/percentage*(100-percentage)
ZeroDivisionError: float division by zero
@rpanderson rpanderson added the bug Something isn't working label Aug 9, 2020
rpanderson added a commit that referenced this issue Aug 9, 2020
@Murilo-Perrone
Copy link

Getting same error here. Checking the code, it will crash whenever seconds is zero or seconds >= duration, since that will result percentage being 0 or 100.

    percentage = min(float(seconds)/self.duration, 1)*100
    time_remaining = (time.time()-self.start_time)/percentage*(100-percentage)

The fix commited by @rpanderson seems to handle the avoid zero crash, but it's in a branch and a new version hasn't been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants