[ffmpeg] 툴 분석 (3)
[ffmpeg] 툴 분석 (3)
Filtering
영상을 인코딩 하기 전에 오디오나 비디오 영상을 libavfilter 라이브러리를 통해서 필터 효과 를 줄수 있습니다.
필터그래프는 여러개픨터가 연결되어 있는 형태를 필터 그래프라고 합니다.
ffmpeg 는 simple 와 complex 을 구분합니다.
Simple filtergraphs
Simple filtergraphs 는 정확히 input 과 output 이 1개만 존재합니다.
_________ ______________
| | | |
| decoded | | encoded data |
| frames |\ _ | packets |
|_________| \ /||______________|
\ __________ /
simple _\|| | / encoder
filtergraph | filtered |/
| frames |
|__________|Simple filtergraphs 의 사용 방법은 옵션으로 -filter 옵션을 주고 같이 쓰이는 옵션은 -vf 는 비디오 -af 는 오디오 필터를 의미합니다.
_______ _____________ _______ ________ | | | | | | | | | input | ---> | deinterlace | ---> | scale | ---> | output | |_______| |_____________| |_______| |________|
deinterlace 는 처음부터 홀수 짝수 가 아니라 위에서 1번 부터 순서대로 쭉~ 보여 주는 방식입니다.
출처 http://www.videoconverterfactory.com/tips/interlaced-video.html
몇몇 필터는 프레임 속성(fps,size)등만 조정하고 비디오 내용은 수정 하지 않는것들도 있습니다.
예를 들면 setpts 필터는 영상의 속도를 조정합니다.
ffmpeg -i input.mkv -filter:v "setpts=0.5*PTS" output.mkv
Complex filtergraphs
_________
| |
| input 0 |\ __________
|_________| \ | |
\ _________ /| output 0 |
\ | | / |__________|
_________ \| complex | /
| | | |/
| input 1 |---->| filter |\
|_________| | | \ __________
/| graph | \ | |
/ | | \| output 1 |
_________ / |_________| |__________|
| | /
| input 2 |/
|_________|예를 들면 Complex filtergraphs 는 overlay 필터(2개의 비디오 input -> 1개의 output 비디오) 오디오 경우 amix 필터 가 있습니다.
overlayer 예제
- Insert a transparent PNG logo in the bottom left corner of the input, using the
ffmpegtool with the-filter_complexoption:ffmpeg -i input -i logo -filter_complex 'overlay=10:main_h-overlay_h-10' output
- Insert 2 different transparent PNG logos (second logo on bottom right corner) using the
ffmpegtool:ffmpeg -i input -i logo1 -i logo2 -filter_complex 'overlay=x=10:y=H-h-10,overlay=x=W-w-10:y=H-h-10' output
참조 : https://ffmpeg.org/ffmpeg-filters.html#overlay-1
amix 예제
ffmpeg -i INPUT1 -i INPUT2 -i INPUT3 -filter_complex amix=inputs=3:duration=first:dropout_transition=3 OUTPUT
참조 : https://ffmpeg.org/ffmpeg-filters.html#amix
Stream copy
영상의 압축 형식을 바꿀때 사용할수 있습니다.
옵션으로는 -codec 을 사용합니다.
_______ ______________ ________ | | | | | | | input | demuxer | encoded data | muxer | output | | file | ---------> | packets | -------> | file | |_______| |______________| |________|