PyNvVideoCodec 2.2.1__cp314-cp314-win_arm64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- PyNvVideoCodec/PyNvVideoCodec_121.cp314-win_arm64.pyd +0 -0
- PyNvVideoCodec/PyNvVideoCodec_130.cp314-win_arm64.pyd +0 -0
- PyNvVideoCodec/VersionCheck.cp314-win_arm64.pyd +0 -0
- PyNvVideoCodec/__init__.py +251 -0
- PyNvVideoCodec/avformat-62.dll +0 -0
- PyNvVideoCodec/avutil-60.dll +0 -0
- PyNvVideoCodec/decoders/SimpleDecoder.py +273 -0
- PyNvVideoCodec/decoders/ThreadedDecoder.py +129 -0
- PyNvVideoCodec/decoders/__init__.py +22 -0
- PyNvVideoCodec/transcoder/Transcoder.py +55 -0
- PyNvVideoCodec/transcoder/__init__.py +22 -0
- benchmarks/cached_decoder_benchmark.py +813 -0
- benchmarks/frame_sampling_benchmark.py +765 -0
- benchmarks/requirements.txt +52 -0
- benchmarks/segmented_transcode_benchmark.py +1546 -0
- benchmarks/setup_pycuda_win_arm64.bat +531 -0
- pynvvideocodec-2.2.1.data/data/external/ffmpeg/readme.txt +39 -0
- pynvvideocodec-2.2.1.data/data/external/ffmpeg/src/ffmpeg-8.1.2.tar.xz +0 -0
- pynvvideocodec-2.2.1.dist-info/METADATA +97 -0
- pynvvideocodec-2.2.1.dist-info/RECORD +63 -0
- pynvvideocodec-2.2.1.dist-info/WHEEL +5 -0
- pynvvideocodec-2.2.1.dist-info/licenses/LICENSE.txt +22 -0
- pynvvideocodec-2.2.1.dist-info/licenses/NOTICES.txt +167 -0
- pynvvideocodec-2.2.1.dist-info/top_level.txt +3 -0
- samples/advanced/decode.py +173 -0
- samples/advanced/decode_from_memory_buffer.py +204 -0
- samples/advanced/decode_perf.py +299 -0
- samples/advanced/decode_reconfigure.py +184 -0
- samples/advanced/decode_sei_msg.py +193 -0
- samples/advanced/decode_with_cuda_control.py +214 -0
- samples/advanced/decode_with_low_latency.py +183 -0
- samples/advanced/encode_config.json +12 -0
- samples/advanced/encode_config_lowlatency.json +13 -0
- samples/advanced/encode_perf.py +338 -0
- samples/advanced/encode_reconfigure.py +211 -0
- samples/advanced/encode_sei_msg.py +188 -0
- samples/advanced/simple_decode_from_memory.py +151 -0
- samples/advanced/simple_decode_stats.py +179 -0
- samples/advanced/transcode.py +288 -0
- samples/basic/create_video_segments.py +187 -0
- samples/basic/encode.py +574 -0
- samples/basic/segments.txt +3 -0
- samples/basic/simple_decode_sampling.py +182 -0
- samples/basic/transcode_config.json +6 -0
- samples/jupyter/ReconfigureDecoder.png +0 -0
- samples/jupyter/SimpleDecoderAPIs.png +0 -0
- samples/jupyter/ThreadedDecoder.png +0 -0
- samples/jupyter/coco_classes.pickle +0 -0
- samples/jupyter/face_protect_tutorial.ipynb +881 -0
- samples/jupyter/object_detection_tutorial.ipynb +781 -0
- samples/jupyter/simple_decode_tutorial.ipynb +674 -0
- samples/requirements.txt +84 -0
- samples/setup_pycuda_win_arm64.bat +531 -0
- samples/utils/Utils.py +405 -0
- samples/utils/__init__.py +36 -0
- samples/utils/decode_parser.py +642 -0
- samples/utils/decode_stats_writer.py +177 -0
- samples/utils/encode_parallel_utils.py +174 -0
- samples/utils/encode_parser.py +379 -0
- samples/utils/frame_utils.py +89 -0
- samples/utils/sei_message_parser.py +223 -0
- samples/utils/sei_parser.py +223 -0
- samples/utils/transcode_parser.py +218 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
# This copyright notice applies to this file only
|
|
2
|
+
#
|
|
3
|
+
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
|
4
|
+
# SPDX-License-Identifier: MIT
|
|
5
|
+
#
|
|
6
|
+
# Permission is hereby granted, free of charge, to any person obtaining a
|
|
7
|
+
# copy of this software and associated documentation files (the "Software"),
|
|
8
|
+
# to deal in the Software without restriction, including without limitation
|
|
9
|
+
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
10
|
+
# and/or sell copies of the Software, and to permit persons to whom the
|
|
11
|
+
# Software is furnished to do so, subject to the following conditions:
|
|
12
|
+
#
|
|
13
|
+
# The above copyright notice and this permission notice shall be included in
|
|
14
|
+
# all copies or substantial portions of the Software.
|
|
15
|
+
#
|
|
16
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
19
|
+
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
22
|
+
# DEALINGS IN THE SOFTWARE.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
'''
|
|
26
|
+
This sample demonstrates multi-file video decoding with frame sampling and tensor conversion.
|
|
27
|
+
It shows how to:
|
|
28
|
+
1. Process multiple video files efficiently
|
|
29
|
+
2. Sample frames evenly across videos
|
|
30
|
+
3. Convert video frames to PyTorch tensors
|
|
31
|
+
4. Handle decoder reconfiguration
|
|
32
|
+
|
|
33
|
+
Key Learning Outcomes:
|
|
34
|
+
- Reconfigure decoder instance to process multiple video files
|
|
35
|
+
- RGB color format output
|
|
36
|
+
- PyTorch tensor conversion
|
|
37
|
+
- CUDA device memory usage
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
Usage:
|
|
41
|
+
python simple_decode_sampling.py video1.mp4 video2.mp4 [options]
|
|
42
|
+
python simple_decode_sampling.py /path/to/videos/*.mp4 [options]
|
|
43
|
+
|
|
44
|
+
Example:
|
|
45
|
+
python simple_decode_sampling.py video1.mp4 video2.mp4 -g 0 -f 16
|
|
46
|
+
|
|
47
|
+
Arguments:
|
|
48
|
+
video_files: One or more video files to process
|
|
49
|
+
-g/--gpu-id: GPU device ID (default: 0)
|
|
50
|
+
-f/--frames: Frames to sample per video (default: 8)
|
|
51
|
+
|
|
52
|
+
Note: Frames are sampled evenly across each video's duration.
|
|
53
|
+
'''
|
|
54
|
+
|
|
55
|
+
import sys
|
|
56
|
+
import torch
|
|
57
|
+
import PyNvVideoCodec as nvc
|
|
58
|
+
import numpy as np
|
|
59
|
+
from typing import List
|
|
60
|
+
from os.path import dirname, abspath
|
|
61
|
+
|
|
62
|
+
# Add the parent directory to Python path in a way that works from any working directory
|
|
63
|
+
current_dir = dirname(abspath(__file__))
|
|
64
|
+
parent_dir = dirname(current_dir)
|
|
65
|
+
if parent_dir not in sys.path:
|
|
66
|
+
sys.path.append(parent_dir)
|
|
67
|
+
|
|
68
|
+
# Import utilities for decoding
|
|
69
|
+
from utils.Utils import convert_frames_to_torch
|
|
70
|
+
from utils.decode_parser import parse_sampling_args
|
|
71
|
+
|
|
72
|
+
def process_multiple_files(video_files: List[str], gpu_id: int = 0, num_frames: int = 8,
|
|
73
|
+
need_scanned_stream_metadata: bool = False) -> None:
|
|
74
|
+
"""
|
|
75
|
+
Process multiple video files using decoder reconfiguration.
|
|
76
|
+
|
|
77
|
+
Args:
|
|
78
|
+
video_files: List of video file paths
|
|
79
|
+
gpu_id: GPU device ID to use
|
|
80
|
+
num_frames: Number of frames to decode per video
|
|
81
|
+
need_scanned_stream_metadata: Whether to scan stream for detailed metadata
|
|
82
|
+
"""
|
|
83
|
+
if not video_files:
|
|
84
|
+
print("No video files provided")
|
|
85
|
+
return
|
|
86
|
+
|
|
87
|
+
decoder = None
|
|
88
|
+
|
|
89
|
+
try:
|
|
90
|
+
for i, video_file in enumerate(video_files):
|
|
91
|
+
# Convert Path to string if needed
|
|
92
|
+
video_path = str(video_file)
|
|
93
|
+
|
|
94
|
+
print(f"\n{'='*60}")
|
|
95
|
+
print(f"Processing file {i+1}/{len(video_files)}: {video_path}")
|
|
96
|
+
print(f"{'='*60}")
|
|
97
|
+
|
|
98
|
+
if i == 0:
|
|
99
|
+
# Create decoder from first file
|
|
100
|
+
print(f"Creating decoder for: {video_path}")
|
|
101
|
+
decoder = nvc.SimpleDecoder(
|
|
102
|
+
video_path,
|
|
103
|
+
gpu_id=gpu_id,
|
|
104
|
+
use_device_memory=True,
|
|
105
|
+
need_scanned_stream_metadata=need_scanned_stream_metadata,
|
|
106
|
+
output_color_type=nvc.OutputColorType.RGB, # RGB format
|
|
107
|
+
max_width=2048,
|
|
108
|
+
max_height=2048
|
|
109
|
+
)
|
|
110
|
+
print(f"Decoder created successfully. Total frames: {len(decoder)}")
|
|
111
|
+
else:
|
|
112
|
+
# Reconfigure decoder for subsequent files
|
|
113
|
+
print(f"Reconfiguring decoder for: {video_path}")
|
|
114
|
+
torch.cuda.current_stream().synchronize()
|
|
115
|
+
decoder.reconfigure_decoder(video_path)
|
|
116
|
+
print(f"Decoder reconfigured successfully. Total frames: {len(decoder)}")
|
|
117
|
+
|
|
118
|
+
# Get total frames and calculate indices
|
|
119
|
+
total_frames = len(decoder)
|
|
120
|
+
|
|
121
|
+
if total_frames == 0:
|
|
122
|
+
print(f"Warning: No frames found in video: {video_file}")
|
|
123
|
+
continue
|
|
124
|
+
|
|
125
|
+
# Sample frames evenly across the video
|
|
126
|
+
frame_indices = np.linspace(0, total_frames-1, num_frames, dtype=int).tolist()
|
|
127
|
+
|
|
128
|
+
print(f"Decoding {num_frames} frames from indices: {frame_indices}")
|
|
129
|
+
|
|
130
|
+
# Get batch of frames by indices
|
|
131
|
+
decoded_frames = decoder.get_batch_frames_by_index(frame_indices)
|
|
132
|
+
|
|
133
|
+
# Convert to torch tensor
|
|
134
|
+
frames_tensor = convert_frames_to_torch(decoded_frames)
|
|
135
|
+
|
|
136
|
+
print(f"Decoded frames shape: {frames_tensor.shape}")
|
|
137
|
+
|
|
138
|
+
# Clean up frames to free memory
|
|
139
|
+
del frames_tensor
|
|
140
|
+
del decoded_frames
|
|
141
|
+
|
|
142
|
+
print(f"\n{'='*60}")
|
|
143
|
+
print("All files processed successfully!")
|
|
144
|
+
print(f"{'='*60}")
|
|
145
|
+
|
|
146
|
+
except Exception as e:
|
|
147
|
+
print(f"Error processing files: {e}")
|
|
148
|
+
raise
|
|
149
|
+
finally:
|
|
150
|
+
# Clean up decoder
|
|
151
|
+
if decoder is not None:
|
|
152
|
+
del decoder
|
|
153
|
+
def main():
|
|
154
|
+
"""Main application entry point"""
|
|
155
|
+
try:
|
|
156
|
+
args, valid_files = parse_sampling_args()
|
|
157
|
+
|
|
158
|
+
# Display configuration
|
|
159
|
+
print("=" * 60)
|
|
160
|
+
print("VIDEO SAMPLING CONFIGURATION")
|
|
161
|
+
print("=" * 60)
|
|
162
|
+
print(f"GPU: {args.gpu_id} ({torch.cuda.get_device_name(args.gpu_id)})")
|
|
163
|
+
print(f"Input Files: {len(valid_files)} files found")
|
|
164
|
+
print(f"Frames per Video: {args.frames}")
|
|
165
|
+
print(f"Need Scanned Stream Metadata: {args.need_scanned_stream_metadata}")
|
|
166
|
+
print("=" * 60)
|
|
167
|
+
|
|
168
|
+
# Process all files
|
|
169
|
+
process_multiple_files(valid_files, args.gpu_id, args.frames, args.need_scanned_stream_metadata)
|
|
170
|
+
|
|
171
|
+
print("=" * 60)
|
|
172
|
+
print("SAMPLING COMPLETE")
|
|
173
|
+
print("=" * 60)
|
|
174
|
+
|
|
175
|
+
except KeyboardInterrupt:
|
|
176
|
+
print("\nApplication interrupted by user")
|
|
177
|
+
sys.exit(0)
|
|
178
|
+
except Exception as e:
|
|
179
|
+
print(f"Application error: {e}")
|
|
180
|
+
sys.exit(1)
|
|
181
|
+
if __name__ == "__main__":
|
|
182
|
+
main()
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|