Skip to content

Allow option to use the swscale library for color conversion instead of filtergraph #205

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
.
  • Loading branch information
ahmadsharif1 committed Sep 24, 2024
commit b1b09eaebb7e5e7c26456ba19da31aad243f5890
2 changes: 1 addition & 1 deletion src/torchcodec/decoders/_core/VideoDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class VideoDecoder {
// --------------------------------------------------------------------------
enum ColorConversionLibrary {
// TODO: Add an AUTO option later.
// Use the libswscale library for color conversion.
// Use the libavfilter library for color conversion.
FILTERGRAPH,
// Use the libswscale library for color conversion.
SWSCALE
Expand Down
32 changes: 6 additions & 26 deletions test/convert_image_to_tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,9 @@
img_file = sys.argv[1]
# Get base filename without extension
base_filename = os.path.splitext(img_file)[0]
extension = os.path.splitext(img_file)[1]
if extension == ".pt":
img_tensor = torch.load(img_file)
print(img_tensor.shape)
print(img_tensor.dtype)
# Save tensor to disk
output_file = base_filename + ".bmp"
if len(sys.argv) > 2:
output_file = sys.argv[2]
if img_tensor.shape[0] == 3:
img_tensor = img_tensor.permute(1, 2, 0)
img_array = img_tensor.cpu().numpy()
img = Image.fromarray(img_array)
img.save(output_file, format="BMP")
print(f"Saved BMP to {output_file}")
else:
pil_image = Image.open(img_file)
img_tensor = torch.from_numpy(np.asarray(pil_image))
print(img_tensor.shape)
print(img_tensor.dtype)
# Save tensor to disk
output_file = base_filename + ".pt"
if len(sys.argv) > 2:
output_file = sys.argv[2]
torch.save(img_tensor, output_file, _use_new_zipfile_serialization=True)
print(f"Saved tensor to {output_file}")
pil_image = Image.open(img_file)
img_tensor = torch.from_numpy(np.asarray(pil_image))
print(img_tensor.shape)
print(img_tensor.dtype)
# Save tensor to disk
torch.save(img_tensor, base_filename + ".pt", _use_new_zipfile_serialization=True)
Loading