c++ - Capturing H264 stream with OpenCV -


so. have been trying raspberry pi 2 capture h264 stream opencv logitech c920 quite time now. have been scavenging internet info, no luck.

a short system description:

  • raspberry pi 2, running raspbian, kernel 3.18
  • logitech hd pro webcam c920
  • opencv 2.4.11
  • bonecv - credits derek molloy (https://github.com/derekmolloy/bonecv)
  • libx264 , ffmpeg (built x264 support)
  • libv4l-dev, v4l-utils, qv4l2, v4l2ucp

i know opencv forces format bgr24 (mjpg). specified in cap_libv4l.cpp. looks this(line 692->):

  /* libv4l convert format v4l2_pix_fmt_bgr24 */   clear (capture->form);   capture->form.type                = v4l2_buf_type_video_capture;   capture->form.fmt.pix.pixelformat = v4l2_pix_fmt_bgr24;   capture->form.fmt.pix.field       = v4l2_field_any;   capture->form.fmt.pix.width = capture->width;   capture->form.fmt.pix.height = capture->height; 

i can set pixelformat manualy v4l2-ctl --set-fmt-video

pi@raspberrypi ~/bonecv$ v4l2-ctl --set-fmt-video=width=1920,height=1080,pixelformat=h264 pi@raspberrypi ~/bonecv$ v4l2-ctl --get-fmt-video format video capture:         width/height  : 1920/1080         pixel format  : 'h264'         field         : none         bytes per line: 3840         size image    : 4147200         colotspace    : srgb 

and if run "./bonecv" - simple capture program captures picture , canny edge detection. (i'll add code in end). this:

pi@raspberrypi ~/bonecv$ ./bonecv pi@raspberrypi ~/bonecv$ v4l2-ctl --get-fmt-video format video capture:         width/height  : 1920/1080         pixel format  : 'mjpg'         field         : none         bytes per line: 0         size image    : 4147200         colorspace    : srgb 

as can se "pixelformat" , "bytes per line" changes. "field" stays @ none , "colourspace" stays @ srgb. tried replace every "v4l2_pix_fmt_bgr24" "v4l2_pix_fmt_h264" in cap_lib4vl.cpp , rebuilded opencv. when ran "./bonecv" 2 .png images black 1 or 2 stripes of white color.

to find out if libv4l or opencv ran "./capture" script follow derek molloys bonecv. uses libv4l directly , captures h264 video stream no problems @ all. have use "./raw2mpg4" able watch it. .mp4 file 1920x1080 @ 30 fps no glitches. , after checked "v4l2-ctl --get-fmt-video" again , got this:

pi@raspberrypi ~/bonecv$ v4l2-ctl --get-fmt-video format video capture:         width/height  : 1920/1080         pixel format  : 'h264'         field         : none         bytes per line: 3840         size image    : 4147200         colotspace    : srgb 

exactly same when did set manualy.

i have come conclusion if want opencv able capture raw h264 streams i'll have change cap_libv4l.cpp, have no idea how. think may because difference in bits per frame and/or colorspace. do know how or how make workaround stil can use opencvs "videocapture" function?

i know alot of raspberry pi , beagleboneblack users ever gratefull if there solution problem. have tried cover think relevant, if there more provide paint picture better, please so.

her links mentioned scripts , programs: (edit. tried post links each of programs, didn't have enough reputation. go derek molloys github page , you'll find bonecv there.)

and no can not use "cv_fourcc('h','2','6','4');" because function not implemented linux yet.


Popular posts from this blog