Skip to content

Conversation

@Dan-Flores
Copy link
Contributor

This PR creates a simple VideoEncoder class, and updates several tests to utilize the VideoEncoder.to_file pattern.

  • test_bad_input_parameterized is the VideoEncoder equivalent to the AudioEncoder test that ensures general error checking occurs, while test_bad_input tests method specific errors.

  • test_contiguity: is the VideoEncoder equivalent to the AudioEncoder test to ensure contiguous and non-contiguous tensors can be encoded, and are encoded equivalently.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 21, 2025
Comment on lines 640 to 641
(torch.rand(num_frames, channels, height, width) * 255)
.to(torch.uint8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use torch.randint(0, 256, size=(num_frames, channels, height, width), dtype=torch.uint8).contiguous()

contiguous_frames.permute(0, 3, 2, 1).contiguous().permute(0, 3, 2, 1)
)
assert non_contiguous_frames.stride() != contiguous_frames.stride()
assert not non_contiguous_frames.is_contiguous()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is good, but you should be able to check for this which is stricter:

assert  non_contiguous_frames.is_contiguous(memory_format=torch.channels_last)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far, I have assumed frames will be in NCHW format. This shape is retained after the permutations, so I do not believe channels_last applies here?

Copy link
Contributor

@NicolasHug NicolasHug Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The frames are always of NCHW shape . But internally they can have any arbitrary memory layout (format). These are mostly orthogonal concepts, i.e. frames can have NCHW shape while still being represented as NHWC layout (channels last).

I realize now the non_contiguous_frames you created are indeed not channels last. But we can force them to be by changing to:

contiguous_frames.permute(0, 2, 3, 1).contiguous().permute(0, 3, 1, 2)

and you should see that assert non_contiguous_frames.is_contiguous(memory_format=torch.channels_last) is passing now. Note how we're now permuting the channels dimension from N*HW to NHW*, and back.

Your test was still correct BTW - I just think it's good to actually explicitly check for channels_last because this is how frames may arrive.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants