akai-katto / dandere2x

Dandere2x - Fast Waifu2x Video Upscaling.
https://www.reddit.com/r/Dandere2x/
GNU General Public License v3.0
1.42k stars 77 forks source link

Upscale job failures & errors on Fedora - Exception in thread, AssertionError #307

Open RooneyMcNibNug opened 2 months ago

RooneyMcNibNug commented 2 months ago

Hello,

I am running into issues when I start an upscale job for a video. OS I am using for this at the moment is Fedora 40. I have installed all dependencies.

user@user:~$ python --version
Python 3.12.3

Here is what I see when I start the "Upscale!":

(.test) user@user:~/Documents/dandere2x-3.7/src$ python3 main.py 
/home/user/Documents/dandere2x-3.7/src/dandere2x/dandere2xlib/wrappers/ffmpeg/ffmpeg.py:137: SyntaxWarning: invalid escape sequence '\d'
  frame_count = re.compile("\d{1,10}").findall(matched_regex)[0]
/home/user/Documents/dandere2x-3.7/src/dandere2x/dandere2x_service/core/waifu2x/abstract_upscaler.py:116: SyntaxWarning: invalid escape sequence '\.'
  """
version 3.6
root 2024-05-21 09:19:01,198 INFO     dandere2x_logger.py set_dandere2x_logger: Dandere2x Console Logger Set
Calling GUI start.
config file: singleprocess
config file: singleprocess
config file: singleprocess
root 2024-05-21 09:20:33,113 INFO     yaml_utils.py load_executable_paths_yaml: main_path option /home/user/.test/bin did not work, trying the next main_path option
root 2024-05-21 09:20:33,115 INFO     yaml_utils.py load_executable_paths_yaml: Main path /home/user/Documents/dandere2x-3.7/src loaded executable_paths.yaml successfully. 
attempting to make or clear /home/user/Documents/dandere2x-3.7/src/workspace/gui
clip.mp4 2024-05-21 09:20:33,413 INFO     dandere2x_logger.py set_dandere2x_logger: Dandere2x Console Logger Set
root 2024-05-21 09:20:33,413 INFO     yaml_utils.py load_executable_paths_yaml: main_path option /home/user/.test/bin did not work, trying the next main_path option
root 2024-05-21 09:20:33,414 INFO     yaml_utils.py load_executable_paths_yaml: Main path /home/user/Documents/dandere2x-3.7/src loaded executable_paths.yaml successfully. 
root 2024-05-21 09:20:33,415 INFO     yaml_utils.py load_executable_paths_yaml: main_path option /home/user/.test/bin did not work, trying the next main_path option
root 2024-05-21 09:20:33,415 INFO     yaml_utils.py load_executable_paths_yaml: Main path /home/user/Documents/dandere2x-3.7/src loaded executable_paths.yaml successfully. 
root 2024-05-21 09:20:33,415 INFO     ffprobe.py get_video_info: Loading video meta-data with ffprobe.. this might take a while.
root 2024-05-21 09:20:33,416 INFO     ffprobe.py get_video_info: Command: ['ffprobe', '-v', 'panic', '-print_format', 'json', '-show_format', '-show_streams', '-i', '/home/user/Videos/clip.mp4']
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib64/python3.12/threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "/home/user/Documents/dandere2x-3.7/src/dandere2x/__init__.py", line 57, in run
    self._root_service_thread.run()
  File "/home/user/Documents/dandere2x-3.7/src/dandere2x/dandere2x_service/service_types/singleprocess_service.py", line 60, in run
    self._pre_process()
  File "/home/user/Documents/dandere2x-3.7/src/dandere2x/dandere2x_service/service_types/singleprocess_service.py", line 57, in _pre_process
    self.dandere2x_service = Dandere2xServiceThread(service_request=self.child_request)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/dandere2x-3.7/src/dandere2x/dandere2x_service/__init__.py", line 67, in __init__
    self.context = Dandere2xServiceContext(service_request)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/dandere2x-3.7/src/dandere2x/dandere2x_service/dandere2x_service_context.py", line 59, in __init__
    video_settings = VideoSettings(ffprobe_dir=ffprobe_path, ffmpeg_dir=ffmpeg_path, video_file = self.service_request.input_file)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/dandere2x-3.7/src/dandere2x/dandere2xlib/wrappers/ffmpeg/videosettings.py", line 20, in __init__
    self.frame_count = int(get_frame_count_ffmpeg(ffmpeg_dir=self.ffmpeg_dir, input_video=video_file))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/Documents/dandere2x-3.7/src/dandere2x/dandere2xlib/wrappers/ffmpeg/ffmpeg.py", line 134, in get_frame_count_ffmpeg
    assert matched_regex
           ^^^^^^^^^^^^^
AssertionError

Looks like an issue with ffprobe module? Let me know if there is any other useful information I can provide, and thanks for your help.

RooneyMcNibNug commented 2 months ago

Went through with the exact same process with Arch just now and had the same results with a separate video.

To note: the pyyaml module could not be installed with the specific version in requirements.txt, so I just installed the latest version.

csjaugustus commented 1 week ago

I was having the exact same issue on Macbook M1. Seems to be an issue related to the function get_frame_count_ffmpeg in /dandere2x/src/dandere2x/dandere2xlib/wrappers/ffmpeg/ffmpeg.py trying to get frame count data from the video metadata, but such info does not exist in the retrieved metadata, so the regex match always gives an empty list.

Here is how I resolved it:

Step 1

In /dandere2x/src/dandere2x/dandere2xlib/wrappers/ffmpeg/ffmpeg.py, define a new function get_frame_count_ffprobe as follows:

def get_frame_count_ffprobe(ffmpeg_dir: str, input_video: str):
    assert get_operating_system() != "win32" or os.path.exists(ffmpeg_dir), "%s does not exist!" % ffmpeg_dir
    assert os.path.exists(input_video), "%s does not exist!" % input_video

    # Construct the ffprobe command
    ffprobe_cmd = [
        ffmpeg_dir.replace("ffmpeg", "ffprobe"),  # Replace ffmpeg path with ffprobe
        "-v", "error",
        "-count_frames",
        "-select_streams", "v:0",
        "-show_entries", "stream=nb_read_frames",
        "-print_format", "json",
        input_video
    ]

    # Run the ffprobe command
    process = subprocess.run(ffprobe_cmd, capture_output=True)
    stdout_as_str = process.stdout.decode("utf-8")

    # Debug prints to understand the ffprobe output
    print("FFprobe command executed:")
    print(" ".join(ffprobe_cmd))
    print("FFprobe command output:")
    print(stdout_as_str)

    # Parse the JSON output
    probe_data = json.loads(stdout_as_str)
    frame_count = int(probe_data['streams'][0]['nb_read_frames'])

    return frame_count

Also, somehow this script is using json but does not import it. So also do import json at the beginning of ffmpeg.py.

Step 2

In /dandere2x/src/dandere2x/dandere2xlib/wrappers/ffmpeg/videosettings.py, replace the function call as such:

        # self.frame_count = int(get_frame_count_ffmpeg(ffmpeg_dir=self.ffmpeg_dir, input_video=video_file))
        self.frame_count = int(get_frame_count_ffprobe(ffmpeg_dir=self.ffmpeg_dir, input_video=video_file))

I am still testing and unsure whether this whole thing will work perfectly but this definitely seems to have fixed this specific AssertionError.