ffmpeg Tutorial

本文最后更新于:2024年8月9日 晚上

What is ffmpeg and basic usage

https://www.ruanyifeng.com/blog/2020/01/ffmpeg.html

How to install

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# macOS
brew install ffmpeg
# centos
sudo yum install epel-release -y
sudo yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
sudo yum install ffmpeg ffmpeg-devel -y
ffmpeg -version
# source code
# https://ffmpeg.org/download.html#releases
# https://gist.githubusercontent.com/hyer/5a63543966dd2642989a/raw/8fc5b0993b4d0dcbf60cb48e1d0a098b38822669/install-ffmpeg.sh
wget https://ffmpeg.org/releases/ffmpeg-5.1.2.tar.xz && tar -xvf ffmpeg-5.1.2.tar.xz && cd ffmpeg-5.1.2
./configure --prefix=/usr/local/ffmpeg && make && make install
echo "export PATH=/usr/local/ffmpeg/bin:$PATH" >> ~/.bashrc
echo "export LD_LIBRARY_PATH=/usr/local/ffmpeg/lib:$LD_LIBRARY_PATH" >> ~/.bashrc && source ~/.bashrc
ffmpeg -version

How to use ffmpeg to make live Broadcast

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#/!bin/bash
# author=Jas0n0ss
# date=2023-01-17
#
# define color
red='\033[0;31m'
green='\033[0;32m'
yellow='\033[0;33m'
font="\033[0m"
##

##
ffmpeg_install() {
echo "ffmpeg checking" | lolcat
ffmpeg -version | lolcat
if [ $? == 0 ]; then
echo -e "${yellow}ffmpeg$font ${green}Installed$font"
else
echo "wegt installing..." | lolcat
yum -y install wget
echo "ffmpeg installing" | lolcat
wget --no-check-certificate https://ffmpeg.org/releases/ffmpeg-5.1.2.tar.xz
tar -xJf ffmpeg-5.1.2.tar.xz && cd ffmpeg-5.1.2
./configure --prefix=/usr/local/ffmpeg && make && make install
echo "export PATH=/usr/local/ffmpeg/bin:$PATH"
echo "export LD_LIBRARY_PATH=/usr/local/ffmpeg/lib:$LD_LIBRARY_PATH"
fi
}

live_start() {
echo "rtmp URL please:" | lolcat
echo -e "$red Leave it blank will lead to default URL $font"
read -r rtmp
url=${rtmp:-"rtmp://live-push.bilivideo.com/live-bvc/?streamname=live_431290720_11083557&key=2c62b2a3a826c488d49663d6d1e1e3db&schedule=rtmp&pflag=1"}
echo -e "$green The rtmp URL is: $font"
echo $rmtp | lolcat
echo "########################" | lolcat
echo "The video path you want to do cycle live:" | lolcat
echo -e "$red Leave it blank will load current path by default !!$font"
read -r v_path
V_PATH=${v_path:-"."}
echo -e "$green video PATH is: $V_PATH $font"
echo "########################" lolcat
echo "Need logo right corner of your screen live(May need better CPU to supprt)?(yes/no):" | lolcat
echo -e "$red Leave it blank will not have logo by default !!$font"
read -r YN
mark=${YN:-"no"}
if [ $mark = "yes" ]; then
echo "The logo file path (v.jpg/v.png/v.bmp):" | lolcat
read -r image
while true; do
for video in $(find $V_PATH -type f -name "*.mp4" | shuf -n1); do
ffmpeg -re -i "$video" -i "$image" -filter_complex overlay=W-w-5:5 -c:v libx264 -c:a aac -b:a 192k -strict -2 -f flv $rtmp
done
done
else
echo "Starting live with no logo..." | lolcat
while true; do
for video in $(find $V_PATH -type f -name "*.mp4" | shuf -n1); do
ffmpeg -re -i "$video" -c:v copy -c:a aac -b:a 192k -strict -2 -f flv $rtmp
done
done
fi
}

live_stop() {
screen -S live -X quit
killall ffmpeg
}

start() {
echo -e "$red Please enter$font $green ffmpeg|start|stop$font"
read -r $1
if [ $1 == "start" ]; then
live_start
elif [ $1 == "stop" ];then
live_stop
elif [ $1 == "ffmpeg"];then
ffmpeg_install
else
exit 0
fi
}
#
echo "Please make sure you have lolcat installed !!!" | lolcat
start

ffmpeg Tutorial
https://git.msft.vip/2023/01/13-ffmpeg-Tutorial/
作者
Jas0n0ss
发布于
2023年1月13日
更新于
2024年8月9日
许可协议