C#:直接调用 OpenFileDialog

C# 直接调用 OpenFileDialog,打开文件夹,选择视频文件,并播放。

编写 openvideo.cs 如下

cs 复制代码
// open a video file
using System;
using System.Diagnostics;
using System.Windows.Forms;
 
public class OpenVideoFile
{
    [STAThread]
    public static void Main()
    {
        OpenFileDialog ofd = new OpenFileDialog();
 
        // 设置对话框属性
        ofd.Title = "请选择Video文件";
        // 设置初始目录
        ofd.InitialDirectory = "D:\\VIDEO";
        // 设置文件过滤器
        ofd.Filter = "avi files (*.avi)|*.avi|All files (*.*)|*.*";
        ofd.FilterIndex = 1; // 设置默认的文件过滤器索引
        ofd.RestoreDirectory = true; // 设置在关闭对话框前还原目录
 
        if (ofd.ShowDialog() == DialogResult.OK) // 显示对话框
        {
            // 获取选中的文件路径
            string filePath = ofd.FileName;
            ProcessStartInfo startInfo = new ProcessStartInfo("D:\\FFModules\\Encoder\\mplayer.exe");
            startInfo.Arguments = " -aspect 4:3 " +filePath;
            startInfo.UseShellExecute = false;
        
            Process process = Process.Start(startInfo);
            process.WaitForExit();
        } else {
            Console.WriteLine("Select null");
        }
    }
}

where csc

C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe

编译 csc /r:System.Windows.Forms.dll /target:winexe openvideo.cs

运行 openvideo

如果你的PC安装了【 格式工厂】这个应用软件,那么实际安装了Windows版的 FFmpeg

在D:\FormatFactory\FFModules\Encoder\ 能找到 mplayer.exe 和 ffmpeg.exe

这里谈谈 mplayer 简单应用:mplayer -h

  1. 播放比例调整

mplayer -aspect 16:9 <videofile>

mplayer -aspect 4:3 <videofile>

  1. 控制热键

基本播放

→     前进10秒

←     后退10秒

↑     前进60秒

↓     后退60秒

PageUP  前进10分钟

PageDown 后退10分钟

Enter   全屏开关

Space   暂停开关

Esc    退出

q     退出

相关推荐
魔法阵维护师17 分钟前
从零开发游戏需要学习的c#模块,第十二章(rpg小游戏入门,中篇,金币收集与ui显示)
学习·游戏·c#
魔法阵维护师22 分钟前
从零开发游戏需要学习的c#模块,第十九章(在游戏画面里显示文字 —— FontStashSharp)
学习·游戏·c#
sinat_367104561 小时前
WPF 常用控件
c#·xaml·控件·wfp
Artech1 小时前
[对比学习LangChain和MAF-03]完全不同的Agent设计哲学
python·ai·langchain·c#·agent·maf
xiaoshuaishuai82 小时前
C# CUDA 到 OpenCL 迁移
开发语言·windows·c#
richard_yuu2 小时前
C#开发全景概述:从零读懂C#的定位、优势与完整技术体系
开发语言·c#
Xin_ye100862 小时前
C# 零基础到精通教程 - 第十二章:异常处理与调试——让程序更健壮
开发语言·c#
楼田莉子2 小时前
C#学习之C#入门学习
开发语言·后端·学习·c#
小钻风33662 小时前
从零入门 Kafka:Java 原生 API 到 Spring Boot 实战全解析
c#·linq
唐青枫2 小时前
C#.NET YARP + OpenTelemetry:网关链路追踪实战
c#·.net