amymcgovern / pyparrot

Python interface for Parrot Drones
MIT License
275 stars 129 forks source link

Bebop ffmpeg vision demo not working #169

Closed Yeb02 closed 5 years ago

Yeb02 commented 5 years ago

I am trying to get pictures live from the bebop2 and followed the docs. It went well until the "Bebop ffmpeg vision demo" code. I get the following error:

(executing file "pyparrot2.py") Setting up mDNS listener since this is not a Mambo Making a browser for _arsdk-090c._udp.local. Service Bebop2-038622._arsdk-090c._udp.local. added, service info: ServiceInfo(type='_arsdk-090c._udp.local.', name='Bebop2-038622._arsdk-090c._udp.local.', addresses=[b'\xc0\xa8*\x01'], port=44444, weight=0, priority=0, server='Bebop2-038622.local.', properties={b'{"device_id":"PI040384AG6I038622"}': False}) {"d2c_port": 43210, "controller_type": "computer", "controller_name": "pyparrot", "arstream2_client_stream_port": 55004, "arstream2_client_control_port": 55005} {'status': 0, 'c2d_port': 54321, 'c2d_update_port': 51, 'c2d_user_port': 21, 'qos_mode': 0, 'arstream2_server_stream_port': 5004, 'arstream2_server_control_port': 5005} c2d_port is 54321 starting listening at Success in setting up the wifi network to the drone! 51 c:\programdata\anaconda3\lib\site-packages\pyparrot\images c:\programdata\anaconda3\lib\site-packages\pyparrot\utils removing all the old images Opening ffmpeg ffmpeg -protocolwhitelist "file,rtp,udp" -i c:\programdata\anaconda3\lib\site-packages\pyparrot\utils/bebop.sdp -r 30 image%03d.png starting vision thread Opening non-blocking readers 'ffmpeg' isn't recognized as an internal command Traceback (most recent call last): File "C:\Users\alpha\Desktop\Informatique\TIPE\pyparrot\pyparrot2.py", line 36, in success = bebopVision.open_video() File "c:\programdata\anaconda3\lib\site-packages\pyparrot\DroneVision.py", line 146, in open_video line_str = line.decode("utf-8") UnicodeDecodeError: 'utf-8' codec can't decode byte 0x82 in position 27: invalid start byte timeout - trying again timeout - trying again timeout - trying again

and it keeps looping on "timeout - trying again"

What did I do wrong ? Btw, is there any command that only takes and sends pictures without starting a video stream ? Thanks,

amymcgovern commented 5 years ago

No, there is not a photo command for the bebop. Did you install ffmpeg? That's the error I see.

Yeb02 commented 5 years ago

I did it twice to be sure, once with pip and then with the official website. But nothing changes. Is this error related to the file's path (directory names) ? https://stackoverflow.com/questions/22216076/unicodedecodeerror-utf8-codec-cant-decode-byte-0xa5-in-position-0-invalid-s Shall I edit the pyparrot code this way ?

amymcgovern commented 5 years ago

The error is here:

'ffmpeg' isn't recognized as an internal command

amymcgovern commented 5 years ago

NOT the utf error. ffmpeg never starts! You need it to be in your python path somehow.

Yeb02 commented 5 years ago

Thank you it finally worked ! The issue was with the ffmpeg release, that had to be zeranoe's.

Yeb02 commented 5 years ago

Well I've had another problem (using windows 10):

[h264 @ 00000187c327ccc0] decode_slice_header error [h264 @ 00000187c327ccc0] Frame num change from 1242 to 1247

and

[h264 @ 00000187c327ccc0] decode_slice_header error [h264 @ 00000187c327ccc0] non-existing PPS 0 referenced

are looping in the shell. Ive seen this problem in previous comments but it didnt seem to be solved.

(loops shorten) full error message:

