From 3e2aa18071d8dbe67ea4619392b097d83b9cf17e Mon Sep 17 00:00:00 2001 From: Jaeho Bang Date: Thu, 13 Aug 2020 13:21:57 -0400 Subject: [PATCH] Adding custom examples and debugging procedures --- examples/encoder_prototyping.py | 49 +++++++++++++++++++++++++++++++++ examples/iframe_extraction.py | 36 ++++++++++++++++++++++++ ffmpeg/_run.py | 1 + 3 files changed, 86 insertions(+) create mode 100644 examples/encoder_prototyping.py create mode 100644 examples/iframe_extraction.py diff --git a/examples/encoder_prototyping.py b/examples/encoder_prototyping.py new file mode 100644 index 00000000..aa3b3f20 --- /dev/null +++ b/examples/encoder_prototyping.py @@ -0,0 +1,49 @@ +import ffmpeg +import numpy as np + +import os +import sys +sys.argv=[''] +sys.path.append('/nethome/jbang36/eva_jaeho') + +from loaders.seattle_loader import SeattleLoader + + + + + + +if __name__ == "__main__": + ###dummy_video = np.ndarray(shape = (10, 100, 200, 3)) -- let's try loading a normal video + original_video = '/nethome/jbang36/eva_jaeho/data/seattle/seattle2_10min.mp4' + + seattle_loader = SeattleLoader() + dummy_video = seattle_loader.load_images(original_video) + ## we will see if we can load and save the dummy video + + + framerate = 25 + _, height, width, _ = dummy_video.shape + fn = '/nethome/jbang36/eva_jaeho/data/seattle/test2.mp4' + + vcodec = 'libx264' + + process = ( + ffmpeg + .input('pipe:', format='rawvideo', r=framerate, pix_fmt='rgb24', s='{}x{}'.format(width, height)) + .output(fn, pix_fmt='yuv420p', vcodec=vcodec) + .overwrite_output() + .run_async(pipe_stdin=True, pipe_stdout=True) + ) + + for frame in dummy_video: + process.stdin.write( + frame + .astype(np.uint8) + .tobytes() + ) + process.stdin.close() + process.wait() + + + diff --git a/examples/iframe_extraction.py b/examples/iframe_extraction.py new file mode 100644 index 00000000..4d76bbae --- /dev/null +++ b/examples/iframe_extraction.py @@ -0,0 +1,36 @@ + + +### testing the ffmpeg-python library + +import ffmpeg + + +if __name__ == "__main__": + ## we will first try running a normal command and see what each function does + import time + st = time.perf_counter() + dir = '/nethome/jbang36/eva_jaeho/data/seattle/seattle2_final.mp4' + ### I think we can add arguments to the input to make the final string + ##stream = ffmpeg.input(dir) + input_kwargs = {'vf': "select='eq(pict_type,I)'", 'vsync':'vfr'} + stream = ffmpeg.input(dir) + + print(f"{time.perf_counter() - st} seconds") + st = time.perf_counter() + stream = stream.output('pipe:', format='rawvideo', pix_fmt='rgb24', vf= "select='eq(pict_type,I)'", vsync='vfr') + print(f"{time.perf_counter() - st} seconds") + st = time.perf_counter() + out, tmp = stream.run(capture_stdout=True) + print(f"{time.perf_counter() - st} seconds") + + + """ + inFile = '/nethome/jbang36/eva_jaeho/data/seattle/seattle2_final.mp4' + outFile = '/nethome/jbang36/eva_jaeho/data/seattle/tmp.jpeg' + + stream = ['ffmpeg', '-i', inFile,'-f', 'image2','-vf', "select='eq(pict_type,PICT_TYPE_I)'",'-vsync','vfr',outFile] + + + arguments = ffmpeg.get_args(stream) + + """ \ No newline at end of file diff --git a/ffmpeg/_run.py b/ffmpeg/_run.py index c9cbb7ce..018660bd 100644 --- a/ffmpeg/_run.py +++ b/ffmpeg/_run.py @@ -281,6 +281,7 @@ def run_async( stdin_stream = subprocess.PIPE if pipe_stdin else None stdout_stream = subprocess.PIPE if pipe_stdout or quiet else None stderr_stream = subprocess.PIPE if pipe_stderr or quiet else None + print(args) return subprocess.Popen( args, stdin=stdin_stream, stdout=stdout_stream, stderr=stderr_stream )