Skip to content
Permalink
Browse files

refactor(preprocessor): use io utils in audio and gif

  • Loading branch information...
jemmyshin committed Aug 28, 2019
1 parent 9a791c2 commit 0c6f4851d9408735b108287c1d1261434b263cb0
@@ -16,24 +16,22 @@
import numpy as np

from ..base import BaseAudioPreprocessor
from ..helper import get_video_length_from_raw, get_audio
from ...proto import array2blob
from ..io_utils.audio import split_audio


class AudioVanilla(BaseAudioPreprocessor):

def __init__(self, audio_interval: int,
def __init__(self,
sample_rate: int, *args, **kwargs):
super().__init__(*args, **kwargs)
self.audio_interval = audio_interval
self.sample_rate = sample_rate

def apply(self, doc: 'gnes_pb2.Document') -> None:
super().apply(doc)

if doc.raw_bytes:
audio = get_audio(doc.raw_bytes, self.sample_rate,
self.audio_interval, get_video_length_from_raw(doc.raw_bytes))
audio = split_audio(input_data=doc.raw_bytes, sample_rate=self.sample_rate)
if len(audio) >= 1:
for ci, chunks in enumerate(audio):
c = doc.chunks.add()
@@ -147,6 +147,7 @@ def split_audio(input_fn: str = 'pipe:',
silence_duration=DEFAULT_SILENCE_DURATION,
start_time: float = None,
end_time: float = None,
sample_rate: int = 16000,
verbose=False):
_check_input(input_fn, input_data)
chunk_times = get_chunk_times(
@@ -157,7 +158,7 @@ def split_audio(input_fn: str = 'pipe:',
start_time=start_time,
end_time=end_time)
audio_chunks = list()
print("chunk_times", chunk_times)
# print("chunk_times", chunk_times)
for i, (start_time, end_time) in enumerate(chunk_times):
time = end_time - start_time
if time < 0:
@@ -169,7 +170,8 @@ def split_audio(input_fn: str = 'pipe:',
}

output_kwargs = {
'format': 'wav'
'format': 'wav',
'ar': sample_rate
}

cmd_args = compile_args(
@@ -19,7 +19,7 @@
import numpy as np

from ..base import BaseVideoPreprocessor, RawChunkPreprocessor
from ..helper import split_video_frames, phash_descriptor, get_gif
from ..helper import split_video_frames, phash_descriptor
from ...proto import gnes_pb2, array2blob, blob2array
from ..io_utils import video as video_util

@@ -187,4 +187,6 @@ def apply(self, doc: 'gnes_pb2.Document') -> None:
class GifChunkPreprocessor(RawChunkPreprocessor, BaseVideoPreprocessor):
@staticmethod
def _parse_chunk(chunk: 'gnes_pb2.Chunk', *args, **kwargs):
return get_gif(blob2array(chunk.blob))
from ..io_utils import gif as gif_util

return gif_util.encode_gif(blob2array(chunk.blob), fps=10)

0 comments on commit 0c6f485

Please sign in to comment.
You can’t perform that action at this time.