Tag Archives: merge

Ubuntu Terminal: How to Join the Parts of a Split AVI Video File CodeUnit 09 MAY 2011

Sometimes you will encounter files that have been split into segments in order to make them more manageable for either download or fixed size media transfer purposes. For example, a common method for doing this on Windows is to make use of the excellent dinosaur (in other words, it appears to have been available on PCs since the dawn of the computing age) application, HJ Split, which neatly chops any files fed to it into nice little manageable chunks of bits.

But now the question arises: say you encounter a AVI video file that you have downloaded all the segments for, but now want to put everything together via your Ubuntu desktop in order to view the full video. How will we do it?

Well a remarkably simple way is to open up a standard terminal window and then concatenate all the pieces together with the bog-standard cat command:

cat video1.avi.001 video1.wmv.002 video1.avi.003 > video1.avi

This should result in a fully watchable, complete AVI video file.

However, this process can sometimes cause the video and audio to fall slightly out of synch. One way of dealing with this is to use the clever little mplayer/memcoder application bundle.

First, install with:

sudo apt-get install mencoder mplayer

Now, force a audio/video resynch with:

mencoder -forceidx -oac copy -ovc copy video1.avi  video1-fixed.avi

This should work on a couple of other formats as well, such as MPG or MPEG video files for example.

Nifty.

PHP: Merge Two Arrays but Keep Their Keys Intact CodeUnit 03 SEP 2010

Combining two or more arrays whilst keeping their keys intact in PHP is deceptively simple – though not if you assume you need to use a function like array_merge to achieve this!

As you scroll through the various array functions available to you, you will notice that quite a few seem to drop the array keys after they are done, which is pretty useless if all you want to do is basically add two arrays to one another to form one big keyed array.

So how do you do this then?

Simple really. Just literally add them together!

$resultarr = $array1 + $array2;

And just in case you are wondering what the hell is going on, remember that when applied to arrays, the + acts as a union operator.

Nice!

PHPExcel: How to Merge Cells CodeUnit 09 JUL 2010

PHPExcel is a phenomenal Excel generating library for PHP which I have mentioned on this site numerous times before, and which is currently my defacto way for quickly knocking out all those annoying Excel downloads that clients always seem to MUST have!

Today’s quick code hint deals with how one sets about merging a cell range using PHPExcell. Unfortunately for me though, the solution is so simple that this will only take one line of my time! :P

So what is the solution then?

Well PHPExcel features a nifty little function named mergeCells, and feeding it a range results in that range being merged into one great big cell.

Nifty.

In code it would look a little something like this:

$workbook = new PHPExcel;
$sheet = $workbook->getActiveSheet();
$sheet->setCellValue('A1','A pretty long sentence that deserves to be in a merged cell');
$sheet->mergeCells('A1:C1');
$writer = new PHPExcel_Writer_Excel5($workbook);
header('Content-type: application/vnd.ms-excel');
$writer->save('php://output');

And there you go, as simple as that!

Related Link: http://phpexcel.codeplex.com