Fixing choppy sound in Fedora and VMware

Sunday, October 03, 2010 Posted by Psyk 0 comments
Sony and Ableton etc. don't support Linux with their major high-end audio applications which is such a damn shame.  Applications such as Ableton Live, Sony Acid Pro and Sony Vegas Pro demand a lot of CPU resources and my system is dual-boot to get the best experience with these apps, but sometimes one needs to do a quick re-edit, re-render and sometimes most of the material is stored on the Linux partitions in ext3/lvm format.... It would be easier if Apple, Sony and Ableton supported Linux... oh well.  The current answer is to run them up in a Windows virtual machine and I've had a lot of success with VMware Workstation.

One of the biggest issues is choppy sound under load within the VM's.  Ableton is extra sensitive and allows you to tweak additional parameters to get the most optimum configuration, since you're virtualized you have multiple layers of tweaking...

Since Fedora (currently on 13) runs Pulseaudio, it's much easier now days to configure and setup the audio parameters. Below are a settings that helped in getting better audio (i.e. without stuttering) in a Vista VM.

1) Run up in a terminal
gedit /etc/pulse/daemon.conf

2)Change the following (most of these will be commented out with a ';' just remove the semi-colon):
high-priority = yes 
nice-level = -11
realtime-scheduling = yes 
realtime-priority = 5 
default-fragments = 25 
default-fragment-size-msec = 25 
resample-method = speex-float-3 

3) Bring up a terminal window as user (i.e. non-root):
[psyk@psyk ~]$ killall pulseaudio
[psyk@psyk ~]$ pulseaudio 

The last entry should restart the pulse daemon.

Fire up your VM and you should get trouble-free sound :)
Labels:

Mounting Truecrypt/Realcrypt with read/write access for users

Sunday, September 05, 2010 Posted by Psyk 0 comments
Mounting realcrypt or truecrypt volumes as a regular user disallows writing to the volumes unless you're root.

A quick fix is as follows.  When mounting your realcrypt volume, click mount -> Options.  You should get the screen below.  In the mount options field enter the relevant uid and gid entries as shown.
Options screen in Realcrypt when mounting a volume
Labels:

Setting up Password-less logins via SSH

