1. CentOS 8에 FFMpeg 설치하기
기본 저장소로는 FFMpeg를 설치할 수 없어 저장소를 추가하고 설치한다.
Step 1: EPEL repository 설치
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
Step 2: RPM Fusion repository 설치
yum install https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-8.noarch.rpm
Step 3: SDL2 Library 설치. FFMpeg는 SDL2 라이브러리를 사용해야 한다.
yum install http://rpmfind.net/linux/epel/7/x86_64/Packages/s/SDL2-2.0.10-1.el7.x86_64.rpm
Step 4: FFMpeg 설치
yum install ffmpeg ffmpeg-devel
2. CentOS 8에 Python 3.8 설치
yum install python38
3. pip3 로 youtube_dl, ffmpeg 설치
yum install youtube_dl
yum install ffmpeg
4. Python 코드 작성
출처: https://gist.github.com/benzap/90ff22790bc0a9c6fd2902e91da4baef
#!/bin/env python
# Requires: youtube_dl module
# Requires: ffmpeg
# Usage:
#
# python youtube2mp3.py <URL>, ...
#
# Example:
#
# python youtube2mp3.py https://www.youtube.com/watch?v=dQw4w9WgXcQ
import youtube_dl
import sys
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}],
}
if __name__ == "__main__":
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
filenames = sys.argv[1:]
ydl.download(filenames)
# youtube-dl --list-subs https://www.youtube.com/watch?v=T2DbiZFmFH8
# youtube-dl --write-sub --sub-lang ko --skip-download -o subtitle https://www.youtube.com/watch?v=T2DbiZFmFH8
# youtube-dl --write-auto-sub --sub-lang ko --skip-download -o subtitle https://www.youtube.com/watch?v=T2DbiZFmFH8
'Python' 카테고리의 다른 글
Jupyter notebook 자동줄바꿈 (0) | 2021.11.17 |
---|---|
Django 참조무결성 무시하고 입력하기 (0) | 2021.08.25 |
jupyter-notebook python3.8 notimplementederror (0) | 2020.01.13 |
[Django] django-debug-toolbar 설치하기 (0) | 2019.09.10 |
파이썬 주요 라이브러리 (bs4, pymysql, selenium) 설치 (0) | 2018.03.21 |