You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

UWP中如何保存视频StorageFile的System.Media.DateEncoded属性?

关于UWP中保存System.Media.DateEncoded到MP4/MOV文件的问题

首先直接给结论:UWP的StorageFile.Properties.SavePropertiesAsync API确实不支持直接写入System.Media.DateEncoded属性到MP4、MOV这类视频文件,这就是你遇到“The method or operation is not implemented”异常的核心原因。

为什么读取正常但写入失败?

读取操作能成功,是因为系统可以从MP4/MOV的元数据结构中解析出System.Media.DateEncoded对应的值;但写入时,这类视频文件采用QuickTime/ISO BMFF这类特定的元数据容器格式,通用的SavePropertiesAsync API并没有实现针对该属性的写入逻辑——它无法正确将你设置的DateTimeOffset值映射到底层文件的对应元数据标签中,因此抛出未实现的异常。

可行的替代方案

你可以使用专门针对视频文件的VideoProperties类来修改DateEncoded属性,这个类已经针对MP4/MOV等主流视频格式做了适配,能正确处理元数据的读写:

public async Task<bool> SaveDateEncoded(StorageFile file) {
    try {
        // 获取视频文件的专属属性操作对象
        var videoProperties = await file.Properties.GetVideoPropertiesAsync();
        var targetDateTime = new DateTimeOffset(2000, 09, 03, 3, 50, 13, new TimeSpan(2, 0, 0));
        // 设置目标编码日期
        videoProperties.DateEncoded = targetDateTime;
        // 保存修改到文件
        await videoProperties.SavePropertiesAsync();
        return true;
    } catch (Exception ex) {
        // 可根据需求添加异常日志或用户提示逻辑
        return false;
    }
}

补充说明

如果你的场景需要更复杂的元数据操作(比如自定义私有标签),可能需要借助Windows.Media.Editing命名空间下的API,或者第三方的视频元数据处理库,但对于修改DateEncoded这类标准属性,VideoProperties已经足够满足需求。

内容的提问来源于stack exchange,提问作者Octopus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 14:02:48