• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright 2024 Huawei Technologies Co., Ltd
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "minddata/dataset/kernels/image/decode_video_op.h"
17 
18 #include "minddata/dataset/kernels/image/image_utils.h"
19 #include "minddata/dataset/kernels/image/video_utils.h"
20 #include "minddata/dataset/util/status.h"
21 
22 namespace mindspore {
23 namespace dataset {
DecodeVideoOp()24 DecodeVideoOp::DecodeVideoOp() {}
25 
Compute(const TensorRow & input,TensorRow * output)26 Status DecodeVideoOp::Compute(const TensorRow &input, TensorRow *output) {
27   IO_CHECK_VECTOR(input, output);
28   // check the input tensor shape
29   if (input[0]->Rank() != 1) {
30     RETURN_STATUS_UNEXPECTED("DecodeVideo: invalid input shape, only support 1D input, got rank: " +
31                              std::to_string(input[0]->Rank()));
32   }
33   return DecodeVideo(input, output);
34 }
35 
OutputShape(const std::vector<TensorShape> & inputs,std::vector<TensorShape> & outputs)36 Status DecodeVideoOp::OutputShape(const std::vector<TensorShape> &inputs, std::vector<TensorShape> &outputs) {
37   RETURN_IF_NOT_OK(TensorOp::OutputShape(inputs, outputs));
38   outputs.clear();
39   // kDefaultImageRank is 3
40   TensorShape visual_shape({-1, -1, -1, kDefaultImageRank});
41   TensorShape audio_shape({-1, -1});
42   if (inputs[0].Rank() == 1) {
43     outputs.emplace_back(visual_shape);
44     outputs.emplace_back(audio_shape);
45   } else {
46     RETURN_STATUS_UNEXPECTED("DecodeVideo: invalid input shape, expected 1D input, but got input dimension: " +
47                              std::to_string(inputs[0].Rank()));
48   }
49   return Status::OK();
50 }
51 
OutputType(const std::vector<DataType> & inputs,std::vector<DataType> & outputs)52 Status DecodeVideoOp::OutputType(const std::vector<DataType> &inputs, std::vector<DataType> &outputs) {
53   RETURN_IF_NOT_OK(TensorOp::OutputType(inputs, outputs));
54   outputs[0] = DataType(DataType::DE_UINT8);
55   outputs[1] = DataType(DataType::DE_UNKNOWN);
56   return Status::OK();
57 }
58 }  // namespace dataset
59 }  // namespace mindspore
60