-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from boostcampaitech3/jj/feat
[feat] 데이터 추가를 위한 비디오를 이미지로 변환하는 코드 #81
- Loading branch information
Showing
1 changed file
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 31, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 32, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def createDir(dir):\n", | ||
" if not os.path.exists(dir):\n", | ||
" os.makedirs(dir)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 33, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"180925_01_07.mp4\n", | ||
"210416_04_CrimeScene_4k_007.mp4\n", | ||
"210416_02_CrimeScene_4k_005.mp4\n", | ||
"210416_03_CrimeScene_4k_023.mp4\n", | ||
"210416_01_CrimeScene_4k_021.mp4\n", | ||
"210416_03_CrimeScene_4k_025.mp4\n", | ||
"210416_03_CrimeScene_4k_032.mp4\n", | ||
"210416_01_CrimeScene_4k_012.mp4\n", | ||
"180925_01_03.mp4\n", | ||
"210416_03_CrimeScene_4k_030.mp4\n", | ||
"180925_01_05.mp4\n", | ||
"210416_01_CrimeScene_4k_027.mp4\n", | ||
"180925_01_06.mp4\n", | ||
"210416_04_CrimeScene_4k_012.mp4\n", | ||
"180925_01_04.mp4\n", | ||
"180925_02_04.mp4\n", | ||
"210416_01_CrimeScene_4k_016.mp4\n", | ||
"210416_03_CrimeScene_4k_033.mp4\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# 동영상 폴더 경로 넣기\n", | ||
"vid_path = 'JJ/'\n", | ||
"file_list = os.listdir(vid_path)\n", | ||
"\n", | ||
"blood_vid_list = []\n", | ||
"\n", | ||
"for file in file_list:\n", | ||
" if file[-4:] == '.mp4':\n", | ||
" print(file)\n", | ||
" blood_vid_list.append(file)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 34, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"num of blood vids: 18\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"print('num of blood vids:', len(blood_vid_list))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 35, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"createDir('frame_images')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 36, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for b in blood_vid_list:\n", | ||
" file_path = os.path.join(vid_path, b)\n", | ||
"\n", | ||
" if ' ' in file_path:\n", | ||
" \n", | ||
" new_name = file_path.replace(' ', '')\n", | ||
" os.rename(file_path, new_name)\n", | ||
" file_path = new_name\n", | ||
" \n", | ||
" os.system(\"ffmpeg -hide_banner -loglevel error -i \"+ file_path +' -vf fps=1 -s 640x360 -qscale:v 4 -b 800k frame_images/'+b[:-4]+'-%6d.jpg'\" < /dev/null\")\n", | ||
" " | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 37, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"360" | ||
] | ||
}, | ||
"execution_count": 37, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"len(os.listdir('./frame_images/'))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3.8.10 64-bit", | ||
"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.8.10" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |