ubuntu20.04 ffmpeg mp4转AES加密的m3u8分片视频

样本视频(时长2分35秒):

大雄兔_百度百科

大雄兔_百度百科不知大家否看过世界上第一部开源电影:Elephants Dream(大象之梦)。这是一部由主要由开源软件Blender制作的电影短片,证明了用开源软件也能制作出效果媲美大公司的作品。icon-default.png?t=N7T8https://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 -y 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-az193-390:/tmp# hexdump  -C ./enc.key
00000000  f0 07 cf 79 b2 f4 9d ce  fe b9 62 ce 06 3c 05 f0  |...y......b..<..|
00000010
root@fv-az193-390:/tmp# 

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# 

参考文档:
Examplesicon-default.png?t=N7T8http://jackzhang1204.github.io/sewise/sewise_player/demos/

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.icon-default.png?t=N7T8https://www.cnraksmart.com/7512.html

测试使用:

https://www.bootcdn.cn/hls.js/

<script src="https://cdn.bootcdn.net/ajax/libs/hls.js/0.14.9/hls.js"></script>

python -m http.server 80

如下是 index.html 

<head>
  <meta charset='UTF-8'>
  <title>test</title>
</head>
<body>
  <video width=800 controls src=''>URL99</video>
  <script src="https://cdn.bootcdn.net/ajax/libs/hls.js/0.14.9/hls.js"></script>
  <script>
    if(Hls.isSupported()) {
      var video3 = document.getElementsByTagName('video')[0];
      var hls2 = new Hls( {debug: true} );
      hls2.loadSource("http://192.168.50.1:60443/z/ffmpeg_0/ffmpeg_playlist.m3u8?c="+Math.random()  );
      hls2.attachMedia(video3);
      hls2.on(Hls.Events.MANIFEST_PARSED,function() { video3.play()  }); 
   }
  </script>
</body>

 

使用ckplayer来测试(使用hls插件):

cd /tmp;git clone https://gitee.com/niandeng/ckplayer;


#  https://www.ckplayer.com/manual/13.html#m102

<!DOCTYPE html>
<html>
	<head>
		<script type="text/javascript" src="ckplayer/hls.js/hls.min.js"></script>
		<link rel="stylesheet" type="text/css" href="ckplayer/css/ckplayer.css">
		<script type="text/javascript" src="ckplayer/js/ckplayer.js"></script>
	</head>
	<body>
		<div class="video" style="width: 100%; height: 500px;max-width: 800px;" ></div>
		<script>
			var videoObject = {
				container: '.video',  //容器的ID或className
				plug:'hls.js',   //设置使用hls插件
				video:"http://192.168.50.1:60443/z/ffmpeg_0/ffmpeg_playlist.m3u8?c="+Math.random() 
			};
			new ckplayer(videoObject);
		</script>
	</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值