{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"[Resized Train Dataset [1GB]](https://www.kaggle.com/datasets/yokuyama/dfl-resize-384x216)","metadata":{}},{"cell_type":"code","source":"!git clone https://git.videolan.org/git/ffmpeg/nv-codec-headers.git\n!cd nv-codec-headers && sudo make install","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-31T04:07:34.847930Z","iopub.execute_input":"2022-07-31T04:07:34.848320Z","iopub.status.idle":"2022-07-31T04:07:37.814036Z","shell.execute_reply.started":"2022-07-31T04:07:34.848243Z","shell.execute_reply":"2022-07-31T04:07:37.812731Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import os\nimport subprocess\nfrom pathlib import Path\n\nimport pandas as pd\n\nos.environ[\"NVIDIA_VISIBLE_DEVICES\"] = \"all\"","metadata":{"execution":{"iopub.status.busy":"2022-07-31T04:07:37.816147Z","iopub.execute_input":"2022-07-31T04:07:37.816452Z","iopub.status.idle":"2022-07-31T04:07:37.822941Z","shell.execute_reply.started":"2022-07-31T04:07:37.816421Z","shell.execute_reply":"2022-07-31T04:07:37.821691Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"SAVE_DIR = Path(\"./train_resize\")\nos.makedirs(SAVE_DIR, exist_ok=True)\n\ndf_train = pd.read_csv(\"../input/dfl-bundesliga-data-shootout/train.csv\")\ndf_train[\"file_path\"] = \"../input/dfl-bundesliga-data-shootout/train/\" + df_train[\"video_id\"] + \".mp4\"","metadata":{"execution":{"iopub.status.busy":"2022-07-31T04:07:37.824555Z","iopub.execute_input":"2022-07-31T04:07:37.825359Z","iopub.status.idle":"2022-07-31T04:07:37.870460Z","shell.execute_reply.started":"2022-07-31T04:07:37.825316Z","shell.execute_reply":"2022-07-31T04:07:37.869444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"target_size = \"384x216\"  # 20% of FullHD\ntarget_files = df_train.file_path.unique()[:1]","metadata":{"execution":{"iopub.status.busy":"2022-07-31T04:07:37.873537Z","iopub.execute_input":"2022-07-31T04:07:37.873840Z","iopub.status.idle":"2022-07-31T04:07:37.881390Z","shell.execute_reply.started":"2022-07-31T04:07:37.873816Z","shell.execute_reply":"2022-07-31T04:07:37.880410Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"USE_GPU = True\n\nfor i, fp in enumerate(target_files):\n    save_path = SAVE_DIR / os.path.basename(fp)\n    if USE_GPU:\n        cmd = f\"ffmpeg -y -c:v h264_cuvid -i {fp} -an -s {target_size} -c:v h264_nvenc {save_path}\"\n    else:\n        cmd = f\"ffmpeg -y -i {fp} -an -s {target_size} {save_path}\"\n    print(f\"{i+1:02}/{len(target_files):02} {fp}\")\n    subprocess.run(cmd, shell=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-31T04:07:49.379745Z","iopub.execute_input":"2022-07-31T04:07:49.380203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}