YoutubeをWebpageに変換するYoutube2Webpage

YoutubeをWebpage に変換する Youtube2Webpage を少し試してみました.

これは yt-dlp でYoutube から動画と文字起こしファイルを入手し,文字起こし部分のスクリーンショットを取得してWebpage にするというもののようです.

試しにオープンソースカンファレンスの動画を変換してみました.

$ sudo apt install yt-dlp ffmpeg (1)
$ git clone https://github.com/obra/Youtube2Webpage
$ cd Youtube2Webpage
$ ./yt-to-webpage.pl "【MTG】NetBSDのご紹介 2023-7-29 C-5" 'https://www.youtube.com/watch?v=TnviEtERcVw' (2)
$ python3 -m http.server --bind 127.0.0.1 --directory ./"【MTG】NetBSDのご紹介 2023-7-29 C-5" 8080 (3)
$ xdg-open http://127.0.0.1:8080/index.html (4)
  1. yt-dlp と ffmpeg を導入
  2. 任意のタイトルとYoutube URL を指定して実行
  3. httpd を起動
  4. ウェブブラウザで開く

youtube2webpage

変換されています.
眺めてみるとまず文字起こし翻訳ファイルで en のものが使われています.
そして元動画でWebPage を画面共有しているのであまりスクリーンショットから内容がよくわかりません.

まず文字起こしテキストは --sub-langs ja オプションを付けて日本語を利用するようにしました.

$ git diff ./yt-to-webpage.pl
diff --git a/yt-to-webpage.pl b/yt-to-webpage.pl
index 41b8acf..4174658 100755
--- a/yt-to-webpage.pl
+++ b/yt-to-webpage.pl
@@ -15,7 +15,7 @@ if (!$url || $url !~ m|^https://www.youtube.com|) {

 mkdir($slug);
 chdir($slug);
-my $video_file = `yt-dlp --console-title  --write-auto-subs --write-subs "$url" --print filename --no-simulate`;
+my $video_file = `yt-dlp --console-title  --write-auto-subs --write-subs --sub-langs ja "$url" --print filename --no-simulate`;
 chomp($video_file);
 my ($vtt) = glob('*.vtt');
 open(my $fh, "<", $vtt);

画像サイズについては,抜き出された画像群のサイズはそこそこ大きいです.css でサイズに制限がかかってるので大きくしました.

$ git diff ./styles.css
diff --git a/styles.css b/styles.css
index 156f994..8972e87 100644
--- a/styles.css
+++ b/styles.css
@@ -56,8 +56,8 @@ li {
 }

 li img{
-    max-width: 288px;
-    max-height: 216px;
+    max-width: 1280px;
+    max-height: 720px;
     transition: all 0.3s;
 }

これで再度コマンドを実行するとファイルがすでにあるというエラーに.一旦ディレクトリごと消して再度実行すると日本語文字起こしテキストかつサイズの大きい画像になりました.

後は文字起こしテキストの精度が悪いですね.(“NetBSD” が “Netflix” や “ネットビジネス” になってたり……)でもこれはYoutube のせいでこのscript の問題ではないです.自分の管理下の動画ならYoutube に任せずOpenAI のWhisper(.cpp) などで文字起こしして手直し後Youtube にアップロードして差し替えるのがいいんでしょうね.

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

To respond on your own website, enter the URL of your response which should contain a link to this post's permalink URL. Your response will then appear (possibly after moderation) on this page. Want to update or remove your response? Update or delete your post and re-enter your post's URL again. (Find out more about Webmentions.)