Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions benchmarks/decoders/benchmark_decoders_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ def get_frames_from_video(self, video_file, pts_list):
decoder,
num_threads=self._num_threads,
color_conversion_library=self._color_conversion_library,
device=self._device,
)
metadata = json.loads(get_json_metadata(decoder))
best_video_stream = metadata["bestVideoStreamIndex"]
Expand All @@ -137,6 +138,7 @@ def get_consecutive_frames_from_video(self, video_file, numFramesToDecode):
decoder,
num_threads=self._num_threads,
color_conversion_library=self._color_conversion_library,
device=self._device,
)

frames = []
Expand Down Expand Up @@ -176,6 +178,7 @@ def get_consecutive_frames_from_video(self, video_file, numFramesToDecode):
decoder,
num_threads=self._num_threads,
color_conversion_library=self._color_conversion_library,
device=self._device,
)

frames = []
Expand All @@ -187,10 +190,11 @@ def get_consecutive_frames_from_video(self, video_file, numFramesToDecode):


class TorchCodecCoreBatch(AbstractDecoder):
def __init__(self, num_threads=None, color_conversion_library=None):
def __init__(self, num_threads=None, color_conversion_library=None, device="cpu"):
self._print_each_iteration_time = False
self._num_threads = int(num_threads) if num_threads else None
self._color_conversion_library = color_conversion_library
self._device = device

def get_frames_from_video(self, video_file, pts_list):
decoder = create_from_file(video_file)
Expand All @@ -199,6 +203,7 @@ def get_frames_from_video(self, video_file, pts_list):
decoder,
num_threads=self._num_threads,
color_conversion_library=self._color_conversion_library,
device=self._device,
)
metadata = json.loads(get_json_metadata(decoder))
best_video_stream = metadata["bestVideoStreamIndex"]
Expand All @@ -214,6 +219,7 @@ def get_consecutive_frames_from_video(self, video_file, numFramesToDecode):
decoder,
num_threads=self._num_threads,
color_conversion_library=self._color_conversion_library,
device=self._device,
)
metadata = json.loads(get_json_metadata(decoder))
best_video_stream = metadata["bestVideoStreamIndex"]
Expand All @@ -225,17 +231,22 @@ def get_consecutive_frames_from_video(self, video_file, numFramesToDecode):


class TorchCodecPublic(AbstractDecoder):
def __init__(self, num_ffmpeg_threads=None):
def __init__(self, num_ffmpeg_threads=None, device="cpu"):
self._num_ffmpeg_threads = (
int(num_ffmpeg_threads) if num_ffmpeg_threads else None
)
self._device = device

def get_frames_from_video(self, video_file, pts_list):
decoder = VideoDecoder(video_file, num_ffmpeg_threads=self._num_ffmpeg_threads)
decoder = VideoDecoder(
video_file, num_ffmpeg_threads=self._num_ffmpeg_threads, device=self._device
)
return decoder.get_frames_played_at(pts_list)

def get_consecutive_frames_from_video(self, video_file, numFramesToDecode):
decoder = VideoDecoder(video_file, num_ffmpeg_threads=self._num_ffmpeg_threads)
decoder = VideoDecoder(
video_file, num_ffmpeg_threads=self._num_ffmpeg_threads, device=self._device
)
frames = []
count = 0
for frame in decoder:
Expand Down
Loading