본문 바로가기
Programming/Computer Vision

FFMPEG로 다양한 input-output 소스 스트리밍하기 (option 설명 포함)

by a voyager 2021. 10. 23.
728x90
반응형

 

FFMPEG은 영상을 인코딩/디코딩하는데 사용되는 프로그램이다. 영상처리의 특성상 설정할 수 있는 변수들이 수도 없이 많다. 그중에 몇가지 live streaming 관련해서 유용하게 쓸 수 있는 명령어를 정리해 보았다. 관련 옵션도 함께 정리하였으며, 이렇게 해 두면 다음에 다시 찾기도 편할 것으로 생각된다. 

 

Case 1: MP4 ---> MP4 

ffmpeg -re -i myvideo.mp4 -codec copy -f mp4 output.mp4

설명: myvideo.mp4를 (-re)로 고유의 프레임 속도로 읽어서 (-f) mp4 포맷으로 출력한다. 

 

 

Case 2: rtsp live stream ---> MP4

ffmpeg -rtsp_transport tcp -i rtsp source -r 10 -t 60 \
-vcodec copy -acodec copy -y output.mp4

 

-rtsp_transport tcp: force FFmpeg to use TCP protocol when reading a RTSP stream 

 

설명: rtsp live streaming을 tcp protocol로 읽으면서, fps=10 (-r 10) 60초 동안 (-t 60) 비디오와 오디오를 포함해 (-vcodec copy -acodec) mp4 포맷으로 출력한다. 이때 같은 이름의 파일이 있으면 덮어쓴다 (-y 옵션). 

 

 

Case 3: rtsp live stream ---> rtmp (로컬 웹서버)

ffmpeg -rtsp_transport tcp -i rtsp source -f flv -r 25 -s 1920x1080 -an rtmp-url

설명: rtsp live streaming을 rtmp-url (로컬 웹서버)로 streaming 한다. 

이때, 출력 형태는 flash video (-f flv), fps=25 (-r 25), 그리고 출력 화질은 1920x1080으로 한다.  

 

 

Case 4: MP4 ---> rtmp 

ffmpeg -re -i path-to-myvideo.mp4 \
-f flv -s 1920x1080 -an \
-flvflags no_duration_filesize  \
rtmp_url

설명: 내 컴퓨터에 있는 mp4 파일을 rtmp 로컬 웹서버로 streaming 한다. 

 

-flvflags no_duration_filesize (added to handle the following errors during encoding) 

Failed to update header with correct duration

[flv @ 0x14201a800] Failed to update header with correct duration.e= 395.1 kbits/s speed=0.988x       

[flv @ 0x14201a800] Failed to update header with correct filesize.

 

At the end of muxing a flv file, FFmpeg updates the header (at front of file) with duration and file size values. However, when you are streaming, ffmpeg can't seek to the front, so the warnings are displayed. 

 

 

Case 5: image ---> rtmp

ffmpeg -loop 1 -i path-to-my-image.png -f flv rtmp_url

 설명: 한 이미지를 무한 loop으로(-loop 1) 지정한 rtmp 로컬 웹서버로 스트리밍 한다. 

 

ffmpeg -loop 1 -i -re -t 120 path-to-my-image.png -f flv rtmp_url

설명: 한 이미지를 120초 동안 지정한 rtmp 웹서버로 스트리밍한다. 

 

 

사용된 FFMPEG 옵션 정리  

-i : input source (as url, including file path on your machine) 

-y: overwrite output file without asking 

-loop 1: endless loop in streaming at rtmp 

-t 120:  limit the duration of data read from input (120 sec for instance) 

-re: read input at native frame rate 

-s: target resolution for streaming 

-f: force input or output file format (ex. flv for flash video) 

-an: one of options for stream selection (-an: inclusion of audio)  

-r: force a frame rate of input or output file 

-vcodec:  set the video codec (alias for -codec:v)

-acodec: set the audio codec (alias for -codec:a) 

 

 

참고한 링크 

 

728x90
반응형

댓글