When preparing static video resources for use with LiveKit, videos should be encoded into specific H.264 bitstream formats to ensure compatibility and performance. The following ffmpeg commands demonstrate how to encode a source video (e.g., butterfly.mp4) into various resolutions and bitrates, ranging from 1080p down to 180p.
Key encoding parameters used for these resources include:
-c:v libx264: Uses the H.264 codec.-bsf:v h264_mp4toannexb: Converts the bitstream to Annex B format.-profile baseline: Uses the baseline profile for maximum compatibility.-pix_fmt yuv420p: Sets the pixel format to YUV 420p.-x264-params keyint=120: Sets the GOP (Group of Pictures) size.-bf 0: Disables B-frames.
# 1080p @ 30fps, 3M bitrate
ffmpeg -i butterfly.mp4 \
-c:v libx264 -bsf:v h264_mp4toannexb \
-b:v 3M -vf "scale=1920:1080, fps=30" \
-profile baseline -pix_fmt yuv420p \
-x264-params keyint=120 -max_delay 0 -bf 0 \
butterfly_1080_3000.h264
# 720p @ 30fps, 2M bitrate
ffmpeg -i butterfly.mp4 \
-c:v libx264 -bsf:v h264_mp4toannexb \
-b:v 2M -vf "scale=1280:720, fps=30" \
-profile baseline -pix_fmt yuv420p \
-x264-params keyint=120 -max_delay 0 -bf 0 \
butterfly_720_2000.h264
# 540p @ 25fps, 800K bitrate
ffmpeg -i butterfly.mp4 \
-c:v libx264 -bsf:v h264_mp4toannexb \
-b:v 800K -vf "scale=960:540, fps=25" \
-profile baseline -pix_fmt yuv420p \
-x264-params keyint=120 -max_delay 0 -bf 0 \
butterfly_540_800.h264
# 360p @ 20fps, 400K bitrate
ffmpeg -i butterfly.mp4 \
-c:v libx264 -bsf:v h264_mp4toannexb \
-b:v 400K -vf "scale=640:360, fps=20" \
-profile baseline -pix_fmt yuv420p \
-x264-params keyint=120 -max_delay 0 -bf 0 \
butterfly_360_400.h264
# 180p @ 15fps, 150K bitrate
ffmpeg -i butterfly.mp4 \
-c:v libx264 -bsf:v h264_mp4toannexb \
-b:v 150K -vf "scale=320:180, fps=15" \
-profile baseline -pix_fmt yuv420p \
-x264-params keyint=120 -max_delay 0 -bf 0 \
butterfly_180_150.h264