Saturday, December 10, 2011

AVCHD in Avidemux

AVCHD is a HD movie format that is present on many consumer cameras, most notably on Panasonic TZ (SZ in America) compact series. Searching for a decent replacement for VirtualDub (Swiss army knife for video editing) for Windows I came across Avidemux. It is a nice tool but still in development stage so it has some problems with editing AVCHD movies - for example, trying to save a part of a AVCHD movie into MPEG4 format without recording (video copy, audio copy) produces corrupt movies with either sound not working or not synchronized with picture etc. But there is a solution or at least a workaround for it: replace the AVCHD container* with MPEG4v2 and the editing works as it should.

In this step FFmpeg utility comes handy - with a simple script, similar to the one mentioned in the "Batch convert MP3 bitrate on Windows using lame MP3 encoder" post we can change the container:


forfiles /m *.mts /c "cmd /c ffmpeg.exe -i @file -acodec copy -vcodec copy @file.mp4"

But be sure to have enough free disk space before starting the process. :) After the conversion you have the choice: delete the AVCHD (*.MTS) files and keep the new MPEG4 files for archiving purposes or vice versa. But be aware: FFmpeg does not support the hdmv_pgs_subtitle data stream (GPS information embedded in the video) so this information could be lost with the conversion.

*What is a container (or mux/demux)? It is a "receipt" how video and audio stream(s) are saved inside a file. So by changing the container the video and audio streams get somehow reordered inside the file but the actual content of a streams do not change. There is no recoding involved, just pure copying from source to destination file. This is a quite important because:
  1. It is fast.
  2. There is no loss in quality.

Thursday, November 24, 2011

Get signal quality from GPRS modem

A quite sophisticated bash script for getting signal quality (AT+CSQ) from GPRS modem:



#!/bin/bash


function get_response
{
        local ECHO
        # cat will read the response, then die on timeout
        cat <&5 >$TMP &
        echo "$1" >&5
        # wait for cat to die
        wait $!


        exec 6<$TMP
        read ECHO <&6
        if [ "$ECHO" != "$1" ]
        then
                exec 6<&-
                return 1
        fi


        read ECHO <&6
        read RESPONSE <&6
        exec 6<&-
        return 0
}


TMP="/tmp/response"


# Clear out old response
: > $TMP


# Set modem with timeout of 5/10 a second
stty -F /dev/ttyACM0 -echo igncr -icanon onlcr ixon min 0 time 5


# Open modem on FD 5
exec 5<>/dev/ttyACM0


get_response "AT" || echo "Bad response"
RESPONSE=`cat $TMP`
echo "Response was ${RESPONSE}"


echo


get_response "AT+CSQ" || echo "Bad response"
RESPONSE=`cat $TMP`
echo "Response was ${RESPONSE}"


exec 5<&-

Tuesday, November 15, 2011

GCC 4: error: lvalue required as increment operand

If you are compiling C code with GCC 4.x version you might receive the error:

error: lvalue required as increment operand
But the code compiled flawlessly with older versions of GCC.

The problem lies in GCC 4 which is a little more picky about the code. So we need to fix the code. Here is an example of the problematic code:
void CopyFromFrame8900(void *Dest, unsigned int Size)
{
    *((unsigned int *)Dest)++ = ReadFrame8900();
}
And the fix for it:
void CopyFromFrame8900(void *Dest, unsigned int Size)
{
    *((unsigned int *)Dest) = ReadFrame8900();
    Dest = (void *)Dest + 1;
}

Sunday, November 13, 2011

Preferred video/audio codecs in Windows

Ever tried to open a AVCHD (h264) video stream in VirtualDub? Well, it is not that simple - VirtualDub is designed for Video For Windows (VFW) interface, but AVCHD decoders work as DirectShow filters. It is like expecting an iPhone application to work on the Android phone.

The solution for the problem (opening AVCHD in VirtualDub) is to use DirectShow plugin for VirtualDub that allows you to open the video. You can get the plugin here: http://forums.virtualdub.org/index.php?act=ST&f=7&t=15093&st=0

Of course you also need an AVCHD (h264) decoder that is VirtualDub compatible (supports RGB decoded output) where Microsoft DTV-DVD Video Decoder isn't. But there are many options, FFmepeg is one of them, feel free to choose one yourself.

So you have DirectShow plugin and some RGB-compatible decoder installed but the video is still not displayed in VirtualDub. You see a green area where the actual video picture should be previewed and VirtualDub might be complaining about decoder's RGB compatibility. The problem is in the priority list of decoders that still picks MS DTV-DVD decoder. You can change this with some registry editing but there is something better - a utility for changing decoder priorities: http://www.codecguide.com/windows7_preferred_filter_tweaker.htm
The usage is straight forward so happy video editing once it works.

