步骤:
1.Adobe Flash Media Live Encoder 2.5推送h.264 main profile给nginx-rtmp;
2.nginx-rtmp做hls切片;
3.ipad播放hls,画面抖动。
切片结果分析:
1.ffmpeg(Adobe Flash Media Live Encoder 2.5, h.264 main profile)
测试结果:会抖动,有B帧时,因为P帧的PTS比后面的B帧的PTS小
IDR PCR:18900000 PTS:126000
P PCR:20736000 PTS:132120
B PCR:22572000 PTS:138240
B PCR:24408000 PTS:144360
B PCR:26244000 PTS:150480
P PCR:28080000 PTS:156600
2.nginx-rtmp(Adobe Flash Media Live Encoder 2.5, h.264 main profile)
测试结果:会抖动,有B帧时,因为P帧的PTS比后面的B帧的PTS小
IDR PCR:5044194000 PTS:16939980
P PTS:16946100
B PTS:16949160
B PTS:16955280
B PTS:16961400
P PTS:16967520
3.nginx-rtmp(Adobe Flash Media Live Encoder 2.5, h.264 baseline profile)
测试结果:不会抖动,无B帧时,各帧按正常递增式PTS顺序显示
IDR PCR:2576961477600 PTS:63000
P PTS:77310
P PTS:83430
P PTS:89460
P PTS:95670
P PTS:101790
日志:
2014/11/05 12:43:44 [debug ] 5741#5741: *1 hls: video pts=1112850, dts=1112850, cts=0
2014/11/05 12:43:44 [debug ] 5741#5741: *1 hls: video pts=1118970, dts=1118970, cts=0
2014/11/05 12:43:44 [debug ] 5741#5741: *1 hls: video pts=1125090, dts=1125090, cts=0
2014/11/05 12:43:44 [debug ] 5741#5741: *1 hls: video pts=1131210, dts=1131210, cts=0
2014/11/05 12:43:44 [debug ] 5741#5741: *1 hls: video pts=1137330, dts=1137330, cts=0
2014/11/05 12:43:44 [debug ] 5741#5741: *1 hls: video pts=1143450, dts=1143450, cts=0
2014/11/05 12:43:44 [debug ] 5741#5741: *1 hls: video pts=1149570, dts=1149570, cts=0
2014/11/05 12:43:44 [debug ] 5741#5741: *1 hls: video pts=1155690, dts=1155690, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1161810, dts=1161810, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1167930, dts=1167930, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1174050, dts=1174050, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1180260, dts=1180260, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1186380, dts=1186380, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1192500, dts=1192500, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1198620, dts=1198620, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1204740, dts=1204740, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1210860, dts=1210860, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1216980, dts=1216980, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1220040, dts=1220040, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1226160, dts=1226160, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1232280, dts=1232280, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1238400, dts=1238400, cts=0
2014/11/05 12:43:45 [debug ] 5741#5741: *1 hls: video pts=1244520, dts=1244520, cts=0
2014/11/05 12:43:46 [debug ] 5741#5741: *1 hls: video pts=1250640, dts=1250640, cts=0
2014/11/05 12:43:46 [debug ] 5741#5741: *1 hls: video pts=1256760, dts=1256760, cts=0
2014/11/05 12:43:46 [debug ] 5741#5741: *1 hls: video pts=1262880, dts=1262880, cts=0
2014/11/05 12:43:46 [debug ] 5741#5741: *1 hls: video pts=1268820, dts=1268820, cts=0
2014/11/05 12:43:46 [debug ] 5741#5741: *1 hls: video pts=1275030, dts=1275030, cts=0
2014/11/05 12:43:46 [debug ] 5741#5741: *1 hls: video pts=1281150, dts=1281150, cts=0
4.nginx-rtmp(Adobe Flash Media Live Encoder 3.2, h.264 main profile)
测试结果:不会抖动,有B帧时,因为P帧的PTS比后面的B帧的PTS大
IDR PCR:1468908000 PTS:5028570 DTS:5022360
P PTS:5053050 DTS:5028570
B PTS:5034690
B PTS:5040810
B PTS:5046930
P PTS:5065290 DTS:5053050
日志:
2014/11/05 12:46:17 [debug ] 5760#5760: *2 hls: video pts=14130, dts=0, cts=157
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=32400, dts=14130, cts=203
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=20250, dts=20250, cts=0
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=26370, dts=26370, cts=0
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=50760, dts=32400, cts=204
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=38520, dts=38520, cts=0
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=44640, dts=44640, cts=0
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=75150, dts=50760, cts=271
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=56970, dts=56970, cts=0
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=63090, dts=63090, cts=0
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=69120, dts=69120, cts=0
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=93600, dts=75240, cts=204
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=81360, dts=81360, cts=0
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=87480, dts=87480, cts=0
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=111960, dts=93600, cts=204
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=99810, dts=99810, cts=0
2014/11/05 12:46:18 [debug ] 5760#5760: *2 hls: video pts=105930, dts=105930, cts=0
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=130410, dts=112050, cts=204
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=118170, dts=118170, cts=0
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=124290, dts=124290, cts=0
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=151830, dts=130410, cts=238
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=136530, dts=136530, cts=0
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=142650, dts=142650, cts=0
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=148770, dts=148770, cts=0
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=179370, dts=154890, cts=272
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=157950, dts=157950, cts=0
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=164070, dts=164070, cts=0
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=170190, dts=170190, cts=0
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=194670, dts=176310, cts=204
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=182430, dts=182430, cts=0
2014/11/05 12:46:19 [debug ] 5760#5760: *2 hls: video pts=188640, dts=188640, cts=0
2014/11/05 12:46:20 [debug ] 5760#5760: *2 hls: video pts=219240, dts=194760, cts=272
2014/11/05 12:46:20 [debug ] 5760#5760: *2 hls: video pts=200880, dts=200880, cts=0
2014/11/05 12:46:20 [debug ] 5760#5760: *2 hls: video pts=207000, dts=207000, cts=0
2014/11/05 12:46:20 [debug ] 5760#5760: *2 hls: video pts=213120, dts=213120, cts=0
2014/11/05 12:46:20 [debug ] 5760#5760: *2 hls: video pts=243720, dts=219240, cts=272
2014/11/05 12:46:20 [debug ] 5760#5760: *2 hls: video pts=225360, dts=225360, cts=0
结论:
1.抖动原因与h.264编码无直接关系,在adobe Flash Media Live Encoder 2.5版本推送h.264 main profile, rtmp的时间戳和cts有误,造成生成出错误的b帧和p帧pts。
2.正确PTS:P帧的PTS要比后面的B帧的PTS大!
3.该问题由编码器导致
cts:参考ISO 14496-12, 8.15.3