Skip to content

Commit 823e7f0

Browse files
committed
WIP
1 parent 387328a commit 823e7f0

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

src/torchcodec/_core/Encoder.cpp

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,13 @@ void AudioEncoder::initializeEncoder(
184184
// not related to the input sampes.
185185
setDefaultChannelLayout(avCodecContext_, outNumChannels_);
186186

187-
outSampleRate_ = static_cast<int>(
188-
audioStreamOptions.sampleRate.value_or(sampleRateInput_));
187+
outSampleRate_ = audioStreamOptions.sampleRate.value_or(sampleRateInput_);
189188
validateSampleRate(*avCodec, outSampleRate_);
190189
avCodecContext_->sample_rate = outSampleRate_;
191190

192-
// Input waveform is expected to be FLTP. Not all encoders support FLTP,
193-
// so we may need to convert the wf into a supported output sample format,
194-
// which is what the `.sample_fmt` defines.
191+
// Input waveform is expected to be FLTP. Not all encoders support FLTP, so we
192+
// may need to convert the wf into a supported output sample format, which is
193+
// what the `.sample_fmt` defines.
195194
avCodecContext_->sample_fmt = findBestOutputSampleFormat(*avCodec);
196195

197196
int status = avcodec_open2(avCodecContext_.get(), avCodec, nullptr);
@@ -223,9 +222,9 @@ torch::Tensor AudioEncoder::encodeToTensor() {
223222
}
224223

225224
void AudioEncoder::encode() {
226-
// To be on the safe side we enforce that encode() can only be called once
227-
// on an encoder object. Whether this is actually necessary is unknown, so
228-
// this may be relaxed if needed.
225+
// To be on the safe side we enforce that encode() can only be called once on
226+
// an encoder object. Whether this is actually necessary is unknown, so this
227+
// may be relaxed if needed.
229228
TORCH_CHECK(!encodeWasCalled_, "Cannot call encode() twice.");
230229
encodeWasCalled_ = true;
231230

@@ -279,11 +278,11 @@ void AudioEncoder::encode() {
279278
}
280279
pwf += numBytesToEncode;
281280

282-
// Above, we set the AVFrame's .nb_samples to AVCodecContext.frame_size
283-
// so that the frame buffers are allocated to a big enough size. Here,
284-
// we reset it to the exact number of samples that need to be encoded,
285-
// otherwise the encoded frame would contain more samples than necessary
286-
// and our results wouldn't match the ffmpeg CLI.
281+
// Above, we set the AVFrame's .nb_samples to AVCodecContext.frame_size so
282+
// that the frame buffers are allocated to a big enough size. Here, we reset
283+
// it to the exact number of samples that need to be encoded, otherwise the
284+
// encoded frame would contain more samples than necessary and our results
285+
// wouldn't match the ffmpeg CLI.
287286
avFrame->nb_samples = numSamplesToEncode;
288287
encodeInnerLoop(autoAVPacket, avFrame);
289288

0 commit comments

Comments
 (0)