How to use media compositions and editing in WinFrom App project?

john zyd 421 Reputation points
2021-10-13T21:40:49.327+00:00

Hello:

I found Microsoft has some package for Media Editing, from this URL:
https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/media-compositions-and-editing

However, I need to run a WinForm project to merge some video files. I am using Windows 10 (Version 21H1), my IDE is Visual Studio 2019 (Version 16.11.5)
For example, I have two MP4 files: C:\Videos\1.mp4 and C:\Videos\2.mp4, each of them has the same resolution with its own audio.
I want to merge them into one file: C:\Videos\3.mp4, 1.mp4 at the beginning of the merged video with its own audio, and 2.mp4 being the ending of the merged video with its own audio.
I can use FFMPEG, but it has issue with merged video, the merged video didn’t keep both video and audio, I lost either the first audio or the second video.
Since I have to use SQL Server database, so I need some C# code only in WinForm App, not the UWP project.
Please share some C# code, so I can merge 1.mp4 and 2.mp4 to generate 3.mp4, in which both video and audio inside are kept the same.
Thanks,

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,249 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,726 Reputation points
    2021-10-13T23:18:16.893+00:00

    In Winforms, you must add references to :

    C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd
    C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETCore\v4.5\System.Runtime.WindowsRuntime.dll

    then you can access MediaComposition :

    140353-mediacomposition.jpg


0 additional answers

Sort by: Most helpful