Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
fix(preprocessor): add solution for raw_video
Browse files Browse the repository at this point in the history
  • Loading branch information
raccoonliukai committed Sep 25, 2019
1 parent 965349d commit 3b1f963
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions gnes/preprocessor/video/video_decode.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import numpy as np
from typing import List

from gnes.preprocessor.base import BaseVideoPreprocessor
from gnes.proto import gnes_pb2, array2blob
from gnes.preprocessor.io_utils import video
Expand All @@ -38,17 +35,28 @@ def __init__(self,
def apply(self, doc: 'gnes_pb2.Document') -> None:
super().apply(doc)

if doc.raw_bytes:
all_frames = video.capture_frames(
input_data=doc.raw_bytes,
scale=self.scale,
fps=self.frame_rate,
vframes=self.vframes)

c = doc.chunks.add()
c.doc_id = doc.doc_id
c.blob.CopyFrom(array2blob(all_frames))
c.offset = 0
c.weight = 1.0
all_frames = []
if doc.WhichOneof('raw_data'):
raw_type = type(getattr(doc, doc.WhichOneof('raw_data')))
if doc.raw_bytes:
all_frames = video.capture_frames(
input_data=doc.raw_bytes,
scale=self.scale,
fps=self.frame_rate,
vframes=self.vframes)
elif raw_type == gnes_pb2.NdArray:
all_frames = blob2array(doc.raw_video)
if self.vframes > 0:
all_frames = video_frames[0:self.vframes, :].copy()

num_frames = len(all_frames)
if num_frames > 0:
c = doc.chunks.add()
c.doc_id = doc.doc_id
c.blob.CopyFrom(array2blob(all_frames))
c.offset = 0
c.weight = 1.0
else:
self.logger.error('bad document: "raw_bytes" or "raw_video" is empty!')
else:
self.logger.error('bad document: "raw_bytes" is empty!')

0 comments on commit 3b1f963

Please sign in to comment.