@@ -37,11 +37,11 @@ TORCH_LIBRARY(torchcodec_ns, m) {
3737 m.def (
3838 " _encode_audio_to_file_like(Tensor samples, int sample_rate, str format, int file_like_context, int? bit_rate=None, int? num_channels=None, int? desired_sample_rate=None) -> ()" );
3939 m.def (
40- " encode_video_to_file(Tensor frames, int frame_rate, str filename, str? pixel_format=None, float? crf=None) -> ()" );
40+ " encode_video_to_file(Tensor frames, int frame_rate, str filename, str? pixel_format=None, float? crf=None, str? preset=None ) -> ()" );
4141 m.def (
42- " encode_video_to_tensor(Tensor frames, int frame_rate, str format, str? pixel_format=None, float? crf=None) -> Tensor" );
42+ " encode_video_to_tensor(Tensor frames, int frame_rate, str format, str? pixel_format=None, float? crf=None, str? preset=None ) -> Tensor" );
4343 m.def (
44- " _encode_video_to_file_like(Tensor frames, int frame_rate, str format, int file_like_context, str? pixel_format=None, float? crf=None) -> ()" );
44+ " _encode_video_to_file_like(Tensor frames, int frame_rate, str format, int file_like_context, str? pixel_format=None, float? crf=None, str? preset=None ) -> ()" );
4545 m.def (
4646 " create_from_tensor(Tensor video_tensor, str? seek_mode=None) -> Tensor" );
4747 m.def (
@@ -603,11 +603,13 @@ void encode_video_to_file(
603603 const at::Tensor& frames,
604604 int64_t frame_rate,
605605 std::string_view file_name,
606- std::optional<std::string> pixel_format = std::nullopt ,
607- std::optional<double > crf = std::nullopt ) {
606+ std::optional<std::string_view> pixel_format = std::nullopt ,
607+ std::optional<double > crf = std::nullopt ,
608+ std::optional<std::string_view> preset = std::nullopt ) {
608609 VideoStreamOptions videoStreamOptions;
609610 videoStreamOptions.pixelFormat = pixel_format;
610611 videoStreamOptions.crf = crf;
612+ videoStreamOptions.preset = preset;
611613 VideoEncoder (
612614 frames,
613615 validateInt64ToInt (frame_rate, " frame_rate" ),
@@ -620,12 +622,14 @@ at::Tensor encode_video_to_tensor(
620622 const at::Tensor& frames,
621623 int64_t frame_rate,
622624 std::string_view format,
623- std::optional<std::string> pixel_format = std::nullopt ,
624- std::optional<double > crf = std::nullopt ) {
625+ std::optional<std::string_view> pixel_format = std::nullopt ,
626+ std::optional<double > crf = std::nullopt ,
627+ std::optional<std::string_view> preset = std::nullopt ) {
625628 auto avioContextHolder = std::make_unique<AVIOToTensorContext>();
626629 VideoStreamOptions videoStreamOptions;
627630 videoStreamOptions.pixelFormat = pixel_format;
628631 videoStreamOptions.crf = crf;
632+ videoStreamOptions.preset = preset;
629633 return VideoEncoder (
630634 frames,
631635 validateInt64ToInt (frame_rate, " frame_rate" ),
@@ -640,8 +644,9 @@ void _encode_video_to_file_like(
640644 int64_t frame_rate,
641645 std::string_view format,
642646 int64_t file_like_context,
643- std::optional<std::string> pixel_format = std::nullopt ,
644- std::optional<double > crf = std::nullopt ) {
647+ std::optional<std::string_view> pixel_format = std::nullopt ,
648+ std::optional<double > crf = std::nullopt ,
649+ std::optional<std::string_view> preset = std::nullopt ) {
645650 auto fileLikeContext =
646651 reinterpret_cast <AVIOFileLikeContext*>(file_like_context);
647652 TORCH_CHECK (
@@ -651,6 +656,7 @@ void _encode_video_to_file_like(
651656 VideoStreamOptions videoStreamOptions;
652657 videoStreamOptions.pixelFormat = pixel_format;
653658 videoStreamOptions.crf = crf;
659+ videoStreamOptions.preset = preset;
654660
655661 VideoEncoder encoder (
656662 frames,
0 commit comments