@@ -89,15 +89,15 @@ STABLE_TORCH_LIBRARY(torchcodec_ns, m) {
8989 m.def (
9090 " _test_frame_pts_equality(Tensor(a!) decoder, *, int frame_index, float pts_seconds_to_test) -> bool" );
9191 m.def (" scan_all_streams_to_update_metadata(Tensor(a!) decoder) -> ()" );
92- m.def (" create_streaming_encoder_to_file(str filename) -> Tensor" );
93- m.def (
94- " create_streaming_encoder_to_file_like(str format, int file_like_context) -> Tensor" );
92+ m.def (" create_streaming_encoder() -> Tensor" );
9593 m.def (" streaming_encoder_close(Tensor(a!) encoder) -> ()" );
9694 m.def (
9795 " streaming_encoder_add_video_stream(Tensor(a!) encoder, int height, int width, float frame_rate, str device=\" cpu\" , str? codec=None, str? pixel_format=None, float? crf=None, str? preset=None, str[]? extra_options=None) -> ()" );
9896 m.def (
9997 " streaming_encoder_add_audio_stream(Tensor(a!) encoder, int sample_rate, int num_channels, int? bit_rate=None) -> ()" );
100- m.def (" streaming_encoder_open(Tensor(a!) encoder) -> ()" );
98+ m.def (" streaming_encoder_open_file(Tensor(a!) encoder, str filename) -> ()" );
99+ m.def (
100+ " streaming_encoder_open_file_like(Tensor(a!) encoder, str format, int file_like_context) -> ()" );
101101 m.def (
102102 " streaming_encoder_add_frames(Tensor(a!) encoder, Tensor frames) -> ()" );
103103 m.def (
@@ -1202,22 +1202,8 @@ void scan_all_streams_to_update_metadata(torch::stable::Tensor& decoder) {
12021202 videoDecoder->scanFileAndUpdateMetadataAndIndex ();
12031203}
12041204
1205- torch::stable::Tensor create_streaming_encoder_to_file (std::string file_name) {
1206- auto encoder = std::make_unique<MultiStreamEncoder>(file_name);
1207- return wrapMultiStreamEncoderPointerToTensor (std::move (encoder));
1208- }
1209-
1210- torch::stable::Tensor create_streaming_encoder_to_file_like (
1211- std::string format,
1212- int64_t file_like_context) {
1213- auto fileLikeContext =
1214- reinterpret_cast <AVIOFileLikeContext*>(file_like_context);
1215- STD_TORCH_CHECK (
1216- fileLikeContext != nullptr , " file_like_context must be a valid pointer" );
1217- std::unique_ptr<AVIOFileLikeContext> avioContextHolder (fileLikeContext);
1218-
1219- auto encoder = std::make_unique<MultiStreamEncoder>(
1220- format, std::move (avioContextHolder));
1205+ torch::stable::Tensor create_streaming_encoder () {
1206+ auto encoder = std::make_unique<MultiStreamEncoder>();
12211207 return wrapMultiStreamEncoderPointerToTensor (std::move (encoder));
12221208}
12231209
@@ -1252,8 +1238,23 @@ void streaming_encoder_add_video_stream(
12521238 std::move (extraOptionsMap));
12531239}
12541240
1255- void streaming_encoder_open (torch::stable::Tensor& encoder) {
1256- unwrapTensorToGetMultiStreamEncoder (encoder)->open ();
1241+ void streaming_encoder_open_file (
1242+ torch::stable::Tensor& encoder,
1243+ std::string filename) {
1244+ unwrapTensorToGetMultiStreamEncoder (encoder)->open (filename);
1245+ }
1246+
1247+ void streaming_encoder_open_file_like (
1248+ torch::stable::Tensor& encoder,
1249+ std::string format,
1250+ int64_t file_like_context) {
1251+ auto fileLikeContext =
1252+ reinterpret_cast <AVIOFileLikeContext*>(file_like_context);
1253+ STD_TORCH_CHECK (
1254+ fileLikeContext != nullptr , " file_like_context must be a valid pointer" );
1255+ std::unique_ptr<AVIOFileLikeContext> avioContextHolder (fileLikeContext);
1256+ unwrapTensorToGetMultiStreamEncoder (encoder)->open (
1257+ format, std::move (avioContextHolder));
12571258}
12581259
12591260void streaming_encoder_add_audio_stream (
@@ -1357,19 +1358,18 @@ STABLE_TORCH_LIBRARY_IMPL(torchcodec_ns, BackendSelect, m) {
13571358 m.impl (" encode_video_to_file" , TORCH_BOX (&encode_video_to_file));
13581359 m.impl (" encode_video_to_tensor" , TORCH_BOX (&encode_video_to_tensor));
13591360 m.impl (" _encode_video_to_file_like" , TORCH_BOX (&_encode_video_to_file_like));
1360- m.impl (
1361- " create_streaming_encoder_to_file" ,
1362- TORCH_BOX (&create_streaming_encoder_to_file));
1363- m.impl (
1364- " create_streaming_encoder_to_file_like" ,
1365- TORCH_BOX (&create_streaming_encoder_to_file_like));
1361+ m.impl (" create_streaming_encoder" , TORCH_BOX (&create_streaming_encoder));
13661362 m.impl (
13671363 " streaming_encoder_add_video_stream" ,
13681364 TORCH_BOX (&streaming_encoder_add_video_stream));
13691365 m.impl (
13701366 " streaming_encoder_add_audio_stream" ,
13711367 TORCH_BOX (&streaming_encoder_add_audio_stream));
1372- m.impl (" streaming_encoder_open" , TORCH_BOX (&streaming_encoder_open));
1368+ m.impl (
1369+ " streaming_encoder_open_file" , TORCH_BOX (&streaming_encoder_open_file));
1370+ m.impl (
1371+ " streaming_encoder_open_file_like" ,
1372+ TORCH_BOX (&streaming_encoder_open_file_like));
13731373 m.impl (
13741374 " streaming_encoder_add_frames" , TORCH_BOX (&streaming_encoder_add_frames));
13751375 m.impl (
@@ -1420,20 +1420,19 @@ STABLE_TORCH_LIBRARY_IMPL(torchcodec_ns, CPU, m) {
14201420 TORCH_BOX (&scan_all_streams_to_update_metadata));
14211421
14221422 m.impl (" _get_backend_details" , TORCH_BOX (&get_backend_details));
1423+ m.impl (" create_streaming_encoder" , TORCH_BOX (&create_streaming_encoder));
14231424 m.impl (
1424- " create_streaming_encoder_to_file" ,
1425- TORCH_BOX (&create_streaming_encoder_to_file));
1425+ " streaming_encoder_open_file" , TORCH_BOX (&streaming_encoder_open_file));
14261426 m.impl (
1427- " create_streaming_encoder_to_file_like " ,
1428- TORCH_BOX (&create_streaming_encoder_to_file_like ));
1427+ " streaming_encoder_open_file_like " ,
1428+ TORCH_BOX (&streaming_encoder_open_file_like ));
14291429 m.impl (" streaming_encoder_close" , TORCH_BOX (&streaming_encoder_close));
14301430 m.impl (
14311431 " streaming_encoder_add_video_stream" ,
14321432 TORCH_BOX (&streaming_encoder_add_video_stream));
14331433 m.impl (
14341434 " streaming_encoder_add_audio_stream" ,
14351435 TORCH_BOX (&streaming_encoder_add_audio_stream));
1436- m.impl (" streaming_encoder_open" , TORCH_BOX (&streaming_encoder_open));
14371436 m.impl (
14381437 " streaming_encoder_add_frames" , TORCH_BOX (&streaming_encoder_add_frames));
14391438 m.impl (
0 commit comments