Skip to content

Commit

Permalink
Update load_video node for more accurate color conversion and chroma …
Browse files Browse the repository at this point in the history
…reconstruction (#2532)

* 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

* Update load_video.py

remove cv2 import as this is no longer needed.

* Format with ruff

---------

Co-authored-by: Joey Ballentine <[email protected]>
  • Loading branch information
mrjschulte and joeyballentine authored Jan 29, 2024
1 parent 7cce5ed commit 7499738
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from pathlib import Path
from typing import Any

import cv2
import ffmpeg
import numpy as np

Expand Down Expand Up @@ -68,7 +67,12 @@ 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)
)

Expand Down Expand Up @@ -123,7 +127,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

Expand Down

0 comments on commit 7499738

Please sign in to comment.