@@ -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, float frame_rate, str filename, str device= \" cpu \" , str ? codec=None, str? pixel_format=None, float? crf=None, str? preset=None, str[]? extra_options=None) -> ()" );
40+ " encode_video_to_file(Tensor frames, float frame_rate, str filename, str? codec=None, str? pixel_format=None, float? crf=None, str? preset=None, str[]? extra_options=None) -> ()" );
4141 m.def (
42- " encode_video_to_tensor(Tensor frames, float frame_rate, str format, str device= \" cpu \" , str ? codec=None, str? pixel_format=None, float? crf=None, str? preset=None, str[]? extra_options=None) -> Tensor" );
42+ " encode_video_to_tensor(Tensor frames, float frame_rate, str format, str? codec=None, str? pixel_format=None, float? crf=None, str? preset=None, str[]? extra_options=None) -> Tensor" );
4343 m.def (
44- " _encode_video_to_file_like(Tensor frames, float frame_rate, str format, int file_like_context, str device= \" cpu \" ,str ? codec=None, str? pixel_format=None, float? crf=None, str? preset=None, str[]? extra_options=None) -> ()" );
44+ " _encode_video_to_file_like(Tensor frames, float frame_rate, str format, int file_like_context, str? codec=None, str? pixel_format=None, float? crf=None, str? preset=None, str[]? extra_options=None) -> ()" );
4545 m.def (
4646 " create_from_tensor(Tensor video_tensor, str? seek_mode=None) -> Tensor" );
4747 m.def (
@@ -640,14 +640,13 @@ void encode_video_to_file(
640640 const at::Tensor& frames,
641641 double frame_rate,
642642 std::string_view file_name,
643- std::string_view device = " cpu" ,
644643 std::optional<std::string_view> codec = std::nullopt ,
645644 std::optional<std::string_view> pixel_format = std::nullopt ,
646645 std::optional<double > crf = std::nullopt ,
647646 std::optional<std::string_view> preset = std::nullopt ,
648647 std::optional<std::vector<std::string>> extra_options = std::nullopt ) {
649648 VideoStreamOptions videoStreamOptions;
650- videoStreamOptions.device = torch::Device ( std::string ( device) );
649+ videoStreamOptions.device = frames. device ( );
651650 videoStreamOptions.codec = std::move (codec);
652651 videoStreamOptions.pixelFormat = std::move (pixel_format);
653652 videoStreamOptions.crf = crf;
@@ -665,15 +664,14 @@ at::Tensor encode_video_to_tensor(
665664 const at::Tensor& frames,
666665 double frame_rate,
667666 std::string_view format,
668- std::string_view device = " cpu" ,
669667 std::optional<std::string_view> codec = std::nullopt ,
670668 std::optional<std::string_view> pixel_format = std::nullopt ,
671669 std::optional<double > crf = std::nullopt ,
672670 std::optional<std::string_view> preset = std::nullopt ,
673671 std::optional<std::vector<std::string>> extra_options = std::nullopt ) {
674672 auto avioContextHolder = std::make_unique<AVIOToTensorContext>();
675673 VideoStreamOptions videoStreamOptions;
676- videoStreamOptions.device = torch::Device ( std::string ( device) );
674+ videoStreamOptions.device = frames. device ( );
677675 videoStreamOptions.codec = std::move (codec);
678676 videoStreamOptions.pixelFormat = std::move (pixel_format);
679677 videoStreamOptions.crf = crf;
@@ -698,7 +696,6 @@ void _encode_video_to_file_like(
698696 double frame_rate,
699697 std::string_view format,
700698 int64_t file_like_context,
701- std::string_view device = " cpu" ,
702699 std::optional<std::string_view> codec = std::nullopt ,
703700 std::optional<std::string_view> pixel_format = std::nullopt ,
704701 std::optional<double > crf = std::nullopt ,
@@ -711,7 +708,7 @@ void _encode_video_to_file_like(
711708 std::unique_ptr<AVIOFileLikeContext> avioContextHolder (fileLikeContext);
712709
713710 VideoStreamOptions videoStreamOptions;
714- videoStreamOptions.device = torch::Device ( std::string ( device) );
711+ videoStreamOptions.device = frames. device ( );
715712 videoStreamOptions.codec = std::move (codec);
716713 videoStreamOptions.pixelFormat = std::move (pixel_format);
717714 videoStreamOptions.crf = crf;
0 commit comments