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(
1431
1431
1432
1432
auto numSamples = avFrame->nb_samples ; // per channel
1433
1433
auto numChannels = getNumChannels (avFrame);
1434
- torch::Tensor outputData =
1435
- torch::empty ({numChannels, numSamples}, torch::kFloat32 );
1436
1434
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
+ }
1443
1448
}
1444
-
1445
- frameOutput.data = outputData;
1446
1449
}
1447
1450
1448
1451
UniqueAVFrame VideoDecoder::convertAudioAVFrameSampleFormatAndSampleRate (
You can’t perform that action at this time.
0 commit comments