ffmpeg 사용해서 mp4, aac 등 합치기

|

## mp3 파일 시간 cut

 

ffmpeg -ss 0 -t 180 -i aa.mp3 -acodec copy bbb.mp3
ffmpeg -ss start_sec -t duration_sec -i input_file -acode copy output_file

 

 

E:\Program\windows_client\ffmpeg.exe -i "movie.mp4" -i "sound.aac" -c:v copy -c:a copy output.mp4

 

crop

ffmpeg -i input.mp4 -filter:v "crop=w:h:x:y" -c:a copy output.mp4
  • -i
    • input.mp4 specifies the input video (input.mp4 being the input / original video in this case)
  • -filter:v (can be abbreviated to -vf)
    • specifies we're using a video filter
  • "crop=W:H:X:Y" 
    • means we're using the "crop" video filter, with 4 values:
      • w the width of the output video (so the width of the cropped region), which defaults to the input video width (input video width = iw, which is the same as in_w); out_w may also be used instead of w
      • h the height of the output video (the height of the cropped region), which defaults to the input video height (input video height = ih, with in_h being another notation for the same thing); out_h may also be used instead of h
      • x the horizontal position from where to begin cropping, starting from the left (with the absolute left margin being 0)
      • y the vertical position from where to begin cropping, starting from the top of the video (the absolute top being 0)
  • output.mp4 
    • is the new, cropped video file

A few notes:
The filter will automatically center the crop if x and y are omitted, so x defaults to (iw-w)/2, and y to (ih-h)/2

  • There is also an optional keep_aspect option that you can set to 1 to force the output display aspect ratio to be the same of the input (example usage: "crop=100:100:0:0:keep_aspect=1"). This won't work with images, that's why you don't see a separate example with screenshot here
  • FFmpeg gets the original input video width (iw) and height (ih) values automatically, so you can perform mathematical operations using those values (e.g. iw/2 for half the input video width, or ih-100 to subtract 100 pixels from the input video height).

 

--------------------------------------------------

Merging audio and video using ffmpeg

  • Open a Command Prompt window in your downloads folder and run the following command
      • In case of MP4 format (all, except 1440p 60fps & 2160p 60fps):
    ffmpeg -i videoplayback.mp4 -i videoplayback.m4a -c:v copy -c:a copy output.mp4
      • In case of WebM format (1440p 60fps and 2160p 60fps):
    ffmpeg -i videoplayback.webm -i videoplayback.m4a -c:v copy -c:a copy output.mkv
  • Wait until ffmpeg finishes merging audio and video into a single file named "output.mp4".

How do I convert WebM video to the MP4

For some qualities Youtube provides videos only in WebM format. WebM could be converted in MP4 with the following ffmpeg command

ffmpeg -i video.webm -i audio.m4a -c:v libx264 -c:a copy out.mp4
 

-----------------------------------------

Copying the audio without re-encoding

If your output container can handle (almost) any codec – like MKV – then you can simply copy both audio and video streams:

ffmpeg -i video.mp4 -i audio.wav -c copy output.mkv 
 
-------------------------------------------------

How to combine WebM and Opus to generate MP4?

ffmpeg -i video.webm -i audio.opus -c:v copy -c:a aac -strict experimental output.mp4 

it should look something like this.

ffmpeg -i audio.opus -i vid.webm  -c:v copy -c:a opus -strict experimental output6.webm 

-----------------------------------------------------------------

 

[동영상을 애니메이션gif로 변환]

-ffmpeg -t <길이 초> -ss <시작지점-00:00:10> -i <원본동영상> -pix_fmt rgb24 <저장할파일>

--> 예> ffmpeg -t 5 -ss 00:00:10 -i sample.avi -pix_fmt rgb24 sample.gif

------> sample.avi에서 10초 지점부터 5초간을 sample.gif로 저장.

 

[동영상을 이미지(jpg)로 연속캡쳐]