Setting up mDNS listener since this is not a Mambo Making a browser for _arsdk-090c._udp.local. Service Bebop2-038622._arsdk-090c._udp.local. added, service info: ServiceInfo(type='_arsdk-090c._udp.local.', name='Bebop2-038622._arsdk-090c._udp.local.', addresses=[b'\xc0\xa8*\x01'], port=44444, weight=0, priority=0, server='Bebop2-038622.local.', properties={b'{"device_id":"PI040384AG6I038622"}': False}) {"d2c_port": 43210, "controller_type": "computer", "controller_name": "pyparrot", "arstream2_client_stream_port": 55004, "arstream2_client_control_port": 55005} {'status': 0, 'c2d_port': 54321, 'c2d_update_port': 51, 'c2d_user_port': 21, 'qos_mode': 0, 'arstream2_server_stream_port': 5004, 'arstream2_server_control_port': 5005} c2d_port is 54321 starting listening at Success in setting up the wifi network to the drone! 51 c:\programdata\anaconda3\lib\site-packages\pyparrot\images c:\programdata\anaconda3\lib\site-packages\pyparrot\utils removing all the old images Opening ffmpeg ffmpeg -protocolwhitelist "file,rtp,udp" -i c:\programdata\anaconda3\lib\site-packages\pyparrot\utils/bebop.sdp -r 30 image%03d.png starting vision thread Opening non-blocking readers ffmpeg version 4.2 Copyright (c) 2000-2019 the FFmpeg developers built with gcc 9.1.1 (GCC) 20190807 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libdav1d --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth --enable-libopenmpt libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat 58. 29.100 / 58. 29.100 libavdevice 58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc 55. 5.100 / 55. 5.100 [udp @ 00000187c327e540] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required) [udp @ 00000187c328e840] 'circular_buffer_size' option was set but it is not supported on this build (pthread support is required) [h264 @ 00000187c327ccc0] SPS unavailable in decode_picture_timing [h264 @ 00000187c327ccc0] non-existing PPS 0 referenced [h264 @ 00000187c327ccc0] SPS unavailable in decode_picture_timing [h264 @ 00000187c327ccc0] non-existing PPS 0 referenced [h264 @ 00000187c327ccc0] decode_slice_header error .............. [h264 @ 00000187c327ccc0] decode_slice_header error [h264 @ 00000187c327ccc0] no frame! [sdp @ 00000187c3269080] max delay reached. need to consume packet [sdp @ 00000187c3269080] RTP: missed 352 packets [h264 @ 00000187c327ccc0] SPS unavailable in decode_picture_timing [h264 @ 00000187c327ccc0] non-existing PPS 0 referenced ............ [h264 @ 00000187c327ccc0] decode_slice_header error [h264 @ 00000187c327ccc0] non-existing PPS 0 referenced [h264 @ 00000187c327ccc0] decode_slice_header error [h264 @ 00000187c327ccc0] no frame! [h264 @ 00000187c327ccc0] SPS unavailable in decode_picture_timing [h264 @ 00000187c327ccc0] non-existing PPS 0 referenced [h264 @ 00000187c327ccc0] SPS unavailable in decode_picture_timing [h264 @ 00000187c327ccc0] non-existing PPS 0 referenced ........... [h264 @ 00000187c327ccc0] non-existing PPS 0 referenced [h264 @ 00000187c327ccc0] decode_slice_header error [h264 @ 00000187c327ccc0] no frame! [h264 @ 00000187c327ccc0] SPS unavailable in decode_picture_timing [h264 @ 00000187c327ccc0] non-existing PPS 0 referenced [h264 @ 00000187c327ccc0] SPS unavailable in decode_picture_timing [h264 @ 00000187c327ccc0] non-existing PPS 0 referenced ......... [h264 @ 00000187c327ccc0] decode_slice_header error [h264 @ 00000187c327ccc0] no frame! [sdp @ 00000187c3269080] max delay reached. need to consume packet [sdp @ 00000187c3269080] RTP: missed 329 packets [h264 @ 00000187c327ccc0] out of range intra chroma pred mode [h264 @ 00000187c327ccc0] error while decoding MB 22 16 [h264 @ 00000187c327ccc0] Frame num change from 1242 to 1247 ......... [h264 @ 00000187c327ccc0] Frame num change from 1242 to 1247 [h264 @ 00000187c327ccc0] decode_slice_header error [h264 @ 00000187c327ccc0] Frame num change from 1242 to 1247 [h264 @ 00000187c327ccc0] decode_slice_header error [h264 @ 00000187c327ccc0] concealing 2347 DC, 2347 AC, 2347 MV errors in P frame [sdp @ 00000187c3269080] max delay reached. need to consume packet [sdp @ 00000187c3269080] RTP: missed 790 packets [h264 @ 00000187c327ccc0] concealing 1360 DC, 1360 AC, 1360 MV errors in P frame [sdp @ 00000187c3269080] max delay reached. need to consume packet [sdp @ 00000187c3269080] RTP: missed 666 packets [h264 @ 00000187c327ccc0] concealing 640 DC, 640 AC, 640 MV errors in P frame timeout - trying again Input #0, sdp, from 'c:\programdata\anaconda3\lib\site-packages\pyparrot\utils/bebop.sdp': Duration: N/A, start: 4.671333, bitrate: N/A Stream #0:0: Video: h264 (Constrained Baseline), yuv420p(progressive), 1280x720, 23.98 fps, 23.98 tbr, 90k tbn, 47.95 tbc Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> png (native)) Vision successfully started! Fly me around by hand! timeout - trying again Moving the camera using velocity timeout - trying again timeout - trying again timeout - trying again timeout - trying again timeout - trying again timeout - trying again Finishing demo and stopping vision Killing the ffmpeg subprocess Sending a second kill call to the ffmpeg process timeout - trying again disconnecting

According to stack overflow :

That just means that ffmpeg has not seen a keyframe yet, which carries SPS and PPS information. SPS and PPS are crucial in decoding an incoming frame/slice. Keyframes are sent periodically(i.e. every 5-10 seconds or more); so if turns out that you joined a stream before the keyframe arrived; you will see this warning for every frame until a keyframe shows up. As soon as the keyframe shows up from the wire, ffmpeg will have enough information to decode that frame(and any subsequent frames until the next keyframe), so those warnings will go away.

But the stream ran for 30 secs and never gets the needed SPS. WHat can I do to solve this ? Thank you,

amymcgovern commented 5 years ago

ffmpeg prints out a LOT of messages. And sometimes it takes awhile to get a keyframe. I'd say just be patient. They are sent every 5-10 seconds and I've seen the stream take ~20 to start sometimes. Since you are on a bebop, the best thing is to move to 5Ghz if your laptop supports it. It drops a LOT less frames than 2Ghz.