#include #include #include using namespace std; int main(){ //准备缓冲区 char* buffer = new char[1024](); char* info = new char[10240](); uint32_t bytesRead=0, readCount=0; //转码命令行 string command = "ffmpeg -ss 0 -t 3 -i -vcodec libx264 -s 640x360 -y 2>&1 "; //注意:Linux系统下要修改绝对路径 //打开管道 #ifdef WIN32 FILE *pPipe = _popen(command.c_str(), "r"); #else FILE *pPipe = popen(command.c_str(), "r"); #endif if (!pPipe) { printf( "popen failed!\n"); return -1; } //循环读取ffmepg的输出信息 while (true) { bytesRead = fread(buffer, 1, 1024, pPipe); if (bytesRead == 0) { break; } memcpy(info + readCount, buffer, bytesRead); readCount += bytesRead; } //转码完成,打印输出信息 printf("finished,ok, readCount=%d!\n", readCount); printf("Console out:%s!\n", info); //释放缓冲区,关闭管道 if(buffer){ delete [] buffer; buffer = NULL; } if(info){ delete [] info; info = NULL; } #ifdef WIN32 _pclose(pPipe); #else pclose(pPipe); #endif return 0; }