使用V4L2在Android上捕获视频时,得到的所有数据0 [英] get all 0 data when capture video using v4l2 on android

查看:401
本文介绍了使用V4L2在Android上捕获视频时,得到的所有数据0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图捕捉视频在Android上使用V4L2下JNI。我发现了一些指导,遵循如下步骤:

i am trying to capture video on android using v4l2 under jni. i found some guide and followed the step:

fd = open("/dev/video0", O_RDWR);

/* init part */
ioctl(fd, VIDIOC_QUERYCAP, &caps);
ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc);
ioctl(fd, VIDIOC_S_FMT, &fmt);
ioctl(fd, VIDIOC_REQBUFS, &req);
ioctl(fd, VIDIOC_QUERYBUF, &buf);
ioctl(fd, VIDIOC_QBUF, &buf);

/* capture part */
FILE *fp = fopen("/sdcard/img.yuv", "wb");
for (i = 0; i < 20; i++)
{
    ioctl(fd, VIDIOC_DQBUF, &buf);
    fwrite(buffers[buf.index].start, 1, buf.bytesused, fp);
    ioctl(fd, VIDIOC_QBUF, &buf);
}
fclose(fp);

这是我的code的主要结构。所有的正常运行,但返回0的功能,当我打开二进制查看器输出文件中,我发现,所有数据都是0。

this is the main structure of my code. all the function run correctly and return 0. however, when i open the output file with binary viewer, i found that all the data is 0.

在那里与我的code什么问题?我糊涂了,因为所有的函数返回0。

is there any problem with my code? i got confused because all the functions returned 0.

谢谢!

推荐答案

您使用的是所谓的缓冲区[]数组。但我不能看到它的声明或代表的一切。如果没有code上述失踪,你总是会得到0使得你正在写缓冲区[]的文件,而不是从你得到V4L2东西。
更进一步,帽子,fmtdesc,格式化,REQ和BUF的ioctl命令前的初始值将是有趣了。根据他们的inital的价值观,你将有不同的通信接口。问题可能隐藏在这些部分。

You are using an array called buffers[]. But I can't see where it's declared or what it stands for. If there is no code missing above, you will always get zeros cause you are writing buffer[] to the file and not the stuff you get from v4l2. Further more, the initial values of caps, fmtdesc, fmt, req and buf prior to the ioctl command would be interesting too. Depending on their inital values, you will have different communication interfaces. Issues could be hidden in these parts.

当你在你的问题中写道,所有的ioctl命令将返回0,应该没有错误。如果一切按预期运行。检查问题的另一种方法是调用

As you wrote in your question, all ioctl commands would return 0, there should be no error. If everything behaves as expected. Another way to check for issues is calling

perror("<your comment or hint to line above>");

每个ioctl命令后。这将打印您提供上STD-出错误的详细信息。 (可当我应该使用这个线程找到有关PERROR更多的细节 - PERROR( &QUOT; ...&QUOT;)和fprintf(标准错误,&QUOT; ...&QUOT;)

after each ioctl command. This would print you more information about errors on your std-out. ( more details about perror can be found in this thread when I should use - perror("...") and fprintf(stderr, "..."))

您想从摄像机的图像?在部分Android设备上的相机具有通过使用其他设备驱动程序之外videoXY复杂的程序启动(您在上面采用的是背凸轮某些手机video0的)。并尝试而官方相机​​应用程序正在运行可能难以从video0的获取图像。这位官员V4L2 API说:

Are you trying to get the images from the camera? (on some phones video0 you used above is the back cam) On some android devices the camera has to be started by complex procedure using other device drivers besides videoXY. And trying to get the images from video0 while the official camera app is running might be difficult. The official v4l2 api says:

v412驱动不应支持多个应用读或复制缓冲剂,时间复用或类似装置写一个设备对相同的数据流。这是更好地在用户空间的代理应用程序处理。

V4L2 drivers should not support multiple applications reading or writing the same data stream on a device by copying buffers, time multiplexing or similar means. This is better handled by a proxy application in user space.

来源: http://linuxtv.org/downloads/v4l- DVB-的API / common.html#idp18553208

您可以发布更多(详细)code?我也许能帮助,因为我做的非常相似的东西。

Can you post more (detailed) code? I might be able to help, as I'm doing very similar stuff.

要能够重现它,这将是非常有趣的与Android设备你的工作(类型/型号/ Android版本)。

To be able to reproduce it, it would be very interesting with which android device you are working (type / model number / android version).

这篇关于使用V4L2在Android上捕获视频时,得到的所有数据0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