TIL: ffmpeg으로 비디오 채널 분리하기

며칠 전에 고속도로 정체로 서 있다가 뒷차가 추돌하는 일을 당했다. 보험금 청구(?)를 위해서 대시캠 영상을 달라고 해서 그 영상을 가져와보니, 3개 채널로 된 미디어 파일이더라. mediainfo 로 열어보면 아래와 같다.

General
Complete name                            : SomeFileName.avi
Format                                   : AVI
Format/Info                              : Audio Video Interleave
File size                                : 49.2 MiB
Duration                                 : 20 s 301 ms
Overall bit rate                         : 20.3 Mb/s

Video #1
ID                                       : 0
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : [email protected]
Format settings                          : CABAC / 1 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 1 frame
Format settings, GOP                     : M=1, N=30
Codec ID                                 : H264
Duration                                 : 20 s 66 ms
Bit rate                                 : 10.1 Mb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Original height                          : 1 088 pixels
Display aspect ratio                     : 16:9
Frame rate                               : 30.051 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.161
Stream size                              : 24.0 MiB (49%)

Video #2
ID                                       : 1
Format                                   : AVC
Format/Info                              : Advanced Video Codec
Format profile                           : [email protected]
Format settings                          : CABAC / 1 Ref Frames
Format settings, CABAC                   : Yes
Format settings, Reference frames        : 1 frame
Format settings, GOP                     : M=1, N=30
Codec ID                                 : H264
Duration                                 : 20 s 301 ms
Bit rate                                 : 8 052 kb/s
Width                                    : 1 920 pixels
Height                                   : 1 080 pixels
Original height                          : 1 088 pixels
Display aspect ratio                     : 16:9
Frame rate                               : 30.048 FPS
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Scan type                                : Progressive
Bits/(Pixel*Frame)                       : 0.129
Stream size                              : 19.5 MiB (40%)

Audio
ID                                       : 2
Format                                   : PCM
Format settings                          : Little / Signed
Codec ID                                 : 1
Duration                                 : 20 s 0 ms
Bit rate mode                            : Constant
Bit rate                                 : 384 kb/s
Channel(s)                               : 1 channel
Sampling rate                            : 24.0 kHz
Bit depth                                : 16 bits
Stream size                              : 938 KiB (2%)
Alignment                                : Aligned on interleaves
Interleave, duration                     : 50  ms (1.51 video frames)

후면 카메라 영상 어떻게 저장하나 했는데 별도 채널로 집어넣는거였다. 손해보험사 웹 페이지에 업로드해달라는데 크기 제한이 있어서 이걸 앞/뒤로 쪼개고, 음성을 뺐다. 이걸 아래 명령으로 처리했다.

# 전면 카메라; 채널 0
ffmpeg  -i ./SomeFileName.avi -c:v copy -map 0:v:0 dashcam-front.mp4

# 후면 카메라; 채널 1
ffmpeg  -i ./SomeFileName.avi -c:v copy -map 0:v:1 dashcam-rear.mp4

Video transcoding 없이 복사 (-c:v copy)하는 거라서 거의 시간이 걸리지 않더라.