๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๊ฐœ๋ฐœ

[FFMPEG] ํŠธ๋žœ์Šค์ฝ”๋”ฉ, ํ•„ํ„ฐ, ํ•„ํ„ฐ ์ฒด์ด๋‹ ๊ธฐ๋ณธ ๋ฌธ๋ฒ•

๋ฐ˜์‘ํ˜•

 

๐Ÿ“„ ๋ชฉ์ฐจ

 

ffmpeg์˜ ๊ธฐ๋Šฅ - ํŠธ๋žœ์Šค์ฝ”๋”ฉ๊ณผ ํ•„ํ„ฐ๋ง

1. ํŠธ๋žœ์Šค์ฝ”๋”ฉ (Transcoding)

์ธํ’‹์„ ๋‹ค๋ฅธ ํฌ๋ฉง์œผ๋กœ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒƒ

input -> Demux(Unpack) -> Decode(Uncompress) -> Encode(Compress) -> Mux(Pack) -> output

 

2. ํ•„ํ„ฐ๋ง (Filtering)

๋ฏธ๋””์–ด์˜ ์˜ค๋””์˜ค์™€ ๋น„๋””์˜ค์— ์ผ๋ถ€ ๋ณ€ํ™”๋ฅผ ์ฃผ๋Š” ๊ฒƒ

input -> Demux(Unpack) -> Decode(Uncompress) -> filter1 -> filter2 -> filter2 -> ... ->  Encode(Compress) -> Mux(Pack) -> output

 

ffmpeg์˜ ๊ธฐ๋ณธ ๋ฌธ๋ฒ• 

ffmpeg

-f <input device or format> // ๋”ฐ๋กœ ๋ช…์‹œํ•˜์ง€ ์•Š์„ ๊ฒฝ์šฐ ffmpeg๊ฐ€ ์•Œ์•„์„œ ์ถ”์ •ํ•จ

-i <input-protocol>:<input-identifier>

.. <filters and other options>

-f <output device or format>

<output-protocol>:<output-identifier>

 

์ง€์›ํ•˜๋Š” devices, format, protocol ํ™•์ธ

ffmpeg -devices

ffmpeg -formats

ffmpeg -protocols

 

mac์—์„œ ffmpeg -devices ๊ฒฐ๊ณผ

์Šคํฌ๋ฆฐ ์บก์ณ๋ฅผ ๋ฐ”๋กœ ์ธํ’‹์œผ๋กœ ๋„ฃ๋Š” ๊ฒƒ๋„ ๊ฐ€๋Šฅํ•จ

windows ffmpeg -f gdigrab -i desktop ...
macOS ffmpeg -f avfoundation -i "1"
Linux ffmpeg -f x11grab -i $DISPLAY

ํŒŒ์ดํ”„๋ผ์ธ์„ ์ธํ’‹,์•„์›ƒํ’‹์œผ๋กœ๋„ ๊ฐ€๋Šฅํ•จ

ffmpeg -f mov -i - ... -f mxf -

ffmpeg -f mov -i pipe:0 ... -f mxf pipe:1

 

์ธํ’‹์„ ์ƒ์„ฑํ•ด์„œ ๋„ฃ๋Š”๊ฒƒ๋„ ๊ฐ€๋Šฅํ•จ

ffmpeg -f lavfi -i testsrc=duration=1:size=1920x1080

ffmpeg -f lavfi -i color=color=red

 

์ŠคํŠธ๋ฆผ ์„ ํƒ

ํ•„ํ„ฐ์™€ ์•„์›ƒํ’‹์—์„œ๋Š” -map ์˜ต์…˜์„ ํ†ตํ•ด ์ŠคํŠธ๋ฆผ์„ ์ง€์ •ํ•ด ์ฃผ์–ดํ– ํ•จ

<input-index>:<stream-type>:<stream-index>

ex) 0:v:1 (์ฒซ๋ฒˆ์งธ ์ธํ’‹์˜ ๋น„๋””์˜ค ์ŠคํŠธ๋ฆผ ์ค‘ ๋‘๋ฒˆ์งธ), 0:v (์ฒซ๋ฒˆ์งธ ์ธํ’‹์˜ ๋น„๋””์˜ค ์ŠคํŠธ๋ฆผ ์ „์ฒด)

๋”ฐ๋กœ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ์˜ค๋””์˜ค ์ฑ„๋„ 1๊ฐœ ๋น„๋””์˜ค ์ฑ„๋„ 1๊ฐœ๋งŒ ์•„์›ƒํ’‹์— ํฌํ•จ๋จ

 

