"Fast Forward (영상 표준화 그룹)MPEG"
 - 응용프로그래밍 개발과정에서 '멀티 미디어'를 다룰일이 있을때~
 - 어설프게 어줍잖은 각종 lib 쓰다... 좌절하고, 걍! ffmpeg-binary를 직접 subprocess화 해보니 좋았다.

  • ffmpeg : command line tool to convert multimedia files between formats.
    • 1) 실행 로그레벨 옵션
      • 'ffmpeg -loglevel repeat+level+info ... '
      • repeat : repeated log output should not be compressed to the first line...
      • level : log output should add a [level] prefix to each message line...
      • +(quiet, panic, fatal, error, warning, info, verbose, debug, trace)
    • 2) 사진or동영상 -> 특정 해상도 영상으로 리사이징
      • ffmpeg -f lavfi -t 2 -i "anullsrc=r=44100:cl=stereo" -t 2 -i "인트로.mp4" -vf "scale=852:480:force_original_aspect_ratio=decrease,pad=852:480:(ow-iw)/2:(oh-ih)/2,setsar=1" "인트로2.mp4"
      • ffmpeg -f lavfi -t 1 -i "anullsrc=r=44100:cl=stereo" -loop 1 -t 3 -i "사진.jpg" -vf "scale=852:480:force_original_aspect_ratio=decrease,pad=852:480:(ow-iw)/2:(oh-ih)/2,setsar=1" "아웃풋.mp4"
      • ffmpeg -f lavfi -t 1 -i "anullsrc=r=44100:cl=stereo" -i "소리없는동영상.mp4" -vf "scale=852:480:force_original_aspect_ratio=decrease,pad=852:480:(ow-iw)/2:(oh-ih)/2,setsar=1" -t 60 "아웃풋.mp4"
      • ffmpeg -i "동영상.mp4" -vf "scale=852:480:force_original_aspect_ratio=decrease,pad=852:480:(ow-iw)/2:(oh-ih)/2,setsar=1" -t 60 "아웃풋.mp4"
      • -f : Force input or output file format.
      • lavfi : Libavfilter input virtual device. This input device reads data from the open output pads of a libavfilter filtergraph.
      • force_original_aspect_ratio : 
        • disable : Scale the video as specified and disable this feature.
        • decrease : The output video dimensions will automatically be decreased if needed.
        • increase : The output video dimensions will automatically be increased if needed.
      • pad : 꺄옦!!! '이미지 crop' 의 반대말이 뭘까? 한참 고민 삽질하다... 이땐, 'pad'라를 단어를 쓴다!!!
      • setdar , setsar :
        • DAR : Display Aspect Ratio.
        • SAR : Sample(aka Pixel) Aspect Ratio.
        • (DAR = HORIZONTAL_RESOLUTION / VERTICAL_RESOLUTION * SAR)
        • (setdar 혹은 setsar 을 미리 일괄화 해두는것이, 나중에 다양한 재사용 과정에서~ 좋을것? 같아 보여썼다...)
    • 3) 영상 합치기
      • ffmpeg -i "영상1.mp4" -vsync 2 -i "영상2.mp4" -vsync 2 -i "영상3.mp4" -vsync 2  -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]" "아웃풋.mp4
      • -vsync : Video sync method.
        • 0, passthrough : Each frame is passed with its timestamp from the demuxer to the muxer.
        • 1, cfr : Frames will be duplicated and dropped to achieve exactly the requested constant frame rate.
        • 2, vfr : Frames are passed through with their timestamp or dropped so as to prevent 2 frames from having the same timestamp.
        • drop : As passthrough but destroys all timestamps, making the muxer generate fresh timestamps based on frame-rate.
        • -1, auto : Chooses between 1 and 2 depending on muxer capabilities. This is the default method.
      • -filter_complex : 컴플랙스 필터링에는 아주 많은 기능이 있다... 자세한 설명은 생략한다.
    • 4) 자막 "특정 폰트"로!!! 합성
      • ffmpeg -i "동영상.mp4" -vf " subtitles='자막.srt':fontsdir='폰트경로':force_style='FontName='폰트명',Fontsize=32,BorderStyle=1,Outline=2,Shadow=2,MarginV=185' " "아웃풋.mp4"
      • "자막.srt" 및 "폰트.ttf" 파일을 준비해서 사용하면 된다.
      • 원래 폰트는... 해당 OS 차원의 '디폴트 폰트 디렉토리'에서 찾게 되는것 인데~
      • 이런식으로, 원하는 "폰트.ttf"를 특정위치에 복사해서... 해당 폰트명(ttf 파일에 명시되있음)를 지정하면 된다.
    • 4) (자막 심화)
    • 5) BGM 깔기 (오디오 노멀라이즈)
      • ffmpeg -i "동영상.mp4" -i "브금.mp3" -filter_complex "[1]volume=0.05[a1];[0][a1]amix=inputs=2:duration=first,loudnorm=I=-24:LRA=7:TP=-2" "아웃풋.mp4"
      • -filter_complex 값형식
        • 뭔가... 희한한 구조다. input에 변화를 주고 ; 으로 끝맺은뒤, 그걸 뒤에서 명시하는가 하면~
        • 특정 같은성격? 옵션값은 : 으로 구분하고... 또다른 성격? 옵션값은 , 으로 구분하는거 같다...
      • volume : -10dB or 0.01 이런식으로 조절 가능.
      •  amix:duration
        • longest : The duration of the longest input. (default)
        • shortest : The duration of the shortest input.
        • first : The duration of the first input.
      • amix:dropout_transition : The transition time, in seconds, for volume renormalization when an input stream ends. The default value is 2 seconds.
      • amix:weights : Specify weight of each input audio stream as sequence. Each weight is separated by space. By default all inputs have same weight.
      • 오디오 노멀라이즈 이슈
        • 음... 그냥 오디오 믹싱을 하면, 먼가 전체적으로 음량이 자동튜닝? 되는 현상으로 골치 아팟다... 
        • https://superuser.com/questions/323119/how-can-i-normalize-audio-using-ffmpeg/323127
        • loudnorm
          • normalization according to EBU R128. You can set an integrated loudness target, a loudness range target, or maximum true peak.
          • This is recommended for publishing audio and video and it is used by broadcasters all over the world.
        • dynaudnorm
          • "intelligent" loudness normalization without clipping, which applies normalization dynamically over windowed portions of the file.
          • This may change the characteristics of the sound, so it should be applied with caution.
      • loudnorm:I : Set integrated loudness target. Range is -70.0 - -5.0. Default value is -24.0.
      • loudnorm:LRA : Set loudness range target. Range is 1.0 - 20.0. Default value is 7.0.
      • loudnorm:TP : Set maximum true peak. Range is -9.0 - +0.0. Default value is -2.0.
      • ...
    • 6) 특정지점에 싸운드 믹싱
      • ffmpeg -i "동영상.mp4" -i "소리1.mp3" -i "소리2.mp3"  -filter_complex "[1]adelay=밀리초|밀리초,volume=-1dB[a1];[2]adelay=밀리초|밀리초,volume=-1dB[a2];[0][a1][a2]amix=inputs=3" "아웃풋.mp4"
      • adelay : 특정 milli-second 지점으로 사운드를 지정할수있다.
    • 7) 워터마크(watermark) 찍기
      • ffmpeg -i "동영상.mp4" -i "워터마크.png" -filter_complex "overlay=100:100" -codec:a copy "아웃풋.mp4"
      • 가로세로 (100,100) 픽셀위치에, 워터마크를 표시할수있다.
    • 8) 썸네일용 스크린샷 추출하기
      • ffmpeg -t 00:00:초 -ss 00:00:초 -i "동영상.mp4" -s 200x100 -vcodec mjpeg -vframes 1 "썸네일.png"
      • 해당 지점의 화면을 추출할수있다.
      • (ffmpeg -i test.mp4 -vcodec png -vframes 1 -vf thumbnail=10 test.png)
  •  기본옵션정리
    • ...
  • ffprobe : simple multimedia stream analyzer.
    • 1) 멀티미디어 길이 측정
      • ffprobe -i "mp3혹은mp4" -show_entries format=duration -v quiet -of csv="p=0"
      • 원하는 정보만, json 또는 csv 등등의 형식으로 뽑을수있다.
      • (ffprobe -select_streams v:0 -show_entries stream_tags=rotate -of json test.mp4)
      • (ffprobe -select_streams v:0 -show_entries side_data=rotation -of json test.mp4)

-끝-

'멀티미디어' 카테고리의 다른 글

ffmpeg2  (0) 2023.06.27
Text, Image, Audio, Video, ...  (1) 2021.07.21
だめだね だめよ だめなのよ 딥페이크  (0) 2021.03.27
3D 아바타 blendshape coefficient 데이터  (0) 2021.03.27
ffmpeg1  (0) 2020.11.23

+ Recent posts