Monthly Archives: October 2013

ssh escape sequence

Help sequence is:

ENTER
~?

This will output available options:

user@host:~$ ~?
Supported escape sequences:
  ~.  - terminate connection (and any multiplexed sessions)
  ~B  - send a BREAK to the remote system
  ~C  - open a command line
  ~R  - Request rekey (SSH protocol 2 only)
  ~^Z - suspend ssh
  ~#  - list forwarded connections
  ~&  - background ssh (when waiting for connections to terminate)
  ~?  - this message
  ~~  - send the escape character by typing it twice
(Note that escapes are only recognized immediately after newline.)

Video editing in linux

avconv is the new converter to use, ffmpeg is deprecated?!

http://libav.org/avconv.html

guides of interest

Video Editing on Linux

Kdenlive allows you to overlay videos on top of each other.

19 ffmpeg commands for all needs

Published on September 22nd, 2008 by Jean-Baptiste Jung.

http://www.catswhocode.com/blog/19-ffmpeg-commands-for-all-needs

ffmpeg is a multiplatform, open-source library for video and audio files. I have compiled 19 useful and amazing commands covering almost all needs: video conversion, sound extraction, encoding file for iPod or PSP, and more.

Getting infos from a video file

ffmpeg -i video.avi

Turn X images to a video sequence

ffmpeg -f image2 -i image%d.jpg video.mpg

This command will transform all the images from the current directory (named image1.jpg, image2.jpg, etc…) to a video file named video.mpg.

Turn a video to X images

ffmpeg -i video.mpg image%d.jpg

This command will generate the files named image1.jpg, image2.jpg, …

The following image formats are also availables : PGM, PPM, PAM, PGMYUV, JPEG, GIF, PNG, TIFF, SGI.

Encode a video sequence for the iPpod/iPhone

ffmpeg -i source_video.avi input -acodec aac -ab 128kb -vcodec mpeg4 \
     -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 \
     -s 320x180 -title X final_video.mp4

Explanations

Source : source_video.avi
Audio codec : aac
Audio bitrate : 128kb/s
Video codec : mpeg4
Video bitrate : 1200kb/s
Video size : 320px par 180px
Generated video : final_video.mp4

Encode video for the PSP

ffmpeg -i source_video.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac final_video.mp4

Explanations

Source : source_video.avi
Audio codec : aac
Audio bitrate : 32kb/s
Video codec : xvid
Video bitrate : 1200kb/s
Video size : 320px par 180px
Generated video : final_video.mp4

Extracting sound from a video, and save it as Mp3

ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3

Explanations

Source video : source_video.avi
Audio bitrate : 192kb/s
output format : mp3
Generated sound : sound.mp3

Convert a wav file to Mp3

ffmpeg -i son_origine.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 son_final.mp3

Convert .avi video to .mpg

ffmpeg -i video_origine.avi video_finale.mpg

Convert .mpg to .avi

ffmpeg -i video_origine.mpg video_finale.avi

Convert .avi to animated gif(uncompressed)

ffmpeg -i video_origine.avi gif_anime.gif

Mix a video with a sound file

ffmpeg -i son.wav -i video_origine.avi video_finale.mpg

Convert .avi to .flv

ffmpeg -i video_origine.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv video_finale.flv

Convert .avi to dv

ffmpeg -i video_origine.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 video_finale.dv

Or:

ffmpeg -i video_origine.avi -target pal-dv video_finale.dv

Convert .avi to mpeg for dvd players

ffmpeg -i source_video.avi -target pal-dvd -ps 2000000000 -aspect 16:9 finale_video.mpeg

Explanations

target pal-dvd : Output format
ps 2000000000 maximum size for the output file, in bits (here, 2 Gb)
aspect 16:9 : Widescreen

Compress .avi to divx

ffmpeg -i video_origine.avi -s 320x240 -vcodec msmpeg4v2 video_finale.avi

Compress Ogg Theora to Mpeg dvd

ffmpeg -i film_sortie_cinelerra.ogm -s 720x576 -vcodec mpeg2video -acodec mp3 film_termine.mpg

Compress .avi to SVCD mpeg2

NTSC format:

ffmpeg -i video_origine.avi -target ntsc-svcd video_finale.mpg

PAL format:

ffmpeg -i video_origine.avi -target pal-svcd video_finale.mpg

Compress .avi to VCD mpeg2

NTSC format:

ffmpeg -i video_origine.avi -target ntsc-vcd video_finale.mpg

PAL format:

ffmpeg -i video_origine.avi -target pal-vcd video_finale.mpg

Multi-pass encoding with ffmpeg

ffmpeg -i fichierentree -pass 2 -passlogfile ffmpeg2pass fichiersortie-2

Mencoder way

it is a two pass.

first

mencoder uncompressedfile.whatever -ovc lavc -lavcopts \
    vcodec=msmpeg4v2:vpass=1:vbitrate=8000000:mbd=2:keyint=132:vqblur=1.0:cmp=2:subcmp=2:dia=2:mv0:last_pred=3 \
    -nosound -o avs.avi

second

mencoder -ovc lavc -lavcopts \
    vcodec=msmpeg4v2:vpass=2:vbitrate=8000000:mbd=2:keyint=132:vqblur=1.0:cmp=2:subcmp=2:dia=2:mv0:last_pred=3 \
    -nosound -o compressedfile.avi avs.avi

old way

