@@ -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, str? preset=None, str[]? codec_options=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, str[]? codec_options=None) -> ()" );
4141 m.def (
42- " encode_video_to_tensor(Tensor frames, int frame_rate, str format, str? pixel_format=None, float? crf=None, str? preset=None, str[]? codec_options=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, str[]? codec_options=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, str? preset=None, str[]? codec_options=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, str[]? codec_options=None) -> ()" );
4545 m.def (
4646 " create_from_tensor(Tensor video_tensor, str? seek_mode=None) -> Tensor" );
4747 m.def (
@@ -613,11 +613,13 @@ void encode_video_to_file(
613613 const at::Tensor& frames,
614614 int64_t frame_rate,
615615 std::string_view file_name,
616+ std::optional<std::string> codec = std::nullopt ,
616617 std::optional<std::string_view> pixel_format = std::nullopt ,
617618 std::optional<double > crf = std::nullopt ,
618619 std::optional<std::string_view> preset = std::nullopt ,
619620 std::optional<std::vector<std::string>> codec_options = std::nullopt ) {
620621 VideoStreamOptions videoStreamOptions;
622+ videoStreamOptions.codec = codec;
621623 videoStreamOptions.pixelFormat = pixel_format;
622624 videoStreamOptions.crf = crf;
623625 videoStreamOptions.preset = preset;
@@ -639,12 +641,14 @@ at::Tensor encode_video_to_tensor(
639641 const at::Tensor& frames,
640642 int64_t frame_rate,
641643 std::string_view format,
644+ std::optional<std::string> codec = std::nullopt ,
642645 std::optional<std::string_view> pixel_format = std::nullopt ,
643646 std::optional<double > crf = std::nullopt ,
644647 std::optional<std::string_view> preset = std::nullopt ,
645648 std::optional<std::vector<std::string>> codec_options = std::nullopt ) {
646649 auto avioContextHolder = std::make_unique<AVIOToTensorContext>();
647650 VideoStreamOptions videoStreamOptions;
651+ videoStreamOptions.codec = codec;
648652 videoStreamOptions.pixelFormat = pixel_format;
649653 videoStreamOptions.crf = crf;
650654 videoStreamOptions.preset = preset;
@@ -668,6 +672,7 @@ void _encode_video_to_file_like(
668672 int64_t frame_rate,
669673 std::string_view format,
670674 int64_t file_like_context,
675+ std::optional<std::string> codec = std::nullopt ,
671676 std::optional<std::string_view> pixel_format = std::nullopt ,
672677 std::optional<double > crf = std::nullopt ,
673678 std::optional<std::string_view> preset = std::nullopt ,
@@ -679,6 +684,7 @@ void _encode_video_to_file_like(
679684 std::unique_ptr<AVIOFileLikeContext> avioContextHolder (fileLikeContext);
680685
681686 VideoStreamOptions videoStreamOptions;
687+ videoStreamOptions.codec = codec;
682688 videoStreamOptions.pixelFormat = pixel_format;
683689 videoStreamOptions.crf = crf;
684690 videoStreamOptions.preset = preset;
0 commit comments