Concatenate multiple PDF files into one PDF file

For this purpose we need ghostscript, but basically this software comes pre-installed in most linux distribution.

So to concatenate multiple PDFs (file1.pdf, file2.pdf, file3.pdf), into one file (output.pdf), simply run this:

$ gs -q -sPAPERSIZE=a4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=output.pdf file1pdf file2.pdf file3.pdf

Yes, it’s a long command, I know. To change the output paper size we can replace “a4” with “legal” for US Legal or “letter” for US Letter.

Advertisements

Join/Merge Multiple mp4 Files Into One File Without Re-Encoding

Install GPAC first, easily from ubuntu repository:
$ sudo apt-get install gpac

Then using one of GPAC’s tool, named MP4Box, we can join or merge multiple mp4 files by concatenating into one file. With concatenating we save a huge amount of processing time which is usually spent for rendering/re-encoding.
$ MP4Box -cat file1.mp4 -cat file2.mp4 -cat file3.mp4 OutputFile.mp4

Getting IP and MAC Address from BASH/Shell Script

Ever wondered how to get your IP address and MAC address and then use it in a Linux shell script? Here’s how:

#!/bin/sh
# showIPandMAC.sh

IP=$(ip addr show wlan0 | awk '/inet / {print $2}' | cut -d/ -f 1)
MAC=$(ip link show wlan0 | awk '/ether/ {print $2}')

echo "IP Address: $IP"
echo "MAC Address: $MAC"

# EndOfFile

You can change the wlan0 into whatever device you have, e.g. eth0.

Convert Multiple Images Into PDF in Ubuntu Linux

First of all make sure you have imagemagick installed, otherwise checking won’t hurt:
$ sudo apt-get install imagemagick

Then in this case, I would like to join multiple image files of scanned documents with sortable file names (e.g. file01.jpg, file02.jpg, etc.). Finally to join those files together in A4 PDF format we do this in terminal:
$ convert -page A4+0+0 file* OutputFile.pdf

Looping Through Files with Spaces and Special Characters in BASH

This is useful for batch processing of files with special characters such as space, ampersand (&), underscore, etc. The example below is to do mass conversion of mp4 files I downloaded from youtube into mp3 files.

Instead of giving the command directly, I prefer always to “echo” the command so I can see whether it’s giving the desired batch command or not. If all okay, then remove the echo.

$ find ./ -type f | sed 's/.mp4//' | sed 's/\.\///' | while read FILE;
do
echo ffmpeg -i \"$FILE.mp4\" -ab 192k \"$FILE.mp3\";
done

But the with the above script, somehow ffmpeg won’t accept the filenames – although I already put quote in both end. Strange enough, if I give the command directly for example:
$ ffmpeg -i "Some file (3_11)_.mp4"
It works.

Let’s just focus on getting the job done shall we? The easiest workaround is by redirecting the output of the script above into a file by putting
> batch.sh
in the end of the script (right after “done”). So the batch file will look like this:

ffmpeg -i "Chaka Khan _ I'm Every Woman _(360p_H.264-AAC).mp4" -ab 192k "Chaka Khan _ I'm Every Woman _(360p_H.264-AAC).mp3"
ffmpeg -i "David Foster _ Winter Games _(360p_H.264-AAC).mp4" -ab 192k "David Foster _ Winter Games _(360p_H.264-AAC).mp3"
ffmpeg -i "Earth, Wind & Fire (3_11) - Fantasy(360p_H.264-AAC).mp4" -ab 192k "Earth, Wind & Fire (3_11) - Fantasy(360p_H.264-AAC).mp3"
ffmpeg -i "Earth, Wind & Fire (4_11) - Sing a song(360p_H.264-AAC).mp4" -ab 192k "Earth, Wind & Fire (4_11) - Sing a song(360p_H.264-AAC).mp3"

Then make the file executable
$ chmod +x batch.sh
and run it
$ ./batch.sh

Using Android as Wireless Mouse

Just a quick post as my personal documentation.

Use PRemoteDroid

Download the JAVA-based server.

Then you can connect to your phone using WiFi if both phone and laptop are on the same network. For connection via bluetooth under Ubuntu, first you have to download/install these files using apt-get:
– libbluetooth-dev
– bluez

Don’t forget to switch on the bluetooth before starting the server! Then the server should start quietly without long outputs.

Combining Multiple PDF Files Into One PDF File in Linux

This post is inspired (and 68% taken) from here. 😀

There are times when you need to combine multiple PDF files into one single PDF file. In Windows or Mac, it’s easy (as long as you are willing to spend some amount of money to buy the software), you can use Adobe Acrobat Professional. Sadly Adobe didn’t come up with Acrobat Professional for Linux platform, but luckily we have several options to do such job in a Linux box. Here’s one.

GhostScript is an interpreter for PostScript language and PDF files, and as far as I know, GhostScript is widely available by default on various Linux distro. In this post I will show you a simple trick to use GhostScript to combine any numbers of PDF files into one single PDF file. Although combining files with GhostScript has its own drawbacks, but still, for most purposes GhostScript does the job well.

Here’s the voodoo mantra, spell them on Linux terminal:
$ gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=finished.pdf file1.pdf file2.pdf ...