ffmpeg -ss 00:00:01 -t 00:00:02 -i fgong.avi fgong_%3d.jpg

--> fgong.avi의 1초 지점부터 2초간 캡처해서 fgong_1, fgong_2 형식으로 저장함.

 

[연속된 이미지를 동영상으로]

ffmpeg -f image2 -i %04d.jpg -vcodec libx264 movie.mp4

 

0000.jpg, 0001.jpg 이런 식으로 네 자리 연속된 숫자의 파일들을 movie.mp4 로 만듭니다.

 

-f : 입력 파일의 포맷을 의미하며 image2 는 jpg 파일을 의미합니다.

-i : 입력 파일

 

-vcodec : 출력 파일의 압축 코덱을 의미하며 H264가 대게 가장 무난하게 좋습니다.

 

[mp4 -> avi]

ffmpeg -i xx.mp4 -acodec copy -vcodec copy xx.avi

 

[mp4 -> flv]

ffmpeg -i xxx.mp4 -c copy xxx.flv

 

[동영상 크롭(Crop)]

ffmpeg -i 원본영상.mp4 -filter:v "crop=영상가로:영상세로:X:Y" 결과물.mp4
(원본영상.mp4 를 X,Y 지점부투 영상가로x영상세로 영역만큼만 뽑아냄)

 

[두개의 영상을 한화면에 나란히(Side by Side)]

ffmpeg -i 영상1.mp4 -vf "[in] pad=2*iw:ih [left]; movie=영상2.mp4 [right]; [left][right] overlay=main_w/2:0 [out]" 결과물.mp4

(화면크기가 같은 2개의 동영상 영상1.mp4, 영상2.mp4 를 나란히 좌우로 붙여 결과물.mp4로)

 

[동영상 일정구간 자르기]

ffmpeg -i 동영상.avi -ss 600 -t 120 결과물.avi

(동영상.avi 의 600초 지점부터 120초간 자르고 결과물.avi로 저장)

 

[동영상 프레임 늘리기(슬로우/패스트 비디오 만들기)]

ffmpeg -i ~baekrokdam.mov -vf "setpts=(1/4)*PTS" -an baekrokdam4x.mov

setpts=(1/4)*PTS의 1/4를 원하는 배속으로 수정.

오디오는 재생 속도가 변경되지 않으므로 -an 옵션으로 오디오 제거.

 

[화면회전]

ffmpeg -i in.mov -vf "transpose=1" out.mov

0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip

 

[자막파일 smi -> srt 변환]

ffmpeg -i 자막파일.smi 자막파일.srt

============================================================

메인옵션

-L : 라이센스 표시

-h : 헬프표시

-formats : 현재 사용할 수 있는 포맷, 코덱, 프로토콜을 표시

-f fmt : 포맷을 지정 (fmt의 부분에 -formats 그리고 조사한 포맷명이 들어간다)

-img img_fmt : 화상의 포맷을 지정 (img_fmt의 부분에 -formats 그리고 조사한 포맷명이 들어간다)

-i filename : 입력파일명

-y : 동일 파일 존재시 덮어쓰기

-t duration : 완성되는 파일의 시간을 지정한다 (duration의 부분에 0을 넣으면 10초 부분까지 기록)

-ss : 변환시작할 시간

 

영상옵션

-s : 사이즈 (가로x세로)

-sameq : 원본과 동일화질

-qscale : 0 ~ 255 (낮을수록 고화질)

-r : frame rate (Hz value, fraction or abbreviation)

-aspect : 비율 (4:3, 16:9 or 1.3333, 1.7777)

-b : bitrate (ex 512k)

 

'개발/활용정보 > Windows' 카테고리의 다른 글

내 pc 안에 namesapce 폴더 삭제  (0) 2020.09.02
windows 10 시작프로그램  (0) 2018.10.24
Windows 7 command  (0) 2017.11.09
SSLv3, TLSv1  (0) 2017.09.25
windows 10 에서 wmencoder64 설치  (0) 2017.01.01
And