Twitterで配信されたライブ動画のアーカイブをダウンロードしてみました.
とあるイベントがTwitter で配信されていたらしくYouTube にもあるのではと思ったけど見当たりません.Twitter にアーカイブが残っているのですが,なんか再生がすぐ止まるので辛い.
ということでダウンロードできないかなと検索するとX/Twitter Broadcast Downloader というものを見つけました.これでダウンロードしてみました.
venv 環境に導入して試す.
$ git clone https://github.com/offish/twitter-x-broadcast-downloader (1) $ cd twitter-x-broadcast-downloader $ python3 -m venv venv (2) $ source venv/bin/activate (3) $ pip install -r "requirements.txt" (4) $ python main.py (5) What is the broadcast URL? https://x.com/i/broadcasts/1qGvvkWeqdBGB (6) Got media key 28_2038539604165640192 Got playback URL https://prod-fastly-ap-northeast-1.video.pscp.tv/Transcoding/v1/hls/PTdVIXd-pzzuOcGNlng6TG9haAxe5-rcN7QaIridcZbNbingfwGFrSiqe9DsliGqOpoLNO8lZ2Pk9a_owkY3aw/non_transcode/ap-northeast-1/periscope-replay-direct-prod-ap-northeast-1-public/master_dynamic_16671870457049479117.m3u8?type=replay Downloading the broadcast as 28_2038539604165640192.mp4... [generic] Extracting URL: https://prod-fastly-ap-northeast-1.video.pscp.tv/Transcoding/v1/hls/PTdVIXd-pzzuOcGNlng6TG9haAxe5...117.m3u8?type=replay [generic] master_dynamic_16671870457049479117: Downloading webpage [generic] master_dynamic_16671870457049479117: Downloading m3u8 information [generic] master_dynamic_16671870457049479117: Checking m3u8 live status [info] master_dynamic_16671870457049479117: Downloading 1 format(s): 5500 [hlsnative] Downloading m3u8 manifest [hlsnative] Total fragments: 6385 [download] Destination: /home/matoken/src/twitter-x-broadcast-downloader/downloads/28_2038539604165640192.mp4 [download] 100% of 3.64GiB in 00:03:49 at 16.24MiB/s [FixupM3u8] Fixing MPEG-TS in MP4 container of "/home/matoken/src/twitter-x-broadcast-downloader/downloads/28_2038539604165640192.mp4" What is the broadcast URL? (7)
source clone
venv 環境を作る
venv を有効に
venv 環境にインストール
X/Twitter Broadcast Downloader を実行
ダウンロードしたいURL を渡す
次のダウンロードしたいURL 待ち
ダウンロードできました.
$ ls -lA downloads/
total 3722204
-rw-rw-r-- 1 matoken matoken 3811532277 Mar 31 18:03 28_2038539604165640192.mp4
-rw-rw-r-- 1 matoken matoken 0 Mar 31 17:57 .gitkeep
$ ffprobe downloads/28_2038539604165640192.mp4 2>&1 | grep -A 99 ^Input
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'downloads/28_2038539604165640192.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf61.7.100
Duration: 03:35:23.76, start: 0.000000, bitrate: 2359 kb/s
Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), 1920x1080, 2187 kb/s, 30 fps, 30 tbr, 90k tbn (default)
Metadata:
handler_name : VideoHandler
vendor_id : [0][0][0][0]
Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 160 kb/s (default)
Metadata:
handler_name : SoundHandler
vendor_id : [0][0][0][0]以下余録.
リモートのVPS でダウンロードしたのですが結構大きいので小さくしてダウンロードします.
ffmpeg コマンドで動画を小さく
$ ffmpeg -i downloads/28_2038539604165640192.mp4 -vcodec libx264 -crf 33 -vf "scale=720:-2" -c:a copy downloads/28_2038539604165640192-720.mp4 $ ls -1s downloads/ total 4172176 449972 28_2038539604165640192-720.mp4 3722204 28_2038539604165640192.mp4
動画の音声を取り出してWhisper.cpp で字幕作成
$ ffmpeg -i ~/Downloads/28_2038539604165640192-720.mp4 -ar 44100 -ac 1 -sample_fmt s16 -af silenceremove=1:0:-50dB clawcon.wav
$ ./build/bin/whisper-cli -m ./models/ggml-large-v3-turbo.bin --output-srt --language auto -f ./clawcon.wav
$ ls -1s clawcon.wav*
1067548 clawcon.wav
152 clawcon.wav.srt
$ head clawcon.wav.srt
1
00:00:00,000 --> 00:00:06,660
Alright everyone, we'll be starting in 10 minutes. Please make your way to the stage area. We'll be starting in 10 minutes.
2
00:00:30,000 --> 00:00:59,980
Thank you.
3
00:01:00,000 --> 00:01:29,980ダウンロード環境
$ dpkg-query -W python3 python3-venv ffmpeg ffmpeg 7:7.1.3-0+deb13u1 python3 3.13.5-1 python3-venv 3.13.5-1 $ lsb_release -dr Description: Debian GNU/Linux 13 (trixie) Release: 13 $ arch x86_64
動画編集,文字起こし環境
$ dpkg-query -W ffmpeg ffmpeg 7:8.1-3+b1 a$ git remote -v origin https://github.com/ggerganov/whisper.cpp.git (fetch) origin https://github.com/ggerganov/whisper.cpp.git (push) $ git log --pretty=oneline -1 95ea8f9bfb03a15db08a8989966fd1ae3361e20d (HEAD -> master, origin/master, origin/HEAD) sync : ggml $ lsb_release -dr Description: Debian GNU/Linux forky/sid Release: n/a $ arch x86_64