And below is the explanation of each mantra:

  • gs
    The GhostScript program.
  • -dBATCH
    tells the program to exit after finishing the job.
  • -dNOPAUSE
    tells the program to keep going without having conversation with the user.
  • -sDEVICE=pdfwrite
    tells the program to use its internal PDF writer to process the files.
  • -sOutputFile=finished.pdf
    tells the program where to put those scattered PDF files into one file whom name you specified.
  • file1.pdf file2.pdf …
    tells the program which PDFs you want to combine.

Tada, now you have combined PDF file, ready to brought anywhere without worry leaving one part behind.

Convert (Any?) Video to PSP video format on linux

Hello.

FFMPEG is a linux based application which is also a solution in streaming and converting almost any audio and video format. That includes video format for gadget or handheld device such as mobile phone video (3gp), iPod, and PSP.

In this writing I will try to elaborate my findings about video conversion, although for now this is still incomplete.

Okay, here’s a simple trick to convert video file into PSP video format, so that the video can be playable on PSP:
$ ffmpeg -i INPUTVIDEO -f psp -r 29.97 -b 512k -ar 24000 -ab 64k -s 320x240 M4V00001.MP4

Then you’ll have M4V00001.MP4, copy that into your PSP. Several articles point out that PSP only reckon video files which follow this file naming rule (M4VXXXXX.mp4). I actually haven’t tried this out because of my PSP is still somewhere on my sister’s room. I’ll update this post as soon as I found the thing.

If the command above doesn’t work (error unsupported codec for output stream), try install this package http://packages.medibuntu.org/lucid/libavcodec-extra-52.html

Or check out these links about converting video into PSP video format:
http://www.ffmpeg.org/faq.html#SEC22
http://brainwagon.org/2005/12/25/using-ffmpeg-to-make-psp-video/
http://opensource.telkomspeedy.com/wiki/index.php/Konversi_Video_untuk_PSP (In Indonesian Language)
http://txt.binnyva.com/2008/08/linux-command-to-convert-a-video-to-psps-mp4-format/

Broadcom BCM4312 Wireless Issues on Ubuntu

Today I was installing Ubuntu Lucid Lynx on my friend’s notebook, a Compaq Presario CQ20. Installation process ran smooth. After reaching desktop, with wireless already switched on, the stupid computer can’t find any wireless network.

It’s been a long time I never had a ubuntu fresh install with devices that doesn’t work. Since Ubuntu Karmic, usually all my installations is “just works”, all devices works just like that.

Okay, enough with the chit chat, let’s get this done fast. Simple googling for the notebook’s spec gives me information about which wireless chipset used by the notebook. It’s a Broadcom BCM4312. Another simple googling with keyword “broadcom bcm4312 ubuntu” leads me to another tutorial about resolving broadcom wireless issue.

The official solution is provided by the vendor here, which is great. But sadly they only provide the source code tarball, no pre-compiled package listed there. Lazily I extract the tarball, then *sigh*, read the manual. Quick read-skip-read takes me to part about steps to install from pre-compiled package, hurray.. Here’s how:

First of all, you have to make sure you have the right device to troubleshoot, by using this command:
$ lspci -vnn | grep 14e4

If you have the right wireless device, then command above should give output more or less like this:
02:00.0 Network controller [0280]: Broadcom Corporation BCM4312 802.11b/g [14e4:4315] (rev 01)
Subsystem: Broadcom Corporation Device [14e4:04b5]

Afterwards, download these packages from other ubuntu system by using apt-get --download-only install PACKAGENAME:

  • patch
  • dkms
  • bcmwl-kernel-source

If you don’t have other ubuntu system which connected to repository server, you can browse for that packages on repository server. But because I don’t have much thing to do, let me do the browsing:

patch for 32bit ubuntu
dkms for all ubuntu
bcmwl for 32bit ubuntu

Click on the link above to download.

Then transfer those files to the target notebook using flash drive or anything.

Last step is calling the mighty dpkg:

$ sudo dpkg -i patch_2.6-2ubuntu1_i386.deb
$ sudo dpkg -i dkms_2.1.1.2-3fakesync1_all.deb
$ sudo dpkg -i bcmwl-modaliases_5.60.48.36+bdcom-0ubuntu3_i386.deb

The process is a bit lengthy, especially when installing bcmwl-kernel-source package, so be patient and keep hoping you don’t crash your notebook.

When the installation finished, reboot, and stay hopeful that you don’t crash your notebook. If reboot success, check wireless access points with network manager applet on upper right of the desktop. If there’s wireless network detected, then voila, you are done.

Tiled Multiple GNOME Terminal

2015 update:

  • now I use the more superior Terminator.
  • I am now aware of tiling window manager (i3, awesome, etc.).

When I do stuff with Linux, 68% of them are terminal/shell work. And most of them needs many tty/terminals at once. In Ubuntu, or generally in GNOME Desktop Manager, arranging multiple terminal layout every time you need it can be such a pain in the ass. Here’s a simple shortcut to open multiple gnome-terminal with arranged (tiled) position:

#!/bin/sh
#

gnome-terminal –geometry=157×22+0+670 &
gnome-terminal –geometry=80×20+700 &
gnome-terminal –geometry=100×20+0 &

You can save the script into a file, and put it in $PATH directory. For example:

/usr/local/bin/multiterm

Then change the file mode bits to make that executable:

$ sudo chmod 755 /usr/local/bin/multiterm

And here is what it looks like

Multiple tiled GNOME Terminal

Multiple tiled gnome-terminal

For the sake of simplicity and ease of access, you can put a shortcut on the GNOME panel to launch the script with a single click of the mouse.