mlsmithjr / transcoder

Python wrapper for ffmpeg for batch and/or concurrent transcoding
GNU General Public License v3.0
117 stars 25 forks source link

Division by zero error #1

Closed vpatel9202 closed 5 years ago

vpatel9202 commented 5 years ago

The MediaInfo class doesn't seem to be properly reading video runtimes for any of my files and I'm not sure why. Here's the source video I'm using: http://jell.yfish.us/media/jellyfish-30-mbps-hd-h264.mkv

The testing profile I have setup is as follows:

x264:
  input_options:
  output_options: |
    -c:v libx264
    -profile:v high
    -level:v 4.1
    -crf 18
    -movflags +faststart
    -c:a aac
    -f mp4
  extension: '.mp4'

Now if I run the same command on the same video by using ffmpeg directly, it works fine and the resulting video is as it should be given the parameters. Pytranscoder, on the other hand, creates the [video].mp4.tmp file and seems to be working as the filesize increases over time, but it gets cut short when the progress calculation fails with a dividing by zero error. Here's the error message:

Exception in thread _default_:
Traceback (most recent call last):
   File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
     self.run()
   File "/home/transcoder/.local/lib/python3.6/site-packages/pytranscoder/transcode.py", line 68, in run
     self.go()
   File "/home/transcoder/.local/lib/python3.6/site-packages/pytranscoder/transcode.py", line 116, in go
     code = self.ffmpeg.run(cli, log_callback)
   File "/home/transcoder/.local/lib/python3.6/site-packages/pytranscoder/ffmpeg.py", line 84, in run
     veto = event_callback(stats)
   File "/home/transcoder/.local/lib/python3.6/site-packages/pytranscoder/transcode.py", line 106, in log_callback
     pct_done, pct_comp = calculate_progress(job.info, stats)
   File "/home/transcoder/.local/lib/python3.6/site-packages/pytranscoder/utils.py", line 43, in calculate_progress
     pct_done = int((stats['time'] / info.runtime) * 100)
 ZeroDivisionError: division by zero

Thinking it could be the .tmp extension throwing it off, I edited line 84 in transcode.py from "outpath = job.inpath.with_suffix(job.profile.extension + '.tmp')" to "outpath = job.inpath.with_suffix(job.profile.extension)".

That didn't seem to do anything, as expected. I'm not sure why it's having trouble reading duration--any help?

FYI, here's the FFMPEG command for easier reading:

ffmpeg -y -i /home/transcoder/shared/test_file.mkv -c:v libx264 -profile:v high -level:v 4.1 -crf 18 -movflags +faststart -c:a aac -f mp4 /home/transcoder/shared/test_file.mp4.tmp
vpatel9202 commented 5 years ago

I changed line 43 to ignore info.runtime if it is less than or equal to 0 as a test to see if that was the only issue, and it seemed work fine:

def calculate_progress(info: MediaInfo, stats: Dict) -> (int, int):
    if info.runtime <= 0:
        pct_done = 0
    else:
        pct_done = int((stats['time'] / info.runtime) * 100)

Of course, this means that it just reports conversion progress at 0% all the time until it's finished, but at least the conversion completes without error.

I don't really understand how MediaInfo works so I haven't figured out why it's not properly reading runtime, but at least as a quick hack, this seems to circumvent the issue.

mlsmithjr commented 5 years ago

Thanks for the report. I'm only parsing out whole minutes so that's why your 30 second video shows a runtime of zero. I'll made adjustments to compensate.

On Sun, May 5, 2019 at 12:16 AM Vash Patel notifications@github.com wrote:

The MediaInfo class doesn't seem to be properly reading video runtimes for any of my files and I'm not sure why. Here's the source video I'm using: http://jell.yfish.us/media/jellyfish-30-mbps-hd-h264.mkv

The testing profile I have setup is as follows:

x264: input_options: output_options: | -c:v libx264 -profile:v high -level:v 4.1 -crf 18 -movflags +faststart -c:a aac -f mp4 extension: '.mp4'

Now if I run the same command on the same video by using ffmpeg directly, it works fine and the resulting video is as it should be given the parameters. Pytranscoder, on the other hand, creates the [video].mp4.tmp file and seems to be working as the filesize increases over time, but it gets cut short when the progress calculation fails with a dividing by zero error. Here's the error message:

Exception in thread default: Traceback (most recent call last): File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner self.run() File "/home/transcoder/.local/lib/python3.6/site-packages/pytranscoder/transcode.py", line 68, in run self.go() File "/home/transcoder/.local/lib/python3.6/site-packages/pytranscoder/transcode.py", line 116, in go code = self.ffmpeg.run(cli, log_callback) File "/home/transcoder/.local/lib/python3.6/site-packages/pytranscoder/ffmpeg.py", line 84, in run veto = event_callback(stats) File "/home/transcoder/.local/lib/python3.6/site-packages/pytranscoder/transcode.py", line 106, in log_callback pct_done, pct_comp = calculate_progress(job.info, stats) File "/home/transcoder/.local/lib/python3.6/site-packages/pytranscoder/utils.py", line 43, in calculate_progress pct_done = int((stats['time'] / info.runtime) * 100) ZeroDivisionError: division by zero

Thinking it could be the .tmp extension throwing it off, I edited line 84 in transcode.py https://github.com/mlsmithjr/transcoder/blob/af3614efc26d86ca902a2e438f489e2dbb12af6d/pytranscoder/transcode.py#L84 from "outpath = job.inpath.with_suffix(job.profile.extension + '.tmp')" to "outpath = job.inpath.with_suffix(job.profile.extension)".

That didn't seem to do anything, as expected. I'm not sure why it's having trouble reading duration--any help?

FYI, here's the FFMPEG command for easier reading:

ffmpeg -y -i /home/transcoder/shared/test_file.mkv -c:v libx264 -profile:v high -level:v 4.1 -crf 18 -movflags +faststart -c:a aac -f mp4 /home/transcoder/shared/test_file.mp4.tmp

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/mlsmithjr/transcoder/issues/1, or mute the thread https://github.com/notifications/unsubscribe-auth/AAHRMTBZJOMQ2ZIL2ZO23B3PTZNQZANCNFSM4HK2KHJA .