Skip to content

Use constant refs for passing samples into encoder #712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/torchcodec/_core/Encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace facebook::torchcodec {

namespace {

torch::Tensor validateSamples(torch::Tensor samples) {
torch::Tensor validateSamples(const torch::Tensor& samples) {
TORCH_CHECK(
samples.dtype() == torch::kFloat32,
"samples must have float32 dtype, got ",
Expand Down Expand Up @@ -101,7 +101,7 @@ AVSampleFormat findBestOutputSampleFormat(const AVCodec& avCodec) {
AudioEncoder::~AudioEncoder() {}

AudioEncoder::AudioEncoder(
const torch::Tensor samples,
const torch::Tensor& samples,
int sampleRate,
std::string_view fileName,
const AudioStreamOptions& audioStreamOptions)
Expand Down Expand Up @@ -132,7 +132,7 @@ AudioEncoder::AudioEncoder(
}

AudioEncoder::AudioEncoder(
const torch::Tensor samples,
const torch::Tensor& samples,
int sampleRate,
std::string_view formatName,
std::unique_ptr<AVIOToTensorContext> avioContextHolder,
Expand Down
4 changes: 2 additions & 2 deletions src/torchcodec/_core/Encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AudioEncoder {
// Passing 44_100 could result in output being 44000 if only 44000 is
// supported.
AudioEncoder(
const torch::Tensor samples,
const torch::Tensor& samples,
// TODO-ENCODING: update this comment when we support an output sample
// rate. This will become the input sample rate.
// The *output* sample rate. We can't really decide for the user what it
Expand All @@ -26,7 +26,7 @@ class AudioEncoder {
std::string_view fileName,
const AudioStreamOptions& audioStreamOptions);
AudioEncoder(
const torch::Tensor samples,
const torch::Tensor& samples,
int sampleRate,
std::string_view formatName,
std::unique_ptr<AVIOToTensorContext> avioContextHolder,
Expand Down
4 changes: 2 additions & 2 deletions src/torchcodec/_core/custom_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ OpsAudioFramesOutput get_frames_by_pts_in_range_audio(
}

void encode_audio_to_file(
const at::Tensor samples,
const at::Tensor& samples,
int64_t sample_rate,
std::string_view file_name,
std::optional<int64_t> bit_rate = std::nullopt,
Expand All @@ -404,7 +404,7 @@ void encode_audio_to_file(
}

at::Tensor encode_audio_to_tensor(
const at::Tensor samples,
const at::Tensor& samples,
int64_t sample_rate,
std::string_view format,
std::optional<int64_t> bit_rate = std::nullopt,
Expand Down
Loading