{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Installation"},{"metadata":{},"cell_type":"markdown","source":"### Installing debian packages"},{"metadata":{"trusted":true},"cell_type":"code","source":"!dpkg -i --force-confdef /kaggle/input/video-tools/dpkgs/*.deb","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### Installing python packages"},{"metadata":{"trusted":true},"cell_type":"code","source":"!pip install /kaggle/input/video-tools/wheelhouse/proglog-0.1.9-cp36-none-any.whl\n!pip install /kaggle/input/video-tools/wheelhouse/PyGObject-3.34.0-cp36-cp36m-linux_x86_64.whl\n!pip install /kaggle/input/video-tools/wheelhouse/ffmpeg_python-0.2.0-py3-none-any.whl\n!pip install /kaggle/input/video-tools/wheelhouse/av-6.2.0-cp36-cp36m-linux_x86_64.whl\n!pip install /kaggle/input/video-tools/wheelhouse/imageio_ffmpeg-0.3.0-py3-none-manylinux2010_x86_64.whl\n!pip install /kaggle/input/video-tools/wheelhouse/scikit_video-1.1.11-py2.py3-none-any.whl\n!pip install /kaggle/input/video-tools/wheelhouse/moviepy-1.0.1-cp36-none-any.whl","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"example_video_path = \"../input/deepfake-detection-challenge/train_sample_videos/aelfnikyqj.mp4\"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import skvideo.io","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"","_uuid":"","trusted":true},"cell_type":"code","source":"%time [ skvideo.io.vread(example_video_path) for i in range(10) ]\n#print(videodata.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import cv2\ndef get_frames(VIDEO_STREAM):\n    frame_count = 0\n    vidcap = cv2.VideoCapture(VIDEO_STREAM)\n    while True:\n        hasFrames,image = vidcap.read()\n        if hasFrames == False:\n            break\n        else:\n            frame_count = frame_count + 1\n    return frame_count","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"%time [ get_frames(example_video_path) for i in range(10) ]\nprint(video_len)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"### ffmpeg extract frame from video"},{"metadata":{"trusted":true},"cell_type":"code","source":"from ipywidgets import interact\nfrom matplotlib import pyplot as plt\nimport ffmpeg\nimport ipywidgets as widgets\nimport numpy as np\n\nprobe = ffmpeg.probe(example_video_path)\nvideo_info = next(s for s in probe['streams'] if s['codec_type'] == 'video')\nwidth = int(video_info['width'])\nheight = int(video_info['height'])\nnum_frames = int(video_info['nb_frames'])\nprint(\"frames = {} [{} {}]\".format(num_frames, height, width))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import time\nstart = time.time()\nout, err = (\n    ffmpeg\n    .input(example_video_path)\n    .output('pipe:', format='rawvideo', pix_fmt='rgb24')\n    .run(capture_stdout=True)\n)\nvideo = (\n    np\n    .frombuffer(out, np.uint8)\n    .reshape([-1, height, width, 3])\n)\nprint(video.shape)\nend = time.time()\nprint(end - start)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from torchvision.datasets.video_utils import VideoClips\nvideo_clips = VideoClips([example_video_path], clip_length_in_frames=32, frames_between_clips=32)\nprint(len(video_clips))","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}