Click here to Skip to main content
15,895,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all

In my main process, i create a ffmpeg child process using CreateProcess(...).
I need to track the status of converting progress to update a progress bar. To do it, I read text from ffmpeg output and extract progress status from it.

I make a sample programm like this:

MIDL
HANDLE rPipe, wPipe;
CreatePipe(&rPipe,&wPipe,&secattr,0);

STARTUPINFO sInfo; 
ZeroMemory(&sInfo,sizeof(sInfo));
PROCESS_INFORMATION pInfo; 
ZeroMemory(&pInfo,sizeof(pInfo));
sInfo.cb=sizeof(sInfo);
sInfo.dwFlags=STARTF_USESTDHANDLES;
sInfo.hStdInput=NULL; 
sInfo.hStdOutput=wPipe; 
sInfo.hStdError=wPipe;

// pStr contain ffmpeg command
CreateProcess(0,(LPTSTR)pStr,0,0,TRUE,NORMAL_PRIORITY_CLASS|CREATE_NO_WINDOW,0,0,&sInfo,&pInfo);
CloseHandle(wPipe);

BOOL ok;
do
{
    memset(buf,0,bufsize);
    ok=::ReadFile(rPipe,buf,100,&reDword,0);
    result += buf;            
}while(ok);


But I couldnt get result interactively updated. My app is held during conversion, and result string update only after ffmpeg's process finish.

How can I have my main process and ffmpeg's run simultaneously, and interactively read from/write to ffmpeg process's output/input?


Thanks for your time!

QUy
Posted
Updated 11-Jul-11 16:47pm
v2

1 solution

The way to handle this would be to have the GUI and the read file in different threads, whenever there's an update, use PostMessage() to send an update to your GUI thread and let it display to the window. That way there's no blocking between either thread.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900