Click here to Skip to main content
12,826,676 members (32,016 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# 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 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170326.1 | Last Updated 3 Jun 2013
Copyright © CodeProject, 1999-2017
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