简体   繁体   English

具有“ int main(int argc,char ** argv)”的VideoCapture

[英]VideoCapture with “ int main(int argc, char **argv) ”

I'm trying to use VideoCapture. 我正在尝试使用VideoCapture。 a part of my code is below. 我的代码的一部分在下面。

when I run my code, I got this : 当我运行我的代码时,我得到了:

Error! 错误! Insufficient parameters provided. 提供的参数不足。

How can I use my video with this code. 如何将我的视频与此代码一起使用。 I want to open a stream with VLC. 我想用VLC打开流。 Or if is there any other way, I'd like to use. 或者,如果还有其他方法,我想使用。

I searched that argv[1] is will be my video file. 我搜索了argv [1]将是我的视频文件。 But I don't know how to show my file and how to define my file to this code. 但是我不知道如何显示我的文件以及如何为此代码定义我的文件。

To help future users, I'd make some changes: 为了帮助将来的用户,我将进行一些更改:

Was: 是:

LOG_DEBUG("Error! Insufficient parameters provided.");

Is: 是:

std::string program(argv[0]);
LOG_DEBUG("Error! Insufficient parameters provided.");
LOG_DEBUG("Please provide a command line argument.");
LOG_DEBUG("Example:  " << program << " VIDEO_FILE_NAME");

Explanation: 说明:

On the command line, when the program is invoked, the arguments from the command line are copied in the array of strings held by argv . 在命令行上,当调用程序时,命令行中的参数将复制到argv保存的字符串数组中。 argv[0] is the first argument and it is the filename of the program itself. argv[0]是第一个参数,它是程序本身的文件名。 Put another way, argv[i] for 0 <= i < argc are populated in the array of strings argv from the command line. 换句话说,从命令行在字符串argv的数组中填充0 <= i < argc argv[i] If you renamed the program executable file, argv[0] would be different the next time you ran the program. 如果重命名了程序可执行文件,则下次运行程序时argv[0]会有所不同。

The array argv is indexed from 0 to argc-1 . 数组argv0索引到argc-1 When main is invoked this array of strings and argc are set. main调用该阵列字符串和的argc的被设置。 It's up to the software to decide what to do. 这取决于软件来决定要做什么。 In this case your application tests argc and finds that if no argument is provided (ie., argc < 2) then the one user argument provided by the user is not present, report the error and return. 在这种情况下,您的应用程序将测试argc并发现,如果未提供任何参数(即argc <2),则该用户提供的一个用户参数不存在,请报告错误并返回。

Incidentally, there's yet another form of main you can use: 顺便说一句,您可以使用另一种形式的main

int main(int argc, char** argv, char** envp)

argc = number of arguments. argc =参数数量。 argv = array of argument strings envp = array of environment variable name=value pairs argv =参数字符串数组envp =环境变量名称=值对的数组

So beyond simple command line argument passing, one could choose to write the main function to grab the environment variables (not shell variables) and decide nuanced action based on that. 因此,除了传递简单的命令行参数外,人们还可以选择编写main函数来获取环境变量(而不是外壳变量),并据此决定细微的动作。 Options abound. 选项比比皆是。

But for the time being, your code would be helpful if it reported why there is an error and the suggestions provided seem to do that. 但是暂时,如果您的代码报告了为什么存在错误,并且所提供的建议似乎可以解决此问题,那么它会有所帮助。

Good luck. 祝好运。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM