Add zero-copy GPU encoding pipeline
- New GPUHLSOutput class for direct GPU-to-NVENC encoding - RGB→NV12 conversion via CUDA kernel (no CPU transfer) - Uses PyNvVideoCodec for zero-copy GPU encoding - ~220fps vs ~4fps with CPU pipe approach - Automatically used when PyNvVideoCodec is available Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -863,8 +863,14 @@ class StreamInterpreter:
|
||||
# Import output classes - handle both package and direct execution
|
||||
try:
|
||||
from .output import PipeOutput, DisplayOutput, FileOutput, HLSOutput, IPFSHLSOutput
|
||||
from .gpu_output import GPUHLSOutput, check_gpu_encode_available
|
||||
except ImportError:
|
||||
from output import PipeOutput, DisplayOutput, FileOutput, HLSOutput, IPFSHLSOutput
|
||||
try:
|
||||
from gpu_output import GPUHLSOutput, check_gpu_encode_available
|
||||
except ImportError:
|
||||
GPUHLSOutput = None
|
||||
check_gpu_encode_available = lambda: False
|
||||
|
||||
self._init()
|
||||
|
||||
@@ -909,8 +915,14 @@ class StreamInterpreter:
|
||||
hls_dir = output[:-9] # Remove /ipfs-hls suffix
|
||||
import os
|
||||
ipfs_gateway = os.environ.get("IPFS_GATEWAY_URL", "https://ipfs.io/ipfs")
|
||||
out = IPFSHLSOutput(hls_dir, size=(w, h), fps=fps, audio_source=audio, ipfs_gateway=ipfs_gateway,
|
||||
on_playlist_update=self.on_playlist_update)
|
||||
# Use GPU encoding if available (zero-copy, much faster)
|
||||
if GPUHLSOutput is not None and check_gpu_encode_available():
|
||||
print(f"[StreamInterpreter] Using GPU zero-copy encoding", file=sys.stderr)
|
||||
out = GPUHLSOutput(hls_dir, size=(w, h), fps=fps, audio_source=audio, ipfs_gateway=ipfs_gateway,
|
||||
on_playlist_update=self.on_playlist_update)
|
||||
else:
|
||||
out = IPFSHLSOutput(hls_dir, size=(w, h), fps=fps, audio_source=audio, ipfs_gateway=ipfs_gateway,
|
||||
on_playlist_update=self.on_playlist_update)
|
||||
else:
|
||||
out = FileOutput(output, size=(w, h), fps=fps, audio_source=audio)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user