问题描述
rtp打包的ps视频流发送到客户端后显示花屏。
数据分析过程
1、用tcpdump抓包
tcpdump -i eth0 -vnn -w rtp.pcap
2、用wireshark提取rtp的payload
保存为record.h264文件
3、用vlc播放器播放
显示花屏
4、提取关键帧
用xxd命令将h264文件转为txt文件
xxd -p record.h264 > record.txt
选取一个关键帧单独保存为frame.txt
000001ba44099d268401003a9bf8000001bb000c801efffde17fe0e800c0c200000001bc0012e1ff000000081be0000090c0000045bddcf4000001e0f81180c00a31026749a111026749a100000001674d001f9a6402802dff35010101400000fa000030d4010000000168ee3c800000000165888010000afff88198fc0704b552be75547b530a9b815add7238af32c6d113fef2fc09f70103eb062510477a8d1fd86ce122d1b474fd48fb62342893af148b9da27a42c4ca6c52f4549aa2e1a3184ab8abd0a28e55c2e6da455f298f9b0e2c0623ae75204592ab79056969cb95348dcee08bebb2c12ed6c1744289062881f2194820c7a154594ce951a87d4f059abceeb607df330a823317e62588275ead9caf1085ab170ae732e6a9f01621ca5bfc9f8977e39449d29cc895d4c6577e59ba89ac90310ef6bd95c41759af85b63124b329ce7c8c20c04e79bcead58f4bcb514857837ae0b90da327c3704365ebc9561d5b97d7743aec97d1960f7549b8301ee8459ba4955ba0699f3d44a70ec2e7234e5f3c0c5e7b8331f0661e0a3cb8c24462f477abbe203ed2fddb4931f65fc1cd073c5fd3799f03fe51d47d40510d1747226a956c237846feeebeb294373ed7983c923f85239f3d889199828383494162818038b815b6ae547773d4e2dad3acca897d8916ffff53244ec8ae08cc3e1db4be1c440059a459fa94b888ae344a248a3d666a83fe1c9778de8733b1bca152af6d0886b77e1b30b84ad5153644357ce4a14da8224de6b5a0a2fee80d91c2b4251c7678e047eff342ea82b86a72d833eb78d955486db661d6a206f14d8ed9ae2769e11223983981ea4ebec9c6b7d5cf08c71a11a84ab692d81d7dc914de59d76e8e3c52df919e0034cde670412983ecfa6ea88d02cb4709a1f67d18fb857bcb882404a7ed0998cb1f3c316b1e0f149ccbf285133f08bb839bebb1a99e2b1ebc28a559bdaf0617905351d56ffa35949cb6ca74f84afd3a208631bf0f62c8482b9565ddda95f9c3d2c40bdd6dd8cef22244dfd7cbb2097aceed269acbd33d72810870abe573f156ab97e67c9e8ece23451ef9795889468dd8ff10a6a2ccc1f464466e11c66958a5659b173adef9b23440dfbf493ae7dbc81514513573e0094dd23c3e27859477052f3977d2fbb472d1eabd29509244bbf6fe1082d0b7f02c3c32efa335ed8c3a16f3d5fe08c3754fd491ea23f81db0301c6b52bdae4112969ee97cf1cdfe6125daf1ff850ad393195234e2ab1ac1ef08c5ddbf11caa63c9e9c1d25864ee9ecdcdc6d7daf050c88c2733603747d04602443c898a6aca2ed70aeb9349d19a0d160af760b0ca2fb582b4c3ba168bd8c8aaa3b2975e6d51c66b0d7934fa6134b3672ffaac8ab9d0a35df14c5c138c6bfe0735ef1e4c5d82f185770554d68f820dbaa55947fb6b537bb1ec711c770d9541413c5f1e649272dafae5a474c8ae47ab86fbd376ed7d012e416ffc16e7de0eea7df918797066c8f07e8c71835a20829bec575b0fdbaeeb53f784031feac7f2a9c4d7f3e98cee262ee333583ecf3632089e438061b0afd59ba02cf8f661321224ac23f2e4d30c5fccb56bc4c45ab8646b9176951d4b94b6b3181fc94aa62ceeb1ee922be177404a5b49c59a17a823db0bae183156cc69af4b86d8623e91aa6928617e4090f0a1f15c6f3e735f3ec15ad693b3fa75b40199e3c25126146a4bb6bc9dafde28944af09d2c0df2df1fb6dcb1e00d4bba784a508ced34bb3f3e35d0e8f2f0acf9412341b8a74ba9646fe6729be2921da06588f2abc86d45504044a26aa0dd88f9b41d10b8f0dfd45ebf63e66fd7f0701a2763b23acc348837d8597e4fc6304b2efa9c8ec5d7338abde9d580c2a5f8c8979bc5c0203bd6bbd61bdba9c21050eef4116bc2f59ed824f4ea7d03307053321609503d5c2d844bc6b7eb5d4f4099ebb38859f67549fd1dd3c8c87771385ecf7b17b162a6607eb42cdfb34e198fcaf280228b489f7a90a409d1cabc7d35d9ba6dd2179182652cb0a95bc70b268883a591fac0d72f82b041f8bdff58d295831541b727a69c7c9aa5e819a0601e916c9c207e993a65a33d9d230a3d4d6fb046030f701c90f36be25d3b8b7f20b45619ab933b09ae3dbbd67492cda5620df574a62b5e6ff6b8a83fd7c90bff2e0956f37bf954ad440185a7559805430e514d0daab1531fa8a9fdda766efa1b09db19fe9ff5e459a3e2bd3b26be261cd18f1cc6a7c245976807cfca557c376e00abf7ba01a11eec784abcb480c5cbc5c4da2077658b02f89ff10b5b582896700a68c72c5e3c5e260c180eeba79a74aa980eff7bc2cb5726130797fcc9c58c481af1b51b7d5942b1d31a4eea850ab91959bdca24fbc5b2a3fc523a81eb3aeb983df546a125e775222113907f2bec084e27df888b4bbaf5c8510573017b2163bab298cb86f18e6aa72e5ae045ad1f91d4b442130e8ddc1065716130b5a9c4debd9f5aa669fc4edf3760bbde607341977f4bcec4738b1cfd5c6ecf364e3ed260e28773f70822f6b1b71da5507f991d494e8aec5e02d2e1ddd076275983912bee679300d6edbb76062dfdef8e3afb59d47f97d8ed4e6d4b6c3d661747631aec957a8f019b1f17565b7ef73b0cc243597da634c4b8a05070598cc0307a42da83cc96f6c427912184ac17af41b631a107c0cfbb9f83d06e5fe904a89ff3457b20292618c8b0f72945596db264df11513bc275a6963ae5b8a01eef66be2ab6e1689635b289e0b05fcae907c27166a5419b26e9a1ce63e2bbca084c4b51f671c4a534aaa2e927836918a8f2cb9b45a895c6330656d5c533243ff4a9bca431927a90c077fa25e5e5481f327cf7ab8d13ec4beb54fdbab700b4b5d8d7b93ef34f7b2386e82da8881197687d524e455fc3ac7f771721cc2fcfb8ccba546bb45965edb8aef4c0c49ef6254a8d44b0f27c07dee29bcd4cea015bcf3415129b1ec71d295488f81792288e3cbcf3acdaf3266e56ae5e430411263accb32ca59025ea6dd8358920c59182851b2d7a42499829d3aafa1821453564fbe308e92c71c21efb27d128fb63fd02a2965e54c3946c5c5d5ba582fb3081720af9c1bfd31f23d2107ab8ef274c9b383c6683b241bbe5aef34d8926ced1500ee2c85715cffff979a8459d2be07325944849edf45b5d048c71ce21b7e42f8c08939205411116400d163eac5502825b420954499a3dab6bdcc2297d642628f5c0fbf8231b5bbf96c03564a2c8d50d5ab4c36cddd91581bfad6b092ab694bd12d3ed6ed9524dba45ab703e5460ea345b21da17088b9e431e5518ace12efadbd38c2d3723fc5de1f5ea5c864cb3410ca25f45bdbcfbd29458a1040e5df18410158eb20f920ca1de4f87c9f59eceabb9e20c3085574ea490f96e17ae79c0a9c2aed6e34f82a672dbce5e79e238ce0edec652823efb49361255554495a41a12220fc8e33108dbebe3fcf078b0f56052d52274c879c2dec2ff127c8296e253bea3d883ccfcb0ffccb02a4ec204ede7b5945a235ab361cab816d9ea9b7241524639210c310d6ce53ec62e448aa34d720da015acfc9b18cd6a2ce6ee566711e9450bff3b9860716d4788ab5890c8b2bb2fb1ee43b3fbd935412e8e7720440ffbae1c395b23eeac74b0c32190d4db9d6ea6974d308b6659e4ef050ed3953de1a0acab3739ab54024fd26582a24e902e
用python脚本将frame.txt转为二进制frame.h264
def hex_string_to_binary_file(hex_string, output_file):# 将十六进制字符串转换为字节binary_data = bytes.fromhex(hex_string)# 将字节数据写入到二进制文件with open(output_file, 'wb') as f:f.write(binary_data)# 读取包含十六进制字符串的文件
input_file = r'frame.txt'
output_file = r'frame.h264'with open(input_file, 'r') as f:hex_string = f.read().strip()# 调用函数进行转换
hex_string_to_binary_file(hex_string, output_file)print(f"Binary file '{output_file}' has been created.")
5、用ffmpeg解码关键帧
下面两条指令都可以
ffmpeg -f h264 -i frame.h264 -vsync 0 -vf "select=eq(n\,0)" -vsync vfr output.png
这个命令强制从输入视频中选择第一个帧,并且不处理时间戳(-vsync 0
),以避免时间戳问题。
ffmpeg -f h264 -i frame.h264 -frames:v 1 output.png
这条命令从视频流中提取一帧并保存为图像。
6、查看图像
显示正常