Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Improve create_dataset, video_to_slomo #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions data/create_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import os.path
from shutil import rmtree, move
import subprocess
import random

# For parsing commandline arguments
Expand Down Expand Up @@ -37,8 +38,9 @@ def extract_frames(videos, inDir, outDir):

for video in videos:
os.mkdir(os.path.join(outDir, os.path.splitext(video)[0]))
retn = os.system('{} -i {} -vf scale={}:{} -vsync 0 -qscale:v 2 {}/%04d.jpg'.format(os.path.join(args.ffmpeg_dir, "ffmpeg"), os.path.join(inDir, video), args.img_width, args.img_height, os.path.join(outDir, os.path.splitext(video)[0])))
if retn:
try:
subprocess.check_call([os.path.join(args.ffmpeg_dir, "ffmpeg"), '-i', os.path.join(inDir, video), '-vf', 'scale={}:{}'.format(args.img_width, args.img_height), '-vsync', '0', '-qscale:v', '2', '{}/%09d.jpg'.format(os.path.join(outDir, os.path.splitext(video)[0]))])
except subprocess.CalledProcessError:
print("Error converting file:{}. Exiting.".format(video))


Expand Down
26 changes: 13 additions & 13 deletions video_to_slomo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import argparse
import os
import os.path
import subprocess
import ctypes
from shutil import rmtree, move
from PIL import Image
Expand Down Expand Up @@ -66,21 +67,20 @@ def extract_frames(video, outDir):
"""


error = ""
print('{} -i {} -vsync 0 -qscale:v 2 {}/%06d.jpg'.format(os.path.join(args.ffmpeg_dir, "ffmpeg"), video, outDir))
retn = os.system('{} -i {} -vsync 0 -qscale:v 2 {}/%06d.jpg'.format(os.path.join(args.ffmpeg_dir, "ffmpeg"), video, outDir))
if retn:
error = "Error converting file:{}. Exiting.".format(video)
return error
cmd = [os.path.join(args.ffmpeg_dir, "ffmpeg"), '-i', video, '-vsync', '0', '-qscale:v', '2', '{}/%06d.jpg'.format(outDir)]
print(' '.join(cmd))
try:
subprocess.check_call(cmd)
except CalledProcessError:
return "Error converting file:{}. Exiting.".format(video)

def create_video(dir):
error = ""
print('{} -r {} -i {}/%d.jpg -qscale:v 2 {}'.format(os.path.join(args.ffmpeg_dir, "ffmpeg"), args.fps, dir, args.output))
retn = os.system('{} -r {} -i {}/%d.jpg -crf 17 -vcodec libx264 {}'.format(os.path.join(args.ffmpeg_dir, "ffmpeg"), args.fps, dir, args.output))
if retn:
error = "Error creating output video. Exiting."
return error

cmd = [os.path.join(args.ffmpeg_dir, "ffmpeg"), '-r', str(args.fps), '-i', '{}/%d.jpg'.format(dir), '-crf', '17', '-vcodec', 'libx264', args.output]
print(' '.join(cmd))
try:
subprocess.check_call(cmd)
except CalledProcessError:
return "Error creating output video. Exiting."

def main():
# Check if arguments are okay
Expand Down