Skip to content

Commit

Permalink
Quickly adding log-chroma analysis files, restructure to follow.
Browse files Browse the repository at this point in the history
  • Loading branch information
frankieeder authored and bmild committed Dec 3, 2019
1 parent ac4e9eb commit 5bf9414
Show file tree
Hide file tree
Showing 3 changed files with 4,613 additions and 0 deletions.
155 changes: 155 additions & 0 deletions temporal/find_cuts.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Install Dependencies\n",
"#!pip install scikit-image\n",
"#!pip install scenedetect[opencv,progress_bar]"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from __future__ import print_function\n",
"import io\n",
"import os\n",
"\n",
"import pandas as pd\n",
"import numpy as np\n",
"\n",
"from skimage import color\n",
"import cv2\n",
"\n",
"import scenedetect\n",
"from scenedetect.video_manager import VideoManager\n",
"from scenedetect.scene_manager import SceneManager\n",
"from scenedetect.frame_timecode import FrameTimecode\n",
"from scenedetect.stats_manager import StatsManager\n",
"from scenedetect.detectors import ContentDetector\n",
"\n",
"STATS_FILE_PATH = 'testvideo.stats.csv'\n",
"dataset_folder = \"../../data/\"\n",
"cuts_folder = \"../../data/cuts/\""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Find video cuts"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def find_video_cuts(dataset_folder, cuts_folder):\n",
" videos_to_detect = [\n",
" os.path.join(dataset_folder, f)\n",
" for f \n",
" in os.listdir(dataset_folder)\n",
" if os.path.isfile(os.path.join(dataset_folder, f))\n",
" ]\n",
" for i, video_dir in enumerate(videos_to_detect):\n",
" print(f\"Finding cuts of Video {video_dir}: {i+1}/{len(videos_to_detect)}\", end='\\r')\n",
"\n",
" # Check for already existing files and skip if already calculated\n",
" yt_id = vid_file.split('.')[0]\n",
" vid_cut_file = f'{yt_id}_cuts.npy'\n",
" vid_cut_dir = os.path.join(cuts_folder, vid_cut_file)\n",
" if os.path.exists(vid_cut_dir):\n",
" continue\n",
"\n",
" # Create a video_manager point to video file testvideo.mp4. Note that multiple\n",
" # videos can be appended by simply specifying more file paths in the list\n",
" # passed to the VideoManager constructor. Note that appending multiple videos\n",
" # requires that they all have the same frame size, and optionally, framerate.\n",
" try:\n",
" video_manager = VideoManager([video_dir])\n",
" stats_manager = StatsManager()\n",
" scene_manager = SceneManager(stats_manager)\n",
" # Add ContentDetector algorithm (constructor takes detector options like threshold).\n",
" scene_manager.add_detector(ContentDetector())\n",
" base_timecode = video_manager.get_base_timecode()\n",
"\n",
" try:\n",
" # Set downscale factor to improve processing speed (no args means default).\n",
" video_manager.set_downscale_factor()\n",
"\n",
" # Start video_manager.\n",
" video_manager.start()\n",
"\n",
" # Perform scene detection on video_manager.\n",
" scene_manager.detect_scenes(frame_source=video_manager)\n",
"\n",
" # Obtain list of detected scenes.\n",
" scene_list = scene_manager.get_scene_list(base_timecode)\n",
" # Like FrameTimecodes, each scene in the scene_list can be sorted if the\n",
" # list of scenes becomes unsorted.\n",
"\n",
" times = np.array([s[0].get_frames() for s in scene_list])\n",
" np.save(vid_cut_dir, times)\n",
" finally:\n",
" video_manager.release()\n",
" except:\n",
" pass"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Find Cinematic Video Cuts\n",
"find_video_cuts(\n",
" dataset_folder=\"../../data/\",\n",
" cuts_folder=\"../../data/cuts/\"\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Find Casual Video Cuts\n",
"find_video_cuts(\n",
" dataset_folder=\"../../data/casual/\",\n",
" cuts_folder=\"../../data/casual/cuts/\"\n",
")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit 5bf9414

Please sign in to comment.