样本视频(时长2分35秒):
大雄兔_百度百科
大雄兔_百度百科不知大家否看过世界上第一部开源电影:Elephants Dream(大象之梦)。这是一部由主要由开源软件Blender制作的电影短片,证明了用开源软件也能制作出效果媲美大公司的作品。https://baike.baidu.com/item/%E5%A4%A7%E9%9B%84%E5%85%94/9902566
curl -k -O https://vd3.bdstatic.com/mda-mh4d5tn0e89vvqrm/480p/h264/1628155168851423956/mda-mh4d5tn0e89vvqrm.mp4;
root@fv-az741-166:/tmp# md5sum mda-mh4d5tn0e89vvqrm.mp4
bd961709a04977012168b2ca8e2d03dc mda-mh4d5tn0e89vvqrm.mp4
root@fv-az741-166:/tmp# ls -al mda-mh4d5tn0e89vvqrm.mp4
-rw-r--r-- 1 root root 12971533 Jun 3 05:05 mda-mh4d5tn0e89vvqrm.mp4
root@fv-az741-166:/tmp#
安装ffmpeg:
sudo apt update;\
sudo apt install ffmpeg;\
ffmpeg -decoders;\
ffmpeg -version;
检查openssl版本:
root@fv-az741-166:/tmp# openssl version
OpenSSL 1.1.1f 31 Mar 2020
root@fv-az741-166:/tmp# grep NA /etc/os-release
NAME="Ubuntu"
PRETTY_NAME="Ubuntu 20.04.6 LTS"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal
root@fv-az741-166:/tmp#
root@fv-az741-166:/tmp# ffmpeg -version;
ffmpeg version 4.2.7-0ubuntu0.1 Copyright (c) 2000-2022 the FFmpeg developers
built with gcc 9 (Ubuntu 9.4.0-1ubuntu1~20.04.1)
configuration: --prefix=/usr --extra-version=0ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil 56. 31.100 / 56. 31.100
libavcodec 58. 54.100 / 58. 54.100
libavformat 58. 29.100 / 58. 29.100
libavdevice 58. 8.100 / 58. 8.100
libavfilter 7. 57.100 / 7. 57.100
libavresample 4. 0. 0 / 4. 0. 0
libswscale 5. 5.100 / 5. 5.100
libswresample 3. 5.100 / 3. 5.100
libpostproc 55. 5.100 / 55. 5.100
root@fv-az741-166:/tmp#
生成密钥文件:
cd /tmp;
openssl rand 16 > enc.key ;
cat <<EOF>enc.keyinfo
./enc.key
/tmp/enc.key
$(openssl rand -hex 16)
EOF
root@fv-az741-166:/tmp# cd /tmp;
root@fv-az741-166:/tmp# openssl rand 16 > enc.key ;
root@fv-az741-166:/tmp#
root@fv-az741-166:/tmp# cat enc.key
m¥ݳ¸<7":root@fv-az741-166:/tmp# cat <<EOF>enc.keyinfo
> ./enc.key
> /tmp/enc.key
> $(openssl rand -hex 16)
> EOF
root@fv-az741-166:/tmp#
root@fv-az741-166:/tmp# cat enc.keyinfo
./enc.key
/tmp/enc.key
ac521b411402a5d47f5dcbea63e1dc30
root@fv-az741-166:/tmp#
切分mp4视频:
ffmpeg -y \
-i "/tmp/mda-mh4d5tn0e89vvqrm.mp4" \
-hls_time "10" \
-hls_key_info_file "/tmp/enc.keyinfo" \
-hls_playlist_type "vod" \
-hls_list_size "0" \
-hls_segment_filename "/tmp/ffmpeg_%d.ts" \
"/tmp/ffmpeg_playlist.m3u8"
hls_time:指定生成 ts 视频切片的每片时间长度
hls_key_info_file:enc.keyinfo文件的位置
hls_list_size: 索引播放列表的最大列数 默认5,0 为不限制
hls_segment_filename:生成ts和m3u8文件的路径及文件名
root@fv-az741-166:/tmp# cat ffmpeg_playlist.m3u8
#EXTM3U
#EXT-X-VERSION:3
#EXT-X-TARGETDURATION:14
#EXT-X-MEDIA-SEQUENCE:0
#EXT-X-PLAYLIST-TYPE:VOD
#EXT-X-KEY:METHOD=AES-128,URI="./enc.key",IV=0xac521b411402a5d47f5dcbea63e1dc30
#EXTINF:11.080000,
ffmpeg_0.ts
#EXTINF:12.760000,
ffmpeg_1.ts
#EXTINF:8.200000,
ffmpeg_2.ts
#EXTINF:10.160000,
ffmpeg_3.ts
#EXTINF:8.200000,
ffmpeg_4.ts
#EXTINF:12.560000,
ffmpeg_5.ts
#EXTINF:7.040000,
ffmpeg_6.ts
#EXTINF:10.960000,
ffmpeg_7.ts
#EXTINF:9.880000,
ffmpeg_8.ts
#EXTINF:9.840000,
ffmpeg_9.ts
#EXTINF:9.360000,
ffmpeg_10.ts
#EXTINF:11.400000,
ffmpeg_11.ts
#EXTINF:8.880000,
ffmpeg_12.ts
#EXTINF:11.120000,
ffmpeg_13.ts
#EXTINF:14.320000,
ffmpeg_14.ts
#EXT-X-ENDLIST
root@fv-az741-166:/tmp# ls -al ff*
-rw-r--r-- 1 root root 1068032 Jun 3 05:14 ffmpeg_0.ts
-rw-r--r-- 1 root root 1207344 Jun 3 05:14 ffmpeg_1.ts
-rw-r--r-- 1 root root 1314880 Jun 3 05:14 ffmpeg_10.ts
-rw-r--r-- 1 root root 995472 Jun 3 05:14 ffmpeg_11.ts
-rw-r--r-- 1 root root 1607600 Jun 3 05:14 ffmpeg_12.ts
-rw-r--r-- 1 root root 1166176 Jun 3 05:14 ffmpeg_13.ts
-rw-r--r-- 1 root root 1009376 Jun 3 05:14 ffmpeg_14.ts
-rw-r--r-- 1 root root 655936 Jun 3 05:14 ffmpeg_2.ts
-rw-r--r-- 1 root root 838864 Jun 3 05:14 ffmpeg_3.ts
-rw-r--r-- 1 root root 557616 Jun 3 05:14 ffmpeg_4.ts
-rw-r--r-- 1 root root 1426736 Jun 3 05:14 ffmpeg_5.ts
-rw-r--r-- 1 root root 921584 Jun 3 05:14 ffmpeg_6.ts
-rw-r--r-- 1 root root 1164288 Jun 3 05:14 ffmpeg_7.ts
-rw-r--r-- 1 root root 1482016 Jun 3 05:14 ffmpeg_8.ts
-rw-r--r-- 1 root root 1161856 Jun 3 05:14 ffmpeg_9.ts
-rw-r--r-- 1 root root 657 Jun 3 05:14 ffmpeg_playlist.m3u8
root@fv-az741-166:/tmp#
参考文档:
https://blog.csdn.net/sinat_36106456/article/details/126301704
Ubuntu 20.04安装ffmpeg详细教程-便宜VPS测评root@ubuntu-s-1vcpu-1gb-lon1-01:~# do-release-upgrade Checking for a new Ubuntu release You have not rebooted after updating a package which requires a reboot. https://www.cnraksmart.com/7512.html