Take the 2-minute tour ×

I have a set of binary file chunks from a video file. They are partly overlapping.

To exemplify say that the video file binary data can be represented like this:




is a header.

The chunks can be represented like this (simplified because there are some differences in the header part for each chunk):

chunk 1: "---ABCD"
chunk 2: "---DEFG"
chunk 3: "---GHIJ"
chunk 4: "---JKLM"

I need a command line tool that merges these files. It should take the end part of chunk 1, search chunk 2 for that pattern, join chunk 1 to the part of chunk 2 from pattern to end (ignoring all data in chunk 2 before the pattern start).

Then repeat the operation for all remaining chunks until we have the complete video file.

share|improve this question

2 Answers 2

If you know the length of the header (---) and the length of each segment (A, B, C, etc) you could use head and tail commands. If such lengths vary from file to file then you are looking at a substring search problem (search the biggest substring in chunk 2 appearing in chunk 1). You might be able to automate it with awk or else with Python.

To get an answer to that, you might want to ask in stackoverflow. Nevertheless, if you only have one video stream you want to join, I agree with Brian Fenton.

share|improve this answer

I would just use a good binary editor and do it by hand.

share|improve this answer

Your Answer


