# Combine video files with different start times

**URL:** <https://forum.opencv.org/t/combine-video-files-with-different-start-times/5790>\
**Category:** Python\
**Tags:** videoio\
**Created:** [October 22, 2021, 9:36am UTC](https://forum.opencv.org/t/combine-video-files-with-different-start-times/5790 "2021-10-22T09:36:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pj1098](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/pj1098/32/3355_2.png) [@Pj1098](https://forum.opencv.org/u/Pj1098)\
**Post date:** [October 22, 2021, 9:36am UTC](https://forum.opencv.org/t/combine-video-files-with-different-start-times/5790/1 "2021-10-22T09:36:01Z")

</div>

I have multiple videos with different start times .I would like to combine these two video files into one file so that:

1. They appear next to each other and
2. That they are mixed with taking the time stamps of the start times into account.

for example if i have two videos v1 =200 sec and v2 = 100sec I want v1 play the whole time and v1 to show on the screen according to its timestamp.  
At the end i want to save the combine video into a local file.

I have just started with open cv. Any help would be appreciated  
Thanks a lot

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [October 22, 2021, 10:53am UTC](https://forum.opencv.org/t/combine-video-files-with-different-start-times/5790/3 "2021-10-22T10:53:58Z")

</div>

learn how to use ffmpeg, it was made for tasks like that

---

<div class="post-metadata">

**Author:** ![Pj1098](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/pj1098/32/3355_2.png) [@Pj1098](https://forum.opencv.org/u/Pj1098)\
**Post date:** [October 22, 2021, 11:01am UTC](https://forum.opencv.org/t/combine-video-files-with-different-start-times/5790/4 "2021-10-22T11:01:25Z")

</div>

okay I was just trying to find a way to do it using open cv

---

<div class="post-metadata">

**Author:** ![Alejandro\_Silvestri](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/alejandro_silvestri/32/357_2.png) [@Alejandro\_Silvestri](https://forum.opencv.org/u/Alejandro_Silvestri)\
**Post date:** [October 22, 2021, 1:01pm UTC](https://forum.opencv.org/t/combine-video-files-with-different-start-times/5790/5 "2021-10-22T13:01:41Z")

</div>

Hi @Pj1098

[Here is a list of tutorials about VideoCapture and VideoWriter](https://docs.opencv.org/3.3.0/df/d2c/tutorial_table_of_content_videoio.html).

Recipe:  
1- Open both videos with VideoCapture (one VideoCapture for each video)  
2- Analyse duration, frame rate, whatever you need  
3- Move to the frame where you want to start consuming de video  
4- Create a VideoWriter for your output video file

in a loop:  
1- Read one frame from each VideoCapture, you will have two Mat (two images)  
2- Combine both images into a new one in the way you like it more, don’t change its size in successive frames  
3- Write it to the VideoWriter

At the end, close all. The final video will be silent, no sound.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [October 22, 2021, 5:00pm UTC](https://forum.opencv.org/t/combine-video-files-with-different-start-times/5790/6 "2021-10-22T17:00:12Z")

</div>

I would recommend a video editing program, of the “non-linear” kind. does the job, requires no programming.

you would drag the video clips into a timeline and adjust their positions in time.

video editing programs take care of differing frame rates and all that complicated stuff.

don’t bother trying to get that done with OpenCV. it isn’t made for that. and don’t even think of “seeking” in a video with OpenCV, that’s broken in many cases.

by the way: tagging a thread as `opencv` in this forum, which _is called_ “OpenCV”, is very pointless.
