Skip to content
Permalink
Browse files

Add max duration for time segments, and a joiner, it works!

  • Loading branch information...
burningion committed Feb 28, 2019
1 parent d05742b commit 75e52c87ea8c2e3d82907e440db51ad56761985a
Showing with 26 additions and 5 deletions.
  1. +1 −0 Dockerfile
  2. +13 −0 joiner.py
  3. +12 −5 splitter.py
@@ -39,6 +39,7 @@ RUN python3 -m pip install -r requirements.txt
COPY app.py .
COPY video-to-json.py /workspace/pytorch-yolo-v3
COPY splitter.py .
COPY joiner.py .
EXPOSE 5007
ENV NVIDIA_VISIBLE_DEVICES all
CMD ["ddtrace-run", "python3", "app.py"]
@@ -0,0 +1,13 @@
import subprocess
import glob
import random

filelist = glob.glob('*.mp4')

with open('/downloads/slices/filelist.txt', 'w') as f:
for i in range(100):
f.write("file %s\n" % random.choice(filelist))

f.close()


@@ -14,14 +14,21 @@ def get_sec(time_str):
h, m, s = time_str.split(':')
return int(h) * 3600 + int(m) * 60 + int(s)

def getHrMinSec(seconds):
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
return '{:d}:{:02d}:{:02d}'.format(h, m, s)

for inference in b['inferences']:
for i in range(len(inference['clock_segments'])):
#length = 2
#if get_sec(inference['clock_segments'][i]['length']) >= 2:
# length = get_sec(inference['clock_segments'][i]['length'])
length = getHrMinSec(10)
if get_sec(inference['clock_segments'][i]['length']) >= 10:
length = getHrMinSec(10)
else:
length = get_sec(inference['clock_segments'][i]['length'])
if inference['filename'][-4:] == 'webm':
command = f"ffmpeg -hwaccel cuvid -c:v vp8_cuvid -i '{inference['filename']}' -ss {inference['clock_segments'][i]['start']} -t {inference['clock_segments'][i]['length']} -f mp4 -filter:v scale_npp=w=1280:h=720:format=yuv420p:interp_algo=lanczos -c:v h264_nvenc -preset slow -acodec aac -r 30 /downloads/slices/{counter:05d}.mp4 -hide_banner"
command = f"ffmpeg -hwaccel cuvid -c:v vp8_cuvid -i '{inference['filename']}' -ss {inference['clock_segments'][i]['start']} -t {length} -f mp4 -filter:v scale_npp=w=1280:h=720:format=yuv420p:interp_algo=lanczos -c:v h264_nvenc -preset slow -acodec aac -r 30 /downloads/slices/{counter:05d}.mp4 -hide_banner"
else:
command = f"ffmpeg -hwaccel cuvid -c:v h264_cuvid -i '{inference['filename']}' -ss {inference['clock_segments'][i]['start']} -t {inference['clock_segments'][i]['length']} -f mp4 -filter:v scale_npp=w=1280:h=720:format=yuv420p:interp_algo=lanczos -c:v h264_nvenc -preset slow -acodec aac -r 30 /downloads/slices/{counter:05d}.mp4 -hide_banner"
command = f"ffmpeg -hwaccel cuvid -c:v h264_cuvid -i '{inference['filename']}' -ss {inference['clock_segments'][i]['start']} -t {length} -f mp4 -filter:v scale_npp=w=1280:h=720:format=yuv420p:interp_algo=lanczos -c:v h264_nvenc -preset slow -acodec aac -r 30 /downloads/slices/{counter:05d}.mp4 -hide_banner"
subprocess.call(shlex.split(command))
counter += 1

0 comments on commit 75e52c8

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