@@ -1057,6 +1057,7 @@ MultiStreamEncoder::MultiStreamEncoder() {
10571057}
10581058
10591059void MultiStreamEncoder::open (std::string_view fileName) {
1060+ STD_TORCH_CHECK (!closed_, " Cannot open after close() was called." );
10601061 STD_TORCH_CHECK (!headerWritten_, " open() was already called." );
10611062
10621063 AVFormatContext* avFormatContext = nullptr ;
@@ -1086,6 +1087,7 @@ void MultiStreamEncoder::open(std::string_view fileName) {
10861087void MultiStreamEncoder::open (
10871088 std::string_view formatName,
10881089 std::unique_ptr<AVIOContextHolder> avioContextHolder) {
1090+ STD_TORCH_CHECK (!closed_, " Cannot open after close() was called." );
10891091 STD_TORCH_CHECK (!headerWritten_, " open() was already called." );
10901092
10911093 avioContextHolder_ = std::move (avioContextHolder);
@@ -1148,6 +1150,13 @@ int MultiStreamEncoder::addAudioStream(
11481150 STD_TORCH_CHECK (sampleRate > 0 , " sample_rate must be > 0, got " , sampleRate);
11491151 STD_TORCH_CHECK (
11501152 numChannels > 0 , " num_channels must be > 0, got " , numChannels);
1153+ STD_TORCH_CHECK (
1154+ numChannels <= AV_NUM_DATA_POINTERS ,
1155+ " Trying to encode " ,
1156+ numChannels,
1157+ " channels, but FFmpeg only supports " ,
1158+ AV_NUM_DATA_POINTERS ,
1159+ " channels per frame." );
11511160
11521161 AudioStream audioStream;
11531162 audioStream.inSampleRate = sampleRate;
@@ -1412,6 +1421,7 @@ void MultiStreamEncoder::openStreamsAndWriteHeader() {
14121421void MultiStreamEncoder::addFrames (
14131422 const torch::stable::Tensor& frames,
14141423 int streamIndex) {
1424+ STD_TORCH_CHECK (!closed_, " Cannot add frames after close() was called." );
14151425 STD_TORCH_CHECK (headerWritten_, " Call open() before addFrames()." );
14161426 STD_TORCH_CHECK (
14171427 streamIndex >= 0 && streamIndex < static_cast <int >(videoStreams_.size ()),
@@ -1501,6 +1511,7 @@ void MultiStreamEncoder::encodeVideoFrame(
15011511void MultiStreamEncoder::addSamples (
15021512 const torch::stable::Tensor& samples,
15031513 int streamIndex) {
1514+ STD_TORCH_CHECK (!closed_, " Cannot add samples after close() was called." );
15041515 STD_TORCH_CHECK (headerWritten_, " Call open() before addSamples()." );
15051516 STD_TORCH_CHECK (
15061517 streamIndex >= 0 && streamIndex < static_cast <int >(audioStreams_.size ()),
0 commit comments