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

How to catch errors using split_video functions? #209

Closed
AdrienLF opened this issue Mar 1, 2021 · 6 comments
Closed

How to catch errors using split_video functions? #209

AdrienLF opened this issue Mar 1, 2021 · 6 comments
Milestone

Comments

@AdrienLF
Copy link

AdrienLF commented Mar 1, 2021

Hi,
I'm trying to use CUDA with video_splitter.split_video_ffmpeg. It works well for most videos, however some codecs don't play well with this. So I try to catch it with an error, like so:

try:
    video_splitter.split_video_ffmpeg([video], scene_list, str(final_destination) + os.sep + video_name + " " + -$SCENE_NUMBER" + PurePath(video).suffix, video, arg_override="-c:v h264_nvenc", suppress_output=True, hide_progress=False)
except Exception as e:
    print(e)
    video_splitter.split_video_ffmpeg([video], scene_list, str(final_destination) + os.sep + video_name + " " + "-$SCENE_NUMBER" + PurePath(video).suffix, video, suppress_output=True, hide_progress=False)

It does display the error however, it doesn't register as one, and therefore doesn't trigger the exception. Is there a way to trigger it? I'm not great with exception handling in python.

Thank you!

@Breakthrough
Copy link
Owner

Breakthrough commented Mar 2, 2021

Hey @AdrienLF;

This typically won't result in an exception, since those functions invoke ffmpeg via subprocess.call(), which requires examining the return value or the string output obtained via the command.

Right now the split video functions don't return anything, but it should be pretty easy to modify it to return the error code / return value from invoking ffmpeg (right now it just calls a logging statement at the bottom of video_splitter.py, but you could instead just add return ret_val).

Does this help?

@Breakthrough
Copy link
Owner

Could you also provide an example of the output you get for both cases? Are there any samples you can share?

@AdrienLF
Copy link
Author

AdrienLF commented Mar 2, 2021

The error I get is when I try to process PRORES with h264_nvenc.

0%| | 0/1386 [00:00<?, ?frame/s]root INFO Average processing speed 2684.29 frames/sec. root ERROR Error splitting video (ffmpeg returned 1).

It then continues with the code without raising an exception. I would prefer that it tries again without the arg override (which works correctly).

I'll try to modify the function to return ret_val, and I think in general it would be nice to be able to catch exceptions when PySceneDetect is used in a larger app.

Thanks!

@AdrienLF
Copy link
Author

AdrienLF commented Mar 2, 2021

Here's how I solved it, after modifying the function to return ret_val

ret_val = split_video_ffmpeg([video], scene_list, str(final_destination) + os.sep + video_name + " " + "-$SCENE_NUMBER" + PurePath(video).suffix, video, arg_override="-c:v h264_nvenc", suppress_output=True, hide_progress=False)
print(ret_val)
if ret_val ==1:
	print("Retrying splitting video")
	split_video_ffmpeg([video], scene_list, str(final_destination) + os.sep + video_name + " " + "-$SCENE_NUMBER" + PurePath(video).suffix, video, suppress_output=True, hide_progress=False)

Interestingly it prints before displaying the error, but it works in the end:

1
Retrying splitting video
root             ERROR    Error splitting video (ffmpeg returned 1).
root             INFO     Splitting input video using ffmpeg, output path template:
 ...Montage part1 PRORES -$SCENE_NUMBER.mov

@Breakthrough
Copy link
Owner

Breakthrough commented Mar 4, 2021

These functions definitely could use some API work. I'll mark this as an improvement, and set it so that the split_video functions return the last exit code rather than nothing.

Note that the logger defaults to stderr right now (so the output you show is definitely possible), but as part of #205 it will likely be changed to stdout for info/debug statements. After #205, those functions also won't display any output when suppress_output=True making them more suitable for integration in other applications.

@Breakthrough Breakthrough changed the title How to catch errors? How to catch errors using split_video functions? Mar 4, 2021
@Breakthrough Breakthrough added this to the v0.5.6 milestone Mar 4, 2021
Breakthrough added a commit that referenced this issue Mar 4, 2021
@Breakthrough
Copy link
Owner

Breakthrough commented Mar 4, 2021

Completed in v0.5.6 branch (see 4e53915).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants