Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/torchcodec/_core/Encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ void tryToValidateCodecOption(
"] for this codec. For more details, run 'ffmpeg -h encoder=",
avCodec.name,
"'");
} catch (const std::invalid_argument& e) {
} catch (const std::invalid_argument&) {
TORCH_CHECK(
false,
"Option ",
Expand Down
18 changes: 9 additions & 9 deletions src/torchcodec/_core/custom_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -613,14 +613,14 @@ void encode_video_to_file(
const at::Tensor& frames,
int64_t frame_rate,
std::string_view file_name,
std::optional<std::string> codec = std::nullopt,
std::optional<std::string_view> codec = std::nullopt,
std::optional<std::string_view> pixel_format = std::nullopt,
std::optional<double> crf = std::nullopt,
std::optional<std::string_view> preset = std::nullopt,
std::optional<std::vector<std::string>> extra_options = std::nullopt) {
VideoStreamOptions videoStreamOptions;
videoStreamOptions.codec = codec;
videoStreamOptions.pixelFormat = pixel_format;
videoStreamOptions.codec = std::move(codec);
videoStreamOptions.pixelFormat = std::move(pixel_format);
videoStreamOptions.crf = crf;
videoStreamOptions.preset = preset;

Expand All @@ -641,15 +641,15 @@ at::Tensor encode_video_to_tensor(
const at::Tensor& frames,
int64_t frame_rate,
std::string_view format,
std::optional<std::string> codec = std::nullopt,
std::optional<std::string_view> codec = std::nullopt,
std::optional<std::string_view> pixel_format = std::nullopt,
std::optional<double> crf = std::nullopt,
std::optional<std::string_view> preset = std::nullopt,
std::optional<std::vector<std::string>> extra_options = std::nullopt) {
auto avioContextHolder = std::make_unique<AVIOToTensorContext>();
VideoStreamOptions videoStreamOptions;
videoStreamOptions.codec = codec;
videoStreamOptions.pixelFormat = pixel_format;
videoStreamOptions.codec = std::move(codec);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you share the lint warning related to that? I'm surprised we need std::move for codec and pixel_format but not for preset?

Made me realize we should make this a string_view like the rest, instead of a string. Same below in the other function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comes from clang-tidy:
parameter 'codec' is passed by value and only copied once; consider moving it to avoid unnecessary copies.
Perhaps because preset can be an int, the lint is not raised?

we should make this a string_view like the rest, instead of a string

Thanks for catching this, I'll update this PR

videoStreamOptions.pixelFormat = std::move(pixel_format);
videoStreamOptions.crf = crf;
videoStreamOptions.preset = preset;

Expand All @@ -672,7 +672,7 @@ void _encode_video_to_file_like(
int64_t frame_rate,
std::string_view format,
int64_t file_like_context,
std::optional<std::string> codec = std::nullopt,
std::optional<std::string_view> codec = std::nullopt,
std::optional<std::string_view> pixel_format = std::nullopt,
std::optional<double> crf = std::nullopt,
std::optional<std::string_view> preset = std::nullopt,
Expand All @@ -684,8 +684,8 @@ void _encode_video_to_file_like(
std::unique_ptr<AVIOFileLikeContext> avioContextHolder(fileLikeContext);

VideoStreamOptions videoStreamOptions;
videoStreamOptions.codec = codec;
videoStreamOptions.pixelFormat = pixel_format;
videoStreamOptions.codec = std::move(codec);
videoStreamOptions.pixelFormat = std::move(pixel_format);
videoStreamOptions.crf = crf;
videoStreamOptions.preset = preset;

Expand Down
6 changes: 3 additions & 3 deletions src/torchcodec/_core/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def encode_video_to_file_abstract(
frames: torch.Tensor,
frame_rate: int,
filename: str,
codec: Optional[str],
codec: Optional[str] = None,
pixel_format: Optional[str] = None,
preset: Optional[str] = None,
crf: Optional[Union[int, float]] = None,
Expand All @@ -345,7 +345,7 @@ def encode_video_to_tensor_abstract(
frames: torch.Tensor,
frame_rate: int,
format: str,
codec: Optional[str],
codec: Optional[str] = None,
pixel_format: Optional[str] = None,
preset: Optional[str] = None,
crf: Optional[Union[int, float]] = None,
Expand All @@ -360,7 +360,7 @@ def _encode_video_to_file_like_abstract(
frame_rate: int,
format: str,
file_like_context: int,
codec: Optional[str],
codec: Optional[str] = None,
pixel_format: Optional[str] = None,
preset: Optional[str] = None,
crf: Optional[Union[int, float]] = None,
Expand Down
2 changes: 1 addition & 1 deletion src/torchcodec/encoders/_video_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def __init__(self, frames: Tensor, *, frame_rate: int):
def to_file(
self,
dest: Union[str, Path],
extra_options: Optional[Dict[str, Any]] = None,
*,
codec: Optional[str] = None,
pixel_format: Optional[str] = None,
crf: Optional[Union[int, float]] = None,
preset: Optional[Union[str, int]] = None,
extra_options: Optional[Dict[str, Any]] = None,
) -> None:
"""Encode frames into a file.
Expand Down
Loading