Click here to Skip to main content
11,489,549 members (73,073 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0
Hi All,

Is there any way to merge two video in C#.

Merging - like video 2 is appended to video 1

have tried by file appending ,FFMPEG but did not get the result.

Please provide any code which can show the way.

I am using encoder to creating the video.
Posted 11-Dec-12 23:57pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

This is possible but the two videos MUST have the same properties (frame rate, resolution...etc). If they don't, you will have to convert one of them to be compatible with the other.
I have found the following example that does this:
Merge videos[^]
Hope it is useful.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can use splicer

public static void MergeVideosWithSplicer(string outputVideoPath, string firstVideoFilePath, string secondVideoFilePath)
if (File.Exists(outputVideoPath))
using (ITimeline timeline = new DefaultTimeline())
double overlayEffectLength = 30;
// greate our default audio track

// add a video group, 32bpp, 320x240 (32bpp required to allow for an alpha channel)
IGroup videoGroup = timeline.AddVideoGroup(32, 640, 480);

// add our default video track
videoGroup.AddTrack();//.AddImage(Resources.watermark, InsertPosition.Absolute, 0, 2, 10);

// to the first audio track.
IAudioVideoClipPair firstVideoPair = timeline.AddVideoWithAudio(firstVideoFilePath);
videoGroup.AddEffect(firstVideoPair.VideoClip.Duration - (overlayEffectLength / 2), overlayEffectLength,
new EffectDefinition(StandardEffects.MirrorAndGrayscaleEffect));

IAudioVideoClipPair secondVideoPair = timeline.AddVideoWithAudio(secondVideoFilePath);

//IClip clip = videoGroup.AddTrack().AddImage(Resources.watermark, secondVideoPair.VideoClip.Offset, secondVideoPair.VideoClip.Duration + secondVideoPair.VideoClip.Offset);
//clip.StretchMode = ResizeFlags.Crop;


//using (var renderer = new AviFileRenderer(timeline, outputVideoPath /*, WindowsMediaProfiles.HighQualityVideo */ ))
using (var renderer = new WindowsMediaRenderer(timeline, outputVideoPath, WindowsMediaProfiles.HighQualityVideo))

Member 10876869 at 7-May-15 6:11am
Am getting error like this, please help me on this
Exception Details: System.Runtime.InteropServices.COMException: The parameter is incorrect.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 OriginalGriff 278
2 Maciej Los 180
3 _duDE_ 141
4 Frankie-C 135
0 Sergey Alexandrovich Kryukov 9,488
1 OriginalGriff 8,425
2 Sascha Lefèvre 3,344
3 Maciej Los 3,066
4 Richard Deeming 2,370

Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 3 Jun 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100