Last active
September 20, 2022 16:07
-
-
Save mizar/34453d0822b5f6ccaf722c50b90f71ef to your computer and use it in GitHub Desktop.
vrc-lt-converter
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
{ | |
"nbformat": 4, | |
"nbformat_minor": 0, | |
"metadata": { | |
"colab": { | |
"name": "vrc-lt-converter", | |
"provenance": [], | |
"collapsed_sections": [], | |
"include_colab_link": true | |
}, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3" | |
}, | |
"language_info": { | |
"name": "python" | |
} | |
}, | |
"cells": [ | |
{ | |
"cell_type": "markdown", | |
"metadata": { | |
"id": "view-in-github", | |
"colab_type": "text" | |
}, | |
"source": [ | |
"<a href=\"https://colab.research.google.com/gist/mizar/34453d0822b5f6ccaf722c50b90f71ef/vrc-lt-converter_4k.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>" | |
] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [ | |
"# VRC-LT スライド変換ツール\n", | |
"\n", | |
"https://vrc-lt.org/\n", | |
"\n", | |
"pdf形式スライドファイルを、1ページあたり2秒・画面アスペクト比16:9のmp4動画ファイルに変換します。\n", | |
"\n", | |
"出力する解像度を選択してから、ランタイム→すべてのセルを実行(Ctrl+F9)で処理を開始し、変換したいpdfファイルをアップロードしてください。処理が終了したら、変換後のmp4ファイルをダウンロードできます。" | |
], | |
"metadata": { | |
"id": "OJ6zTFo8AlRF" | |
} | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#@title 出力解像度を選択してからランタイムを実行してください\n", | |
"output_resolution = \"720p\" #@param [\"720p\", \"1080p\", \"1440p\", \"2160p\"]\n", | |
"output_resolution_xy = {\"720p\": (1280, 720), \"1080p\": (1920, 1080), \"1440p\": (2560, 1440), \"2160p\": (3840, 2160)}[output_resolution]" | |
], | |
"metadata": { | |
"id": "QC7OoHLSw9PR", | |
"cellView": "form" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#@title pdfファイルをアップロードしてください\n", | |
"from google.colab import files\n", | |
"import os\n", | |
"!rm -f *.pdf\n", | |
"result = files.upload()\n", | |
"pdf_file_name = list(result.keys())[0]\n", | |
"base_file_name = os.path.splitext(pdf_file_name)[0]\n" | |
], | |
"metadata": { | |
"id": "ke7xDndQfVoG", | |
"cellView": "form" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#@title 環境をセットアップしています...\n", | |
"!sudo apt update\n", | |
"!sudo apt install --no-install-recommends ffmpeg poppler-utils poppler-data fonts-liberation2 fonts-noto-cjk\n", | |
"!mkdir -p ~/.config/fontconfig/\n", | |
"!echo -e \"<?xml version='1.0'?>\\n<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>\\n<fontconfig>\\n<alias><family>serif</family><prefer><family>Noto Serif</family><family>Noto Serif CJK JP</family></prefer></alias>\\n<alias><family>sans-serif</family><prefer><family>Noto Sans</family><family>Noto Sans CJK JP</family></prefer></alias>\\n<alias><family>monospace</family><prefer><family>Noto Sans Mono</family><family>Noto Sans Mono CJK JP</family></prefer></alias>\\n<alias><family>Ryumin</family><prefer><family>Noto Serif</family><family>Noto Serif CJK JP</family></prefer></alias>\\n<alias><family>GothicBBB</family><prefer><family>Noto Sans</family><family>Noto Sans CJK JP</family></prefer></alias>\\n</fontconfig>\" > ~/.config/fontconfig/fonts.conf\n", | |
"!fc-cache -f\n" | |
], | |
"metadata": { | |
"id": "imAz2ee-Zell", | |
"cellView": "form", | |
"colab": { | |
"base_uri": "https://localhost:8080/" | |
}, | |
"outputId": "10a255f0-5712-4a95-fa49-385045a3f7c7" | |
}, | |
"execution_count": 1, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"name": "stdout", | |
"text": [ | |
"\u001b[33m\r0% [Working]\u001b[0m\r \rGet:1 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/ InRelease [3,626 B]\n", | |
"\u001b[33m\r0% [Connecting to archive.ubuntu.com (185.125.190.36)] [Connecting to security.\u001b[0m\u001b[33m\r0% [Connecting to archive.ubuntu.com (185.125.190.36)] [Connecting to security.\u001b[0m\u001b[33m\r0% [1 InRelease gpgv 3,626 B] [Connecting to archive.ubuntu.com (185.125.190.36\u001b[0m\r \rHit:2 http://archive.ubuntu.com/ubuntu bionic InRelease\n", | |
"\u001b[33m\r0% [1 InRelease gpgv 3,626 B] [Waiting for headers] [Waiting for headers] [Wait\u001b[0m\r \rGet:3 http://ppa.launchpad.net/c2d4u.team/c2d4u4.0+/ubuntu bionic InRelease [15.9 kB]\n", | |
"\u001b[33m\r0% [1 InRelease gpgv 3,626 B] [Waiting for headers] [Waiting for headers] [Wait\u001b[0m\r \rGet:4 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB]\n", | |
"\u001b[33m\r0% [1 InRelease gpgv 3,626 B] [Waiting for headers] [4 InRelease 14.2 kB/88.7 k\u001b[0m\u001b[33m\r0% [Waiting for headers] [4 InRelease 14.2 kB/88.7 kB 16%] [Waiting for headers\u001b[0m\u001b[33m\r0% [2 InRelease gpgv 242 kB] [Waiting for headers] [4 InRelease 14.2 kB/88.7 kB\u001b[0m\r \rGet:5 https://cloud.r-project.org/bin/linux/ubuntu bionic-cran40/ Packages [92.1 kB]\n", | |
"Ign:6 https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 InRelease\n", | |
"Hit:7 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64 InRelease\n", | |
"Get:8 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [88.7 kB]\n", | |
"Hit:9 https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64 Release\n", | |
"Hit:10 http://ppa.launchpad.net/cran/libgit2/ubuntu bionic InRelease\n", | |
"Get:12 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [74.6 kB]\n", | |
"Hit:13 http://ppa.launchpad.net/deadsnakes/ppa/ubuntu bionic InRelease\n", | |
"Get:14 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1,545 kB]\n", | |
"Hit:15 http://ppa.launchpad.net/graphics-drivers/ppa/ubuntu bionic InRelease\n", | |
"Get:16 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [1,202 kB]\n", | |
"Get:17 http://ppa.launchpad.net/c2d4u.team/c2d4u4.0+/ubuntu bionic/main Sources [2,108 kB]\n", | |
"Get:18 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [2,989 kB]\n", | |
"Get:19 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [2,322 kB]\n", | |
"Get:20 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [1,161 kB]\n", | |
"Get:21 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [3,421 kB]\n", | |
"Get:22 http://ppa.launchpad.net/c2d4u.team/c2d4u4.0+/ubuntu bionic/main amd64 Packages [1,080 kB]\n", | |
"Fetched 16.2 MB in 2s (7,976 kB/s)\n", | |
"Reading package lists... Done\n", | |
"Building dependency tree \n", | |
"Reading state information... Done\n", | |
"38 packages can be upgraded. Run 'apt list --upgradable' to see them.\n", | |
"Reading package lists... Done\n", | |
"Building dependency tree \n", | |
"Reading state information... Done\n", | |
"ffmpeg is already the newest version (7:3.4.11-0ubuntu0.1).\n", | |
"The following package was automatically installed and is no longer required:\n", | |
" libnvidia-common-460\n", | |
"Use 'sudo apt autoremove' to remove it.\n", | |
"The following additional packages will be installed:\n", | |
" libpoppler-dev libpoppler-private-dev libpoppler73\n", | |
"Suggested packages:\n", | |
" fonts-noto-cjk-extra ghostscript fonts-japanese-mincho\n", | |
" | fonts-ipafont-mincho fonts-japanese-gothic | fonts-ipafont-gothic\n", | |
" fonts-arphic-ukai fonts-arphic-uming fonts-nanum\n", | |
"The following NEW packages will be installed:\n", | |
" fonts-liberation2 fonts-noto-cjk poppler-data poppler-utils\n", | |
"The following packages will be upgraded:\n", | |
" libpoppler-dev libpoppler-private-dev libpoppler73\n", | |
"3 upgraded, 4 newly installed, 0 to remove and 35 not upgraded.\n", | |
"Need to get 59.7 MB of archives.\n", | |
"After this operation, 109 MB of additional disk space will be used.\n", | |
"Get:1 http://archive.ubuntu.com/ubuntu bionic/main amd64 poppler-data all 0.4.8-2 [1,479 kB]\n", | |
"Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 fonts-liberation2 all 2.00.1-7~18.04.2 [1,455 kB]\n", | |
"Get:3 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 fonts-noto-cjk all 1:20190409+repack1-0ubuntu0.18.04 [55.7 MB]\n", | |
"Get:4 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpoppler-private-dev amd64 0.62.0-2ubuntu2.14 [169 kB]\n", | |
"Get:5 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpoppler-dev amd64 0.62.0-2ubuntu2.14 [4,616 B]\n", | |
"Get:6 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 libpoppler73 amd64 0.62.0-2ubuntu2.14 [800 kB]\n", | |
"Get:7 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 poppler-utils amd64 0.62.0-2ubuntu2.14 [154 kB]\n", | |
"Fetched 59.7 MB in 2s (25.2 MB/s)\n", | |
"debconf: unable to initialize frontend: Dialog\n", | |
"debconf: (No usable dialog-like program is installed, so the dialog based frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 76, <> line 7.)\n", | |
"debconf: falling back to frontend: Readline\n", | |
"debconf: unable to initialize frontend: Readline\n", | |
"debconf: (This frontend requires a controlling tty.)\n", | |
"debconf: falling back to frontend: Teletype\n", | |
"dpkg-preconfigure: unable to re-open stdin: \n", | |
"Selecting previously unselected package poppler-data.\n", | |
"(Reading database ... 155569 files and directories currently installed.)\n", | |
"Preparing to unpack .../0-poppler-data_0.4.8-2_all.deb ...\n", | |
"Unpacking poppler-data (0.4.8-2) ...\n", | |
"Selecting previously unselected package fonts-liberation2.\n", | |
"Preparing to unpack .../1-fonts-liberation2_2.00.1-7~18.04.2_all.deb ...\n", | |
"Unpacking fonts-liberation2 (2.00.1-7~18.04.2) ...\n", | |
"Selecting previously unselected package fonts-noto-cjk.\n", | |
"Preparing to unpack .../2-fonts-noto-cjk_1%3a20190409+repack1-0ubuntu0.18.04_all.deb ...\n", | |
"Unpacking fonts-noto-cjk (1:20190409+repack1-0ubuntu0.18.04) ...\n", | |
"Preparing to unpack .../3-libpoppler-private-dev_0.62.0-2ubuntu2.14_amd64.deb ...\n", | |
"Unpacking libpoppler-private-dev:amd64 (0.62.0-2ubuntu2.14) over (0.62.0-2ubuntu2.13) ...\n", | |
"Preparing to unpack .../4-libpoppler-dev_0.62.0-2ubuntu2.14_amd64.deb ...\n", | |
"Unpacking libpoppler-dev:amd64 (0.62.0-2ubuntu2.14) over (0.62.0-2ubuntu2.13) ...\n", | |
"Preparing to unpack .../5-libpoppler73_0.62.0-2ubuntu2.14_amd64.deb ...\n", | |
"Unpacking libpoppler73:amd64 (0.62.0-2ubuntu2.14) over (0.62.0-2ubuntu2.13) ...\n", | |
"Selecting previously unselected package poppler-utils.\n", | |
"Preparing to unpack .../6-poppler-utils_0.62.0-2ubuntu2.14_amd64.deb ...\n", | |
"Unpacking poppler-utils (0.62.0-2ubuntu2.14) ...\n", | |
"Setting up poppler-data (0.4.8-2) ...\n", | |
"Setting up fonts-liberation2 (2.00.1-7~18.04.2) ...\n", | |
"Setting up fonts-noto-cjk (1:20190409+repack1-0ubuntu0.18.04) ...\n", | |
"Setting up libpoppler73:amd64 (0.62.0-2ubuntu2.14) ...\n", | |
"Setting up poppler-utils (0.62.0-2ubuntu2.14) ...\n", | |
"Setting up libpoppler-dev:amd64 (0.62.0-2ubuntu2.14) ...\n", | |
"Setting up libpoppler-private-dev:amd64 (0.62.0-2ubuntu2.14) ...\n", | |
"Processing triggers for man-db (2.8.3-2ubuntu0.1) ...\n", | |
"Processing triggers for fontconfig (2.12.6-0ubuntu2) ...\n", | |
"Processing triggers for libc-bin (2.27-3ubuntu1.5) ...\n" | |
] | |
} | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#@title 変換しています...\n", | |
"output_resolution_x = output_resolution_xy[0]\n", | |
"output_resolution_y = output_resolution_xy[1]\n", | |
"mp4_file_name = base_file_name + \".\" + str(output_resolution_y) + \"p.mp4\"\n", | |
"!rm -f image-*.png *.mp4\n", | |
"!echo -e \"\\e[36;1m[pdftoppm]\\e[0m $pdf_file_name -> image-*.png $output_resolution_xy\"\n", | |
"!pdftoppm -scale-to-x -1 -scale-to-y $output_resolution_y -png \"$pdf_file_name\" image\n", | |
"!echo -e \"\\e[36;1m[ffmpeg]\\e[0m image-*.png -> $mp4_file_name\"\n", | |
"!ffmpeg -y -pattern_type glob -r 1/2 -i \"image-*.png\" -vf \"crop=min(ih*16/9\\,iw):ih,scale=-2:$output_resolution_y:flags=lanczos,pad=x=-2:aspect=16/9\" -c:v libx264 -r 30 -pix_fmt yuv420p \"$mp4_file_name\"\n" | |
], | |
"metadata": { | |
"id": "X5_YlHOgeLIY", | |
"cellView": "form" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "code", | |
"source": [ | |
"#@title mp4ファイルをダウンロードします...\n", | |
"files.download(mp4_file_name)" | |
], | |
"metadata": { | |
"id": "ykJ1MMQRi2Wj", | |
"cellView": "form" | |
}, | |
"execution_count": null, | |
"outputs": [] | |
}, | |
{ | |
"cell_type": "markdown", | |
"source": [], | |
"metadata": { | |
"id": "HLyKQWM-lIC8" | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment