File tree Expand file tree Collapse file tree 1 file changed +13
-10
lines changed
src/torchcodec/decoders/_core Expand file tree Collapse file tree 1 file changed +13
-10
lines changed Original file line number Diff line number Diff line change @@ -1431,18 +1431,21 @@ void VideoDecoder::convertAudioAVFrameToFrameOutputOnCPU(
14311431
14321432 auto numSamples = avFrame->nb_samples ; // per channel
14331433 auto numChannels = getNumChannels (avFrame);
1434- torch::Tensor outputData =
1435- torch::empty ({numChannels, numSamples}, torch::kFloat32 );
14361434
1437- uint8_t * outputChannelData = static_cast <uint8_t *>(outputData.data_ptr ());
1438- auto numBytesPerChannel = numSamples * av_get_bytes_per_sample (format);
1439- for (auto channel = 0 ; channel < numChannels;
1440- ++channel, outputChannelData += numBytesPerChannel) {
1441- memcpy (
1442- outputChannelData, avFrame->extended_data [channel], numBytesPerChannel);
1435+ frameOutput.data = torch::empty ({numChannels, numSamples}, torch::kFloat32 );
1436+
1437+ if (numSamples > 0 ) {
1438+ uint8_t * outputChannelData =
1439+ static_cast <uint8_t *>(frameOutput.data .data_ptr ());
1440+ auto numBytesPerChannel = numSamples * av_get_bytes_per_sample (format);
1441+ for (auto channel = 0 ; channel < numChannels;
1442+ ++channel, outputChannelData += numBytesPerChannel) {
1443+ memcpy (
1444+ outputChannelData,
1445+ avFrame->extended_data [channel],
1446+ numBytesPerChannel);
1447+ }
14431448 }
1444-
1445- frameOutput.data = outputData;
14461449}
14471450
14481451UniqueAVFrame VideoDecoder::convertAudioAVFrameSampleFormatAndSampleRate (
You can’t perform that action at this time.
0 commit comments