8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pythonとyoutube-dlで簡単にmp4を部分ダウンロードする!

Posted at

##目的
pythonとyoutube-dlで簡単にmp4を部分ダウンロードする!

##環境

$python3 --version
Python 3.7.3

mkv,mp4変換のためのffmpegをインストールする

$brew install ffmpeg

DLフォルダ作成

$mkdir mp4-download

Python用仮想環境

$cd mp4-download
$python3 -m venv venv
$source venv/bin/activate

youtube-dlをpipでインストール

$pip install youtube-dl

動画(mkv)を部分ダウンロード

$ ffmpeg $(youtube-dl -g 'https://www.youtube.com/watch?v=Nyg2qysqgpg' | sed "s/.*/-ss 03:55:00 -i &/") -t 00:01:00 -c copy out.mkv

mkvをmp4に変換

$ for f in *.mkv;do ffmpeg -i "$f" -c:v copy -c:a aac -b:a 256k -strict -2 "${f%mkv}mp4";done

##ダウンロード結果確認

$ open out.mp4

よかったよかった

8
10
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
8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?