Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 영상처리
- MATLAB
- BAEKJOON
- C++
- BFS
- rao
- ARM
- MDP
- 백준
- bloc
- Algorithm
- Image Processing
- Kaggle
- ML
- Dreamhack
- DART
- system hacking
- Flutter
- Widget
- Stream
- llm을 활용 단어장 앱 개발일지
- BOF
- Got
- 파이토치 트랜스포머를 활용한 자연어 처리와 컴퓨터비전 심층학습
- Computer Architecture
- pytorch
- study book
- fastapi를 사용한 파이썬 웹 개발
- FastAPI
- PCA
Archives
- Today
- Total
Bull
[Python] 유튜브 오디오 추출하기(.wav) 본문
ffmpeg Tool을 사용한다.
명령어 사용법
Window
https://ffmpeg.org/download.html
Download FFmpeg
If you find FFmpeg useful, you are welcome to contribute by donating. More downloading options Git Repositories Since FFmpeg is developed with Git, multiple repositories from developers and groups of developers are available. Release Verification All FFmpe
ffmpeg.org
직접 설치 후 환경변수를 통해 명령어 사용.
Linux
sudo apt update
sudo apt install ffmpeg
MacOS
brew install ffmpeg
Code
pip install pytube
from pytube import YouTube
import os
# YouTube 동영상 URL
video_url = 'https://www.youtube.com/watch?v=example'
# YouTube 객체 생성
yt = YouTube(video_url)
# 오디오 스트림 선택
audio_stream = yt.streams.filter(only_audio=True).first()
# 오디오 파일 다운로드
output_file = audio_stream.download(filename='audio.mp4')
# ffmpeg를 사용하여 mp4를 wav로 변환하고 앞부분 10초만 추출
wav_file = 'audio_10sec.wav'
os.system(f'ffmpeg -i "{output_file}" -t 10 -acodec pcm_s16le -ar 44100 -ac 2 "{wav_file}"')
# 임시 파일 삭제
os.remove(output_file)
print(f'오디오 파일의 앞부분 10초가 {wav_file}로 저장되었습니다.')
코랩에서 음석인식 AI 분석 과제 중 음성파일이 필요하여 GPT를 통해 알아낸 코드이다.
다양한 방식으로 추출이 필요하면 ffmpeg 명령을 찾아봐야 한다.
'Computer Language > Python' 카테고리의 다른 글
[python:syntax] zip (0) | 2024.05.18 |
---|---|
[python/lib:numpy] np.stack()과 np.comcatenate() (0) | 2024.04.18 |