Ver3.0 ๐ฌ FFmpeg๋ก ๋ง๋๋ ๋์์ ์๋ ํธ์ง ๋ฐ ์ธ์ฝ๋ฉ ์์ ์ ๋ณต ๊ฐ์ด๋

๐ฌ FFmpeg๋ก ๋ง๋๋ ๋์์ ์๋ ํธ์ง ๋ฐ ์ธ์ฝ๋ฉ ์์ ์ ๋ณต ๊ฐ์ด๋
์ด๋ณด์๋ ๋ฐ๋ผํ ์ ์๋ ์ค์ ์์ค์ฝ๋์ ํ์ฉ ๋ ธํ์ฐ ๋๊ณต๊ฐ ใ ใ ใ
์์ฆ ์ ํ๋ธ๋ ํฑํก ๊ฐ์ ํ๋ซํผ์์ ์์ ์ฝํ
์ธ ์ ์์ด ๋์ธ์์์? ๊ทผ๋ฐ ๋งค๋ฒ ์๋์ผ๋ก ์์ ํธ์งํ๊ณ ์ธ์ฝ๋ฉํ๋ ๊ฑฐ ์ง์ง ๊ฐ๊ท์ฐฎ์ฃ ใ
ใ
ใ
ํนํ ๋๋์ ์์์ ์ฒ๋ฆฌํด์ผ ํ๋ ๊ฒฝ์ฐ์ ๋๋์ฑ์! ๐ซ
๊ทธ๋์ ์ค๋์ FFmpeg์ด๋ผ๋ ๊ฐ๋ ฅํ ์คํ์์ค ๋๊ตฌ๋ฅผ ํ์ฉํด์ ๋์์ ํธ์ง๊ณผ ์ธ์ฝ๋ฉ์ ์๋ํํ๋ ๋ฐฉ๋ฒ์ ์์ ํํค์ณ๋ณผ๊ฒ์. ํ๋ก๊ทธ๋๋ฐ ์ง์์ด ์ข ์์ผ๋ฉด ๋ ์ข์ง๋ง, ์ด๋ณด์๋ ์ถฉ๋ถํ ๋ฐ๋ผ์ฌ ์ ์๊ฒ ์ค๋ช
ํ ํ
๋๊น ๊ฑฑ์ ๋
ธ๋
ธ~ ๐
๐ฏ FFmpeg์ด ๋ญ๋ฐ? ์ ์ด๊ฑธ ์จ์ผ ํ๋๋ฐ?
FFmpeg์ ์คํ์์ค ๋ฉํฐ๋ฏธ๋์ด ํ๋ ์์ํฌ์ธ๋ฐ์, ์์งํ ๋งํ๋ฉด ์์/์ค๋์ค ์ฒ๋ฆฌ๊ณ์ ์ค์์ค ์๋ฏธ ๋์ดํ๋ผ๊ณ ๋ณด๋ฉด ๋ฉ๋๋ค ใ
ใ
ใ
๊ฑฐ์ ๋ชจ๋ ํฌ๋งท์ ์ง์ํ๊ณ , ๋ช
๋ น์ด ํ ์ค๋ก ์์ฒญ๋ ์์
์ ํ ์ ์์ด์. ๐ฅ
Adobe Premiere๋ Final Cut Pro ๊ฐ์ ๋น์ผ ํ๋ก๊ทธ๋จ ์์ด๋ ํ๋ก๊ทธ๋๋ฐ์ผ๋ก ์์ ํธ์ง์ ์๋ํํ ์ ์๋ค๋ ๊ฒ ์ต๊ณ ์ฅ์ ์ด์ฃ . ํนํ ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ์์ ํธ์ง ์๋น์ค๋ฅผ ์ ๊ณตํ๋ ๋ถ๋คํํ
๋ ์์ ํ์ํ
์ด์์!
2. ํฌ๋ก์ค ํ๋ซํผ: Windows, macOS, Linux ๋ชจ๋ ์ง์
3. ๊ฐ๋ ฅํ ์ฑ๋ฅ: ํ๋์จ์ด ๊ฐ์(GPU) ์ง์์ผ๋ก ์ด๊ณ ์ ์ฒ๋ฆฌ
4. ๋ฐฉ๋ํ ํฌ๋งท ์ง์: MP4, AVI, MOV, MKV, WebM ๋ฑ ๊ฑฐ์ ๋ชจ๋ ํฌ๋งท
5. ์๋ํ ์ต์ ํ: ์คํฌ๋ฆฝํธ๋ก ๋ฐฐ์น ์ฒ๋ฆฌ ๊ฐ๋ฅ
โ๏ธ FFmpeg ์ค์นํ๊ธฐ (OS๋ณ ์์ ์ ๋ณต)
๋ณธ๊ฒฉ์ ์ผ๋ก ์์ํ๊ธฐ ์ ์ FFmpeg์ ์ค์นํด์ผ๊ฒ ์ฃ ? OS๋ณ๋ก ๋ฐฉ๋ฒ์ด ์กฐ๊ธ์ฉ ๋ค๋ฅธ๋ฐ, ํ๋์ฉ ์๋ ค๋๋ฆด๊ฒ์!
๊ฐ์ฅ ๊ฐ๋จํ ๋ฐฉ๋ฒ์ ๊ณต์ ์ฌ์ดํธ(ffmpeg.org)์์ ๋น๋๋ ๋ฐ์ด๋๋ฆฌ๋ฅผ ๋ค์ด๋ฐ๋ ๊ฑฐ์์. ๊ทผ๋ฐ ์์งํ ์ด๊ฒ๋ ๊ท์ฐฎ์ผ๋ฉด Chocolatey ํจํค์ง ๋งค๋์ ์ฐ๋ ๊ฒ ๊ฐ๊ฟ ใ ใ ใ
# Chocolatey๋ก ์ค์น (๊ด๋ฆฌ์ ๊ถํ PowerShell)
choco install ffmpeg
# ์ค์น ํ์ธ
ffmpeg -version
๋งฅ ์ ์ ๋ผ๋ฉด Homebrew๊ฐ ๋ต์ด์ฃ ! ํฐ๋ฏธ๋ ์ด๊ณ ๋ช ๋ น์ด ํ ์ค์ด๋ฉด ๋~
# Homebrew๋ก ์ค์น
brew install ffmpeg
# ์ถ๊ฐ ์ฝ๋ฑ ํฌํจ ์ค์น (๊ถ์ฅ)
brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-libass --with-libvorbis --with-libvpx --with-opus --with-x265
๋ฆฌ๋ ์ค๋ ๋ฐฐํฌํ๋ง๋ค ํจํค์ง ๋งค๋์ ๊ฐ ๋ค๋ฅด์ง๋ง, ๋๋ถ๋ถ ๊ธฐ๋ณธ ์ ์ฅ์์ ํฌํจ๋์ด ์์ด์.
# Ubuntu/Debian
sudo apt update
sudo apt install ffmpeg
# CentOS/RHEL
sudo yum install ffmpeg
# Arch Linux
sudo pacman -S ffmpeg
ffmpeg -version ๋ช
๋ น์ด๋ฅผ ์คํํ์ ๋ ๋ฒ์ ์ ๋ณด๊ฐ ์ฃผ๋ฅด๋ฅต ๋์ค๋ฉด ์ฑ๊ณต! ๋ง์ฝ "command not found" ์๋ฌ๊ฐ ๋๋ฉด ํ๊ฒฝ๋ณ์(PATH) ์ค์ ์ ํ์ธํด๋ณด์ธ์.
๐ฌ ๊ธฐ๋ณธ ๋ช ๋ น์ด ๋ง์คํฐํ๊ธฐ
FFmpeg์ ๊ธฐ๋ณธ ๋ฌธ๋ฒ์ ์ด๋ ๊ฒ ์๊ฒผ์ด์:
ffmpeg [์
๋ ฅ ์ต์
] -i ์
๋ ฅํ์ผ [์ถ๋ ฅ ์ต์
] ์ถ๋ ฅํ์ผ
๊ฐ๋จํ์ฃ ? ๊ทผ๋ฐ ์ต์
์ด ์ง์ง ๊ฐ๋ง์์ ์ฒ์์ ์ข ํท๊ฐ๋ฆด ์ ์์ด์ ใ
ใ
ใ
์์ฃผ ์ฐ๋ ๊ฒ๋ค๋ถํฐ ํ๋์ฉ ์์๋ณผ๊ฒ์!
๐น ํฌ๋งท ๋ณํ (๊ฐ์ฅ ๊ธฐ๋ณธ)
# MP4๋ฅผ AVI๋ก ๋ณํ
ffmpeg -i input.mp4 output.avi
# MOV๋ฅผ WebM์ผ๋ก ๋ณํ
ffmpeg -i input.mov output.webm
# ์ฌ๋ฌ ํ์ผ ํ๋ฒ์ ๋ณํ (๋ฐฐ์น ์ฒ๋ฆฌ)
for file in *.mp4; do ffmpeg -i "$file" "${file%.mp4}.avi"; done
โ๏ธ ์์ ์๋ฅด๊ธฐ (ํธ๋ฆฌ๋ฐ)
# ์์ ์๊ฐ๋ถํฐ ํน์ ๊ธธ์ด๋งํผ ์๋ฅด๊ธฐ
ffmpeg -i input.mp4 -ss 00:00:10 -t 00:00:30 output.mp4
# 10์ด๋ถํฐ 30์ด ๊ธธ์ด๋งํผ ์ถ์ถ
# ํน์ ๊ตฌ๊ฐ ์ถ์ถ (์์~๋)
ffmpeg -i input.mp4 -ss 00:01:00 -to 00:02:30 output.mp4
# 1๋ถ๋ถํฐ 2๋ถ 30์ด๊น์ง ์ถ์ถ
# ๊ณ ์ ์ฒ๋ฆฌ (์ฌ์ธ์ฝ๋ฉ ์์ด)
ffmpeg -ss 00:00:10 -i input.mp4 -t 00:00:30 -c copy output.mp4
-ss ์ต์
์ -i ์์ ๋๋ฉด ์
๋ ฅ ํ์ผ์ ๋น ๋ฅด๊ฒ ํ์(seek)ํ ์ ์์ด์. ๋ค์ ๋๋ฉด ์ ํ๋๋ ๋์ง๋ง ๋๋ ค์. -c copy๋ ์ฌ์ธ์ฝ๋ฉ ์์ด ์คํธ๋ฆผ์ ๋ณต์ฌ๋ง ํ๋๊น ์ด๊ณ ์ ์ฒ๋ฆฌ ๊ฐ๋ฅ! ๋จ, ํคํ๋ ์ ์์น์ ๋ฐ๋ผ ์ ํ๋๊ฐ ๋จ์ด์ง ์ ์์ด์.
๐ ํด์๋ ๋ณ๊ฒฝ ๋ฐ ๋ฆฌ์ฌ์ด์ง
# ํน์ ํด์๋๋ก ๋ณ๊ฒฝ
ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4
# ๊ฐ๋ก ๊ณ ์ , ์ธ๋ก ๋น์จ ์ ์ง
ffmpeg -i input.mp4 -vf scale=1920:-1 output.mp4
# ์ธ๋ก ๊ณ ์ , ๊ฐ๋ก ๋น์จ ์ ์ง
ffmpeg -i input.mp4 -vf scale=-1:1080 output.mp4
# ๋น์จ ์ ์งํ๋ฉฐ ์ต๋ ํฌ๊ธฐ ์ ํ
ffmpeg -i input.mp4 -vf "scale='min(1920,iw)':'min(1080,ih)':force_original_aspect_ratio=decrease" output.mp4
-sws_flags lanczos ์ต์
์ ์ถ๊ฐํ๋ฉด ๋ ๊ณ ํ์ง ๋ฆฌ์ฌ์ด์ง์ด ๊ฐ๋ฅํด์. ๋์ ์ฒ๋ฆฌ ์๊ฐ์ ์ข ๋ ๊ฑธ๋ฆฌ์ฃ ใ
ใ
๐ต ์ค๋์ค ์ถ์ถ ๋ฐ ๋ณํ
# ์์์์ ์ค๋์ค๋ง ์ถ์ถ
ffmpeg -i input.mp4 -vn -acodec copy output.aac
# MP3๋ก ๋ณํํ๋ฉฐ ๋นํธ๋ ์ดํธ ์ง์
ffmpeg -i input.mp4 -vn -ab 320k output.mp3
# ์ค๋์ค ์๋ ์์ ๋ง๋ค๊ธฐ
ffmpeg -i input.mp4 -an output.mp4
# ์ค๋์ค ๋ณผ๋ฅจ ์กฐ์
ffmpeg -i input.mp4 -af "volume=2.0" output.mp4 # 2๋ฐฐ ์ฆํญ
ffmpeg -i input.mp4 -af "volume=0.5" output.mp4 # 50% ๊ฐ์
๐ ๊ณ ๊ธ ํธ์ง ๊ธฐ๋ฅ (์ง์ง ๊ฟํ๋ค)
์ด์ ๋ถํฐ๊ฐ ์ง์ง ์ฌ๋ฐ๋ ๋ถ๋ถ์ด์์! FFmpeg์ ํํฐ ์์คํ ์ ํ์ฉํ๋ฉด ํ๋ฆฌ๋ฏธ์ด ํ๋ก ๋ชป์ง์์ ํธ์ง์ด ๊ฐ๋ฅํ๊ฑฐ๋ ์ ใ ใ ใ
๐จ ์ํฐ๋งํฌ ์ถ๊ฐํ๊ธฐ
# ์ด๋ฏธ์ง ์ํฐ๋งํฌ ์ถ๊ฐ (์ฐ์ธก ์๋จ)
ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=W-w-10:10" output.mp4
# ์ข์ธก ํ๋จ์ ๋ฐฐ์น
ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=10:H-h-10" output.mp4
# ์ค์ ๋ฐฐ์น
ffmpeg -i input.mp4 -i watermark.png -filter_complex "overlay=(W-w)/2:(H-h)/2" output.mp4
# ํฌ๋ช
๋ ์กฐ์
ffmpeg -i input.mp4 -i watermark.png -filter_complex "[1:v]format=rgba,colorchannelmixer=aa=0.5[logo];[0:v][logo]overlay=W-w-10:10" output.mp4
๐ ์๋ง ์ฝ์ ํ๊ธฐ
# SRT ์๋ง ํ์ผ ์ฝ์
(ํ๋์๋ธ)
ffmpeg -i input.mp4 -vf "subtitles=subtitle.srt" output.mp4
# ์๋ง ์คํ์ผ ์ปค์คํฐ๋ง์ด์ง
ffmpeg -i input.mp4 -vf "subtitles=subtitle.srt:force_style='FontName=Arial,FontSize=24,PrimaryColour=&H00FFFF'" output.mp4
# ASS ์๋ง ์ฌ์ฉ (๋ ๋ง์ ์คํ์ผ ์ต์
)
ffmpeg -i input.mp4 -vf "ass=subtitle.ass" output.mp4
# ์ํํธ์๋ธ (์๋ง ์คํธ๋ฆผ์ผ๋ก ์ถ๊ฐ)
ffmpeg -i input.mp4 -i subtitle.srt -c copy -c:s mov_text output.mp4
๐๏ธ ์ฌ๋ฌ ์์ ์ด์ด๋ถ์ด๊ธฐ (Concatenation)
# ๋ฐฉ๋ฒ 1: ํ์ผ ๋ฆฌ์คํธ ์ฌ์ฉ (๊ถ์ฅ)
# filelist.txt ํ์ผ ์์ฑ
file 'video1.mp4'
file 'video2.mp4'
file 'video3.mp4'
ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4
# ๋ฐฉ๋ฒ 2: concat ํํฐ ์ฌ์ฉ (์ฌ์ธ์ฝ๋ฉ ํ์)
ffmpeg -i video1.mp4 -i video2.mp4 -i video3.mp4 -filter_complex "[0:v][0:a][1:v][1:a][2:v][2:a]concat=n=3:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" output.mp4
# ๋ฐฉ๋ฒ 3: ๊ฐ๋จํ ์คํฌ๋ฆฝํธ๋ก ์๋ํ
for f in *.mp4; do echo "file '$f'" >> list.txt; done
ffmpeg -f concat -safe 0 -i list.txt -c copy output.mp4
๐ญ ํ์ด๋ ์ธ/์์ ํจ๊ณผ
# ๋น๋์ค ํ์ด๋ ์ธ (์ฒ์ 2์ด)
ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=2" output.mp4
# ๋น๋์ค ํ์ด๋ ์์ (๋ง์ง๋ง 3์ด)
ffmpeg -i input.mp4 -vf "fade=t=out:st=27:d=3" output.mp4
# st๋ ์์ ์๊ฐ(์ด), d๋ ์ง์ ์๊ฐ(์ด)
# ์ค๋์ค ํ์ด๋ ์ธ/์์
ffmpeg -i input.mp4 -af "afade=t=in:st=0:d=2,afade=t=out:st=27:d=3" output.mp4
# ๋น๋์ค+์ค๋์ค ๋์ ํ์ด๋
ffmpeg -i input.mp4 -vf "fade=t=in:st=0:d=2,fade=t=out:st=27:d=3" -af "afade=t=in:st=0:d=2,afade=t=out:st=27:d=3" output.mp4
๐ผ๏ธ ์ธ๋ค์ผ ์ถ์ถํ๊ธฐ
# ํน์ ์๊ฐ์ ํ๋ ์ ์ถ์ถ
ffmpeg -i input.mp4 -ss 00:00:05 -vframes 1 thumbnail.jpg
# 1์ด๋ง๋ค ์ธ๋ค์ผ ์ถ์ถ
ffmpeg -i input.mp4 -vf "fps=1" thumbnail_%03d.jpg
# ๊ณ ํ์ง ์ธ๋ค์ผ (ํด์๋ ์ง์ )
ffmpeg -i input.mp4 -ss 00:00:10 -vframes 1 -vf scale=1920:1080 -q:v 2 thumbnail.jpg
# ์ฌ๋ฌ ์๊ฐ๋์ ์ธ๋ค์ผ ์๋ ์ถ์ถ
ffmpeg -i input.mp4 -vf "select='eq(pict_type,I)'" -vsync vfr thumbnail_%03d.jpg
select='eq(pict_type,I)' ํํฐ๋ I-ํ๋ ์(ํคํ๋ ์)๋ง ์ถ์ถํด์. ์ด๊ฒ ํ์ง์ด ๊ฐ์ฅ ์ข๊ฑฐ๋ ์! ์์ ๋ฏธ๋ฆฌ๋ณด๊ธฐ ์ด๋ฏธ์ง ๋ง๋ค ๋ ์์ ์ ์ฉํฉ๋๋ค ใ
ใ
โก ์ธ์ฝ๋ฉ ์ต์ ํ (์๋ vs ํ์ง)
์ธ์ฝ๋ฉ์ ์๊ฐ์ด ์ค๋ ๊ฑธ๋ฆฌ๋ ์์ ์ด๋ผ ์ต์ ํ๊ฐ ์ง์ง ์ค์ํด์. ์ํฉ์ ๋ง๋ ์ค์ ์ ์ ํํ๋ฉด ์๊ฐ์ ์์ฒญ ์ ์ฝํ ์ ์์ฃ !
๐ฏ ์ฝ๋ฑ ์ ํ ๊ฐ์ด๋
| ์ฝ๋ฑ | ์ฅ์ | ๋จ์ | ์ถ์ฒ ์ฉ๋ |
|---|---|---|---|
| H.264 (libx264) | ํธํ์ฑ ์ต๊ณ , ์์ ์ | ์์ถ๋ฅ ๋ณดํต | ๋ฒ์ฉ ๋ชฉ์ , ์ ํ๋ธ |
| H.265 (libx265) | ์์ถ๋ฅ ์ฐ์, ๊ณ ํ์ง | ์ธ์ฝ๋ฉ ๋๋ฆผ, ํธํ์ฑ ๋ฎ์ | 4K ์์, ์ ์ฅ ๊ณต๊ฐ ์ ์ฝ |
| VP9 | ๋ฌด๋ฃ, ์น ์ต์ ํ | ์ธ์ฝ๋ฉ ๋งค์ฐ ๋๋ฆผ | ์น ์คํธ๋ฆฌ๋ฐ, ์ ํ๋ธ |
| AV1 | ์ฐจ์ธ๋ ์ฝ๋ฑ, ์ต๊ณ ์์ถ๋ฅ | ์ธ์ฝ๋ฉ ๊ทน๋๋ก ๋๋ฆผ | ๋ฏธ๋ ๋๋น, ์คํ์ ์ฉ๋ |
๐ H.264 ์ธ์ฝ๋ฉ ์ค์ (๊ฐ์ฅ ๋ง์ด ์)
# ๊ธฐ๋ณธ ์ค์ (๊ท ํ์กํ ํ์ง)
ffmpeg -i input.mp4 -c:v libx264 -preset medium -crf 23 output.mp4
# ๊ณ ์ ์ธ์ฝ๋ฉ (ํ์ง ์ฝ๊ฐ ํฌ์)
ffmpeg -i input.mp4 -c:v libx264 -preset ultrafast -crf 23 output.mp4
# ๊ณ ํ์ง ์ธ์ฝ๋ฉ (์๊ฐ ์ค๋ ๊ฑธ๋ฆผ)
ffmpeg -i input.mp4 -c:v libx264 -preset slow -crf 18 output.mp4
# ์ ํ๋ธ ์ต์ ํ ์ค์
ffmpeg -i input.mp4 -c:v libx264 -preset slow -crf 18 -c:a aac -b:a 192k -pix_fmt yuv420p -movflags +faststart output.mp4
โข 0 = ๋ฌด์์ค (ํ์ผ ํฌ๊ธฐ ์์ฒญ ํผ)
โข 18 = ์๊ฐ์ ์ผ๋ก ๋ฌด์์ค์ ๊ฐ๊น์ (๊ณ ํ์ง)
โข 23 = ๊ธฐ๋ณธ๊ฐ (์ข์ ํ์ง, ์ ๋นํ ํฌ๊ธฐ)
โข 28 = ๋ฎ์ ํ์ง (์์ ํ์ผ ํฌ๊ธฐ)
โข 51 = ์ต์ ์ ํ์ง (๊ฑฐ์ ์ ์)
๋ณดํต 18~28 ์ฌ์ด์์ ์ ํํ๋ฉด ๋๊ณ , ์ซ์๊ฐ ๋ฎ์์๋ก ํ์ง ์ข๊ณ ํ์ผ ์ปค์ ธ์!
๐ฌ ํ๋ฆฌ์ ๋น๊ต
| ํ๋ฆฌ์ | ์ธ์ฝ๋ฉ ์๋ | ์์ถ ํจ์จ | ์ฌ์ฉ ์๋๋ฆฌ์ค |
|---|---|---|---|
| ultrafast | ๋งค์ฐ ๋น ๋ฆ | ๋ฎ์ | ์ค์๊ฐ ์คํธ๋ฆฌ๋ฐ, ํ ์คํธ |
| superfast | ๋น ๋ฆ | ๋ณดํต | ๋น ๋ฅธ ์ฒ๋ฆฌ ํ์์ |
| veryfast | ๋น ๋ฆ | ๋ณดํต | ์ผ๋ฐ ์์ |
| faster | ์ฝ๊ฐ ๋น ๋ฆ | ์ข์ | ์ผ๋ฐ ์์ |
| fast | ์ฝ๊ฐ ๋น ๋ฆ | ์ข์ | ์ผ๋ฐ ์์ |
| medium | ๋ณดํต | ์ข์ | ๊ธฐ๋ณธ ๊ถ์ฅ ์ค์ |
| slow | ๋๋ฆผ | ์ฐ์ | ์ต์ข ๋ฐฐํฌ์ฉ |
| slower | ๋งค์ฐ ๋๋ฆผ | ์ฐ์ | ๊ณ ํ์ง ํ์์ |
| veryslow | ๊ทน๋๋ก ๋๋ฆผ | ์ต๊ณ | ์์นด์ด๋น, ๋ง์คํฐ ํ์ผ |
๐ช ํ๋์จ์ด ๊ฐ์ ํ์ฉ
# NVIDIA GPU ๊ฐ์ (NVENC)
ffmpeg -hwaccel cuda -i input.mp4 -c:v h264_nvenc -preset fast -crf 23 output.mp4
# Intel Quick Sync ๊ฐ์
ffmpeg -hwaccel qsv -c:v h264_qsv -i input.mp4 -c:v h264_qsv -preset fast output.mp4
# AMD GPU ๊ฐ์ (AMF)
ffmpeg -hwaccel d3d11va -i input.mp4 -c:v h264_amf -quality speed output.mp4
# macOS VideoToolbox ๊ฐ์
ffmpeg -hwaccel videotoolbox -i input.mp4 -c:v h264_videotoolbox -b:v 5M output.mp4
๐ต ์ค๋์ค ์ธ์ฝ๋ฉ ์ต์ ํ
# AAC ์ธ์ฝ๋ฉ (๊ฐ์ฅ ๋ฒ์ฉ์ )
ffmpeg -i input.mp4 -c:v copy -c:a aac -b:a 192k output.mp4
# ๊ณ ํ์ง ์ค๋์ค (256kbps)
ffmpeg -i input.mp4 -c:v copy -c:a aac -b:a 256k output.mp4
# ์ ์ฉ๋ ์ค๋์ค (128kbps, ์์ฑ ์์ฃผ)
ffmpeg -i input.mp4 -c:v copy -c:a aac -b:a 128k output.mp4
# Opus ์ฝ๋ฑ (์น ์คํธ๋ฆฌ๋ฐ ์ต์ )
ffmpeg -i input.mp4 -c:v copy -c:a libopus -b:a 128k output.webm
# ์ค๋์ค ์ ๊ทํ (๋ณผ๋ฅจ ๊ท ์ผํ)
ffmpeg -i input.mp4 -af loudnorm output.mp4
๐ค ์๋ํ ์คํฌ๋ฆฝํธ ๋ง๋ค๊ธฐ
์ด์ ์ง์ง ํต์ฌ! FFmpeg ๋ช ๋ น์ด๋ฅผ ํ๋ก๊ทธ๋๋ฐ ์ธ์ด์ ๊ฒฐํฉํ๋ฉด ์์ ์๋ํ๋ ์์ ์ฒ๋ฆฌ ์์คํ ์ ๋ง๋ค ์ ์์ด์ ใ ใ ใ ์ค์ ์์ ๋ฐ๋ก ์ธ ์ ์๋ ์์ ๋ค์ ๋ณด์ฌ๋๋ฆด๊ฒ์!
๐ Python์ผ๋ก ๋ฐฐ์น ์ฒ๋ฆฌ ์๋ํ
import subprocess
import os
from pathlib import Path
def batch_convert_videos(input_dir, output_dir, target_format='mp4'):
"""
ํด๋ ๋ด ๋ชจ๋ ์์์ ํน์ ํฌ๋งท์ผ๋ก ๋ณํ
"""
# ์ถ๋ ฅ ๋๋ ํ ๋ฆฌ ์์ฑ
Path(output_dir).mkdir(parents=True, exist_ok=True)
# ์ง์ํ๋ ์์ ํ์ฅ์
video_extensions = ['.mp4', '.avi', '.mov', '.mkv', '.flv', '.wmv']
# ์
๋ ฅ ๋๋ ํ ๋ฆฌ์ ๋ชจ๋ ํ์ผ ํ์
for filename in os.listdir(input_dir):
file_path = os.path.join(input_dir, filename)
# ์์ ํ์ผ์ธ์ง ํ์ธ
if any(filename.lower().endswith(ext) for ext in video_extensions):
# ์ถ๋ ฅ ํ์ผ๋ช
์์ฑ
output_filename = f"{Path(filename).stem}.{target_format}"
output_path = os.path.join(output_dir, output_filename)
# FFmpeg ๋ช
๋ น์ด ๊ตฌ์ฑ
cmd = [
'ffmpeg',
'-i', file_path,
'-c:v', 'libx264',
'-preset', 'medium',
'-crf', '23',
'-c:a', 'aac',
'-b:a', '192k',
'-y', # ๋ฎ์ด์ฐ๊ธฐ ํ์ธ ์์ด
output_path
]
print(f"๋ณํ ์ค: {filename} -> {output_filename}")
try:
# FFmpeg ์คํ
subprocess.run(cmd, check=True, capture_output=True)
print(f"โ
์๋ฃ: {output_filename}")
except subprocess.CalledProcessError as e:
print(f"โ ์คํจ: {filename} - {e}")
# ์ฌ์ฉ ์์
if __name__ == "__main__":
batch_convert_videos(
input_dir='./input_videos',
output_dir='./output_videos',
target_format='mp4'
)
๐ฌ ์๋ ์ธ๋ค์ผ ์์ฑ๊ธฐ
import subprocess
import os
from pathlib import Path
def generate_thumbnails(video_path, output_dir, count=5):
"""
์์์์ ๊ท ๋ฑํ ๊ฐ๊ฒฉ์ผ๋ก ์ธ๋ค์ผ ์ถ์ถ
"""
Path(output_dir).mkdir(parents=True, exist_ok=True)
# ์์ ๊ธธ์ด ๊ฐ์ ธ์ค๊ธฐ
duration_cmd = [
'ffprobe',
'-v', 'error',
'-show_entries', 'format=duration',
'-of', 'default=noprint_wrappers=1:nokey=1',
video_path
]
try:
result = subprocess.run(duration_cmd, capture_output=True, text=True, check=True)
duration = float(result.stdout.strip())
# ์ธ๋ค์ผ ์ถ์ถ ๊ฐ๊ฒฉ ๊ณ์ฐ
interval = duration / (count + 1)
video_name = Path(video_path).stem
for i in range(1, count + 1):
timestamp = interval * i
output_path = os.path.join(output_dir, f"{video_name}_thumb_{i:02d}.jpg")
# ์ธ๋ค์ผ ์ถ์ถ ๋ช
๋ น์ด
thumb_cmd = [
'ffmpeg',
'-ss', str(timestamp),
'-i', video_path,
'-vframes', '1',
'-vf', 'scale=1280:720',
'-q:v', '2',
'-y',
output_path
]
subprocess.run(thumb_cmd, check=True, capture_output=True)
print(f"โ
์ธ๋ค์ผ ์์ฑ: {output_path} (์๊ฐ: {timestamp:.2f}์ด)")
except Exception as e:
print(f"โ ์ค๋ฅ ๋ฐ์: {e}")
# ์ฌ์ฉ ์์
generate_thumbnails('sample_video.mp4', './thumbnails', count=5)
๐ ์์ ์ ๋ณด ๋ถ์๊ธฐ
import subprocess
import json
def analyze_video(video_path):
"""
์์ ํ์ผ์ ์์ธ ์ ๋ณด ์ถ์ถ
"""
cmd = [
'ffprobe',
'-v', 'quiet',
'-print_format', 'json',
'-show_format',
'-show_streams',
video_path
]
try:
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
data = json.loads(result.stdout)
# ๋น๋์ค ์คํธ๋ฆผ ์ฐพ๊ธฐ
video_stream = next((s for s in data['streams'] if s['codec_type'] == 'video'), None)
audio_stream = next((s for s in data['streams'] if s['codec_type'] == 'audio'), None)
info = {
'ํ์ผ๋ช
': video_path,
'ํฌ๋งท': data['format']['format_name'],
'ํ์ผํฌ๊ธฐ': f"{int(data['format']['size']) / (1024*1024):.2f} MB",
'์ฌ์์๊ฐ': f"{float(data['format']['duration']):.2f}์ด",
}
if video_stream:
info.update({
'๋น๋์ค์ฝ๋ฑ': video_stream['codec_name'],
'ํด์๋': f"{video_stream['width']}x{video_stream['height']}",
'ํ๋ ์๋ ์ดํธ': eval(video_stream['r_frame_rate']),
'๋นํธ๋ ์ดํธ': f"{int(video_stream.get('bit_rate', 0)) / 1000:.0f} kbps"
})
if audio_stream:
info.update({
'์ค๋์ค์ฝ๋ฑ': audio_stream['codec_name'],
'์ํ๋ ์ดํธ': f"{audio_stream['sample_rate']} Hz",
'์ฑ๋': audio_stream['channels']
})
return info
except Exception as e:
return {'์ค๋ฅ': str(e)}
# ์ฌ์ฉ ์์
video_info = analyze_video('sample_video.mp4')
for key, value in video_info.items():
print(f"{key}: {value}")
๐ ์งํ๋ฅ ํ์ ๊ธฐ๋ฅ ์ถ๊ฐ
import subprocess
import re
import sys
def convert_with_progress(input_file, output_file):
"""
์งํ๋ฅ ์ ํ์ํ๋ฉฐ ์์ ๋ณํ
"""
# ๋จผ์ ์์ ๊ธธ์ด ๊ฐ์ ธ์ค๊ธฐ
duration_cmd = [
'ffprobe',
'-v', 'error',
'-show_entries', 'format=duration',
'-of', 'default=noprint_wrappers=1:nokey=1',
input_file
]
duration_result = subprocess.run(duration_cmd, capture_output=True, text=True)
total_duration = float(duration_result.stdout.strip())
# FFmpeg ๋ช
๋ น์ด
cmd = [
'ffmpeg',
'-i', input_file,
'-c:v', 'libx264',
'-preset', 'medium',
'-crf', '23',
'-c:a', 'aac',
'-progress', 'pipe:1', # ์งํ๋ฅ ์ ๋ณด๋ฅผ stdout์ผ๋ก
'-y',
output_file
]
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
# ์งํ๋ฅ ํ์ฑ
for line in process.stdout:
if line.startswith('out_time_ms='):
time_ms = int(line.split('=')[1])
current_time = time_ms / 1000000 # ๋ง์ดํฌ๋ก์ด๋ฅผ ์ด๋ก ๋ณํ
progress = (current_time / total_duration) * 100
# ์งํ๋ฅ ํ์
sys.stdout.write(f"\r์งํ๋ฅ : {progress:.1f}% [{current_time:.1f}s / {total_duration:.1f}s]")
sys.stdout.flush()
process.wait()
print("\nโ
๋ณํ ์๋ฃ!")
# ์ฌ์ฉ ์์
convert_with_progress('input.mp4', 'output.mp4')
๐จ ์ํฐ๋งํฌ ์๋ ์ฝ์ ์์คํ
import subprocess
from pathlib import Path
class WatermarkProcessor:
def __init__(self, watermark_path):
self.watermark_path = watermark_path
def add_watermark(self, input_video, output_video, position='top-right', opacity=0.7):
"""
์์์ ์ํฐ๋งํฌ ์ถ๊ฐ
position: 'top-right', 'top-left', 'bottom-right', 'bottom-left', 'center'
"""
# ์์น๋ณ overlay ์ขํ ์ค์
positions = {
'top-right': 'W-w-10:10',
'top-left': '10:10',
'bottom-right': 'W-w-10:H-h-10',
'bottom-left': '10:H-h-10',
'center': '(W-w)/2:(H-h)/2'
}
overlay_pos = positions.get(position, positions['top-right'])
# ํํฐ ๊ตฌ์ฑ
filter_complex = f"[1:v]format=rgba,colorchannelmixer=aa={opacity}[logo];[0:v][logo]overlay={overlay_pos}"
cmd = [
'ffmpeg',
'-i', input_video,
'-i', self.watermark_path,
'-filter_complex', filter_complex,
'-c:a', 'copy',
'-y',
output_video
]
try:
subprocess.run(cmd, check=True, capture_output=True)
print(f"โ
์ํฐ๋งํฌ ์ถ๊ฐ ์๋ฃ: {output_video}")
return True
except subprocess.CalledProcessError as e:
print(f"โ ์ค๋ฅ ๋ฐ์: {e}")
return False
def batch_watermark(self, input_dir, output_dir, position='top-right'):
"""
ํด๋ ๋ด ๋ชจ๋ ์์์ ์ํฐ๋งํฌ ์ผ๊ด ์ถ๊ฐ
"""
Path(output_dir).mkdir(parents=True, exist_ok=True)
video_files = list(Path(input_dir).glob('*.mp4'))
total = len(video_files)
for idx, video_file in enumerate(video_files, 1):
print(f"\n[{idx}/{total}] ์ฒ๋ฆฌ ์ค: {video_file.name}")
output_path = Path(output_dir) / f"watermarked_{video_file.name}"
self.add_watermark(str(video_file), str(output_path), position)
# ์ฌ์ฉ ์์
processor = WatermarkProcessor('logo.png')
processor.batch_watermark('./input_videos', './watermarked_videos', position='bottom-right')
๐ ์น ์๋น์ค์ ํตํฉํ๊ธฐ
FFmpeg์ ์น ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ์ฐ๋ํ๋ฉด ์ง์ง ๊ฐ๋ ฅํ ์๋น์ค๋ฅผ ๋ง๋ค ์ ์์ด์! Flask๋ FastAPI ๊ฐ์ ํ๋ ์์ํฌ์ ๊ฒฐํฉํ ์์ ๋ฅผ ๋ณด์ฌ๋๋ฆด๊ฒ์ ใ ใ
๐ FastAPI๋ก ์์ ๋ณํ API ๋ง๋ค๊ธฐ
from fastapi import FastAPI, File, UploadFile, BackgroundTasks
from fastapi.responses import FileResponse
import subprocess
import uuid
import os
from pathlib import Path
app = FastAPI(title="Video Converter API")
# ์์ ํ์ผ ์ ์ฅ ๋๋ ํ ๋ฆฌ
UPLOAD_DIR = Path("./uploads")
OUTPUT_DIR = Path("./outputs")
UPLOAD_DIR.mkdir(exist_ok=True)
OUTPUT_DIR.mkdir(exist_ok=True)
def convert_video(input_path: str, output_path: str, target_format: str):
"""
๋ฐฑ๊ทธ๋ผ์ด๋์์ ์์ ๋ณํ ์คํ
"""
cmd = [
'ffmpeg',
'-i', input_path,
'-c:v', 'libx264',
'-preset', 'medium',
'-crf', '23',
'-c:a', 'aac',
'-b:a', '192k',
'-y',
output_path
]
try:
subprocess.run(cmd, check=True, capture_output=True)
print(f"โ
๋ณํ ์๋ฃ: {output_path}")
except Exception as e:
print(f"โ ๋ณํ ์คํจ: {e}")
@app.post("/convert/")
async def convert_video_endpoint(
background_tasks: BackgroundTasks,
file: UploadFile = File(...),
target_format: str = "mp4"
):
"""
์์ ํ์ผ์ ์
๋ก๋ํ๊ณ ๋ณํ ์์ฒญ
"""
# ๊ณ ์ ํ์ผ๋ช
์์ฑ
file_id = str(uuid.uuid4())
input_filename = f"{file_id}_{file.filename}"
output_filename = f"{file_id}_converted.{target_format}"
input_path = UPLOAD_DIR / input_filename
output_path = OUTPUT_DIR / output_filename
# ํ์ผ ์ ์ฅ
with open(input_path, "wb") as buffer:
content = await file.read()
buffer.write(content)
# ๋ฐฑ๊ทธ๋ผ์ด๋์์ ๋ณํ ์์
์คํ
background_tasks.add_task(convert_video, str(input_path), str(output_path), target_format)
return {
"message": "๋ณํ ์์
์ด ์์๋์์ต๋๋ค",
"file_id": file_id,
"download_url": f"/download/{output_filename}"
}
@app.get("/download/{filename}")
async def download_file(filename: str):
"""
๋ณํ๋ ํ์ผ ๋ค์ด๋ก๋
"""
file_path = OUTPUT_DIR / filename
if not file_path.exists():
return {"error": "ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค"}
return FileResponse(
path=file_path,
filename=filename,
media_type='application/octet-stream'
)
@app.get("/info/{filename}")
async def get_video_info(filename: str):
"""
์์ ํ์ผ ์ ๋ณด ์กฐํ
"""
file_path = UPLOAD_DIR / filename
if not file_path.exists():
return {"error": "ํ์ผ์ ์ฐพ์ ์ ์์ต๋๋ค"}
cmd = [
'ffprobe',
'-v', 'quiet',
'-print_format', 'json',
'-show_format',
'-show_streams',
str(file_path)
]
result = subprocess.run(cmd, capture_output=True, text=True)
return {"data": result.stdout}
# ์๋ฒ ์คํ: uvicorn main:app --reload
๐ฑ ์ค์๊ฐ ์งํ๋ฅ ์ถ์ (WebSocket)
from fastapi import FastAPI, WebSocket
import subprocess
import asyncio
import re
app = FastAPI()
@app.websocket("/ws/convert")
async def websocket_convert(websocket: WebSocket):
await websocket.accept()
# ํด๋ผ์ด์ธํธ๋ก๋ถํฐ ํ์ผ ์ ๋ณด ๋ฐ๊ธฐ
data = await websocket.receive_json()
input_file = data['input_file']
output_file = data['output_file']
# ์์ ๊ธธ์ด ๊ฐ์ ธ์ค๊ธฐ
duration_cmd = [
'ffprobe',
'-v', 'error',
'-show_entries', 'format=duration',
'-of', 'default=noprint_wrappers=1:nokey=1',
input_file
]
duration_result = subprocess.run(duration_cmd, capture_output=True, text=True)
total_duration = float(duration_result.stdout.strip())
# FFmpeg ํ๋ก์ธ์ค ์์
cmd = [
'ffmpeg',
'-i', input_file,
'-c:v', 'libx264',
'-preset', 'medium',
'-crf', '23',
'-progress', 'pipe:1',
'-y',
output_file
]
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
)
# ์งํ๋ฅ ์ค์๊ฐ ์ ์ก
for line in process.stdout:
if line.startswith('out_time_ms='):
time_ms = int(line.split('=')[1])
current_time = time_ms / 1000000
progress = min((current_time / total_duration) * 100, 100)
await websocket.send_json({
'progress': round(progress, 1),
'current_time': round(current_time, 1),
'total_duration': round(total_duration, 1),
'status': 'processing'
})
process.wait()
# ์๋ฃ ๋ฉ์์ง
await websocket.send_json({
'progress': 100,
'status': 'completed',
'output_file': output_file
})
await websocket.close()
๐ ๊ณ ๊ธ ํํฐ ํ์ฉ๋ฒ
FFmpeg์ ์ง์ง ํ์๋ ํํฐ ์์คํ ์ ์์ด์! ๋ณต์กํ ํํฐ ์ฒด์ธ์ ๊ตฌ์ฑํ๋ฉด ํ๋ฆฌ๋ฏธ์ด ํ๋ก ๋ชป์ง์์ ํธ์ง์ด ๊ฐ๋ฅํ์ฃ ใ ใ
๐ ์๋ณด์ ๋ฐ ์์ ์กฐ์
# ๋ฐ๊ธฐ ์กฐ์
ffmpeg -i input.mp4 -vf "eq=brightness=0.1" output.mp4
# ๋๋น ์กฐ์
ffmpeg -i input.mp4 -vf "eq=contrast=1.5" output.mp4
# ์ฑ๋ ์กฐ์
ffmpeg -i input.mp4 -vf "eq=saturation=1.3" output.mp4
# ์ข
ํฉ ์๋ณด์
ffmpeg -i input.mp4 -vf "eq=brightness=0.05:contrast=1.2:saturation=1.1" output.mp4
# ์์จ๋ ์กฐ์ (๋ฐ๋ปํ๊ฒ)
ffmpeg -i input.mp4 -vf "colortemperature=5500" output.mp4
# ํ๋ฐฑ ๋ณํ
ffmpeg -i input.mp4 -vf "hue=s=0" output.mp4
# ์ธํผ์ ํค
ffmpeg -i input.mp4 -vf "colorchannelmixer=.393:.769:.189:0:.349:.686:.168:0:.272:.534:.131" output.mp4
๐ฌ ์๋ค๋งํฑ ํจ๊ณผ
# ๋ ํฐ๋ฐ์ค (์๋ค๋ง์ค์ฝํ ๋น์จ)
ffmpeg -i input.mp4 -vf "pad=iw:ih*1.2:(ow-iw)/2:(oh-ih)/2:black" output.mp4
# ๋น๋คํ
ํจ๊ณผ (๊ฐ์ฅ์๋ฆฌ ์ด๋ก๊ฒ)
ffmpeg -i input.mp4 -vf "vignette=PI/4" output.mp4
# ํ๋ฆ ๊ทธ๋ ์ธ ํจ๊ณผ
ffmpeg -i input.mp4 -vf "noise=alls=20:allf=t+u" output.mp4
# ๋ชจ์
๋ธ๋ฌ
ffmpeg -i input.mp4 -vf "minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=60'" output.mp4
๐ ํฌ๋กญ ๋ฐ ํจ๋ฉ
# ์ค์ ํฌ๋กญ (์ ์ฌ๊ฐํ)
ffmpeg -i input.mp4 -vf "crop=ih:ih" output.mp4
# ํน์ ์์ญ ํฌ๋กญ
ffmpeg -i input.mp4 -vf "crop=1280:720:0:0" output.mp4
# ํ์: crop=width:height:x:y
# ์๋ ํฌ๋กญ (๊ฒ์ ์ฌ๋ฐฑ ์ ๊ฑฐ)
ffmpeg -i input.mp4 -vf "cropdetect=24:16:0" -f null -
# ์ ๋ช
๋ น์ด๋ก ํฌ๋กญ ๊ฐ ํ์ธ ํ ์ ์ฉ
# ํจ๋ฉ ์ถ๊ฐ (16:9๋ฅผ 4:3์ผ๋ก)
ffmpeg -i input.mp4 -vf "pad=ih*4/3:ih:(ow-iw)/2:0:black" output.mp4
๐ ํ์ ๋ฐ ๋ค์ง๊ธฐ
# 90๋ ์๊ณ๋ฐฉํฅ ํ์
ffmpeg -i input.mp4 -vf "transpose=1" output.mp4
# 90๋ ๋ฐ์๊ณ๋ฐฉํฅ ํ์
ffmpeg -i input.mp4 -vf "transpose=2" output.mp4
# 180๋ ํ์
ffmpeg -i input.mp4 -vf "transpose=2,transpose=2" output.mp4
# ์ข์ฐ ๋ฐ์
ffmpeg -i input.mp4 -vf "hflip" output.mp4
# ์ํ ๋ฐ์
ffmpeg -i input.mp4 -vf "vflip" output.mp4
# ๋ฉํ๋ฐ์ดํฐ ๊ธฐ๋ฐ ์๋ ํ์
ffmpeg -i input.mp4 -vf "transpose=2" -metadata:s:v rotate=0 output.mp4
โก ์๋ ์กฐ์ (์ฌ๋ก์ฐ/ํ์๋ฉ์ค)
# 2๋ฐฐ์ (ํ์๋ฉ์ค)
ffmpeg -i input.mp4 -filter:v "setpts=0.5*PTS" -filter:a "atempo=2.0" output.mp4
# 0.5๋ฐฐ์ (์ฌ๋ก์ฐ ๋ชจ์
)
ffmpeg -i input.mp4 -filter:v "setpts=2.0*PTS" -filter:a "atempo=0.5" output.mp4
# 4๋ฐฐ์ (์ค๋์ค ์ ๊ฑฐ)
ffmpeg -i input.mp4 -filter:v "setpts=0.25*PTS" -an output.mp4
# ๋ถ๋๋ฌ์ด ์ฌ๋ก์ฐ ๋ชจ์
(ํ๋ ์ ๋ณด๊ฐ)
ffmpeg -i input.mp4 -filter:v "minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=120',setpts=4*PTS" output.mp4
atempo=2.0,atempo=2.0
๐จ ๋ณตํฉ ํํฐ ์ฒด์ธ
# ์ฌ๋ฌ ํจ๊ณผ ๋์ ์ ์ฉ
ffmpeg -i input.mp4 -vf "scale=1920:1080,eq=brightness=0.05:contrast=1.2,unsharp=5:5:1.0:5:5:0.0" output.mp4
# ์ํฐ๋งํฌ + ํ
์คํธ + ํ์ด๋
ffmpeg -i input.mp4 -i logo.png -filter_complex \
"[0:v]fade=t=in:st=0:d=2,fade=t=out:st=28:d=2[v1]; \
[v1]drawtext=text='Sample Video':fontsize=48:fontcolor=white:x=(w-text_w)/2:y=h-100[v2]; \
[v2][1:v]overlay=W-w-10:10[outv]" \
-map "[outv]" -map 0:a output.mp4
# PIP (Picture in Picture) ํจ๊ณผ
ffmpeg -i main.mp4 -i pip.mp4 -filter_complex \
"[1:v]scale=320:240[pip]; \
[0:v][pip]overlay=W-w-10:H-h-10" \
output.mp4
๐ฏ ์ค์ ํ๋ก์ ํธ ์์
์ด์ ๋ฐฐ์ด ๊ฑธ ์ข ํฉํด์ ์ค์ ๋ก ์ธ ์ ์๋ ํ๋ก์ ํธ๋ฅผ ๋ง๋ค์ด๋ณผ๊ฒ์! ์์ ์ค์ฉ์ ์ธ ์์ ๋ค์ด์์ ใ ใ
๐บ ์ ํ๋ธ ์๋ ์ ๋ก๋ ์์คํ
import subprocess
from pathlib import Path
import json
class YouTubeVideoProcessor:
def __init__(self, intro_path, outro_path, watermark_path):
self.intro_path = intro_path
self.outro_path = outro_path
self.watermark_path = watermark_path
def process_for_youtube(self, input_video, output_video, title_text):
"""
์ ํ๋ธ ์
๋ก๋์ฉ ์์ ์๋ ์ฒ๋ฆฌ
- ์ธํธ๋ก/์์ํธ๋ก ์ถ๊ฐ
- ์ํฐ๋งํฌ ์ฝ์
- ํ์ดํ ํ
์คํธ ์ค๋ฒ๋ ์ด
- ์ ํ๋ธ ์ต์ ํ ์ธ์ฝ๋ฉ
"""
# 1๋จ๊ณ: ํ์ผ ๋ฆฌ์คํธ ์์ฑ
filelist_path = 'temp_filelist.txt'
with open(filelist_path, 'w') as f:
f.write(f"file '{self.intro_path}'\n")
f.write(f"file '{input_video}'\n")
f.write(f"file '{self.outro_path}'\n")
# 2๋จ๊ณ: ์์ ํฉ์น๊ธฐ + ํํฐ ์ ์ฉ
filter_complex = (
f"[1:v]drawtext=text='{title_text}':"
f"fontsize=72:fontcolor=white:x=(w-text_w)/2:y=100:"
f"shadowcolor=black:shadowx=2:shadowy=2[titled];"
f"[titled][2:v]overlay=W-w-20:20:format=auto[outv]"
)
cmd = [
'ffmpeg',
'-f', 'concat',
'-safe', '0',
'-i', filelist_path,
'-i', self.watermark_path,
'-filter_complex', filter_complex,
'-map', '[outv]',
'-map', '0:a',
'-c:v', 'libx264',
'-preset', 'slow',
'-crf', '18',
'-c:a', 'aac',
'-b:a', '192k',
'-pix_fmt', 'yuv420p',
'-movflags', '+faststart', # ์น ์คํธ๋ฆฌ๋ฐ ์ต์ ํ
'-y',
output_video
]
try:
subprocess.run(cmd, check=True, capture_output=True)
print(f"โ
์ ํ๋ธ์ฉ ์์ ์ฒ๋ฆฌ ์๋ฃ: {output_video}")
# ์์ ํ์ผ ์ญ์
Path(filelist_path).unlink()
return True
except Exception as e:
print(f"โ ์ฒ๋ฆฌ ์คํจ: {e}")
return False
def create_thumbnail(self, video_path, output_path, timestamp='00:00:05'):
"""
์ ํ๋ธ ์ธ๋ค์ผ ์์ฑ (1280x720)
"""
cmd = [
'ffmpeg',
'-ss', timestamp,
'-i', video_path,
'-vf', 'scale=1280:720',
'-vframes', '1',
'-q:v', '2',
'-y',
output_path
]
subprocess.run(cmd, check=True, capture_output=True)
print(f"โ
์ธ๋ค์ผ ์์ฑ: {output_path}")
# ์ฌ์ฉ ์์
processor = YouTubeVideoProcessor(
intro_path='intro.mp4',
outro_path='outro.mp4',
watermark_path='logo.png'
)
processor.process_for_youtube(
input_video='main_content.mp4',
output_video='youtube_ready.mp4',
title_text='FFmpeg ์์ ์ ๋ณต ๊ฐ์ด๋'
)
processor.create_thumbnail('youtube_ready.mp4', 'thumbnail.jpg')
๐ฑ ์์ ๋ฏธ๋์ด ๋ฉํฐ ํฌ๋งท ์์ฑ๊ธฐ
class SocialMediaConverter:
"""
ํ๋์ ์์์ ์ฌ๋ฌ ์์
๋ฏธ๋์ด ํ๋ซํผ์ฉ์ผ๋ก ์๋ ๋ณํ
"""
PLATFORM_SPECS = {
'youtube': {
'resolution': '1920:1080',
'aspect': '16:9',
'max_duration': None,
'format': 'mp4'
},
'instagram_feed': {
'resolution': '1080:1080',
'aspect': '1:1',
'max_duration': 60,
'format': 'mp4'
},
'instagram_story': {
'resolution': '1080:1920',
'aspect': '9:16',
'max_duration': 15,
'format': 'mp4'
},
'tiktok': {
'resolution': '1080:1920',
'aspect': '9:16',
'max_duration': 60,
'format': 'mp4'
},
'twitter': {
'resolution': '1280:720',
'aspect': '16:9',
'max_duration': 140,
'format': 'mp4'
}
}
def convert_for_platform(self, input_video, platform, output_dir='./social_media'):
"""
ํน์ ํ๋ซํผ์ฉ์ผ๋ก ์์ ๋ณํ
"""
if platform not in self.PLATFORM_SPECS:
raise ValueError(f"์ง์ํ์ง ์๋ ํ๋ซํผ: {platform}")
spec = self.PLATFORM_SPECS[platform]
Path(output_dir).mkdir(parents=True, exist_ok=True)
output_filename = f"{Path(input_video).stem}_{platform}.{spec['format']}"
output_path = Path(output_dir) / output_filename
# ๋น๋์ค ํํฐ ๊ตฌ์ฑ
vf_filters = []
# ํด์๋ ๋ฐ ์ข
ํก๋น ์กฐ์
if spec['aspect'] == '1:1':
# ์ ์ฌ๊ฐํ: ํฌ๋กญ ํ ์ค์ผ์ผ
vf_filters.append(f"crop=min(iw\\,ih):min(iw\\,ih),scale={spec['resolution']}")
elif spec['aspect'] == '9:16':
# ์ธ๋กํ: ํฌ๋กญ ํ ์ค์ผ์ผ
vf_filters.append(f"crop=ih*9/16:ih,scale={spec['resolution']}")
else:
# ๊ธฐ๋ณธ: ์ค์ผ์ผ๋ง
vf_filters.append(f"scale={spec['resolution']}")
# ํจ๋ฉ ์ถ๊ฐ (ํ์์)
vf_filters.append("pad=ceil(iw/2)*2:ceil(ih/2)*2")
vf_string = ','.join(vf_filters)
# FFmpeg ๋ช
๋ น์ด ๊ตฌ์ฑ
cmd = [
'ffmpeg',
'-i', input_video,
'-vf', vf_string,
'-c:v', 'libx264',
'-preset', 'medium',
'-crf', '23',
'-c:a', 'aac',
'-b:a', '128k',
'-movflags', '+faststart',
'-y'
]
# ์ต๋ ๊ธธ์ด ์ ํ
if spec['max_duration']:
cmd.extend(['-t', str(spec['max_duration'])])
cmd.append(str(output_path))
try:
subprocess.run(cmd, check=True, capture_output=True)
print(f"โ
{platform}์ฉ ๋ณํ ์๋ฃ: {output_path}")
return str(output_path)
except Exception as e:
print(f"โ {platform} ๋ณํ ์คํจ: {e}")
return None
def convert_all_platforms(self, input_video, output_dir='./social_media'):
"""
๋ชจ๋ ํ๋ซํผ์ฉ์ผ๋ก ์ผ๊ด ๋ณํ
"""
results = {}
for platform in self.PLATFORM_SPECS.keys():
print(f"\n๐ {platform} ๋ณํ ์ค...")
output_path = self.convert_for_platform(input_video, platform, output_dir)
results[platform] = output_path
return results
# ์ฌ์ฉ ์์
converter = SocialMediaConverter()
results = converter.convert_all_platforms('original_video.mp4')
print("\n๐ ๋ณํ ๊ฒฐ๊ณผ:")
for platform, path in results.items():
if path:
print(f" โ
{platform}: {path}")
else:
print(f" โ {platform}: ์คํจ")
๐ฌ ์๋ ํ์ด๋ผ์ดํธ ํด๋ฆฝ ์์ฑ๊ธฐ
import subprocess
import json
from pathlib import Path
class HighlightGenerator:
def __init__(self, silence_threshold=-30, min_silence_duration=1.0):
"""
silence_threshold: ๋ฌด์์ผ๋ก ๊ฐ์ฃผํ dB ๋ ๋ฒจ
min_silence_duration: ์ต์ ๋ฌด์ ์ง์ ์๊ฐ(์ด)
"""
self.silence_threshold = silence_threshold
self.min_silence_duration = min_silence_duration
def detect_silence(self, video_path):
"""
์์์์ ๋ฌด์ ๊ตฌ๊ฐ ๊ฐ์ง
"""
cmd = [
'ffmpeg',
'-i', video_path,
'-af', f'silencedetect=noise={self.silence_threshold}dB:d={self.min_silence_duration}',
'-f', 'null',
'-'
]
result = subprocess.run(cmd, capture_output=True, text=True, stderr=subprocess.STDOUT)
# ๋ฌด์ ๊ตฌ๊ฐ ํ์ฑ
silence_periods = []
lines = result.stdout.split('\n')
silence_start = None
for line in lines:
if 'silence_start' in line:
silence_start = float(line.split('silence_start: ')[1])
elif 'silence_end' in line and silence_start is not None:
silence_end = float(line.split('silence_end: ')[1].split('|')[0])
silence_periods.append((silence_start, silence_end))
silence_start = None
return silence_periods
def generate_highlights(self, video_path, output_dir, min_clip_duration=5):
"""
๋ฌด์ ๊ตฌ๊ฐ์ ๊ธฐ์ค์ผ๋ก ํ์ด๋ผ์ดํธ ํด๋ฆฝ ์์ฑ
"""
Path(output_dir).mkdir(parents=True, exist_ok=True)
# ๋ฌด์ ๊ตฌ๊ฐ ๊ฐ์ง
silence_periods = self.detect_silence(video_path)
if not silence_periods:
print("๋ฌด์ ๊ตฌ๊ฐ์ ์ฐพ์ ์ ์์ต๋๋ค.")
return []
# ์์ ์ ์ฒด ๊ธธ์ด ๊ฐ์ ธ์ค๊ธฐ
duration_cmd = [
'ffprobe',
'-v', 'error',
'-show_entries', 'format=duration',
'-of', 'default=noprint_wrappers=1:nokey=1',
video_path
]
total_duration = float(subprocess.run(duration_cmd, capture_output=True, text=True).stdout.strip())
# ํ์ด๋ผ์ดํธ ๊ตฌ๊ฐ ๊ณ์ฐ (๋ฌด์ ์ฌ์ด์ ๊ตฌ๊ฐ)
highlights = []
prev_end = 0
for silence_start, silence_end in silence_periods:
if silence_start - prev_end >= min_clip_duration:
highlights.append((prev_end, silence_start))
prev_end = silence_end
# ๋ง์ง๋ง ๊ตฌ๊ฐ
if total_duration - prev_end >= min_clip_duration:
highlights.append((prev_end, total_duration))
# ํ์ด๋ผ์ดํธ ํด๋ฆฝ ์ถ์ถ
output_files = []
for idx, (start, end) in enumerate(highlights, 1):
duration = end - start
output_filename = f"highlight_{idx:02d}.mp4"
output_path = Path(output_dir) / output_filename
cmd = [
'ffmpeg',
'-ss', str(start),
'-i', video_path,
'-t', str(duration),
'-c', 'copy',
'-y',
str(output_path)
]
subprocess.run(cmd, check=True, capture_output=True)
print(f"โ
ํ์ด๋ผ์ดํธ {idx} ์์ฑ: {start:.1f}s ~ {end:.1f}s ({duration:.1f}s)")
output_files.append(str(output_path))
return output_files
# ์ฌ์ฉ ์์
generator = HighlightGenerator(silence_threshold=-35, min_silence_duration=2.0)
highlights = generator.generate_highlights('long_video.mp4', './highlights')
print(f"\n๐ ์ด {len(highlights)}๊ฐ์ ํ์ด๋ผ์ดํธ ํด๋ฆฝ ์์ฑ๋จ")
๐ ํธ๋ฌ๋ธ์ํ & ์์ฃผ ๋ฌป๋ ์ง๋ฌธ
FFmpeg ์ฌ์ฉํ๋ค ๋ณด๋ฉด ์์ฃผ ๋ง์ฃผ์น๋ ๋ฌธ์ ๋ค์ด ์์ด์. ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์ ๋ฆฌํด๋ดค์ต๋๋ค!
โ ์์ฃผ ๋ฐ์ํ๋ ์๋ฌ์ ํด๊ฒฐ๋ฒ
์์ธ: FFmpeg ๋น๋์ ํด๋น ์ฝ๋ฑ์ด ํฌํจ๋์ง ์์
ํด๊ฒฐ: ์ ์ฒด ์ฝ๋ฑ์ด ํฌํจ๋ ๋น๋๋ฅผ ๋ค์ ์ค์นํ๊ฑฐ๋, ๋ค๋ฅธ ์ฝ๋ฑ ์ฌ์ฉ
# ์ฌ์ฉ ๊ฐ๋ฅํ ์ฝ๋ฑ ํ์ธ
ffmpeg -codecs
# ์ฌ์ฉ ๊ฐ๋ฅํ ์ธ์ฝ๋ ํ์ธ
ffmpeg -encoders
# ๋์ฒด ์ฝ๋ฑ ์ฌ์ฉ ์์
ffmpeg -i input.mp4 -c:v libx264 output.mp4 # H.264 ๋์
์์ธ: H.264 ์ฝ๋ฑ์ ๊ฐ๋ก/์ธ๋ก๊ฐ 2์ ๋ฐฐ์์ฌ์ผ ํจ
ํด๊ฒฐ: ์ค์ผ์ผ ํํฐ์์ ์๋์ผ๋ก 2์ ๋ฐฐ์๋ก ์กฐ์
# ์๋ชป๋ ์
ffmpeg -i input.mp4 -vf "scale=1921:1081" output.mp4 # ํ์!
# ์ฌ๋ฐ๋ฅธ ์
ffmpeg -i input.mp4 -vf "scale=1920:1080" output.mp4
# ์๋ ์กฐ์
ffmpeg -i input.mp4 -vf "scale='trunc(iw/2)*2':'trunc(ih/2)*2'" output.mp4
์์ธ: ์๋ชป๋ ์ธ์ฝ๋ฉ ์ค์ ๋๋ ๋นํธ๋ ์ดํธ ๋ถ์กฑ
ํด๊ฒฐ: CRF ๊ฐ ์กฐ์ ๋๋ ๋นํธ๋ ์ดํธ ๋ช ์
# CRF ๋ฐฉ์ (๊ถ์ฅ)
ffmpeg -i input.mp4 -c:v libx264 -crf 18 output.mp4
# ๋นํธ๋ ์ดํธ ๋ฐฉ์
ffmpeg -i input.mp4 -c:v libx264 -b:v 5M output.mp4
# 2-pass ์ธ์ฝ๋ฉ (์ต๊ณ ํ์ง)
ffmpeg -i input.mp4 -c:v libx264 -b:v 5M -pass 1 -f null /dev/null
ffmpeg -i input.mp4 -c:v libx264 -b:v 5M -pass 2 output.mp4
ํด๊ฒฐ: ํ๋ฆฌ์ ์กฐ์ , ํ๋์จ์ด ๊ฐ์ ์ฌ์ฉ, ํด์๋ ๋ฎ์ถ๊ธฐ
# ๋น ๋ฅธ ํ๋ฆฌ์
์ฌ์ฉ
ffmpeg -i input.mp4 -c:v libx264 -preset ultrafast output.mp4
# GPU ๊ฐ์ (NVIDIA)
ffmpeg -hwaccel cuda -i input.mp4 -c:v h264_nvenc -preset fast output.mp4
# ํด์๋ ๋ฎ์ถ๊ธฐ
ffmpeg -i input.mp4 -vf "scale=1280:720" -c:v libx264 -preset fast output.mp4
# ๋ฉํฐ์ค๋ ๋ฉ ํ์ฑํ
ffmpeg -i input.mp4 -threads 8 -c:v libx264 output.mp4
์์ธ: ๊ฐ๋ณ ํ๋ ์๋ ์ดํธ(VFR) ์์ ๋๋ ํ์์คํฌํ ๋ฌธ์
ํด๊ฒฐ: ๊ณ ์ ํ๋ ์๋ ์ดํธ๋ก ๋ณํ ๋๋ ํ์์คํฌํ ์ฌ์์ฑ
# ๊ณ ์ ํ๋ ์๋ ์ดํธ๋ก ๋ณํ
ffmpeg -i input.mp4 -r 30 -c:v libx264 output.mp4
# ํ์์คํฌํ ์ฌ์์ฑ
ffmpeg -i input.mp4 -c copy -fflags +genpts output.mp4
# ์ค๋์ค ์ง์ฐ ๋ณด์ (0.5์ด ์ง์ฐ)
ffmpeg -i input.mp4 -itsoffset 0.5 -i input.mp4 -map 0:v -map 1:a -c copy output.mp4
๐ก ์ฑ๋ฅ ์ต์ ํ ํ
| ์ํฉ | ์ต์ ํ ๋ฐฉ๋ฒ | ์์ ํจ๊ณผ |
|---|---|---|
| ๋๋ ํ์ผ ์ฒ๋ฆฌ | ๋ณ๋ ฌ ์ฒ๋ฆฌ (GNU Parallel ์ฌ์ฉ) | CPU ์ฝ์ด ์๋งํผ ์๋ ํฅ์ |
| ์ค์๊ฐ ์คํธ๋ฆฌ๋ฐ | ultrafast ํ๋ฆฌ์ + GPU ๊ฐ์ | ์ง์ฐ ์๊ฐ ์ต์ํ |
| ์ ์ฅ ๊ณต๊ฐ ๋ถ์กฑ | H.265 ์ฝ๋ฑ + CRF 28 | ํ์ผ ํฌ๊ธฐ 50% ๊ฐ์ |
| ๊ณ ํ์ง ์์นด์ด๋น | veryslow ํ๋ฆฌ์ + CRF 18 | ์ต๊ณ ํ์ง ์ ์ง |
| ์น ์คํธ๋ฆฌ๋ฐ | faststart ํ๋๊ทธ + ์ ์ ํ ๋นํธ๋ ์ดํธ | ๋น ๋ฅธ ๋ก๋ฉ |
๐ง ์ ์ฉํ ๋๋ฒ๊น ๋ช ๋ น์ด
# ์์ ์ ๋ณด ์์ธ ์ถ๋ ฅ
ffprobe -v error -show_format -show_streams input.mp4
# ํ๋ ์๋ณ ์ ๋ณด ํ์ธ
ffprobe -v error -show_frames input.mp4
# ํน์ ์คํธ๋ฆผ๋ง ๋ถ์
ffprobe -v error -select_streams v:0 -show_entries stream=codec_name,width,height input.mp4
# ์ธ์ฝ๋ฉ ์งํ ์ํฉ ์์ธ ๋ก๊ทธ
ffmpeg -i input.mp4 -c:v libx264 -progress - -y output.mp4
# ํํฐ ๊ทธ๋ํ ์๊ฐํ (๋ณต์กํ ํํฐ ๋๋ฒ๊น
์ฉ)
ffmpeg -i input.mp4 -filter_complex "..." -filter_complex_script graph.txt
๐ ๊ณ ๊ธ ํ์ฉ: CI/CD ํ์ดํ๋ผ์ธ ํตํฉ
FFmpeg์ CI/CD ํ์ดํ๋ผ์ธ์ ํตํฉํ๋ฉด ์์ ์ฒ๋ฆฌ๋ฅผ ์์ ์๋ํํ ์ ์์ด์! GitHub Actions๋ GitLab CI ๊ฐ์ ๋๊ตฌ์ ๊ฒฐํฉํ ์์ ๋ฅผ ๋ณด์ฌ๋๋ฆด๊ฒ์ ใ ใ
๐ GitHub Actions ์ํฌํ๋ก์ฐ
# .github/workflows/video-processing.yml
name: Video Processing Pipeline
on:
push:
paths:
- 'videos/**'
workflow_dispatch:
jobs:
process-videos:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install FFmpeg
run: |
sudo apt-get update
sudo apt-get install -y ffmpeg
- name: Process videos
run: |
mkdir -p processed_videos
for video in videos/*.mp4; do
filename=$(basename "$video" .mp4)
# 1080p ๋ฒ์ ์์ฑ
ffmpeg -i "$video" \
-vf "scale=1920:1080" \
-c:v libx264 -preset medium -crf 23 \
-c:a aac -b:a 192k \
"processed_videos/${filename}_1080p.mp4"
# 720p ๋ฒ์ ์์ฑ
ffmpeg -i "$video" \
-vf "scale=1280:720" \
-c:v libx264 -preset medium -crf 23 \
-c:a aac -b:a 128k \
"processed_videos/${filename}_720p.mp4"
# ์ธ๋ค์ผ ์์ฑ
ffmpeg -i "$video" \
-ss 00:00:05 -vframes 1 \
-vf "scale=1280:720" \
"processed_videos/${filename}_thumb.jpg"
done
- name: Upload processed videos
uses: actions/upload-artifact@v3
with:
name: processed-videos
path: processed_videos/
- name: Deploy to S3 (optional)
if: github.ref == 'refs/heads/main'
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
aws s3 sync processed_videos/ s3://my-bucket/videos/ --acl public-read
๐ณ Docker ์ปจํ ์ด๋ํ
# Dockerfile
FROM jrottenberg/ffmpeg:4.4-alpine
# Python ์ค์น (์คํฌ๋ฆฝํธ ์คํ์ฉ)
RUN apk add --no-cache python3 py3-pip
# ์์
๋๋ ํ ๋ฆฌ ์ค์
WORKDIR /app
# ์์กด์ฑ ์ค์น
COPY requirements.txt .
RUN pip3 install -r requirements.txt
# ์คํฌ๋ฆฝํธ ๋ณต์ฌ
COPY video_processor.py .
# ๋ณผ๋ฅจ ๋ง์ดํธ ํฌ์ธํธ
VOLUME ["/input", "/output"]
# ์คํ ๋ช
๋ น
ENTRYPOINT ["python3", "video_processor.py"]
# docker-compose.yml
version: '3.8'
services:
video-processor:
build: .
volumes:
- ./input_videos:/input
- ./output_videos:/output
environment:
- PRESET=medium
- CRF=23
- OUTPUT_FORMAT=mp4
command: --input /input --output /output
โ๏ธ ํ ์์คํ ๊ณผ ํตํฉ (Celery + Redis)
# tasks.py
from celery import Celery
import subprocess
from pathlib import Path
app = Celery('video_tasks', broker='redis://localhost:6379/0')
@app.task(bind=True)
def convert_video(self, input_path, output_path, options=None):
"""
๋น๋๊ธฐ ์์ ๋ณํ ์์
"""
options = options or {}
cmd = [
'ffmpeg',
'-i', input_path,
'-c:v', options.get('video_codec', 'libx264'),
'-preset', options.get('preset', 'medium'),
'-crf', str(options.get('crf', 23)),
'-c:a', options.get('audio_codec', 'aac'),
'-b:a', options.get('audio_bitrate', '192k'),
'-progress', 'pipe:1',
'-y',
output_path
]
process = subprocess.Popen(
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True
)
# ์งํ๋ฅ ์
๋ฐ์ดํธ
for line in process.stdout:
if line.startswith('out_time_ms='):
time_ms = int(line.split('=')[1])
# Celery ํ์คํฌ ์ํ ์
๋ฐ์ดํธ
self.update_state(
state='PROGRESS',
meta={'current': time_ms, 'status': 'Converting...'}
)
process.wait()
if process.returncode == 0:
return {'status': 'completed', 'output': output_path}
else:
raise Exception(f"FFmpeg failed with code {process.returncode}")
# ์์ปค ์คํ: celery -A tasks worker --loglevel=info
# api.py (FastAPI์ ํตํฉ)
from fastapi import FastAPI, UploadFile, BackgroundTasks
from tasks import convert_video
import uuid
app = FastAPI()
@app.post("/convert/")
async def queue_conversion(file: UploadFile):
"""
์์ ๋ณํ ์์
์ ํ์ ์ถ๊ฐ
"""
task_id = str(uuid.uuid4())
input_path = f"/tmp/{task_id}_{file.filename}"
output_path = f"/tmp/{task_id}_output.mp4"
# ํ์ผ ์ ์ฅ
with open(input_path, "wb") as f:
content = await file.read()
f.write(content)
# Celery ํ์คํฌ ์คํ
task = convert_video.delay(input_path, output_path)
return {
"task_id": task.id,
"status": "queued",
"check_url": f"/status/{task.id}"
}
@app.get("/status/{task_id}")
async def check_status(task_id: str):
"""
์์
์งํ ์ํฉ ํ์ธ
"""
task = convert_video.AsyncResult(task_id)
if task.state == 'PENDING':
response = {'state': task.state, 'status': 'Pending...'}
elif task.state == 'PROGRESS':
response = {
'state': task.state,
'current': task.info.get('current', 0),
'status': task.info.get('status', '')
}
elif task.state == 'SUCCESS':
response = {
'state': task.state,
'result': task.result
}
else:
response = {'state': task.state, 'status': str(task.info)}
return response
๐ ์ถ๊ฐ ํ์ต ๋ฆฌ์์ค & ์ปค๋ฎค๋ํฐ
FFmpeg์ ์ ๋ง ๋ฐฉ๋ํ ๋๊ตฌ๋ผ์ ๊ณ์ ๋ฐฐ์ธ ๊ฒ ๋ง์์. ์ ์ฉํ ๋ฆฌ์์ค๋ค์ ์ ๋ฆฌํด๋ดค์ต๋๋ค!
๐ ๊ณต์ ๋ฌธ์ ๋ฐ ๋ ํผ๋ฐ์ค
https://ffmpeg.org/documentation.html
๊ฐ์ฅ ์ ํํ๊ณ ์์ธํ ์ ๋ณด. ๋ชจ๋ ์ต์ ๊ณผ ํํฐ ์ค๋ช ์ด ์์ด์.
https://trac.ffmpeg.org/wiki
์ค์ฉ์ ์ธ ์์ ์ ๊ฐ์ด๋๊ฐ ๋ง์์. ํนํ ์ธ์ฝ๋ฉ ๊ฐ์ด๋ ์น์ ์ถ์ฒ!
'ffmpeg' ํ๊ทธ๋ก ๊ฒ์ํ๋ฉด ๊ฑฐ์ ๋ชจ๋ ๋ฌธ์ ์ ํด๋ต์ ์ฐพ์ ์ ์์ด์ ใ ใ
๐ ํ์ต ํ
๐ผ ์ค๋ฌด ํ์ฉ ์๋๋ฆฌ์ค
| ์ ์ข /๋ถ์ผ | ํ์ฉ ์ฌ๋ก | ํต์ฌ ๊ธฐ๋ฅ |
|---|---|---|
| ์ ํ๋ฒ/ํฌ๋ฆฌ์์ดํฐ | ์์ ์๋ ํธ์ง ๋ฐ ์ ๋ก๋ | ์ธํธ๋ก/์์ํธ๋ก ์ถ๊ฐ, ์ํฐ๋งํฌ, ์ธ๋ค์ผ ์์ฑ |
| ๊ต์ก ํ๋ซํผ | ๊ฐ์ ์์ ์๋ ์ฒ๋ฆฌ | ํ์ง๋ณ ๋ค์ค ๋ฒ์ , ์๋ง ์ฝ์ , ์ฑํฐ ๋ถํ |
| OTT/์คํธ๋ฆฌ๋ฐ | ์ ์ํ ์คํธ๋ฆฌ๋ฐ ์์ฑ | HLS/DASH ๋ณํ, ๋ค์ค ๋นํธ๋ ์ดํธ |
| ์์ ๋ฏธ๋์ด ์์ด์ ์ | ํ๋ซํผ๋ณ ์ต์ ํ | ์ข ํก๋น ๋ณํ, ๊ธธ์ด ์กฐ์ , ํฌ๋งท ๋ณํ |
| ๋ณด์/๊ฐ์ | CCTV ์์ ์์ถ ๋ฐ ๋ณด๊ด | ํ์๋ฉ์ค, ์ ์ฉ๋ ์ธ์ฝ๋ฉ, ๋ฐฐ์น ์ฒ๋ฆฌ |
๐ ๋ง๋ฌด๋ฆฌํ๋ฉฐ
์... ์ฌ๊ธฐ๊น์ง ์ฝ์ผ์
จ๋ค๋ฉด ์ง์ง ๋๋จํ์ธ์! ใ
ใ
ใ
FFmpeg์ ์ฒ์์ ์ข ์ด๋ ต๊ฒ ๋๊ปด์ง ์ ์์ง๋ง, ์ต์ํด์ง๋ฉด ์ ๋ง ๊ฐ๋ ฅํ ๋๊ตฌ์์. ์์ ํธ์ง ํ๋ก๊ทธ๋จ ์์ด๋ ๋ช
๋ น์ด ๋ช ์ค๋ก ํ๋กํ์
๋ํ ๊ฒฐ๊ณผ๋ฌผ์ ๋ง๋ค ์ ์๊ฑฐ๋ ์. ๐
ํนํ ํ๋ก๊ทธ๋๋ฐ๊ณผ ๊ฒฐํฉํ๋ฉด ์์ ์๋ํ๋ ์์ ์ฒ๋ฆฌ ์์คํ
์ ๊ตฌ์ถํ ์ ์์ด์, ์ฌ๋ฅ๋ท ๊ฐ์ ํ๋ซํผ์์ ์์ ๊ด๋ จ ์๋น์ค๋ฅผ ์ ๊ณตํ๋ ๋ถ๋คํํ
๋ ํ์ ์คํฌ์ด๋ผ๊ณ ํ ์ ์์ฃ !
์ด ๊ฐ์ด๋์์ ๋ค๋ฃฌ ๋ด์ฉ๋ค์ ์ค์ ๋ก ํ๋์ฉ ๋ฐ๋ผํด๋ณด๋ฉด์ ์์ ๋ง์ ์๋ํ ์์คํ
์ ๋ง๋ค์ด๋ณด์ธ์. ์ฒ์์ ์๋ฌ๋ ๋ง์ด ๋๊ณ ํค๋งฌ ์ ์์ง๋ง, ๊ทธ๊ฒ ๋ค ๋ฐฐ์ฐ๋ ๊ณผ์ ์ด์์ ใ
ใ
ํน์ FFmpeg ๊ด๋ จํด์ ๋ ๊ถ๊ธํ ์ ์ด ์๊ฑฐ๋, ํน์ ํ๋ก์ ํธ์ ์ ์ฉํ๊ณ ์ถ์๋ฐ ๋งํ๋ ๋ถ๋ถ์ด ์๋ค๋ฉด ์ฌ๋ฅ๋ท ์ปค๋ฎค๋ํฐ์์ ์ง๋ฌธํด๋ณด์ธ์! ๋ง์ ์ ๋ฌธ๊ฐ๋ค์ด ๋์์ ์ค ๊ฑฐ์์. ๐
๊ทธ๋ผ ์ฌ๋ฌ๋ถ์ ์์ ์๋ํ ํ๋ก์ ํธ๊ฐ ์ฑ๊ณต์ ์ด๊ธธ ๋ฐ๋ผ๋ฉฐ, ์ด๋ง ๋ง์น๊ฒ ์ต๋๋ค! ํ์ดํ
! ๐ชโจ
์ฌ๋ฌ๋ถ์ ์ฌ๋ฅ์ ๊ณต์ ํ๊ณ , ๋ค๋ฅธ ์ ๋ฌธ๊ฐ๋ค๊ณผ ๊ต๋ฅํ ์ ์๋ ๊ณต๊ฐ์ ๋๋ค. ๐ฏ
๊ด๋ จ ํค์๋
๋๊ธ ์์ฑ
์ด ๊ธ์ ๋ํ ์ฌ๋ฌ๋ถ์ ์๊ฐ์ ๋ค๋ ค์ฃผ์ธ์
๋ก๊ทธ์ธ์ด ํ์ํฉ๋๋ค
๋๊ธ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ ๋ก๊ทธ์ธํด์ฃผ์ธ์.
๋๊ธ 0
์ง์์ธ์ ์ฒ - ์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
์ง์ ์ฌ์ฐ๊ถ ๋ณดํธ ๊ณ ์ง
- ์ ์๊ถ ๋ฐ ์์ ๊ถ: ๋ณธ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ๋ ์ AI ๊ธฐ์ ๋ก ์์ฑ๋์์ผ๋ฉฐ, ๋ํ๋ฏผ๊ตญ ์ ์๊ถ๋ฒ ๋ฐ ๊ตญ์ ์ ์๊ถ ํ์ฝ์ ์ํด ๋ณดํธ๋ฉ๋๋ค.
- AI ์์ฑ ์ปจํ ์ธ ์ ๋ฒ์ ์ง์: ๋ณธ AI ์์ฑ ์ปจํ ์ธ ๋ ์ฌ๋ฅ๋ท์ ์ง์ ์ฐฝ์๋ฌผ๋ก ์ธ์ ๋๋ฉฐ, ๊ด๋ จ ๋ฒ๊ท์ ๋ฐ๋ผ ์ ์๊ถ ๋ณดํธ๋ฅผ ๋ฐ์ต๋๋ค.
- ์ฌ์ฉ ์ ํ: ์ฌ๋ฅ๋ท์ ๋ช ์์ ์๋ฉด ๋์ ์์ด ๋ณธ ์ปจํ ์ธ ๋ฅผ ๋ณต์ , ์์ , ๋ฐฐํฌ, ๋๋ ์์ ์ ์ผ๋ก ํ์ฉํ๋ ํ์๋ ์๊ฒฉํ ๊ธ์ง๋ฉ๋๋ค.
- ๋ฐ์ดํฐ ์์ง ๊ธ์ง: ๋ณธ ์ปจํ ์ธ ์ ๋ํ ๋ฌด๋จ ์คํฌ๋ํ, ํฌ๋กค๋ง, ๋ฐ ์๋ํ๋ ๋ฐ์ดํฐ ์์ง์ ๋ฒ์ ์ ์ฌ์ ๋์์ด ๋ฉ๋๋ค.
- AI ํ์ต ์ ํ: ์ฌ๋ฅ๋ท์ AI ์์ฑ ์ปจํ ์ธ ๋ฅผ ํ AI ๋ชจ๋ธ ํ์ต์ ๋ฌด๋จ ์ฌ์ฉํ๋ ํ์๋ ๊ธ์ง๋๋ฉฐ, ์ด๋ ์ง์ ์ฌ์ฐ๊ถ ์นจํด๋ก ๊ฐ์ฃผ๋ฉ๋๋ค.
์์ง ๋๊ธ์ด ์์ต๋๋ค.