From 4e29169e4668f46797f2083707c45f5c9a0e90da Mon Sep 17 00:00:00 2001 From: MrJs <30782821+mrjschulte@users.noreply.github.com> Date: Sun, 28 Jan 2024 14:28:54 -0800 Subject: [PATCH 1/3] Update load_video.py for more accurate color conversion and chroma reconstruction This PR updates the ffmpeg based load_video node to use a more accurate color decoding and chroma reconstruction path. This node now uses lanczos filtering by default and also skips the previously present extra conversion from rgb24 to bgr24 by having ffmpeg send a bgr24 rawvideo pipe natively to chaiNNer --- .../chaiNNer_standard/image/video_frames/load_video.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/packages/chaiNNer_standard/image/video_frames/load_video.py b/backend/src/packages/chaiNNer_standard/image/video_frames/load_video.py index 1781617f4..ae8b27f00 100644 --- a/backend/src/packages/chaiNNer_standard/image/video_frames/load_video.py +++ b/backend/src/packages/chaiNNer_standard/image/video_frames/load_video.py @@ -68,7 +68,7 @@ def load_video_node( ffmpeg_reader = ( ffmpeg.input(path) - .output("pipe:", format="rawvideo", pix_fmt="rgb24") + .output("pipe:", format="rawvideo", pix_fmt="bgr24", sws_flags="lanczos+accurate_rnd+full_chroma_int+full_chroma_inp+bitexact") .run_async(pipe_stdout=True, cmd=ffmpeg_path) ) @@ -123,7 +123,6 @@ def iterator(): print("Can't receive frame (stream end?). Exiting ...") break in_frame = np.frombuffer(in_bytes, np.uint8).reshape([height, width, 3]) - in_frame = cv2.cvtColor(in_frame, cv2.COLOR_RGB2BGR) yield in_frame, index index += 1 From 50d7a4572cbfea8f79bc0fbf545ace29ccb39eab Mon Sep 17 00:00:00 2001 From: MrJs <30782821+mrjschulte@users.noreply.github.com> Date: Sun, 28 Jan 2024 19:31:54 -0800 Subject: [PATCH 2/3] Update load_video.py remove cv2 import as this is no longer needed. --- .../packages/chaiNNer_standard/image/video_frames/load_video.py | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/packages/chaiNNer_standard/image/video_frames/load_video.py b/backend/src/packages/chaiNNer_standard/image/video_frames/load_video.py index ae8b27f00..6f51ccec4 100644 --- a/backend/src/packages/chaiNNer_standard/image/video_frames/load_video.py +++ b/backend/src/packages/chaiNNer_standard/image/video_frames/load_video.py @@ -4,7 +4,6 @@ from pathlib import Path from typing import Any -import cv2 import ffmpeg import numpy as np From efb9883ab692c3c7020cf9614082551bbe907289 Mon Sep 17 00:00:00 2001 From: Joey Ballentine Date: Sun, 28 Jan 2024 22:57:08 -0500 Subject: [PATCH 3/3] Format with ruff --- .../chaiNNer_standard/image/video_frames/load_video.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backend/src/packages/chaiNNer_standard/image/video_frames/load_video.py b/backend/src/packages/chaiNNer_standard/image/video_frames/load_video.py index 6f51ccec4..4b51ddd26 100644 --- a/backend/src/packages/chaiNNer_standard/image/video_frames/load_video.py +++ b/backend/src/packages/chaiNNer_standard/image/video_frames/load_video.py @@ -67,7 +67,12 @@ def load_video_node( ffmpeg_reader = ( ffmpeg.input(path) - .output("pipe:", format="rawvideo", pix_fmt="bgr24", sws_flags="lanczos+accurate_rnd+full_chroma_int+full_chroma_inp+bitexact") + .output( + "pipe:", + format="rawvideo", + pix_fmt="bgr24", + sws_flags="lanczos+accurate_rnd+full_chroma_int+full_chroma_inp+bitexact", + ) .run_async(pipe_stdout=True, cmd=ffmpeg_path) )