转自 H.265/HEVC Codec 编解码 (MP4 和 TS)
1. H.265/HEVC 播放器
1) VLC media player 2.1.3 (目前不支持H.265 TS播放)
2) ffmpeg中的ffplay (如:ffplay hevc.ts)
3) GPAC中的MP4Client (如:MP4Client hevc.ts, 或MP4Client hevc.mp4)
2. H.265/HEVC编码器
所有编码器都是基于x265来做的。其参考命令如下所示:
- ffmpeg.exe -i "E:\video\yak.mp4" -pix_fmt yuv420p -f yuv4mpegpipe - 2> nul | x265.exe -p medium --crf 26 --fps 30 -f 2283 -o "E:\video\test\temp0.hvc" --y4m -
常用的工具如下所示:
2.1 CINEMARTIN CINEC v.2.7.5 Gold
CINEMARTIN CINEC v.2.7.5 Gold是一个商业软件,做4K H.265压缩时经常出现crash。且占用大量硬盘空间。对于H.265可产生hevc文件,可供MP4Box作为输入以生成.mp4文件,从而使用mp42ts生成.ts文件。
2.2 Internet Friendly Media Encoder
Internet Friendly Media Encoder是一款ssf开源项目,其性能和功能很好。只是目前可用,代码还没有开放。且在执行过程中,还会显示其详细log信息,不占用硬盘空间,共关键的命令如下所示:
- Internet Friendly Media Encoder工作步骤:
- 1)[ ok ] Loaded ffmpeg.exe
- [info] Command: -i "E:\video\kayak.mp4" -vn -ar 44100 -y "E:\video\test\temp1.wav"
- 2)[ ok ] Loaded libfaac.dll
- [info] Command: -b 96 -o "E:\video\test\temp1.aac" "E:\video\test\temp1.wav"
- 3)[info] Command: ffmpeg.exe -i "E:\video\kayak.mp4" -pix_fmt yuv420p -f yuv4mpegpipe - 2> nul | x265.exe -p medium --crf 26 --fps 30 -f 2283 -o "E:\video\test\temp0.hvc" --y4m -
- 4)[ ok ] Loaded libmp4.dll
- [info] Command: -add "E:\video\test\temp0.hvc#video:name=Encoded with IFME v3.2.
- 0.0:fmt=HEVC:fps=30" -add "E:\video\test\temp1.aac#audio:name=Track 1" "E:\video
- \test\kayak.mp4"
- Syntax: x265 [options] infile [-o] outfile
- infile can be YUV or Y4M
- outfile is raw HEVC bitstream
- ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
目前只能输出H.265 .mp4和.mkv文件。
2.3 ffmpeg
ffmpeg是一款功能强大且基础的软件,其使用示例如下所示:
- ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
- ffmpeg -i ./kayak.mp4 -c copy -bsf h264_mp4toannexb -mpegts_original_network_id 0x1122 -mpegts_transport_stream_id 0x3344 -mpegts_service_id 0x5566 -mpegts_pmt_start_pid 0x1500 -mpegts_start_pid 0x150 -metadata service_provider="Some provider" -metadata service_name="Some Channel" -y out0.ts //h.264
- ffmpeg -i ./kayak.mp4 -c copy -bsf h264_mp4toannexb -y out1.ts //h.264
- ffmpeg -i ./test.mp4 -c copy -bsf h264_mp4toannexb -y out.ts //h.264
- ffmpeg -i ./test.mp4 -vframes 200 -r 25 -s 3840x2160 -aspect 16:9 -b:v 12000000 -vcodec hevc -y out.ts // h.265/hevc
- ffmpeg -i ./test.mp4 -vframes 200 -r 25 -s 3840x2160 -aspect 16:9 -b:v 12000000 -vcodec hevc -mpegts_original_network_id 0x1122 -mpegts_transport_stream_id 0x3344 -mpegts_service_id 0x5566 -mpegts_pmt_start_pid 0x1500 -mpegts_start_pid 0x150 -metadata service_provider="Some provider" -metadata service_name="Some Channel" -y out.ts //h.265/hevc
使用ffmpeg可以生成H.265 .TS和.MP4文件。
2.4 GPAC
GPAC可以把x265生成的hevc流(.hevc)打包成.mp4和.ts文件,其使用方法如下:
How to embed HEVC into MP4 file format
- ./MP4Box -add name_of_annexB_bitstream.(bit,bin,265) -fps 50 -new output.mp4
- ./MP4Box -v -add Catus_1920x1080_50_qp32.bin:FMT=HEVC -fps 50 -new output.mp4
- ./MP4Client output.mp4 # to play HEVC mp4 content
2.4.2 mp42ts
How to embed HEVC into TS- ./mp42ts -prog=hevc.mp4 -dst-file=test.ts
- ./mp42ts -prog=output.mp4 -dst-file=hevc.ts
- ./MP4Client test.ts # to play HEVC transport streams
参考信息:
1. Handbrake Support H.265: http://handbrake.fr/nightly.php
2. H.265 官网:http://x265.org/
3. OpenHEVC:https://github.com/OpenHEVC