Skip to content
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
7 changes: 4 additions & 3 deletions src/torchcodec/_core/SingleStreamDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,13 +848,14 @@ AudioFramesOutput SingleStreamDecoder::getFramesPlayedInRangeAudio(
std::to_string(*stopSecondsOptional) + ").");
}

StreamInfo& streamInfo = streamInfos_[activeStreamIndex_];

if (stopSecondsOptional.has_value() && startSeconds == *stopSecondsOptional) {
// For consistency with video
return AudioFramesOutput{torch::empty({0, 0}), 0.0};
int numChannels = getNumChannels(streamInfo.codecContext);
return AudioFramesOutput{torch::empty({numChannels, 0}), 0.0};
}

StreamInfo& streamInfo = streamInfos_[activeStreamIndex_];

auto startPts = secondsToClosestPts(startSeconds, streamInfo.timeBase);
if (startPts < streamInfo.lastDecodedAvFramePts +
streamInfo.lastDecodedAvFrameDuration) {
Expand Down
2 changes: 1 addition & 1 deletion test/test_decoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ def test_not_at_frame_boundaries(self, asset):
def test_start_equals_stop(self, asset):
decoder = AudioDecoder(asset.path)
samples = decoder.get_samples_played_in_range(start_seconds=3, stop_seconds=3)
assert samples.data.shape == (0, 0)
assert samples.data.shape == (asset.num_channels, 0)

def test_frame_start_is_not_zero(self):
# For NASA_AUDIO_MP3, the first frame is not at 0, it's at 0.138125.
Expand Down
2 changes: 1 addition & 1 deletion test/test_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def test_decode_start_equal_stop(self, asset):
frames, pts_seconds = get_frames_by_pts_in_range_audio(
decoder, start_seconds=1, stop_seconds=1
)
assert frames.shape == (0, 0)
assert frames.shape == (asset.num_channels, 0)
assert pts_seconds == 0

@pytest.mark.parametrize("asset", (NASA_AUDIO, NASA_AUDIO_MP3))
Expand Down
Loading