I am attempting to capture the output of an ffmpeg command to a text file using command line args:
ffmpeg.exe -i d:\testing\ValidFLV.flv 2>d:\testing\outPut.txt

Command works like a charm when executed from cmd prompt.

Within a C++ app I am Creating a Process to execute this command line and although CreateProcess "succeeds" the text file is not created and GetLastError() returns 5 which is AccessDenied. Other operations executed in this same manner work such as converting flv to asf and vice-a-versa. As well as pulling frames from a flv and/or asf movie. Even though the requested actions are completed and images and/or movie files are created GetLastError() returns 5. I am wondering if ffmpeg is having issues writing to stdout/stderr. I attempted to use _popen to pipe output directly to app and this doesn't work either nor does reading from stdout/stderr.

I am using WindowsServer2003 and this is a back office app that runs locally. No network access is required. Files and their subsequent output are stored locally.
Am compiling app with Visual Studio 2005.

code snipet:

bool ExecFFMPEG( )
{
	bool bRet = true;
	STARTUPINFO si;
	PROCESS_INFORMATION pi;
	si.cb = sizeof(STARTUPINFO);
	si.lpReserved = NULL;
	si.lpReserved2 = NULL;
	si.cbReserved2 = 0;
	si.lpTitle = NULL;
	si.lpDesktop = NULL;
	si.dwFlags = STARTF_USESHOWWINDOW;

	SECURITY_ATTRIBUTES sa;
	sa.bInheritHandle = TRUE;
	sa.lpSecurityDescriptor = NULL;
	sa.nLength = sizeof(SECURITY_ATTRIBUTES);

	char cComm[128];
	strcpy_s( cComm, 512, "ffmpeg.exe -i d:\testing\ValidFLV.flv 2> d:\testing\Logout.txt");
	if( CreateProcess(NULL, cComm, &sa, &sa, TRUE, CREATE_PRESERVE_CODE_AUTHZ_LEVEL|HIGH_PRIORITY_CLASS, NULL, NULL, &si, &pi) != 0 )
		WaitForSingleObject(pi.hProcess, INFINITE);
	else
		bRet = false;
		
	int ex = 0;
	TerminateProcess(pi.hProcess, ex); 
	CloseHandle(pi.hThread);
	CloseHandle(pi.hProcess);
	
	if( bRet )
	{	
		int nErr = GetLastError();

		if( nErr == 0 && _access_s("d:\testing\Logout.txt", 0) == 0 )
		{
			...
			...
		}
	}
	return bRet;
}

This may be more of a VS05 question than an FFMPEG issue but I don't have this problem when shelling other apps
THanks

Comments

cesareof’s picture

Assigned: cesareof » Unassigned
cesareof’s picture

I figured away around it so I guess this issue can be considered solved, although I still believe that ffmpeg is having issues writing out to stdout/stderr, because although the following is a solution for me it still can not read output from the standard streams made available in the c++ language.

bool GetFLVInfo( )
{
	bool bRet = false;
	char cComm[MAX_STRING_MEDIUM];
	char cOutput[MAX_STRING_EXTRALARGE];
	char cLogFile[MAX_PATH];
	char cDuration[MAX_STRING_TINY];
	FILE *pPipe = 0;
		
	DurationInSec = 0 ;
	cDuration[0] = NULL;

	strcpy_s( cLogFile, MAX_PATH, "d:\\SomeTest\\LogOut.txt"); 
	sprintf_s( cComm, 512, "ffmpeg.exe -i d:\\SomeTest\\Movie.flv 2> %s", cLogFile);
	if(cComm[0] )	
	{
		pPipe = _popen( cComm, "rt");
		int i = 0;
		while( i < 2056 )	
		{
			char cBuf[256];
			cBuf[0] = NULL;
			if( fgets(cBuf, 256, pPipe) == NULL)	
				break;
			i += sprintf_s( cOutput + i, 2056 - i, "%s", cBuf); 
		}
		_pclose(pPipe);
	}

	if( _access_s(cLogFile, 0) == 0 )
	{
		...	...
		bRet = true;
	}
	return bRet; 
}