AR.Drone 2,ffmpeg avcodec_decode_video2()分段错误

时间:2014-03-04 01:36:45

标签: c++ ffmpeg segmentation-fault video-streaming libavcodec

我一直试图从AR.Drone 2.0(http://ardrone2.parrot.com/)解码视频流一段时间但没有成功。尽管我一直密切关注几个例子(我粘贴链接,但我不允许)我无法逃避ffmpeg libavcodec库中的分段错误。我想也许我在我正在构建的多线程结构中犯了一些错误,所以除了你需要连接到无人机的最小值,从无人机收集一个帧,并将其发送到ffmpeg之外,我删除了所有内容。 avcodec_decode_video2()函数。

我编译了ffmpeg源代码(我实际上尝试了三个不同版本!)并且可以使用ffplay实用程序来显示无人机的视频TCP流。该视频显着滞后,但至少我知道无人机并没有给我完全的胡言乱语。

之前有没有人遇到这样的问题?可能导致此分段错误的原因,我该怎么办呢?有没有办法隔离ffmpeg上的测试,以便我可以确定它是库,而不是我一直在做的事情?

感谢您的时间。

我的代码的pastebin: http://pastebin.com/NYTf0NeT

关于我的ffmpeg和编译器设置的一些细节:

ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers
  built on Mar  3 2014 18:05:42 with gcc 4.8 (Ubuntu 4.8.1-2ubuntu1~12.04)
  configuration: 
  libavutil      52. 66.100 / 52. 66.100
  libavcodec     55. 52.102 / 55. 52.102
  libavformat    55. 33.100 / 55. 33.100
  libavdevice    55. 10.100 / 55. 10.100
  libavfilter     4.  2.100 /  4.  2.100
  libswscale      2.  5.101 /  2.  5.101
  libswresample   0. 18.100 /  0. 18.100

我的代码输出和分段错误的回溯:

*********************** START ***********************



booting...

[h264 @ 0x604040] err{or,}_recognition separate: 1; 1

[h264 @ 0x604040] err{or,}_recognition combined: 1; 1

[h264 @ 0x604040] Unsupported bit depth: 0

asked for 40000 bytes, received packet of 1448 bytes

PaVE synchronized. YIPEEEEEEEEEEEEEEEEEEEEEEEE



---------------------------

Codec : H264

StreamID : 1 

Timestamp : 1031517 ms

Encoded dims : 640 x 368

Display dims : 640 x 360

Header size : 76

Payload size : 17583

Size of SPS inside payload : 14

Size of PPS inside payload : 10

Slices in the frame : 1

Frame Type / Number : IDR-Frame : 31467 : slide 1/1

---------------------------




gathering payload...

asked for 16211 bytes, received packet of 1448 bytes

gathering payload...

asked for 14763 bytes, received packet of 1448 bytes

gathering payload...

asked for 13315 bytes, received packet of 1448 bytes

gathering payload...

asked for 11867 bytes, received packet of 1448 bytes

gathering payload...

asked for 10419 bytes, received packet of 1448 bytes

gathering payload...

asked for 8971 bytes, received packet of 1448 bytes

gathering payload...

asked for 7523 bytes, received packet of 1448 bytes

gathering payload...

asked for 6075 bytes, received packet of 1448 bytes

gathering payload...

asked for 4627 bytes, received packet of 1448 bytes

gathering payload...

asked for 3179 bytes, received packet of 1448 bytes

gathering payload...

asked for 1731 bytes, received packet of 1448 bytes

gathering payload...

asked for 283 bytes, received packet of 283 bytes

payload complete, attempting to decode frame




Program received signal SIGSEGV, Segmentation fault.

0x00007ffff73fccba in ?? () from /usr/lib/x86_64-linux-gnu/libavcodec.so.53

(gdb) bt

#0  0x00007ffff73fccba in ?? () from /usr/lib/x86_64-linux-gnu/libavcodec.so.53

#1  0x00007ffff73fd8f5 in avcodec_decode_video2 () from /usr/lib/x86_64-linux-gnu/libavcodec.so.53

#2  0x000000000040159f in fetch_and_decode(int, parrot_video_encapsulation_t, AVCodecContext*, AVFrame*)

    ()

#3  0x00000000004019c6 in main ()

编辑:我使用Valgrind试图更好地了解seg故障,并收到以下信息:

==4730== Invalid read of size 1
==4730==    at 0x5265CBA: ??? (in /usr/lib/x86_64-linux-gnu/libavcodec.so.53.35.0)
==4730==    by 0x52668F4: avcodec_decode_video2 (in /usr/lib/x86_64-linux-gnu/libavcodec.so.53.35.0)
==4730==    by 0x40140E: fetch_and_decode(int, AVCodecContext*, AVFrame*) (main.cpp:176)
==4730==    by 0x401757: main (main.cpp:273)
==4730==  Address 0x280056c46f9 is not stack'd, malloc'd or (recently) free'd
==4730== 
==4730== 
==4730== Process terminating with default action of signal 11 (SIGSEGV)
==4730==  Access not within mapped region at address 0x280056C46F9
==4730==    at 0x5265CBA: ??? (in /usr/lib/x86_64-linux-gnu/libavcodec.so.53.35.0)
==4730==    by 0x52668F4: avcodec_decode_video2 (in /usr/lib/x86_64-linux-gnu/libavcodec.so.53.35.0)
==4730==    by 0x40140E: fetch_and_decode(int, AVCodecContext*, AVFrame*) (main.cpp:176)
==4730==    by 0x401757: main (main.cpp:273)

“读取大小无效1”是指尝试访问数组边界外的字节。这是否意味着库试图访问我给它的数组范围之外的东西?我检查了AVPkt,这似乎很好。我还是难过!

1 个答案:

答案 0 :(得分:0)

我最终想出来了。需要注意的关键是回溯中的特定FFMPEG共享库文件。这不是新的,手动编译的源代码库版本。我没有正确链接到更新的文件,而是链接到Ubuntu上的任何默认值。

修复此问题需要重新编译FFMPEG并确保我已正确链接到正确的共享库。

还有一些其他内存问题,但没有任何分类。我解决了一些较小的问题并将结果粘贴在这里: http://pastebin.com/rLEKB5Va

这可以正确捕捉并显示视频。