@@ -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, int? crf=None) -> ()" );
40+ " encode_video_to_file(Tensor frames, int frame_rate, str filename, str? pixel_format=None, int? crf=None) -> ()" );
4141 m.def (
42- " encode_video_to_tensor(Tensor frames, int frame_rate, str format, int? crf=None) -> Tensor" );
42+ " encode_video_to_tensor(Tensor frames, int frame_rate, str format, str? pixel_format=None, int? crf=None) -> Tensor" );
4343 m.def (
44- " _encode_video_to_file_like(Tensor frames, int frame_rate, str format, int file_like_context, int? crf=None) -> ()" );
44+ " _encode_video_to_file_like(Tensor frames, int frame_rate, str format, int file_like_context, str? pixel_format=None, int? crf=None) -> ()" );
4545 m.def (
4646 " create_from_tensor(Tensor video_tensor, str? seek_mode=None) -> Tensor" );
4747 m.def (
@@ -603,8 +603,10 @@ 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 ,
606607 std::optional<int64_t > crf = std::nullopt ) {
607608 VideoStreamOptions videoStreamOptions;
609+ videoStreamOptions.pixelFormat = pixel_format;
608610 videoStreamOptions.crf = crf;
609611 VideoEncoder (
610612 frames,
@@ -618,9 +620,11 @@ at::Tensor encode_video_to_tensor(
618620 const at::Tensor& frames,
619621 int64_t frame_rate,
620622 std::string_view format,
623+ std::optional<std::string> pixel_format = std::nullopt ,
621624 std::optional<int64_t > crf = std::nullopt ) {
622625 auto avioContextHolder = std::make_unique<AVIOToTensorContext>();
623626 VideoStreamOptions videoStreamOptions;
627+ videoStreamOptions.pixelFormat = pixel_format;
624628 videoStreamOptions.crf = crf;
625629 return VideoEncoder (
626630 frames,
@@ -636,6 +640,7 @@ void _encode_video_to_file_like(
636640 int64_t frame_rate,
637641 std::string_view format,
638642 int64_t file_like_context,
643+ std::optional<std::string> pixel_format = std::nullopt ,
639644 std::optional<int64_t > crf = std::nullopt ) {
640645 auto fileLikeContext =
641646 reinterpret_cast <AVIOFileLikeContext*>(file_like_context);
@@ -644,6 +649,7 @@ void _encode_video_to_file_like(
644649 std::unique_ptr<AVIOFileLikeContext> avioContextHolder (fileLikeContext);
645650
646651 VideoStreamOptions videoStreamOptions;
652+ videoStreamOptions.pixelFormat = pixel_format;
647653 videoStreamOptions.crf = crf;
648654
649655 VideoEncoder encoder (
0 commit comments