Skip to content

[DEBUG] #775

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

Closed
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/linux_cuda_wheel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
ls
- name: Run Python tests
run: |
${CONDA_RUN} FAIL_WITHOUT_CUDA=1 pytest test -v --tb=short
${CONDA_RUN} FAIL_WITHOUT_CUDA=1 pytest test -v --tb=short -k test_num_channels
- name: Run Python benchmark
run: |
${CONDA_RUN} time python benchmarks/decoders/gpu_benchmark.py --devices=cuda:0,cpu --resize_devices=none
2 changes: 1 addition & 1 deletion .github/workflows/linux_wheel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ jobs:
ls
- name: Run Python tests
run: |
pytest test -vvv
pytest test -vvv -k test_num_channels
2 changes: 1 addition & 1 deletion .github/workflows/macos_wheel.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,4 @@ jobs:

- name: Run Python tests
run: |
pytest test -vvv
pytest test -vvv -k test_num_channels
16 changes: 14 additions & 2 deletions src/torchcodec/_core/Encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,18 @@ AVSampleFormat findBestOutputSampleFormat(const AVCodec& avCodec) {
} // namespace

AudioEncoder::~AudioEncoder() {
if (avFormatContext_ && avFormatContext_->pb && !avioContextHolder_) {
avio_close(avFormatContext_->pb);
close_avio();
}

void AudioEncoder::close_avio() {
if (avFormatContext_ && avFormatContext_->pb) {
avio_flush(avFormatContext_->pb);

if (!avioContextHolder_) {
avio_close(avFormatContext_->pb);
// avoids closing again in destructor, which would segfault.
avFormatContext_->pb = nullptr;
}
}
}

Expand Down Expand Up @@ -308,6 +318,8 @@ void AudioEncoder::encode() {
status == AVSUCCESS,
"Error in: av_write_trailer",
getFFMPEGErrorStringFromErrorCode(status));

close_avio();
}

UniqueAVFrame AudioEncoder::maybeConvertAVFrame(const UniqueAVFrame& avFrame) {
Expand Down
1 change: 1 addition & 0 deletions src/torchcodec/_core/Encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class AudioEncoder {
void encodeFrame(AutoAVPacket& autoAVPacket, const UniqueAVFrame& avFrame);
void maybeFlushSwrBuffers(AutoAVPacket& autoAVPacket);
void flushBuffers();
void close_avio();

UniqueEncodingAVFormatContext avFormatContext_;
UniqueAVCodecContext avCodecContext_;
Expand Down
3 changes: 2 additions & 1 deletion test/test_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,8 +367,9 @@ def test_contiguity(self):
@pytest.mark.parametrize("num_channels_input", (1, 2))
@pytest.mark.parametrize("num_channels_output", (1, 2, None))
@pytest.mark.parametrize("method", ("to_file", "to_tensor"))
@pytest.mark.parametrize("i", range(10_000))
def test_num_channels(
self, num_channels_input, num_channels_output, method, tmp_path
self, num_channels_input, num_channels_output, method, tmp_path, i
):
# We just check that the num_channels parameter is respected.
# Correctness is checked in other tests (like test_against_cli())
Expand Down
Loading