ํ•„ํ„ฐ

filter=key1=value1:key2=value2 ...

ex) scale=width=1920:height=1080

 

์—ฌ๋Ÿฌ ํ•„ํ„ฐ๋ฅผ ์ ์šฉํ• ๋•Œ๋Š” ;๋กœ ์ด์–ด๋ถ™์ž„

filter=key1=value1:key2=value2 ...;filter2=key3=value3:key4=value4 ...;

 

input output ๋ ˆ์ด๋ธ”๋ง

๋น„์„ ํ˜• ํ•„ํ„ฐ ๊ทธ๋ž˜ํ”„ ๊ตฌ์„ฑํ•  ๋•Œ ์œ ์šฉํ•จ

[a_label] ํ˜•์‹

์ŠคํŠธ๋ฆผ ์„ ํƒ์ž๋„ ์ธํ’‹ ๋ ˆ์ด๋ธ”๋กœ ์“ฐ์ผ ์ˆ˜ ์žˆ์Œ [0:v], [1:a:2]

ex) [in_1][in_2] ... filter_name=<options...>[out_1][out_2] ... 

 

ํ•„ํ„ฐ ๊ทธ๋ž˜ํ”„

Filter Graph : ์—ฌ๋Ÿฌ ํ•„ํ„ฐ๋ฅผ ์ฒด์ด๋‹ ํ•˜๋Š” ๊ฒƒ

-vf : ๋น„๋””์˜ค ํ•„ํ„ฐ ๊ทธ๋ž˜ํ”„. 1๊ฐœ์˜ ์ธํ’‹, ์•„์›ƒํ’‹

-af : ์˜ค๋””์˜ค ํ•„ํ„ฐ ๊ทธ๋ž˜ํ”„. 1๊ฐœ์˜ ์ธํ’‹, ์•„์›ƒํ’‹

-filter_complex: ์˜ค๋””์˜ค์™€ ๋น„๋””์˜ค, ์—ฌ๋Ÿฌ๊ฐœ์˜ ์ธํ’‹ ์•„์›ƒํ’‹

 

๋น„๋””์˜ค ํ•„ํ„ฐ ์˜ˆ์‹œ) 

ffmpeg -v error -y -i bullfinch.mp4 -vf "split[bg][ol];[bg]scale=width=1920:height=1080,format=gray[bg_out];[ol]scale=-1:480,hflip[ol_out];[bg_out][ol_out]overlay=x=W-w:y=(H-h)/2" ol.mp4

split[bg][ol];

[bg]scale=width=1920:height=1080,format=gray[bg_out];

[ol]scale=-1:480,hflip[ol_out];

[bg_out][ol_out]overlay=x=W-w:y=(H-h)/2

๋น„๋””์˜ค ํ•„ํ„ฐ ์˜ˆ์‹œ

 

์˜ค๋””์˜ค ํ•„ํ„ฐ ์˜ˆ์‹œ)

ffmpeg -y -i four_channel_stream.wav -af "asplit=2[voice][bg];[voice]volume=volume=2,pan=mono|c0=c0+c1[voice_out];[bg]volume=volume=0.5,pan=mono|c0=c2+c3[bg_out];[voice_out][bg_out]amerge=inputs=2" audio_out.wav

asplit=2[voice][bg];

[voice]volume=volume=2,pan=mono|c0=c0+c1[voice_out];

[bg]volume=volume=0.5,pan=mono|c0=c2+c3[bg_out];

[voice_out][bg_out]amerge=inputs=2

์˜ค๋””์˜คํ•„ํ„ฐ ์˜ˆ์‹œ

complex filter ์˜ˆ์‹œ)

ffmpeg -v error -y -i bullfinch.mp4 -i ffmpeg-logo.png -filter_complex "[1:v]scale=-1:200[small_logo];[0:v][small_logo]overlay=x=W-w-50:y=H-h-50,split=2[sd_in][hd_in];[sd_in]scale=-2:480[sd];[hd_in]scale=-2:1080[hd];[0:1]pan=stereo|FL=c0+c2|FR=c1+c3[streo_mix]" -map [sd] sd.mp4 -map [hd] hd.mp4 -map [stero_mix] streo_mix.mp3

[1:v]scale=-1:200[small_logo];

[0:v][small_logo]overlay=x=W-w-50:y=H-h-50,split=2[sd_in][hd_in];

[sd_in]scale=-2:480[sd];

[hd_in]scale=-2:1080[hd];

[0:1]pan=stereo|FL=c0+c2|FR=c1+c3[streo_mix]

 

๋ฐ˜์‘ํ˜•