동영상편집/변환툴

FFMPEG로 동영상 회전 저장하기

RioRex 2020. 5. 9.

폰으로 영상을 찍다보면 뒤집히거나 90도 틀어진 영상들이 있다.

이건 뭐 ... 화면을 돌리면 계속 이상하게 보인다.

아이폰이나, 안드로이드 기기 내에서 변환하는 방법도 있지만,

난 이미 영상을 내려 받아 컴퓨터에 저장한 상태이므로 컴퓨터에서 변환하는 방법을 적어본다.

 

 

FFMPEG는 종합선물 세트

FFMPEG 명령어에 옵션을 줘서 동영상을 회전시킬 수 있다.

 

 

기본 명령어

C:\> ffmpeg -i [영상소스파일명] -vf "transpose=[회전모드]" [저장할 영상 파일명]

 

회전모드

0 = 반 시계방향 90도 회전, 상하 반전(기본 값)

1 =     시계방향 90도 회전

2 = 반 시계방향 90도 회전

3 =     시계방향 90도 회전, 상하 반전

 

예시 (IMG_20200425_135450.MOV 파일을 시계방향 90도 회전 후 MP4 파일로 변환하여 저장함)

> ffmpeg -i IMG_20200425_135450.MOV -vf "transpose=1" IMG_20200425_135450_FIX.MP4

더보기
D:\CoCo_YOU\2020.04.25 AQUARIUM LOTTE\footage\iPhone7_CutDone>c:

C:\Users\Creban>cd D:\CoCo_YOU\2020.04.25 AQUARIUM LOTTE\footage\iPhone7_CutDone

C:\Users\Creban>d:

D:\CoCo_YOU\2020.04.25 AQUARIUM LOTTE\footage\iPhone7_CutDone>ffmpeg -i IMG_20200425_135450.MOV -vf "transpose=1" IMG_20200425_135450_FIX.MP4
ffmpeg version git-2020-04-26-1128aa8 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9.3.1 (GCC) 20200328
  configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libsrt --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --disable-w32threads --enable-libmfx --enable-ffnvcodec --enable-cuda-llvm --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt --enable-amf
  libavutil      56. 43.100 / 56. 43.100
  libavcodec     58. 82.100 / 58. 82.100
  libavformat    58. 42.101 / 58. 42.101
  libavdevice    58.  9.103 / 58.  9.103
  libavfilter     7. 79.100 /  7. 79.100
  libswscale      5.  6.101 /  5.  6.101
  libswresample   3.  6.100 /  3.  6.100
  libpostproc    55.  6.100 / 55.  6.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'IMG_20200425_135450.MOV':
  Metadata:
    major_brand     : qt
    minor_version   : 0
    compatible_brands: qt
    creation_time   : 2020-04-25T04:54:50.000000Z
    com.apple.quicktime.location.ISO6709: +37.5117+127.1014+021.800/
    com.apple.quicktime.make: Apple
    com.apple.quicktime.model: iPhone 7
    com.apple.quicktime.software: 13.4.1
    com.apple.quicktime.creationdate: 2020-04-25T13:54:50+0900
  Duration: 00:00:24.63, start: 0.000000, bitrate: 15533 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080, 15407 kb/s, 29.97 fps, 29.97 tbr, 600 tbn, 1200 tbc (default)
    Metadata:
      rotate          : 90
      creation_time   : 2020-04-25T04:54:50.000000Z
      handler_name    : Core Media Video
      encoder         : H.264
    Side data:
      displaymatrix: rotation of -90.00 degrees
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 95 kb/s (default)
    Metadata:
      creation_time   : 2020-04-25T04:54:50.000000Z
      handler_name    : Core Media Audio
    Stream #0:2(und): Data: none (mebx / 0x7862656D), 18 kb/s (default)
    Metadata:
      creation_time   : 2020-04-25T04:54:50.000000Z
      handler_name    : Core Media Metadata
    Stream #0:3(und): Data: none (mebx / 0x7862656D), 0 kb/s (default)
    Metadata:
      creation_time   : 2020-04-25T04:54:50.000000Z
      handler_name    : Core Media Metadata
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
[libx264 @ 000002c944886700] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 000002c944886700] profile High, level 4.0, 4:2:0, 8-bit
[libx264 @ 000002c944886700] 264 - core 159 - H.264/MPEG-4 AVC codec - Copyleft 2003-2019 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'IMG_20200425_135450_FIX.MP4':
  Metadata:
    major_brand     : qt
    minor_version   : 0
    compatible_brands: qt
    com.apple.quicktime.creationdate: 2020-04-25T13:54:50+0900
    com.apple.quicktime.location.ISO6709: +37.5117+127.1014+021.800/
    com.apple.quicktime.make: Apple
    com.apple.quicktime.model: iPhone 7
    com.apple.quicktime.software: 13.4.1
    encoder         : Lavf58.42.101
    Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1920x1080, q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc (default)
    Metadata:
      encoder         : Lavc58.82.100 libx264
      creation_time   : 2020-04-25T04:54:50.000000Z
      handler_name    : Core Media Video
    Side data:
      cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: N/A
      displaymatrix: rotation of -0.00 degrees
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 69 kb/s (default)
    Metadata:
      creation_time   : 2020-04-25T04:54:50.000000Z
      handler_name    : Core Media Audio
      encoder         : Lavc58.82.100 aac
