@@ -878,23 +878,27 @@ VideoDecoder::DecodedOutput VideoDecoder::convertAVFrameToDecodedOutput(
878878
879879void VideoDecoder::convertAVFrameToDecodedOutputOnCPU (
880880 VideoDecoder::RawDecodedOutput& rawOutput,
881- DecodedOutput& output) {
881+ DecodedOutput& output,
882+ torch::Tensor* tensor
883+ ) {
882884 int streamIndex = rawOutput.streamIndex ;
883885 AVFrame* frame = rawOutput.frame .get ();
884886 auto & streamInfo = streams_[streamIndex];
885887 if (output.streamType == AVMEDIA_TYPE_VIDEO) {
886888 if (streamInfo.colorConversionLibrary == ColorConversionLibrary::SWSCALE) {
887889 int width = streamInfo.options .width .value_or (frame->width );
888890 int height = streamInfo.options .height .value_or (frame->height );
889- torch::Tensor tensor = torch::empty (
891+ auto tmp = torch::empty (
890892 {height, width, 3 }, torch::TensorOptions ().dtype ({torch::kUInt8 }));
891- rawOutput.data = tensor.data_ptr <uint8_t >();
893+ tensor = &(tmp);
894+ rawOutput.data = tensor->data_ptr <uint8_t >();
892895 convertFrameToBufferUsingSwsScale (rawOutput);
893896
894897 if (streamInfo.options .dimensionOrder == " NCHW" ) {
895- tensor = tensor.permute ({2 , 0 , 1 });
898+ auto tmp = tensor->permute ({2 , 0 , 1 });
899+ tensor = &(tmp);
896900 }
897- output.frame = tensor;
901+ output.frame = * tensor;
898902 } else if (
899903 streamInfo.colorConversionLibrary ==
900904 ColorConversionLibrary::FILTERGRAPH) {
0 commit comments