我试图让我的脚本每5分钟运行一次。
* / 5 * * * * /home/pi/script.sh
我的脚本包含一个C ++程序,用于捕获视频5秒钟,然后将其保存到文件夹并使用ncftp
将其发送到服务器:
#!/ usr / bin / bash / env hbcxx#!/ usr / bin / bash ./ca1 ncftpput -R -v -u" user" -p"密码" 192.168.0.119 / folder / video /
我的视频录制程序是:
string intToString(int number){
std::stringstream ss;
ss << number;
return ss.str();
}
int main(int argc, char* argv[]){
string nama_directory= "video";
int status_D = system("mkdir video" );
bool recording = false;
bool startNewRecording = true;
int inc = 0;
int i = 0;
bool firstRun = true;
bool still = true;
VideoCapture cap(0); // open the video camera no. 0
VideoWriter oVideoWriter;//create videoWriter object, not initialized yet
// if not success, exit program
if (!cap.isOpened()){
cout << "ERROR: Cannot open the video file" << endl;
return -1;
}
namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
double dWidth = cap.get(CV_CAP_PROP_FRAME_WIDTH); //get the width of frames of the video
double dHeight = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //get the height of frames of the video
cout << "Frame Size = " << dWidth << "x" << dHeight << endl;
//set framesize for use with videoWriter
Size frameSize(static_cast<int>(dWidth), static_cast<int>(dHeight));
//clock_t start = clock(), diff;
while (inc<6){
int fps = 0;
while (still) {
if(startNewRecording){
//initialize the VideoWriter object
oVideoWriter = VideoWriter("/home/pi/video/" +
intToString(inc) +
".avi",
CV_FOURCC('D', 'I', 'V', 'X'),
5, frameSize, true);
recording = true;
startNewRecording = false;
cout<<"New video file created MyVideo"+intToString(inc)+".avi "<<endl;
//if not initialize the VideoWriter successfully, exit the program
if ( !oVideoWriter.isOpened() ) {
cout << "ERROR: Failed to initialize video writing" << endl; getchar();
return -1;
}
}
Mat frame;
bool bSuccess = cap.read(frame); // read a new frame from video
//if not success, break loop
if (!bSuccess) {
cout << "ERROR: Cannot read a frame from video file" << endl;
break;
}
//if we're in recording mode, write to file
if(recording){
oVideoWriter.write(frame);
fps++;
//show "REC" in top left corner in red
//be sure to do this AFTER you write to the file so that "REC" doesn't show up
//on the recorded video.
putText(frame,"REC",Point(0,60),2,2,Scalar(0,0,255),2);
}
imshow("MyVideo", frame); //show the frame in "MyVideo" window
if(fps>50){
still=false;
}
} // end of second while
still = true;
startNewRecording = true;
inc++;
} // end of first while
return 0;
}
问题是cron
只是制作目录,但不能制作任何文件avi
。
我做错了什么?
注意:如果只运行它可以运行的脚本。
P.S。:抱歉我的英语不好。