@@ -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? codec=None, str? pixel_format=None, float? crf=None) -> ()" );
40+ " encode_video_to_file(Tensor frames, int frame_rate, str filename, str? codec=None, 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? codec=None, str? pixel_format=None, float? crf=None) -> Tensor" );
42+ " encode_video_to_tensor(Tensor frames, int frame_rate, str format, str? codec=None, 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? codec=None, 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? codec=None, 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 (
@@ -604,12 +604,14 @@ void encode_video_to_file(
604604 int64_t frame_rate,
605605 std::string_view file_name,
606606 std::optional<std::string> codec = std::nullopt ,
607- std::optional<std::string> pixel_format = std::nullopt ,
608- std::optional<double > crf = std::nullopt ) {
607+ std::optional<std::string_view> pixel_format = std::nullopt ,
608+ std::optional<double > crf = std::nullopt ,
609+ std::optional<std::string_view> preset = std::nullopt ) {
609610 VideoStreamOptions videoStreamOptions;
610611 videoStreamOptions.codec = codec;
611612 videoStreamOptions.pixelFormat = pixel_format;
612613 videoStreamOptions.crf = crf;
614+ videoStreamOptions.preset = preset;
613615 VideoEncoder (
614616 frames,
615617 validateInt64ToInt (frame_rate, " frame_rate" ),
@@ -623,13 +625,15 @@ at::Tensor encode_video_to_tensor(
623625 int64_t frame_rate,
624626 std::string_view format,
625627 std::optional<std::string> codec = std::nullopt ,
626- std::optional<std::string> pixel_format = std::nullopt ,
627- std::optional<double > crf = std::nullopt ) {
628+ std::optional<std::string_view> pixel_format = std::nullopt ,
629+ std::optional<double > crf = std::nullopt ,
630+ std::optional<std::string_view> preset = std::nullopt ) {
628631 auto avioContextHolder = std::make_unique<AVIOToTensorContext>();
629632 VideoStreamOptions videoStreamOptions;
630633 videoStreamOptions.codec = codec;
631634 videoStreamOptions.pixelFormat = pixel_format;
632635 videoStreamOptions.crf = crf;
636+ videoStreamOptions.preset = preset;
633637 return VideoEncoder (
634638 frames,
635639 validateInt64ToInt (frame_rate, " frame_rate" ),
@@ -645,8 +649,9 @@ void _encode_video_to_file_like(
645649 std::string_view format,
646650 int64_t file_like_context,
647651 std::optional<std::string> codec = std::nullopt ,
648- std::optional<std::string> pixel_format = std::nullopt ,
649- std::optional<double > crf = std::nullopt ) {
652+ std::optional<std::string_view> pixel_format = std::nullopt ,
653+ std::optional<double > crf = std::nullopt ,
654+ std::optional<std::string_view> preset = std::nullopt ) {
650655 auto fileLikeContext =
651656 reinterpret_cast <AVIOFileLikeContext*>(file_like_context);
652657 TORCH_CHECK (
@@ -657,6 +662,7 @@ void _encode_video_to_file_like(
657662 videoStreamOptions.codec = codec;
658663 videoStreamOptions.pixelFormat = pixel_format;
659664 videoStreamOptions.crf = crf;
665+ videoStreamOptions.preset = preset;
660666
661667 VideoEncoder encoder (
662668 frames,
0 commit comments