Skip to content

Commit 95df50c

Browse files
committed
Some fixes
1 parent 3317f21 commit 95df50c

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

src/torchcodec/_core/Encoder.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,13 @@ int MultiStreamEncoder::addAudioStream(
11531153
STD_TORCH_CHECK(sampleRate > 0, "sample_rate must be > 0, got ", sampleRate);
11541154
STD_TORCH_CHECK(
11551155
numChannels > 0, "num_channels must be > 0, got ", numChannels);
1156+
STD_TORCH_CHECK(
1157+
numChannels <= AV_NUM_DATA_POINTERS,
1158+
"Trying to encode ",
1159+
numChannels,
1160+
" channels, but FFmpeg only supports ",
1161+
AV_NUM_DATA_POINTERS,
1162+
" channels per frame.");
11561163

11571164
AudioStream audioStream;
11581165
audioStream.inSampleRate = sampleRate;

test/test_encoders.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2620,6 +2620,12 @@ def test_audio_to_file_vs_to_file_like(self, tmp_path, format):
26202620
audio_fl.write(source_samples)
26212621
enc_fl.close()
26222622

2623+
if IS_WINDOWS_WITH_FFMPEG_LE_70 and format == "mp3":
2624+
# We're getting a "Could not open input file" on Windows mp3
2625+
# files when decoding.
2626+
# TODO: https://github.com/pytorch/torchcodec/issues/837
2627+
return
2628+
26232629
decoded_from_file = AudioDecoder(str(file_path)).get_all_samples().data
26242630
decoded_from_file_like = (
26252631
AudioDecoder(file_like.getvalue()).get_all_samples().data
@@ -3578,11 +3584,8 @@ def test_add_audio_unsupported_num_channels_errors(self, method, tmp_path):
35783584
sub = tmp_path / "ten_ch"
35793585
sub.mkdir()
35803586
enc2, _, open_kwargs2 = self._create_encoder(method, sub, "wav")
3581-
audio2 = enc2.add_audio(sample_rate=44100, num_channels=10)
3582-
enc2.open(**open_kwargs2)
3583-
samples = torch.randn(10, 1000)
35843587
with pytest.raises(RuntimeError, match="Trying to encode 10 channels"):
3585-
audio2.write(samples)
3588+
enc2.add_audio(sample_rate=44100, num_channels=10)
35863589

35873590
@pytest.mark.parametrize("method", ("to_file", "to_file_like"))
35883591
def test_add_audio_invalid_output_sample_rate_errors(self, method, tmp_path):

0 commit comments

Comments
 (0)