Created
March 11, 2023 14:48
-
-
Save azanium/1dadf32eaab70789b6f078a910d6bafc to your computer and use it in GitHub Desktop.
FFMPEG Explained
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ffmpeg -re \ | |
# -re (input) | |
# Read input at native frame rate. Mainly used to simulate a grab device, or live input stream (e.g. when reading from a file). Should not be used with actual grab devices or live input streams (where it can cause packet loss). By default ffmpeg attempts to read the input(s) as fast as possible. This option will slow down the reading of the input(s) to the native frame rate of the input(s). It is useful for real-time output (e.g. live streaming). | |
# (!) Turns out this will interrupt the stream by the audio input, making the output stream fps looks extremely low | |
-pix_fmt uyuv442 \ | |
-framerate 30 \ | |
-f avfoundation \ | |
# Pixel format & Framerate for FFMPEG-device: https://www.ffmpeg.org/ffmpeg-devices.html#avfoundation | |
-i "0" \ | |
# Use input "0" from avfoundation | |
-pix_fmt yuv420p \ | |
# Pixel format of the transcoded | |
-c:v libx264 \ | |
# Use x264 library for video codec | |
-profile:v high \ | |
-s 1280x720 \ | |
-tune zerolatency \ | |
-preset ultrafast \ | |
# Profile, Tune, Presets for H.264: https://trac.ffmpeg.org/wiki/Encode/H.264 | |
# Followings are all x264 encoding options | |
-bf 0 \ | |
# B-frames: https://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping | |
-refs 3 \ | |
# Reference frames: https://sites.google.com/site/linuxencoding/x264-ffmpeg-mapping | |
-b:v 2M \ | |
# -b bitrate, video bitrate: https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate | |
-bufsize 2M \ | |
# Buffer to maintain the bitrate: https://trac.ffmpeg.org/wiki/Limiting%20the%20output%20bitrate | |
-movflags frag_keyframe+empty_moov+default_base_moof+faststart \ | |
# MP4 Muxer options: https://ffmpeg.org/ffmpeg-formats.html#mov_002c-mp4_002c-ismv | |
-hls_segment_type fmp4 \ | |
-hls_time 1 \ | |
-hls_list_size 10 \ | |
-hls_flags delete_segments+append_list+split_by_time \ | |
# HLS Muxer options: https://ffmpeg.org/ffmpeg-formats.html#hls-2 | |
-f hls \ | |
# Enforce Output format as HLS: https://ffmpeg.org/ffmpeg.html#Main-options | |
hls.m3u8 | |
ffmpeg -pix_fmt uyvy422 -framerate 30 -f avfoundation -i "0:0" \ | |
> -pix_fmt yuv420p -c:v libx264 \ | |
> -c:a aac -b:a 128k -ar 44100 \ | |
> -tune zerolatency -profile:v high -s 1280x720 \ | |
> -preset ultrafast -bf 0 -refs 3 -g 30 -b:v 2M -bufsize 2M \ | |
> -movflags frag_keyframe+empty_moov+default_base_moof+faststart \ | |
> -vf "drawtext=fontfile='/../OpenSans-Bold.ttf':text='%{localtime}:box=1:fontcolor=black:boxcolor=white:fontsize=100':x=40:y=400'" \ | |
> -hls_segment_type fmp4 -hls_time 1 -hls_list_size 10 \ | |
> -hls_flags delete_segments+append_list+split_by_time \ | |
> -f hls master.m3u8 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment