I am working on a program that allows to assemble to merge several video files into one and run as a whole. I have tried finding on the internet but all I can find is merging text files, I am wondering if it is possible to merge video files in python.

Recommended Answers

All 4 Replies

Not a python question.

In general a file is a stream of bytes. You merge two files by reading them one after the another and writing them.
fo=open("outfile","wb")
fo.write(open("infile1").read())
fo.write(open("infile2").read())
fo.close()

Thats the general part of it.

However a file is interpreted by a program. A videofile is interpreted by a videoplayer. If infile1 and infile2 can be interpreted that does not mean neccesarily that the abovewise merged file can be interpreted, too. There can be magic numbers at the beginning and the end of the file, which give commands to the interpreter.

So you have to find a tool that can do that for you.
Google for: mplayer merge video files

commented: true +13

But I need to write the codes for enabling it to merge several video files together. Are you saying that I need an external source for it?

If simply appending the two files - as mentioned in my general part - does not solve your problem, then yes. You should find a utility or a library that does that for you.
If you do the google search you will find mencoder quickly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.