mencoder umaps2.avi -o output.mpg -ofps 25 -vf scale=900:720,harddup -of lavf -lavfopts format=mpg \
    -oac lavc -lavcopts acodec=mp2:abitrate=1224 -ovc lavc -lavcopts \
    vcodec=mpeg1video:vrc_buf_size=1327:keyint=15:vrc_maxrate=11152:vbitrate=11152:vmax_b_frames=0

kyle’s way

ffmpeg -i <inputfile.ext> -vcodec msmpeg4v2 -acodec mp3 <file.avi>

website explaining how to encode with mencoder.

http://personal.cscs.ch/~mvalle/mencoder/mencoder.html

 

encrypted home

Make encrypted partition

Source http://www.mayrhofer.eu.org/ssd-linux-benchmark

cryptsetup -c aes-xts-plain -s 256 luksFormat /dev/sda6    
cryptsetup luksOpen /dev/sda6 sda6_luks_crypt

mkfs.ext4 /dev/mapper/sda6_luks_crypt 
# or
mkfs.btrfs /dev/mapper/sda6_luks_crypt

mkdir /home2
mount /dev/mapper/sda6_luks_crypt /home2

Mount at boot

In /etc/crypttab add this line

sda6_luks_crypt /dev/sda6 none luks

In /etc/fstab add this line

/dev/mapper/sda6_luks_crypt           /home2       ext4    noatime,nodiratime,errors=remount-ro 0        0       2
# or
/dev/mapper/sda6_luks_crypt           /home2       btrfs    noatime,nodiratime 0        0       2

Set that partition as home

Source https://help.ubuntu.com/community/Partitioning/Home/Moving

Copy files

I did it one by one to skip ecryptfs stuff:

rsync -aXS /home/ftp   /home2/
rsync -aXS /home/nenad /home2/

Make the move

  • Change fstab from /home2 to /home
  • Move /home to /old_home
  • Reboot
  • If everything worked right, you can remove /old_home

Backup luks container

cryptsetup luksHeaderBackup --header-backup-file <file> <device>
cryptsetup luksHeaderRestore --header-backup-file <file> <device>

cryptsetup luksHeaderBackup --header-backup-file /opt/sda6_luks_crypt.header /dev/sda6

Links

git

Branches

  • List all branches
    git branch
  • Switch to the BRANCH branch
    git checkout <BRANCH>
  • Merge branch B1 into branch B2
    git checkout <B2>
    git merge <B1>
  • Create branch based on HEAD
    git branch <BRANCH>
  • Create branch based on another
    git branch <new> <base>
  • Delete a branch
    git branch -d <branch>
  • Compare two branches in GIT
    git diff master..branch
    git log master..branch
    git shortlog master..branch
    git diff --name-status master..branch

GIT-SVN branches

  • View all branches and tags you have cloned
    git branch -r # remote branches
  • Check out existing branch
    git checkout -b waldo-svn remotes/waldo
    The -svn suffix is to avoid warnings of the form warning: refname 'waldo' is ambiguous.
  • To update the git branch waldo-svn
    git checkout waldo-svn
  • Create a new branch in SVN
    git svn branch waldo
  • Reset your master to waldo
    git reset --hard remotes/waldo

Imaging drive partitions using tar

Imaging drive partitions using ‘tar’

Boot using a live CD or USB

Mount both partitions. Assumptions:

  • /mnt/a – has linux installed
  • /mnt/b – is empty
  • Running Ubuntu 12.04

tar it up

su -
cd /mnt/a
tar -cf image.tar *
cp image.tar /mnt/b
cd /mnt/b
tar -xf image.tar

set /mnt/b/etc/fstab to point to /mnt/b UUID

- you can get UUID with `blkid` command

rename /mnt/b/boot/grub

- `mv /mnt/b/boot/grub /mnt/b/boot/grub.bak`

boot into /mnt/a

- should be just a restart

update-grub should recognize that there are two bootable partitions

If you need to add kernel parameters like noapic for macs

  • open /boot/grub/grub.cfg
  • find the menu item that boots /mnt/b (should be under OS_PROBER)
  • copy that entry to the end of /etc/grub.d/40_custom
  • add kernel parameter to the line that starts with linux
  • Optionally disable OS_PROBER to keep grub menu clean
    • sudo chmod a-x /etc/grub.d/30_os-prober
  • sudo update-grub
  • check if your configuration worked in /boot/grub/grub.cfg

gdb scheduler

While debugging a multi-threaded program, you might want to turn off the scheduler so you don’t jump into a different thread. These are the magic commands:

show scheduler-locking
scheduler-locking on|off

Don’t forget to unlock it before continuing…

Ubuntu networking without network-manager

Source, Source

Disable the Network Manager and ‘hard-code’ a static IP address

In /etc/NetworkManager/NetworkManager.conf under [ifupdown] set managed=true

Edit interfaces

Sample /etc/network/interfaces (with virtual adapters):

auto lo iface lo inet loopback
auto eth0
iface eth0 inet static
    address 192.168.1.100
    netmask 255.255.255.0
    network 192.168.1.0
    broadcast 192.168.1.255
    gateway 192.168.1.254
    dns-nameservers 8.8.8.8 8.8.4.4
    dns-search example.com
auto eth0:0
iface eth0:0 inet static
    address 192.168.1.101
    netmask 255.255.255.0
    gateway 192.168.1.254

DHCP

Sample /etc/network/interfaces

auto eth0
iface eth0 inet dhcp

Restart services

 sudo /etc/init.d/network-manager restart