FFmpeg进度跟踪 [英] FFmpeg progress tracking

查看:261
本文介绍了FFmpeg进度跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

在我的主要流程中,我使用CreateProcess(...)创建ffmpeg子流程.
我需要跟踪转换进度的状态以更新进度栏.为此,我从ffmpeg输出中读取文本并从中提取进度状态.

我制作了一个这样的示例程序:

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:

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);



但是我无法交互地更新result.我的应用在转换过程中被保留,并且result string仅在ffmpeg的处理完成后才更新.

如何使我的主进程和ffmpeg的进程同时运行,并以交互方式读取/写入ffmpeg进程的输出/输入?


感谢您的宝贵时间!

QUy



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

推荐答案

处理此问题的方法是将GUI和读取的文件放在不同的线程中,只要有更新,就使用PostMessage()将更新发送到您的GUI线程,然后将其显示在窗口中.这样,两个线程之间就不会阻塞.
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.


这篇关于FFmpeg进度跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