Saturday, June 12, 2010 Posted by Psyk 0 comments
This allows you to SSH into many machines (great for managing a number of VM's) without having to continually enter login and password.

On your main server (e.g. your management server), configure the SSH keys:  
# mkdir -p $HOME/.ssh
# chmod 0700 $HOME/.ssh
# ssh-keygen -t dsa -f $HOME/.ssh/id_dsa -P ''


This command creates two files: $HOME/.ssh/id_dsa (private key) and $HOME/.ssh/
id_dsa.pub (public key).
# ssh-copy-id -i $HOME/.ssh/id_dsa.pub (your.other.linux.servers)



From your 'management server' test the results by ssh'ing into each of the servers:
# ssh (your.other.linux.servers)
Labels:

Update to PS3 encoding using mencoder in MP4 format

Sunday, January 24, 2010 Posted by Psyk 3 comments
Further to my old (and probably obsolete) entry here I thought it worthwhile to add an update in regards to encoding to MP4 format playable on Windows Media Centres and PS3's, although it should work on other platforms such as the Xbox but can't be sure as I don't have one for testing.

One of the biggest issues I had with the previous method was the reliability in muxing it into an MP4 via MP4Box and especially when trying to get the audio, video sync right which I think had to do with it not being able to detect the FPS correctly.  In any case, the procedure involves converting everthing to an AVI (mencoder's preferred format) and then ripping/converting them raw and muxing it back into an MP4 using MP4box, mencoder can do MP4's but it's broken.

First things first, and I can't take all the credit for this.  Credit goes to the h264enc project which uses mencoder heavily and has some great built-in profiles.  Excellent display of show-casing mencoder's power and versatility.

Lets, start...

Add a new profile entry in ~/.mplayer/mencoder.conf  
 [H264ENC]  
 profile-desc="taken from h264enc, PS3 compatible encode with high quality."  
 vf=pp=al:c,softskip,scale=720:-10,harddup   
 aspect=16:9  
 af=volnorm=2,lavcresample=48000:16:1   
 srate=48000  
 oac=faac=yes   
 faacopts=mpeg=4:br=160:tns=yes:object=2  
 ovc=x264=yes  
 x264encopts=crf=19:me=umh:me_range=24:nodct_decimate:nointerlaced:8x8dct:nofast_pskip:trellis=1:partitions=p8x8,b8x8,i8x8,i4x4:mixed_refs:keyint=240:keyint_min=24:psy_rd=0.8,0.2:frameref=3:bframes=3:b_adapt=2:b_pyramid:weight_b:direct_pred=auto:subq=7:chroma_me:cabac:aud:aq_mode=1:deblock:vbv_maxrate=20000:vbv_bufsize=20000:level_idc=41:threads=auto:ssim:psnr  
Obviously you can add your own parameters here especially in the "vf" section where you can adjust the scale, add some additional features (e.g. pullup,softskip, yadif etc.)

I won't go into all the details here, but basically this scales the image down to a 720p type format, normalizes the volume and resamples it to 48kHz, encodes it to AAC at 160kb and uses a constant rate factor for h264 of '19' for higher-end quality without much regard for final file size (i.e. it focuses on maximizing the video quality).

Once you have your profile you can run:
 mencoder -profile H264ENC "source_movie_file.ext" -o "source_movie_file.avi"  
This is the encoding process and the lengthiest bit...

If you want to hardsub an SRT file you can specify the -sub "name_of_srt_file.srt" and the -subfont-autoscale 1 parameters to the mencoder line above.

For example:
 mencoder -profile H264ENC "source_movie_file.ext" -o "source_movie_file.ext.avi" -sub "name_of_srt_file.srt" -subfont-autoscale 1  

Once this is finished, you'll have a h264 encoded video and aac encoded audio muxed into an AVI format, which is not very friendly format and container combo, only mencoder/mplayer/vlc player friendly :)

Next process requires us to split the video and audio into 'raw' input files that MP4Box can handle. We'll do the video first:
 mencoder "source_movie_file.avi" -nosound -ovc copy -of rawvideo -o h264_video.h264  
This will output a file called "h264_video.h264" in a raw stream that MP4Box can understand. As we've already done the encoding in the first step this will be quick as we're just ripping it from the AVI file.

Next, is the audio:
 MP4Box -aviraw audio "source_movie_file.avi" -out aac.raw  
Here we're using MP4Box to rip the audio from the AVI to a file called "aac_audio.raw" as MP4Box will rename the output.

Rename it so that MP4Box can manage it as an AAC input:
 mv aac_audio.raw aac_audio.aac  

The next step is to pick up the framerate (FPS) of the original movie source for correct interpretation into MP4.
 mplayer "source_movie_file.avi" -noconfig all -loop 1 -identify -nosound -vo null -nocache -frames 1 2>/dev/null | grep '^ID_VIDEO_FPS' | tail -n 1 | awk -F= '{print $2}' > mp4fps.fps  
This outputs the FPS of the original converted movie (AVI file) to a file called mp4fps.fps.

The final step muxes the video and audio into an MP4 container compatible with the many MP4 hardware devices and media centres. This may not work with an iPod as it uses some advanced parameters in the encoding. I'll try and post up the iPod parameters another time...
 MP4Box -fps $(cat "mp4fps.fps") -add "h264_video.h264" -add "aac_audio.aac"#audio:name="LC-AAC Stereo" -itags name="source_movie_file.avi":comment="Tagged by Psyk on $(date)" -mpeg4 -new "source_movie_file.avi".mp4  
The final output will be something like "Source_movie_file.avi.mp4". You can obviously change these output files and edit the tags.

Lastly, the cleanup:
 rm h264_video.h264  
 rm aac_audio.aac  
 rm mp4fps.fps  

To make things easier I put all of these into a very simple shell-script.
 mencoder -profile H264ENC "$1" -o "$1".avi  
 sleep 2  
 mencoder "$1".avi -nosound -ovc copy -of rawvideo -o h264_video.h264  
 sleep 2  
 MP4Box -aviraw audio "$1".avi -out aac.raw  
 sleep 2  
 mv aac_audio.raw aac_audio.aac  
 mplayer "$1".avi -noconfig all -loop 1 -identify -nosound -vo null -nocache -frames 1 2>/dev/null | grep '^ID_VIDEO_FPS' | tail -n 1 | awk -F= '{print $2}' > mp4fps  
 .fps  
 MP4Box -fps $(cat "mp4fps.fps") -add "h264_video.h264" -add "aac_audio.aac"#audio:name="LC-AAC Stereo" -itags name="$1":comment="Tagged by lazza on $(date)" -mpeg4  
  -new "$1".mp4  
 sleep 2  
 rm h264_video.h264  
 rm aac_audio.aac  
 rm mp4fps.fps  
Labels:

Using Handbrake for conversion

Wednesday, January 20, 2010 Posted by Psyk 0 comments
I've been playing around with HandBrake for a little while now and it's a very good and versatile encoder.  One of the reasons I like it so much is that it combines two of my favourite encoders being FFmpeg and Mencoder.

One of the more challenging items is adjusting the aspect ratio of your final video. It requires some understanding of Pixel Aspect Ratio which is different to your standard aspect ratio. I won't go into detail here, but basically to change your video format from 4:3 to 16:9 you'll need to feed the PAR parameters.

Here are the rough PAR specs on standard DVD's.
NTSC 4:3 - storage resolution 720 x 480,PAR 8/9 - display resolution 640 x 480 (= 4:3 aspect ratio)
NTSC 16:9 - storage resolution 720 x 480,PAR 32/27 - display resolution 853 x 480 (= 16:9 aspect ratio)
PAL 4:3 - storage resolution 720 x 576,PAR 16/15 - display resolution 768 x 576 (= 4:3 aspect ratio)
PAL 16:9 - storage resolution 720 x 576,PAR 64/45 - display resolution 1024 x 576 (= 16:9 aspect ratio)

Under HandBrake I've been using the preset settings for doing the encode and they're working well. Here's a list of the preset settings as per 0.94 of Handbrake:
 Apple:  
 Universal: -e x264 -q 20.0 -a 1,1 -E faac,ac3 -B 160,160 -6 dpl2,auto -R 48,Auto -D 0.0,0.0 -f mp4 -X 720 --loose-anamorphic -m -x cabac=0:ref=2:me=umh:bframes=0:8x8dct=0:trellis=0:subme=6  
 iPod: -e x264 -b 700 -a 1 -E faac -B 160 -6 dpl2 -R 48 -D 0.0 -f mp4 -I -X 320 -m -x level=30:bframes=0:cabac=0:ref=1:vbv-maxrate=768:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1:subme=6:8x8dct=0:trellis=0  
 iPhone & iPod Touch: -e x264 -q 20.0 -a 1 -E faac -B 128 -6 dpl2 -R 48 -D 0.0 -f mp4 -X 480 -m -x cabac=0:ref=2:me=umh:bframes=0:subme=6:8x8dct=0:trellis=0  
  AppleTV: -e x264 -q 20.0 -a 1,1 -E faac,ac3 -B 160,160 -6 dpl2,auto -R 48,Auto -D 0.0,0.0 -f mp4 -4 -X 960 --loose-anamorphic -m -x cabac=0:ref=2:me=umh:b-adapt=2:weightb=0:trellis=0:weightp=0  
 ----  
 Regular  
 Normal: -e x264 -q 20.0 -a 1 -E faac -B 160 -6 dpl2 -R 48 -D 0.0 -f mp4 --strict-anamorphic -m -x ref=2:bframes=2:subme=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0  
 High Profile: -e x264 -q 20.0 -a 1,1 -E faac,ac3 -B 160,160 -6 dpl2,auto -R 48,Auto -D 0.0,0.0 -f mp4 --detelecine --decomb --loose-anamorphic -m -x b-adapt=2:rc-lookahead=50  
 ----  
 Legacy  
 Classic: -b 1000 -a 1 -E faac -B 160 -6 dpl2 -R 48 -D 0.0 -f mp4  
 AppleTV Legacy: -e x264 -b 2500 -a 1,1 -E faac,ac3 -B 160,160 -6 dpl2,auto -R 48,Auto -D 0.0,0.0 -f mp4 -4 --strict-anamorphic -m -x ref=1:subme=5:me=umh:no-fast-pskip=1:cabac=0:weightb=0:8x8dct=0:trellis=0  
 iPhone Legacy: -e x264 -b 960 -a 1 -E faac -B 128 -6 dpl2 -R 48 -D 0.0 -f mp4 -I -X 480 -m -x level=30:cabac=0:ref=1:analyse=all:me=umh:no-fast-pskip=1:psy-rd=0,0:bframes=0:subme=6:8x8dct=0:trellis=0  
 iPod Legacy: -e x264 -b 1500 -a 1 -E faac -B 160 -6 dpl2 -R 48 -D 0.0 -f mp4 -I -X 640 -m -x level=30:bframes=0:cabac=0:ref=1:vbv-maxrate=1500:vbv-bufsize=2000:analyse=all:me=umh:no-fast-pskip=1:psy-rd=0,0:subme=6:8x8dct=0:trellis=0  

The Normal and High-Profile settings should work just find on a PS3.

As an example, here are the details on a source DVD I'm encoding for the kids:

  • + title 1:
  • + vts 0, ttn 0, cells 0->0 (0 blocks)
  • + angle(s) 0
  • + duration: 00:39:46
  • + size: 720x576, pixel aspect: 16/15, display aspect: 1.33, 25.000 fps
  • + autocrop: 0/0/12/6
  • + chapters:
  • + 1: cells 0->0, 0 blocks, duration 00:39:46
  • + audio tracks:
  • + 1, Unknown (AC3) (2.0 ch) (iso639-2: und), 48000Hz, 224000bps
  • + subtitle tracks:
  • + combing detected, may be interlaced or telecined
The aspect is 4:3 with a pixel aspect of 16/15.

Another way to pick up the aspect and Pixel Aspect Ratio (PAR) parameters is to use FFmpeg.
For example, you could do something like ffmpeg -i movie.vob :




$ffmpeg -i movie.vob  
 Seems stream 0 codec frame rate differs from container frame rate: 59.94 (60000/1001) -> 29.97 (30000/1001) 
 Input #0, mpeg, from 'mvoie.vob': 
  Duration: 00:03:08.18, start: 0.060000, bitrate: 6939 kb/s 
   Stream #0.0[0x1e0]: Video: mpeg2video, yuv420p, 720x480 [PAR 8:9 DAR 4:3], 8000 kb/s, 29.97 tbr, 90k tbn, 59.94 tbc 
   Stream #0.1[0xa0]: Audio: pcm_s16be, 48000 Hz, stereo, s16, 1536 kb/s 
 At least one output file must be specified 



You'll note the PAR is 8:9 and DAR is 4:3 which matches an NTSC DVD as per above.  Applying a
--pixel-aspect 32:27 in Handbrake would change this to a Widescreen format.

By using HandBrake I was able to re-encode to a compliant MP4 with the correct wide-screen aspect display. The size of the file was slightly larger and the resolution increased slightly from 720x576 (or 704 with cropping) to 1001x576 (with cropping) in Widescreen format. Very handy tool this HandBrake :)

Here's the command I used:
 HandBrakeCLI -v -i source.avi -o target.mp4 --deinterlace --size 700 -e x264 -a 1 -E faac -B 160 -6 dpl2 -R 48 -D 0.0 -f mp4 --custom-anamorphic --pixel-aspect 64:45 -m -x ref=2:bframes=2:subme=6:mixed-refs=0:weightb=0:8x8dct=0:trellis=0   
Labels:

Ripping audio from video files with mplayer

Friday, January 01, 2010 Posted by Psyk 0 comments
Here's a quick fire way to get that sound clip, soundtrack or whatever it is into an audio format from a video file. For example, on youtube, there might be a good video clip with a great soundtrack, and the video is nothing more than just a fixed image and/or you want to stick on your iPod/iPhone etc. Or you might want to get an audio sample for use in a ring tone etc.

Below is a script that I use to rip audio files out of pretty much any video.
 #!/bin/bash  
 echo "Ripping audio......."   
 mplayer -nocorrect-pts -vo null -vc null -ao pcm:fast:file=audiodump.wav "$1"   
 normalize -v audiodump.wav   
 faac -b 256 -c 48000 --mpeg-vers 4 -o audiodump.aac audiodump.wav  
The first line uses mplayer to dump the audio to a standard wav file called "audiodump.wav". The "-nocorrect-pts" corrects errors in some certain video files.

I then normalize the audio file via the "normalize" command (make sure you have the normalize package installed).

It's then encoded into AAC format using faac. You could easily do an mp3 here by using lame. For example, change the line starting with faac to something like:

lame --preset extreme audiodump.wav audiodump.mp3
Labels:

Creating animated GIFS with mplayer

Sunday, November 08, 2009 Posted by Psyk 0 comments
Looking for a quick fire way to create an animated GIF from sections of video's I didn't need to look any further than the multimedia swiss-army knife of the linux world, mplayer/mencoder and ffmpeg.


mplayer -ao null -loop 0 -ss 0:11:22 -endpos 5 file.avi

First is to playback the video and find the section you want. Tweak the "-ss" parameter to find the starting point and the "-endpos" for the finishing point of your video clip.


 mplayer file.avi -ao null -ss 0:11:22 -endpos 5 -vo gif89a:fps=25:output=animated.gif -aspect 16/9 -vf scale=-2:100  

Use mplayer again to write out the animated GIF file. Adjust the "scale" parameter to adjust the size of the animated GIF which is useful if you're going to use it as a signature for web forum etc.
Labels: