vim:
打开需要修改的文件
进入命令模式,输入 :%s/要替换的内容/替换后的内容/g,其中 % 表示对整个文件进行替换,g 表示全局替换。
按下回车键,Vim 会自动替换所有匹配的内容。
你也可以使用正则表达式进行更加灵活的替换操作。例如,如果你想将文件中所有的空格替换为下划线,可以使用以下命令:
:%s/\s/_/g
其中 \s 表示匹配空格,下划线是替换后的内容。
:%s:/old_word/:new_word/ 替换每一行第一个值
:%s:/old_word/:new_word/g 替换全文所有的值
计算文件夹个数
ls -l | grep "^-" | wc -l
windows:
2
方法一:
1.download sourcecode
Windows平台下可以通过命令下载ffmpeg;可以使用MSYS2/MSYS2 MINGW64来下载
如:pacman -S mingw-w64-x86_64-ffmpeg
如需下载libx264/libx265/libfdk-aac则需要下载相应的路,如下:
pacman -S mingw-w64-x86_64-fdk-aac //下载
pacman -S mingw-w64-x86_64-x264
pacman -S mingw-w64-x86_64-x265
ffmpeg.exe -version
2.windows builds by BtbN工具包下载
ffmpeg-master-latest-win64-gpl-shared.zip
ffmpeg-master-latest-win64-gpl.zip
解压执行在cmd终端或者MSYS2运行bin文件下载的ffmpeg.exe -version
方法二:
https://www.gyan.dev/ffmpeg/builds/#release-builds
点击下载ffmpeg-release-essentials.zip
解压添加环境变量
linux:
./configure --enable-gpl --enable-version3 --enable-pthreads --enable-shared --enable-libx264 --enable-pic --enable-libfdk-aac --enable-openssl --enable-nonfree
yum install -y autoconf automake build-essential git libass-dev libfreetype6-dev libsdl2-dev libtheora-dev libtool libva-dev libvdpau-dev libvorbis-dev libxcb1-dev libxcb-shm0-dev libxcb-xfixes0-dev pkg-config texinfo wget zlib1g-dev
方法一:
sudo apt install FFmpeg(ubuntu采用apt/centos采用yum/dnf)
1.更新系统
sudo yum install epel-release -y
sudo yum update -y
sudo shutdown -r now
2.使用安装Nux Dextop YUM
sudo rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
sudo rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm
3.安装FFmpeg和FFmpeg开发包
sudo yum install ffmpeg ffmpeg-devel -y
方法二:
https://ffmpeg.org/download.html
http://yasm.tortall.net/Download.html
http://www.videolan.org/developers/x264.html
https://sourceforge.net/projects/opencore-amr/files/fdk-aac/
安装依赖环境
sudo yum -y install make automake gcc gcc-c++ cc kernel-devel glibc-devel make
sudo yum -y install libxml2 libxml2-devel libxslt libxslt-devel
1.最后装wget https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-amd64-static.tar.xz
或http://www.ffmpeg.org/releases/ffmpeg-5.0.tar.gz
tar -zxvf ffmpeg-5.0.tar.gz -C ../
./configure --enable-gpl --enable-version3 --enable-pthreads --enable-shared --enable-libx264 --enable-static --enable-libfdk-aac --enable-openssl --enable-nonfree
make && make install
warming:
export PATH=$PATH:/path/to/your/pkg-config
#报错 [libavcodec/libavcodec.so.59] Error 1
find / -name libavcodec.so.59
在~/.bash_profile或~/.bashrc或/etc/profile添加环境变量
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/your/library
或
vi /etc/ld.so.conf
#原文加入:/usr/local/lib
执行ldconfig
2.wget http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz
tar -zxvf yasm-1.3.0.tar.gz -C ../
./configure
make && make install
3.wget https://www.nasm.us/pub/nasm/releasebuilds/2.14/nasm-2.14.tar.bz2
# tar -jxvf nasm-2.14.tar.bz2
# cd nasm-2.14
# ./configure
# make & make install
# nasm --version
4.git clone https://code.videolan.org/videolan/x264.git
#cd x264
#./configure --enable-shared
#make & make install
4.wget https://jaist.dl.sourceforge.net/project/opencore-amr/fdk-aac/fdk-aac-2.0.2.tar.gz
#./configure
#make & make install
nginx hls:
server {
listen 8888;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
}
server {
listen 16666;
server_name localhost;
location / {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
add_header 'Access-Control-Allow-Headers' 'Range';
add_header 'Content-Type' 'text/plain charset=UTF-8';
root /var/www/html/cct;
index index.html index.htm;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
#add_header 'Access-Control-Allow-Headers' 'Content-Type';
access_log off;
expires max;
}
location /video_hls {
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';
add_header 'Access-Control-Allow-Headers' 'Range';
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires 0;
#点播配置
types {
application/vnd.apple.mpegurl;
video/m3u8 ts;
}
alias /var/www/html/cct/public/video_hls/;
index index.html
#加载HLS点播配置
#include hls.conf;
access_log off;
expires max;
}
}
nginx配置RTMP:
#RTMP Server 20231012
rtmp {
server {
listen 1935;
#每个RTMP消息的分片大小
chunk_size 1024;
application live {
live on;
#publish_notify on;
#on_publish http://xx/a.php
record off;
}
application vod {
play /var/www/html/cct/public/public_video;
}
application vod_http {
play http://localhost:1935/vod;
}
application hls {
live on; #应用是直播应用
#hls on; #开启hls流
#hls_path /var/www/html/cct/public/public_video/aa;
#hls_fragment 10s;
record off; #关闭录制
#record_suffix .ts;
#record_unique on;
}
}
}
转换:mp4>m3u8
ffmpeg -i ./eye.mp4 -profile:v baseline -level 3.0 -s 640x360 -start_number 0 -hls_time 10 -hls_list_size 0 -f hls eye.m3u8
"-profile:v baseline" 表示设置H.264的配置文件为基本线(Baseline)。
"-level 3.0" 表示设置H.264的编码级别为3.0。
"-s 640x360" 表示设置视频的分辨率为640x360。
-
-i input.mp4
:指定输入文件。 -
-codec: copy
:复制编解码器,以避免重新编码。 -
-start_number 0
:设置序列号为0。 -
-hls_time 10
:每个分段的时长为10秒。 -
-hls_list_size 0
:设置播放列表中的最大条目数,0意味着没有限制。 -
-f hls
:输出格式为HLS。 -
output.m3u8
:输出的M3U8文件和TS分片文件的前缀。 -
-map 0
表示对输入文件的所有流进行操作。 -
-f segment
表示输出分片。 -
-segment_list sk.m3u8
指定输出的M3U8索引文件名。 -
-segment_time 10
表示每个分片的持续时间为10秒。 -
-segment_list_entry_prefix ./output/segment-%03d.ts
和最后的./output/segment-%03d.ts
指定了分片文件的输出路径和文件名格式。
m3u8>mp4
ffmpeg -protocol_whitelist file,http,https,tcp -i "http://yourserver/path/to/playlist.m3u8" -c copy -bsf:a aac_adtstoasc output.mp4
ffmpeg -protocol_whitelist file,http,https,tcp -i "./eye.m3u8" -c copy -bsf:a aac_adtstoasc ./aaa/eye.mp4
-
-protocol_whitelist
:指定允许FFmpeg使用的网络协议。 -
-i
:指定输入文件的URL。 -
-c copy
:复制编码流,不重编码。 -
-bsf:a aac_adtstoasc
:将AAC音频流转换为ASCII序。 -
output.mp4
:输出文件的名称 -
如果你的M3U8文件使用了HLS加密,你还需要提供解密的key,并使用
-hls_playlist_type
和-hls_segment_type
选项来指定类型
测试流媒体:
ffmpeg -re -i /var/www/html/cct/public/public_video/eye.mp4 -vcodec copy -acodec copy -b:v 800k -b:a 32k -f flv rtmp://localhost:1935/live
2.ffmpeg -re -i xx.mp4 -vcodec copy -acodec copy -b:v 800k -b:a 32k -f flv -cors 'X-Custom-Header: CustomValue' rtmp://localhost:1935/hls
3.ffmpeg -re -i input.mp4 -vcodec copy -acodec copy -f flv -headers "X-Custom-Header: CustomValue" rtmp://localhost:1935/stream
ffplay rtmp://localhost:1935/live