Monday, September 26, 2011

Check compact flash (CF) memory card integrity

Sometimes compact flash (CF) memory cards cause troubles. And you don't know if the problem is the card or the reader, maybe something else? A small utility that might come handy in that situation: http://www.thelifedigital.com/scan-the-flash-drive-for-errors-with-check-flash/
Direct link for utility download if the page above dies: http://www.mikelab.kiev.ua/PROGRAMS/ChkFlsh.zip

And may all your bits be with you!

Batch convert MP3 bitrate on Windows using lame MP3 encoder

Sometimes you have to lower the bitrate of your MP3 files to save space (on your phone memory card) or bandwidth (when sending your lecture recording to a friend). There are numerous utilities to do it the click-click way but there is also the terminal option. With the power of Linux/Unix terminal and bash this is no challenge at all but MS Windows is quite a different story. Anyway, the solution that runs inside Windows command prompt (cmd) and changes the bitrate is:

forfiles /m *.mp3 /c "cmd /c c:\lame\lame.exe @file 128\\@file"

This command converts all mp3 files (/m *.mp3) in the current directory to 128kbit (Lame default bitrate) and places the new files inside "128" directory (that you have to create yourself before running the command). For conversion, the Lame MP3 encoder located in "c:\lame\" directory is used.

Feel free to explore further command line options of Lame MP3 Encoder.

P.S.: You can also raise the bitrate this way but I don't see any good reason for doing that. ;)

Monday, September 12, 2011

Move gmail signature on top (above quoted message)

A nice trick taken from http://www.nicoleonthenet.com/488/gmail-signature-trick/
If the link dies the trick is:

  1. Log on to gmail, go to settings.
  2. Click on the "labs" tab.
  3. Enable "Signature tweaks".
That's all folks!

Thursday, August 25, 2011

Backing up NTFS partitions

The reasons for backing up your NTFS filesystem vary but the task is quite simple (if you don't use NTFS advanced features such as bitlocker or compression). You can do it with "ntfsclone" (part of ntfs-3g package) that runs on many operating systems - it is also included in System Rescue CD mentioned in earlier posts.

It's usage is quite simple: ntfsclone -s -o [output file] [input device]
The "-s" switch enables a "special format" that ignores empty space, so the output file is smaller. Without it the file is bigger (it uses sparse file function so it is not THAT big) but you can mount it as a loopback device and access its contents (you can't do that with the "special format").

You can also use compression but better have a fast processor or enough time:
ntfsclone -s -o - [input device] | pigz > [output file]
pigz is a parallel gzip compressor that uses all your CPU cores for compression and is preferred over gzip. But you can also use bzip2, xz or any other compressor that works with standard input/output.

Next article: how to restore the backed-up NTFS partition.

Tuesday, August 23, 2011

HotSwap!

Have you ever wanted to hot-swap a SATA drive in your PC but you didn't know how to turn it off safely? Or Windows didn't show your USB drive in "safely remove hardware" list?

There is a simple solution for that: HotSwap! http://mt-naka.com/hotswap/index_enu.htm
It is a very small and simple program that runs in tray and allows you to safely turn off your storage devices. Of course it is free and runs on x86 and x64 Windows platforms. It requires no installation (just run it) but you need administrative permissions to shutdown a device.

Thanks, Kazuyuki!


Monday, August 22, 2011

System Rescue CD

The Swiss army knife for PC admins. A live Linux (CD, USB etc.) distribution with lots of utilities. It is useful for deployment, backup, recovery etc. More on how to use it in the upcoming posts.

http://www.sysresccd.org/Main_Page

Sunday, August 21, 2011

Booting Windows XP on different disk controller

So you made a virtual machine from the real one with disk2vhd (see previous blog) and now you try to run it inside VirtualBox (or another virtual PC engine) but all you get is a BSOD during the boot? With the error code 7b? The problem is in the disk controller driver - the old machine had a different one that the new has. The solution is to force Windows to use "default" disk drivers. All it requires is a registry hack that is explained here: http://www.biermann.org/philipp/STOP_0x0000007B/
There is also another option if you can boot (WinPE, Winternals ERD etc.)into doomed Windows XP - replace the aaaa\ with SYSTEM\ in the merge reg file and apply it with double clicking (or import in regedit).

Create virtual PC from real computer (Windows)

There is a nice utility from Microsoft called disk2vhd (http://technet.microsoft.com/en-us/sysinternals/ee656415) that converts disk paritions (or whole disks) to VHD image files. It works for NTFS (Win XP and later) and does not require installation - just download and run. They can be later used inside VirtualBox or other virtual PC engines.