@@ -893,7 +893,10 @@ void VideoDecoder::convertAVFrameToDecodedOutputOnCPU(
893893 // TODO: check shape of preAllocatedOutputTensor?
894894 tensor = preAllocatedOutputTensor;
895895 } else {
896- tensor = allocateOutputTensorFromRawOutput (rawOutput);
896+ int width = streamInfo.options .width .value_or (frame->width );
897+ int height = streamInfo.options .height .value_or (frame->height );
898+ tensor = torch::empty (
899+ {height, width, 3 }, torch::TensorOptions ().dtype ({torch::kUInt8 }));
897900 }
898901
899902 rawOutput.data = tensor.data_ptr <uint8_t >();
@@ -920,16 +923,6 @@ void VideoDecoder::convertAVFrameToDecodedOutputOnCPU(
920923 }
921924}
922925
923- torch::Tensor VideoDecoder::allocateOutputTensorFromRawOutput (
924- RawDecodedOutput& rawOutput) {
925- AVFrame* frame = rawOutput.frame .get ();
926- StreamInfo& streamInfo = streams_[rawOutput.streamIndex ];
927- int width = streamInfo.options .width .value_or (frame->width );
928- int height = streamInfo.options .height .value_or (frame->height );
929- return torch::empty (
930- {height, width, 3 }, torch::TensorOptions ().dtype ({torch::kUInt8 }));
931- }
932-
933926VideoDecoder::DecodedOutput VideoDecoder::getFrameDisplayedAtTimestampNoDemux (
934927 double seconds) {
935928 for (auto & [streamIndex, stream] : streams_) {
@@ -963,7 +956,7 @@ VideoDecoder::DecodedOutput VideoDecoder::getFrameDisplayedAtTimestampNoDemux(
963956 return seconds >= frameStartTime && seconds < frameEndTime;
964957 });
965958 // Convert the frame to tensor.
966- auto preAllocatedOutputTensor = allocateOutputTensorFromRawOutput (rawOutput );
959+ auto preAllocatedOutputTensor = torch::empty ({ 0 } );
967960 return convertAVFrameToDecodedOutput (rawOutput, preAllocatedOutputTensor);
968961}
969962
0 commit comments