我们的机型是M300, 保存下来的视频流是 H264 GDR码流格式, ffplay能播放但是也有花屏现象, 然后...
Completed-
关于保存H264花屏的问题,可以参考下述论坛帖: https://sdk-forum.dji.net/hc/zh-cn/articles/900005866646-OSDK%E8%8E%B7%E5%8F%96M300-H20-%E8%A7%86%E9%A2%91%E8%A7%A3%E7%A0%81%E8%8A%B1%E5%B1%8F%E9%97%AE%E9%A2%98%E8%AE%A8%E8%AE%BA 若是使用最新的ffmpeg库,直接使用OSDK sample可能存在不兼容的问题,可以对应修改sample代码(解码相关代码文件:dji_camera_stream_decoder.cpp)。若直接使用sample,ffmpeg版本是2.8.15 -
ffmpeg版本2.8.15 Windows版本网上已经找不到接入库。
直接使用OSDK sample可能存在不兼容的问题,可以对应修改sample代码(解码相关代码文件:dji_camera_stream_decoder.cpp)
我当前是用
ffmpeg_init();
const char * filepath = "D:/dji/H264View-001.h264";
errno_t err = fopen_s(&fp_in, filepath, "rb");
printf("fopen_s %d\n" , err);
if (err != 0)
{
printf("Could not open input stream\n");
return -1;
}
// while (!feof(fp_in)) {
// }
// printf(" cur_size %d\n", cur_size);
//cur_size = fread(in_buffer, 1, in_buffer_size, fp_in
// printf(" cur_size %d\n", cur_size);
int frameNum = 0;while (1){
if (!pCodecParserCtx || !pCodecCtx) {
//DSTATUS("Invalid decoder ctx.");
printf("Invalid decoder ctx");
break;
}
// printf("1 cur_size %d\n", cur_size);
cur_size = fread(in_buffer, 1, in_buffer_size, fp_in);
// printf("=========cur_size %d\n", cur_size);
if (cur_size == 0)
break;AVPacket* packet;
packet = av_packet_alloc();
cur_ptr = in_buffer;while (cur_size > 0)
{
int len = av_parser_parse2(pCodecParserCtx, pCodecCtx,
&packet->data, &packet->size,
cur_ptr, cur_size,
AV_NOPTS_VALUE, AV_NOPTS_VALUE, AV_NOPTS_VALUE);
cur_ptr += len;
cur_size -= len;
if (packet->size == 0)
continue;int gotPicture = -1;
// avcodec_decode_video2(pCodecCtx, pFrameYUV, &gotPicture, &packet);
int ret = avcodec_send_packet(pCodecCtx, packet);
if (ret != 0)
{
// printf("======%s/n", "error");
break;
}
gotPicture = avcodec_receive_frame(pCodecCtx, pFrameYUV); //got_picture = 0 success, a frame was returnedif (!gotPicture)
{
//DSTATUS_PRIVATE("Got Frame, but no picture\n");
continue;
}else
{
// printf("avcodec_send_packet ret: %d ", ret);
printf("--------------------------Got Frame %d ", gotPicture);
int w = pFrameYUV->width;
int h = pFrameYUV->height;
printf("++++++++++++++++++++++++++++++gotPicture w: %d ,h: %d", w, h);
}}av_packet_free(&packet);
}也是解析不出来。 提示出错
[h264 @ 000002222b679140] non-existing PPS 0 referenced
--------------------------Got Frame -11 ++++++++++++++++++++++++++++++gotPicture w: 0 ,h: 0[h264 @ 000002222b679140] SEI type 1 size 1040 truncated at 848
[h264 @ 000002222b679140] non-existing PPS 0 referenced
[h264 @ 000002222b68b440] non-existing PPS 0 referenced
[h264 @ 000002222b68b440] decode_slice_header error
[h264 @ 000002222b68b440] no frame!
--------------------------Got Frame -11 ++++++++++++++++++++++++++++++gotPicture w: 0 ,h: 0[h264 @ 000002222b6a9c00] SEI type 1 size 1040 truncated at 832
[h264 @ 000002222b679140] SEI type 1 size 1040 truncated at 848
[h264 @ 000002222b6a9c00] non-existing PPS 0 referenced
[h264 @ 000002222b6a9c00] decode_slice_header error
[h264 @ 000002222b6a9c00] no frame!
[h264 @ 000002222b679140] non-existing PPS 0 referenced
--------------------------Got Frame -11 ++++++++++++++++++++++++++++++gotPicture w: 0 ,h: 0[h264 @ 000002222b6c8280] SEI type 1 size 1040 truncated at 832
[h264 @ 000002222b679140] SEI type 1 size 1040 truncated at 848
[h264 @ 000002222b679140] non-existing PPS 0 referenced
[h264 @ 000002222b6c8280] non-existing PPS 0 referenced
[h264 @ 000002222b6c8280] decode_slice_header error
[h264 @ 000002222b6c8280] no frame! -
1、这个报错解不出来,是报错没有SPS和PPS帧,实时流可能第一个获取的不是SPS/PPS,可以运行一会。其中报错: [h264 @ 000002222b679140] SEI type 1 size 1040 truncated at 848 是因为SEI帧解不出来,可以通过代码将获取视频流中的SEI帧去掉。参考代码: https://sdk-forum.dji.net/hc/zh-cn/articles/900005817486 ![](https://djisdksupport.zendesk.com/attachments/token/tUlBPwbSseQZR60yjxCFf680g/?name=inline782445943.png) 2、OSDK sample中的dji_camera_stream_decoder.cpp是ffmpeg解码的sample,可以解码H20的视频流。使用的2.8.15版本的API,若使用最新版本需要更新sample,很抱歉,OSDK暂未提供新版本的API调用sample。 3、OSDK不支持windows版本,若使用OSDK解码使用ffmpeg 2.8.15,可以ffmpeg github上获取源码编译。 https://github.com/FFmpeg/FFmpeg/tree/n2.8.15 4、OSDK是机载计算机与飞机的交互,本身不包含推流与拉流功能 -
ffplay 我们用最新版本测过都可以播放。没问题。
现在我们求助是 需要解决怎么通过 ffmpeg , 调用ffmpeg的API解码。
我们在ubuntu上编译出来的ffmpeg V2.8.15 。 我们现在使用命令行 ffmpeg -re -i /home/cck/devdata/projcodes/H264View-001.h264 -c copy -f h264 -y rtmp://192.168.1.143/live/livestream
提示错误: /home/cck/devdata/projcodes/H264View-001.h264: Invalid data found when processing input
要是这能正常执行我们再用代码去调用API解码
-
这个与版本也没有关系,GDR编码直接使用ffmpeg推流会有问题,API解码参考sample代码即可。 如果要直接推流,官方论坛提供的硬解码方案中有提供插入I帧方式,可以将其中的I帧作为获取到的H264裸流首帧。这个有试过是可以推流的,可以评估参考。 https://bbs.dji.com/thread-260759-1-1.html ![](https://djisdksupport.zendesk.com/attachments/token/wpq5BnMBdW59pZQQCdWgsiyhq/?name=inline1418910057.png) -
官方论坛提供的硬解码方案中有提供插入I帧方式, 运行时出错,会是什么原因引起, 出错内如如下:
dji@manifold2:~/Code/onboard-sdk/build/bin$ ./camera-h264-hardware-decode-sample ./UserConfig.txt
Read App ID
User Configuration read successfully.[2291673.240]ERRORLOG/1 @ initVehicle, L215: Failed to initialize Linker channel
Vehicle not initialized, exiting.
dji@manifold2:~/Code/onboard-sdk/build/bin$ ./camera-stream-
camera-stream-callback-sample camera-stream-poll-sample
dji@manifold2:~/Code/onboard-sdk/build/bin$ ./camera-stream-callback-sample ./UserConfig.txt
Please enter the type of camera stream you want to view
m: Main Camera
f: FPV Camera
m
Read App ID
User Configuration read successfully.[2291689.257]ERRORLOG/1 @ initVehicle, L215: Failed to initialize Linker channel
Segmentation fault (core dumped)
dji@manifold2:~/Code/onboard-sdk/build/bin$ ./camera-stream-callback-sample ./UserConfig.txt
Please enter the type of camera stream you want to view
m: Main Camera
f: FPV Camera
f
Read App ID
User Configuration read successfully.[2291693.305]ERRORLOG/1 @ initVehicle, L215: Failed to initialize Linker channel
Segmentation fault (core dumped)
dji@manifold2:~/Code/onboard-sdk/build/bin$ -
串口初始化失败,请检查串口配置和端口名,以及是否有串口操作权限。 ![](https://djisdksupport.zendesk.com/attachments/token/rbTDvmk6YoUHIlo6KvaW6aWPb/?name=inline-1241541216.png) -
抱歉,OSDK获取的视频流不可设置分辨率,与相机有关,获取H20相机的视频流是1080P。请问您是指解码花屏问题吗?解码花屏可能需要结合实际应用进行优化或评估使用硬解码提高性能。保存的H264使用ffplay播放也有花屏的情况,可以参考下述论坛帖: https://sdk-forum.dji.net/hc/zh-cn/articles/900005866646-OSDK%E8%8E%B7%E5%8F%96M300-H20-%E8%A7%86%E9%A2%91%E8%A7%A3%E7%A0%81%E8%8A%B1%E5%B1%8F%E9%97%AE%E9%A2%98%E8%AE%A8%E8%AE%BA
Please sign in to leave a comment.
Comments
19 comments