UWP Sample: MediaEditing
Das Universal Windows Platform Sample Media Editing zeigt
folgende Möglichkeiten, wie man unter UWP ein Video bearbeiten kann:
1)
Trimmen
2)
Anfügen zweier Videos
3)
Audio hinterlegen
4)
Zwei Videos überlagern
Die Sample-Dateien zu C# findet man unter:
Windows-universal-samples-master\Samples\MediaEditing\cs
Man startet immer mit der Microsoft Visual Studio Solution
mit der Endung .sln
Beim Start und Öffnen der Solution:
Als erstest muss man das Zielsystem anpassen von ARM auf x64
Dann kann man unter Lokaler Computer (hier Device) das Windows
Universal Sample auf einem Desktop PC ausführen
Beim Ersten Start des Samples MediaEditing beginnt das
Beispiel wie hier dargestellt
Man muss unter 1) Trimming and saving a clip eine Video
auswählen bei 1. Choose a Video
Unter Choose Video kann man ein .mp4 Video auswählen
Andere Dateitypen von Videos sind nicht möglich und werden
auch nicht angezeigt wie zum Beispiel die .mov Video-Formate die unter Olympus
produziert werden
1)
Trimming and
Saving a Clip
Nach dem Laden kann man es zum Beispiel Trimmen
Dabei wird das Video von 2:29 auf die Hälfte gekürzt
Und anschliessend speichern
2)
Appending multiple Clips
Beim zweiten Sample kann man zwei Videos aneinander
verknüpfen
Dadurch erhält man ein neues Video mit der neuen Gesamtlänge
3)
Adding Background Audio Tracks
Im dritten Beispiel kann man Audio Samples in den
Hintergrund legen.
Möglich sind mp3, wav und flac Dateien
4)
Adding Overlay to a clip
Hier kann man zwei Videos mit einander
überlagern
Quelle:
Man findet das Universal Sample Media Editing unter
https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/MediaEditing
Inhalt:
This sample shows how to use the APIs in the Windows.Media.Editing namespace
to edit and compose media clips. The tasks demonstrated in these scenarios
include opening, trimming, and saving videos, appending multiple video clips
together into a single composition, adding background audio, and using overlays
to composite videos.
Details
/ Beschreibung der Samples:
Scenario 1: Trim and Save Clip:
Press the Choose Video button to launch a file open picker
that allows you to choose a video file to open. Press the Trim Video button
to trim 25% of the videos duration from the beginning and end of the clip .
Press play on the video controls to view the trimmed video clip. Press the Save
Result button to launch a file save picker that allows you to choose a
location and file name with which to save the trimmed video clip.
In the code behind, when the file open
picker is launched and a file is selected, the file is assigned to a MediaElementdefined
in the XAML file with a call to using the SetSource to make it
viewable in the UI.
When the Trim Video button
is pressed, a new MediaClip object is created from the video
file with a call toMediaClip.CreateFromFileAsync. The TrimTimeFromStart and TrimTimeFromEnd methods
of the MediaClip class are called to trim the duration of the
clip. Next, a new MediaComposition object is created and the
trimmed clip is appended to the composition's Clips collection.
A MediaStreamSource is created using the MediaComposition methodGeneratePreviewMediaStreamSource and
then the MediaElement* method **SetMediaStreamSource to make
the composition viewable in the UI.
When the Save Result button
is pressed, a FileSavePicker is created to allow the user to
pick a destination file. TheMediaComposition method RenderToFileAsync saves
the composition to the selected file.
Scenario 2: Append Clips:
Press the Choose First Video button to launch a file open
picker that allows you to choose a video file to open. Press theChoose
Second Video button to select a second video. Press the Append
Videos button to append the videos together into a single composition.
Press play on the video controls to view the trimmed appended clips.
In the code behind, when each file
picker is launched, the resulting file is assigned to the MediaElement defined
in the XAML file with the SetSource method, to make the video
files viewable in the UI. When the Append Videos button is
pressed, a new MediaClip object is created for each of the
video files. Next, a new MediaComposition object is created
and each media clip is added to the composition's Clips collection.
Finally, a MediaStreamSource is created using theMediaComposition method GeneratePreviewMediaStreamSource and
then the MediaElement methodSetMediaStreamSource is
called to make the composition is viewable in the UI.
Scenario 3: Add Audio Tracks
Press the Choose Video button to launch a file open picker
that allows you to choose a video file to open. Press the Add
Background Audio button to launch a file open picker that allows you
to choose a audio file to open. Press play on the video controls to view the
video clip with the added background audio.
In the code behind, when the file open
picker is launched and a video file is selected, the file is assigned to a MediaElementdefined
in the XAML file with a call to using the SetSource. When the Add
Background Audio button is pressed, a newMediaClip is
created from the selected video file, a new MediaComposition is
created, and the MediaClip is added to the composition's Clips collection.
Next the file picker for the audio file is launched. When the file picker
returns, a newBackgroundAudioTrack is created from the selected
audio file by calling CreateFromFileAsync. TheBackgroundAudioTrack is
added to the composition's BackgroundAudioTracks collection.
Finally, a MediaStreamSource is created using the MediaComposition method GeneratePreviewMediaStreamSource and
then the MediaElement methodSetMediaStreamSource is
called to make the composition viewable in the UI.
Scenario 4: Add Overlays Press the Choose
Base Video button to launch a file open picker that allows you to
choose a video file to open. Press the Choose Overlay Video button
to select a second video. Press play on the video controls to view the
overlayed video clip.
In the code behind, when each file
picker is launched, the resulting file is assigned to the MediaElement defined
in the XAML file with the SetSource method, to make the clips
viewable in the UI. To create the overlay, first a new MediaClip is
created from the base video clip, a new MediaComposition is
created, and the base media clip is added to the composition's Clipscollection.
Next, a new MediaClip is created for the overlay video clip.
The GetVideoEncodingProperties method is called to get
information about the format of the clip. A Rect to specify
the placement of the overlay is created, using the encoding properties to make
sure the aspect ratio of the clip is preserved. Next, a MediaOverlay object
is created from the clip. ThePosition of the overlay is set using
the Rect structure and the Opacity of the
overlay is set to 75%. A new OverlayLayer is created, and the MediaOverlay is
added to its Overlays collection. Next the OverlayLayer is
added to the composition'sOverlayLayers collection. Finally, a MediaStreamSource is
created using the MediaComposition methodGeneratePreviewMediaStreamSource and
then the MediaElement method SetMediaStreamSource is
called to make the composition viewable in the UI.