MP4Box - How to pack and unpack content

In order to make your raw H.264 files playable with vlc you should use a container such as MP4.

To pack the h.264 elementary stream into a MP4 container use:
..\MP4Box -fps 25 -add "video.h264" -new "packedvideo.mp4"

If you have audio also then use:
..\MP4Box -fps 25 -add "video.h264" -add "audio.aac" -new "packedvideo.mp4"

To unpack the video run:
..\MP4Box -raw 1 "mergedvideo.mp4" -out "video.h264"

To unpack the audio run:
..\MP4Box -raw 2 "mergedvideo.mp4" -out "audio.aac"


Convert UNIX to DOS and DOS to UNIX format using sed command

Convert DOS to UNIX
$ sed 's/$'"/`echo \\\r`/" input.txt > output.txt

Convert UNIX to DOS
$ sed 's/^M$//' input.txt > output.txt


How to redirect xargs output to individual files

How to batch execute a command to a specific set of files inside a directory and redirect the output of each run to an individual file.

ls *.264 | xargs -t -I{} sh -c "./ldecod.exe -i '{}' -o /dev/null > 'out{}.txt'"

The first ls *.264 will list all .264 files and pipe them to xargs which will execute the ./ldecod.exe replacing '{}' by each element from the ls *.264


Removing file extensions under linux

When scripting something that uses input files and output other files with a different extension we often want to keep the filename and change only the extension.
To accomplish this SED can be used as described:

echo test.txt.264 | sed 's/\.[^.]*$//'

This replaces any characters after the last dot of the filename.



Linux Set Date and Time From the Command Line

You must login as root user to use date command.

Linux Set Date

Use the following syntax to set new data and time:
date set="STRING"

For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
# date -s "2 OCT 2006 18:00:00"
# date set="2 OCT 2006 18:00:00"

You can also simplify format using following syntax:
# date +%Y%m%d -s "20081128"

Linux Set Time

To set time use the following syntax:
# date +%T -s "10:13:13"

  • 10: Hour (hh)
  • 13: Minute (mm)
  • 30: Second (ss)

Use %p locale’s equivalent of either AMhttp://www.cyberciti.biz/faq/howto-set-date-time-from-linux-command-prompt/ or PM, enter:
# date +%T%p -s "6:10:30AM"
# date +%T%p -s "12:10:30PM"

source: http://www.cyberciti.biz/faq/howto-set-date-time-from-linux-command-prompt/


How to do SCP without following symbolic links

SCP is a powerful tool to copy content between computers.
If you have a specific set of files that you use over and over again in different folders, using symbolic links (or hard links) is clever method to save storage.
This is where SCP becomes less appropriate to sync folders. SCP follows symbolic links and copies N copies of the same files instead of keeping the symbolic link. As a result, and if the linked files are big, syncing becomes slow an definitely not efficient.

To overcome this problem I found that rsync is recommended because it keeps symbolic links as they were. Here is the example:
rsync -azuv -e ssh username@xx.xx.xx.xx:folder/* folder/

Make sure that the symbolic links have a valid path in the new pc.
Try to use relative paths instead of the full path when creating symbolic links.

source: http://forums.theplanet.com/lofiversion/index.php/t64844.html


Batch file renaming

To rename all files in a directory and add a new extension the xargs command can be used:
ls | xargs -t -i mv {} {}.old

xargs reads each item from the ls ouput and executes the mv command. The ‘-i’ option tells xargs to replace ‘{}’ with the name of each item. The ‘-t’ option instructs xargs to print the command before executing it.

To rename a subset of files, specify the file names with the ls command:
ls *.log | xargs -t -i mv {} {}.old

Or to add a current timestamp extension you may want to use the date command similar to this one:
ls *.log | xargs -t -i mv {} {}.`date +%F-%H:%M:%S`

The extension will look like “.2006-08-10-19:37:16″.

If you want to rename the extension of files, try the rename command:
rename .log .log_archive.`date +%F-%H:%M:%S` *

This command replaces the first occurrence of ‘.log’ in the name by .log_archive.`date +%F-%H:%M:%S`.

The following command replaces .htm extensions with .html for all files that start with “project*”:
rename .htm .html project*

source: http://puschitz.com/pblog/?p=31