代码拉取完成,页面将自动刷新
支持hevc编码的协议:
因为rtmp在2012年后,协议没有更新,对hevc编码格式的支持在rtmp协议官方文档中没有明确定义。
国内cdn厂商通过修改<video_file_format_spec_v10_1>中CodecID的定义,将flv中的hevc codecid定义为12。
Field | Type | Comment |
---|---|---|
Frame Type | UB [4] | Frame Type Type of video frame. The following values are defined: 1 = key frame (for AVC and HEVC, a seekable frame) 2 = inter frame (for AVC and HEVC, a non-seekable frame) 3 = disposable inter frame (H.263 only) 4 = generated key frame (reserved for server use only) 5 = video info/command frame |
CodecID | UB [4] | Codec Identifier. The following values are defined: 2 = Sorenson H.263 3 = Screen video 4 = On2 VP6 5 = On2 VP6 with alpha channel 6 = Screen video version 2 7 = AVC 12=HEVC |
HVCPacketType | IF CodecID == 12 UI8 |
The following values are defined: 0 = HEVC sequence header 1 = HEVC NALU 2 = HEVC end of sequence (lower level NALU sequence ender is not required or supported |
CompositionTime | IF CodecID==7 OR CodecID == 12 SI24 |
IF AVCPacketType == 1 OR HVCPacketType == 1 Composition time offset ELSE 0 See ISO 14496-12, 8.15.3 for an explanation of composition times. The offset in an FLV file is always in milliseconds. |
VideoTagBody | IF FrameType == 5 UI8 ELSE ( IF CodecID == 2 H263VIDEOPACKET IF CodecID == 3 SCREENVIDEOPACKET IF CodecID == 4 VP6FLVVIDEOPACKET IF CodecID == 5 VP6FLVALPHAVIDEOPACKET IF CodecID == 6 SCREENV2VIDEOPACKET IF CodecID == 7 AVCVIDEOPACKET IF CodecID == 12 HVCVIDEOPACKET ) |
Video frame payload or frame info If FrameType == 5, instead of a video payload, the Video Data Body contains a UI8 with the following meaning: 0 = Start of client-side seeking video frame sequence 1 = End of client-side seeking video frame sequence For all but AVCVIDEOPACKET or HVCVIDEOPACKET, see the SWF File Format Specification for details |
因为当前官方ffmpeg的rtmp推/拉流默认不支持hevc的编码,所以需要重新对ffmpeg进行hevc in flv的自定义修改。
需要修改3个文件即可:
enum { FLV_CODECID_H263 = 2, FLV_CODECID_SCREEN = 3, FLV_CODECID_VP6 = 4, FLV_CODECID_VP6A = 5, FLV_CODECID_SCREEN2 = 6, FLV_CODECID_H264 = 7, FLV_CODECID_REALH263= 8, FLV_CODECID_MPEG4 = 9, FLV_CODECID_HEVC = 12, };
如何编译支持hevc in flv的ffmpeg,请参考ffmpeg supports hevc in flv
在完成支持hevc in flv的定制化ffmpeg编译后,rtmp推流hevc视频编码,如下:
ffmpeg -re -i source.flv -c:v libx265 -c:a copy -f flv rtmp://127.0.0.1/live/livestream
rtmp拉流hevc视频编码格式,如下:
ffmpeg -i rtmp://127.0.0.1/live/livestream -f flv -y livestream.flv
播放:
ffplay rtmp://127.0.0.1/live/livestream
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。