澳门银河网上官方赌场_老品牌值得信赖

ITKeyword,专注技术干货聚合推荐

注册 | 登录

解决c# - Show progress of a video conversion with FFMpeg

itPublisher 分享于

2021腾讯云限时秒杀,爆款1核2G云服务器298元/3年!(领取2860元代金券),
地址https://cloud.tencent.com/act/cps/redirect?redirect=1062

2021阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址https://www.aliyun.com/minisite/goods

I'm using C# WinForms to make a video converter, I'm using NReco.VideoConverter library. It has an EventHandler named ConvertProgress but I have never used EventHandlers, I was searching for some information on internet, but I still don't know how to apply it to my application.

I tried this:

public static event EventHandler<ConvertProgressEventArgs> _getPercent;
//...
_getPercent += ???
progressBar1.Value = ??

I'm stuck there, and I don't know what to do. Can someone help me?? Thanks in advance.

c# ffmpeg progress-bar encoder video-conversion
edited Feb 26 '15 at 22:45 BradleyDotNET 41.3k 8 48 73 asked Feb 24 '15 at 23:59 ChrisCreateBoss 123 9

 | 

1 Answers
1

解决方法

First off, get rid of your custom event. You want to listen/subscribe to their event, not yours.

Second, you need an actual instance of your converter, then subscribe to its event:

FFMpegConverter converter = new FFMpegConverter(); //May not work, for sample only
converter.ConvertProgress += UpdateProgress;

Now you need a method called UpdateProgress (you could also just use a lambda expression above):

private void UpdateProgress(object sender, ConvertProgressEventArgs e)
{
}

And in the body of that method, update your progress bar. Note that you need to marshal your change onto the UI thread. In Windows Forms that's done with Control.Invoke

progressBar1.Invoke(new Action(() =>
{
     progressBar1.Value = e.Processed; //Or whatever calculation you want
}));

For others, and if you haven't seen it, here's the documentation for that event: http://www.nrecosite.com/doc/NReco.VideoConverter/html/E_NReco_VideoConverter_FFMpegConverter_ConvertProgress.htm


edited Feb 26 '15 at 23:18 answered Feb 26 '15 at 22:41 BradleyDotNET 41.3k 8 48 73      Yes I saw the online documetation, but honestly, I didn't know what to do :P... –  ChrisCreateBoss Feb 26 '15 at 22:53      @ChrisCreateBoss Yeah, unless you are familiar with events, its not much help :) FFMpeg documentation is good, but they don't have much in the way of "Usage" examples :( –  BradleyDotNET Feb 26 '15 at 22:54      Yeah that's true... Otherwise, how do I convert your e.Processed to an integer(progressBar.Value needs an integer value to work). –  ChrisCreateBoss Feb 26 '15 at 22:58      @ChrisCreateBoss There's another property on that event "TotalDuration". You would divide by that (to get the percent complete as a double) and scale it for your progress bar –  BradleyDotNET Feb 26 '15 at 22:59      tried that but I still get "cannot implicity convert type TimeSpan to int" –  ChrisCreateBoss Feb 26 '15 at 23:07  |  show more comments


相关阅读排行


相关内容推荐

最新文章

×

×

请激活账号

为了能正常使用评论、编辑功能及以后陆续为用户提供的其他产品,请激活账号。

您的注册邮箱: 修改

重新发送激活邮件 进入我的邮箱

如果您没有收到激活邮件,请注意检查垃圾箱。

澳门银河网上官方赌场