Skip to content

Commit 3a87ea0

Browse files
committed
Define default
1 parent cff8a83 commit 3a87ea0

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/torchcodec/_core/Encoder.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,11 @@ AudioEncoder::AudioEncoder(
5050
TORCH_CHECK(avCodecContext != nullptr, "Couldn't allocate codec context.");
5151
avCodecContext_.reset(avCodecContext);
5252

53-
// TODO-ENCODING I think 0 sets the bit rate to the minimum supported.
54-
// That's not what the ffmpeg CLI would choose by default, so we should try to
55-
// do the same.
5653
if (bit_rate.has_value()) {
5754
TORCH_CHECK(*bit_rate >= 0, "bit_rate=", *bit_rate, " must be >= 0.");
5855
}
56+
// bit_rate=None defaults to 0, which is what the FFmpeg CLI seems to use as
57+
// well when "-b:a" isn't specified.
5958
avCodecContext_->bit_rate = bit_rate.value_or(0);
6059

6160
avCodecContext_->sample_rate = sampleRate_;

test/test_ops.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,7 @@ def test_round_trip(self, tmp_path):
11421142

11431143
# TODO-ENCODING: test more encoding formats
11441144
@pytest.mark.parametrize("asset", (NASA_AUDIO_MP3, SINE_MONO_S32))
1145-
@pytest.mark.parametrize("bit_rate", (None, 0, 1, 44_100))
1145+
@pytest.mark.parametrize("bit_rate", (None, 0, 44_100, 999_999_999))
11461146
def test_against_cli(self, asset, bit_rate, tmp_path):
11471147
# Encodes samples with our encoder and with the FFmpeg CLI, and checks
11481148
# that both decoded outputs are equal
@@ -1151,12 +1151,9 @@ def test_against_cli(self, asset, bit_rate, tmp_path):
11511151
encoded_by_us = tmp_path / "our_output.mp3"
11521152

11531153
subprocess.run(
1154-
[
1155-
"ffmpeg",
1156-
"-i",
1157-
str(asset.path),
1158-
"-b:a",
1159-
f"{bit_rate or 0}", # None == 0 (for now!)
1154+
["ffmpeg", "-i", str(asset.path)]
1155+
+ (["-b:a", f"{bit_rate}"] if bit_rate is not None else [])
1156+
+ [
11601157
str(encoded_by_ffmpeg),
11611158
],
11621159
capture_output=True,

0 commit comments

Comments
 (0)