LoginSignup
10
11

More than 5 years have passed since last update.

FFmpegを使ってHuluを保存する方法

Last updated at Posted at 2017-11-09

ffmpeg を使えばHuluのリアルタイム放送をmp4ファイルに録画(保存・ダウンロード)することができる

  • この記事はmacOS想定
  • ffmpegさえ利用可能にすればWindowsやLinuxでも使えるのでは

Homebrew のインストール

必須ではないが便利

macOS
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

ffmpeg のインストール

macOS
brew instal ffmpeg

インストールできたかの確認

macOS
ffmpeg -version
ffmpeg version N.N Copyright (c) 2000-YYYY the FFmpeg developers

録画したファイルを置く専用フォルダを用意して移動

macOS
$ cd Desktop
$ mkdir video
$ cd video

Huluを録画する

Chromeブラウザを開く

デベロッパーツールを開き、Networkタブへ移動する

表示 > 開発 / 管理 > デベロッパー ツール
"Network"タブを表示する

Huluへログインする

録画したいHuluのリアルタイムチャンネルを開く

https://www.happyon.jp/realtimes/hoge

hoge.m3u8の情報を取得する

Networkコンソールにm3u8を表示する

フィルターにm3u8を指定すると便利

hoge.m3u8を右クリックしてcURLを取得する

Copy > Copy as cURL

2017-11-09_16_01_27.png
master.m3u8 ではなく 01.m3u02.m3u

ffmpeg コマンドラインの構築に必要な情報を抽出する

コピーしたcURLは以下のようになる

curl 'https://hoge.akamaihd.net/hls/live/hoge/akamai/01.m3u8?hdntl=exp=hogehoge~acl=/hls/live/*~data=hdntl~hmac=hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge' -H 'Origin: https://www.happyon.jp' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: ja,en-US;q=0.8,en;q=0.6' -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36' -H 'Accept: */*' -H 'Referer: https://www.happyon.jp/realtimes/hoge' -H 'Connection: keep-alive' --compressed

ffmpeg コマンドラインを構築する

上記の情報を以下のように再構築する

ffmpeg \
-headers 'Origin: https://www.happyon.jp' \
-headers 'Accept-Encoding: gzip, deflate, br' \
-headers 'Accept-Language: ja,en-US;q=0.8,en;q=0.6' \
-headers 'Accept: */*' \
-headers 'Referer: https://www.happyon.jp/realtimes/hoge' \
-headers 'Connection: keep-alive' \
-user_agent "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36" \
-i "https://hoge.akamaihd.net/hls/live/hoge/akamai/01.m3u8?hdntl=exp=hogehoge~acl=/hls/live/*~data=hdntl~hmac=hogehogehogehogehogehogehogehogehogehogehogehogehogehogehogehoge" \
-codec copy \
-bsf:a aac_adtstoasc \
-movflags faststart \
video.mp4

録画する

macOSのターミナルを開き、上記コマンドを実行する。
停止するには q を押す

確認する

フォルダ内を覗くと
video.mp4
ができているはず

高度な操作

ffmpeg Documentation
にたくさんオプションが説明されている

10
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
11