C# 从 WMV 中提取特定帧

发布于 2024-11-13 09:52:13 字数 322 浏览 1 评论 0原文

代码项目上的这个示例几乎正是我所需要的......除了< code>saveFrameFromVideo 采用百分比而不是帧编号...

我如何使用它从 WMV 文件中提取帧 X?

我也尝试过FFmpeg.NET...但是没有任何可下载的版本,我无法'没有得到构建的源代码...

This example on Code Project is almost exactly what I need... except the saveFrameFromVideo takes a percentage instead of a frame number...

How can I use this to extract frame X from a WMV file?

I've also tried FFmpeg.NET... but there weren't any downloadable builds, and I couldn't get the source to build...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

夜光 2024-11-20 09:52:13

您还可以尝试 AsfMojo 来完成此任务,它允许您通过以下方式提取图像时间偏移:

Bitmap bitmap = AsfImage.FromFile(videoFileName)
                        .AtOffset(17.34);

在内部,Media SDK 和一些自定义流操作用于获取帧精确的静止帧(最多 100 毫秒的容差),因此如果您知道媒体文件的帧速率(即 25),您可以计算时间偏移最近的帧:

int frameX = 400; //get 400th frame
double frameRate = 25.0;
double timeOffset = frameX / frameRate;

Bitmap bitmap = AsfImage.FromFile(videoFileName)
                        .AtOffset(timeOffset);

You can also try AsfMojo for this task, it allows you to extract an image by time offset:

Bitmap bitmap = AsfImage.FromFile(videoFileName)
                        .AtOffset(17.34);

Internally the Media SDK and some custom stream manipulation is used to get frame accurate still frames (up to a 100 millisecond tolerance), so if you know the frame rate of your media file (i.e. 25) you can calculate the time offset of the nearest frame:

int frameX = 400; //get 400th frame
double frameRate = 25.0;
double timeOffset = frameX / frameRate;

Bitmap bitmap = AsfImage.FromFile(videoFileName)
                        .AtOffset(timeOffset);
尤怨 2024-11-20 09:52:13

神奇之处在于这一行:

mediaDet.WriteBitmapBits(streamLength * percentagePosition, 
                    target.Width, target.Height, outputBitmapFile);

它根据流的百分比和长度计算帧数。由于您已经知道帧编号,因此请使用它。

The magic is in this line:

mediaDet.WriteBitmapBits(streamLength * percentagePosition, 
                    target.Width, target.Height, outputBitmapFile);

It's calculating the frame number from the percentage and the length of the stream. Since you already know the frame number, use that instead.

有深☉意 2024-11-20 09:52:13

我一直致力于从网络摄像头视频和视频文件中提取帧 - 对于这两者,我使用了 AForge 库 - (您需要添加对 AForge.Video、AForge.Imaging、AForge.Video.Directshow 和 AForge.Video.FFMPEG 的引用) 。对于直播视频,我添加了 videoSourcePlayer_NewFrame(object sender, ref Bitmap image) 来获取帧 - 位图图像包含位图类型中所需的帧。这基本上是我在 Windows 窗体中添加的视频源播放器的事件处理程序。
对于文件中的视频,我使用了:
videoSource=new FileVideoSource(文件名);
视频源.Start();
videoSource.NewFrame += new AForge.Video.NewFrameEventHandler(videoSource_NewFrame);

videoSource_NewFrame 是出现新帧时的事件处理程序。

I have been working on extracting frames from webcam videos and video files- for both, i used the AForge library- (you need to add references to AForge.Video, AForge.Imaging , AForge.Video.Directshow and AForge.Video.FFMPEG). For live videos, I added a videoSourcePlayer_NewFrame(object sender, ref Bitmap image) to get the frame- Bitmap image contains the required frame in type Bitmap. This is basically the event handler for the videosource player i added in the windows form.
For video from a file, i used:
videoSource=new FileVideoSoource(fileName);
videoSource.Start();
videoSource.NewFrame += new AForge.Video.NewFrameEventHandler(videoSource_NewFrame);

videoSource_NewFrame is the event handler in case there is a new frame.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文