frame=  738 fps= 18 q=-1.0 Lsize=   28930kB time=00:00:24.63 bitrate=9619.7kbits/s speed=0.603x
video:28680kB audio:223kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.093443%
[libx264 @ 000002c944886700] frame I:22    Avg QP:24.45  size: 63790
[libx264 @ 000002c944886700] frame P:242   Avg QP:27.15  size: 49666
[libx264 @ 000002c944886700] frame B:474   Avg QP:27.99  size: 33640
[libx264 @ 000002c944886700] consecutive B-frames:  9.9%  9.8% 11.0% 69.4%
[libx264 @ 000002c944886700] mb I  I16..4: 11.9% 75.7% 12.4%
[libx264 @ 000002c944886700] mb P  I16..4: 11.9% 49.3%  6.1%  P16..4: 21.9%  7.0%  1.7%  0.0%  0.0%    skip: 2.1%
[libx264 @ 000002c944886700] mb B  I16..4:  3.9% 12.9%  1.7%  B16..8: 35.4% 12.2%  1.8%  direct: 8.3%  skip:23.7%  L0:50.4% L1:43.2% BI: 6.4%
[libx264 @ 000002c944886700] 8x8 transform intra:72.3% inter:82.0%
[libx264 @ 000002c944886700] coded y,uvDC,uvAC intra: 56.1% 53.7% 6.2% inter: 30.5% 32.6% 0.3%
[libx264 @ 000002c944886700] i16 v,h,dc,p: 13% 48%  3% 36%
[libx264 @ 000002c944886700] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 18% 35% 11%  4%  6%  7%  9%  5%  5%
[libx264 @ 000002c944886700] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 16% 48%  8%  3%  5%  5% 10%  3%  3%
[libx264 @ 000002c944886700] i8c dc,h,v,p: 53% 26% 17%  4%
[libx264 @ 000002c944886700] Weighted P-Frames: Y:2.9% UV:2.5%
[libx264 @ 000002c944886700] ref P L0: 59.4% 11.6% 19.8%  8.7%  0.4%
[libx264 @ 000002c944886700] ref B L0: 86.5% 10.5%  3.0%
[libx264 @ 000002c944886700] ref B L1: 95.3%  4.7%
[libx264 @ 000002c944886700] kb/s:9541.00
[aac @ 000002c944873280] Qavg: 386.470

D:\CoCo_YOU\2020.04.25 AQUARIUM LOTTE\footage\iPhone7_CutDone>

 

1. cmd 실행

 

 

2. 회전이 필요한 영상 확인

뱅뱅TV, 지윤이와 지민이 아쿠아리움 가다, 시계방향 90도 회전해야겠다.

3. ffmpeg 실행하여 변환 진행

ffmpeg -vf "transpose=" 명령어

4. 변환한 파일 실행 하여 확인

완료 하였습니다.

 

----

이상입니다.

FFMPEG는 동영상 관련 거의 모든 것을 처리할 수 있는 최고의 프로그램입니다. FFMPEG 를 실제 사용하는 방법은 지속적으로 올리도록 하겠습니다.

 

감사합니다.

 

 


이상입니다.

퍼가기 하실때는 출처 꼭 같이 남겨주시면 감사하겠습니다.


출처: 코카티비, http://cocatv.tistory.com/261

반응형

댓글