Category Archives: Multimedia

Encode an Audio file to Video file

I wanted to convert an mp3 file to an mp4 or avi file because I wanted to be able to use it on my PS3 ( the PS3 has a basic audio player that doesn’t save position [ particularly troubling for large audiobooks ] ). This although is good for audio posting on youtube… I found a script by Jeremy Tharp that needed a bit of a tuneup (quoting parameters for file names with spaces, fixed exit status, better detection for the duration) and it works pretty good:

Handling display calibration

Though it is the expectation that a monitor is ready as soon as it is removed from the box, most monitors need to be calibrated. A much more vivid, detailed, true experience can become available after it is done that can be enjoyed and “feels right”. Calibrating a monitor correctly requires training of the eye so it initially can take a bit of work.

Hardware

All settings done to calibrate the monitor should be done on a hardware level (except for possibly gamma) as software solutions almost never adjust the image truely. Before beginning, have the monitor on for about ten minutes as it can take the lamp this long to warm up and represent accurate values.

Gamma

Gamma correction is the adjustment of mid-tone luminosity. It is used to compensate for the non-linear relationship between the input signal and the luminance of a monitor. Televisions, computers, and the internet use a gamma of 2.2 as a standard so monitors set to this to be able to correctly display output. Most monitors default to the 2.2 standard but some monitors deviate and therefore hardware and/or software gamma correction is required. A high gamma will look glowy and a low gamma will appear errie and dark.

Alternate

Gamma test and Alternate

There is likely a gamma setting on the monitor if it needs to be adjusted. If there isn’t, or for further adjustment, a software solution is available. The first software solution would be to use the EDID data built-in to the monitor of most modern-day computers. It contains details about the monitor including gamma correction. The Desktop Environment may have the ability to grab the EDID and save it as an ICC profile (GNOME does), otherwise a program like Quickgamma in windows will do. If the monitor does not have EDID information, Quickgamma also has the ability to manually-calibrate the gamma and create an ICC profile from that; it saves the ICC profiles to C:\Windows\System32\spool\drivers\color.

To load an ICC profile put it in ~/.local/share/icc/ and see if your Desktop Environment supports it. If it does not, a good program that can load them is xcalib.

In the image, lightly squint the eyes (or step away) to find the match where gamma blends with the background.

Contrast

Contrast defines the tonality of an image. Tonality is the gradient leveling from light to dark. With a high contrast the light and dark extremes become “crushed” or “blended” together, a low contrast the and images will appear flat. Contrast is also reflects the white-level (the brightness of white) of the monitor; contrast levels are often defined when buying a monitor because they will tell how bright the lamp is.

In this image, turn up the contrast to maximum and the reduce until all whites become distinct and the first block is just barely discernable.

Brightness

Brightness is better-referred to as black-level as it defines the “brightness of black”, or how bright darkness goes. Black is “black” or will be just above the black of the monitor if turned off. Adjust the image so that the left box just barely discernable. It may be necessary to go back and forth between contrast and brightness until the right balance is met.

Note: Discernability of the lightest light boxes and the blackest dark boxes should be possible on a modern monitor; however, it should be known that some monitors are unable to reproduce them.

Color balance

For color the first thing to do is adjust saturation. Saturation is the total amount of color the monitor will display. Too much saturation and images will be heavy with color, too little and they will appear faded. On some monitors the setting will be called Color, on others it will be Saturation, and on others it will be controled through an accumulative adjustment of the Red, Green, and Blue channels. Use the images below to determine saturation. Skin tone is a good indicator for this; however, also look at the colors on the color wheel as “bleeding” will at times occur when over-saturation occurs.

To adjust the color balance, also use the images below with skin tone as a reference. Do one color at a time, go back and forth, back and forth, until it feels right. When doing this be careful not to strain the eye too much as eye fatigue effects colorreception. Take a break after a little bit (get up and strech, make lunch…) and come back and you’ll immediately see, “Ah, the image is too red” or “Ah, the image is too blue”… The base colors Red, Green, and Blue also have complementary colors or complmentary light, the opposite of Red is Cyan, Green Magenta, and Blue is Yellow. If an image has too much Magenta it will need more Green. Again look at the skin tone (the gray in the first image works good). This is where the trained eye comes in. With practive eventually color bents will become discernable. Once it is achieved, the discovery of a well defined monitor can be begun to be enjoyed.

Skin-tone, gray background

Skin-tone, gray background

Light skin-tone

Light skin-tone

Darker skin-tone

Darker skin-tone

Resources

Screencasting Done Easy (Desktop Recording)

I got to test out a good number of screencasting applications and I found a good one, and as usual the easiest was the best. I started with recordMyDesktop.

recordMyDesktop

recordMyDesktop is a basic program that works good. The GTK version has a simple UI that sets a border around the area to be recorded. I has sound recording too.

A minor thing but of note is that the window detection area is off when selecting a windows, but the reason I didn’t use recordMyDesktop was because I found the quality wasn’t that good. It could be because it uses .ogv format, or perhaps it had something to do with my system.

This is and example I did with recordMyDesktop and though it’s enlarged (OpenShot doesn’t have the ability to use the original size) the quality I wanted to be better.

Others

I tried Istanbul and a couple others all with about the same recording results. Istanbul hasn’t been developed in several years and though I got excited about xvidcap it hasn’t been developed in years either. xvidcap grabs screenshots and then concatenates them into a video. I got excited because xvidcap’s preview uses Imagemagick’s animate tool to preview the video and it was real nice. Unfortunately very little works in xvidcap anymore but taking the screenshots. To put them together I used:

fmpeg -i out%04d.xwd -r 15 -vcodec huffyuv test.avi

unfortunately the quality was no better than that of the others.

FFmpeg

The great command line tool to encode and decode video ffmpeg can also do screencasts and I read a lot of how people liked it (and I do too). To use it it’s real basic:

ffmpeg -f x11grab -s wxga -i :0.0 -sameq screencast.mpg

The quality isn’t quite what I want it to be, but I’ve seen other people have nice looking screencasts so I think it must be either my video card or my video driver.

This line can be amended some for better quality, performance, and add sound recording. Using the raw, lossless codecs for video and audio improves processor usage for better FPS recording:

ffmpeg -f x11grab -s wxga -i :0.0 -vcodec huffyuv -sameq -acodec pcm_s16le -f alsa -i pulse -ac 2 screencast.avi
  • -s and -i are for size and input. -s will give the dimensions and -i will define the co-ordinates. wxga is a definition of a video resolution standard (available ones are listed in man ffmpeg)
  • -r can be added to define the frame rate. Default is 25 and is good. Only reason really to change it is if frames are dropped during recording (marked with red).
  • -follow_mouse 100 can be added to follow mouse movements. 100 is the border in pixels that must be reached before the area is moved.

ffcast and FFmpeg

ffcast is a program that grabs and passes X.org server dimensions and co-rodinates to other programs. It has built-in support to pass these parameters for some programs including ffmpeg. So the command will now look like this:

ffcast -s ffmpeg -- -vcodec huffyuv -sameq -acodec pcm_s16le -f alsa -i pulse -ac 2 screencast.avi

ffcast’s -s option will prompt for the screen area and then pass the dimensions and co-orodinates to ffmpeg using --.

Now to make this easy, I put this in a bash script, it runs as such:

 screencast <a|f|m|w> - create screencasts (a)rea (f)ull-screen (m)ouse (w)indow

Here’s the bash script:

An example:

cVLC as Default Video Player



I love MPlayer. I’ve been using it for years. Whenever I needed to watch a video from my camera or downloaded something from YouTube it always did great. However, I revisited recently trying to play a DVD with MPlayer after having gone through a lengthy setup process a ways back and discovered MPlayer still cannot play DVD’s reliably. From the examples I tried it seemed as error-prone as before.

MPlayer always ran dependably and with almost no resources, videos would pop rightup. Learning to use the keyboard to navigate Mplayer was likely having one big remote control. However, I came to the decision that I cannot deal with the quirks of MPlayer anymore (there is good work on the mplayer2 project that is trying to fix a lot of the internal plumbing problems of MPlayer) but I needed something more-reliable. So when I decided just to use VLC, I accidentally learned about clvc.

I don’t normally use VLC because I use GNOME. Having MPlayer open up immediately was a big plus, but with clvc (which is part of the VLC package) videos open just like they did with MPlayer. And the playback quality is good. To play a DVD:

cvlc dvd://

The big thing is I’m going to have to learn all the key mappings again for cvlc, so a made a reference sheet:

Key Mappings

Desktop Recognition

To have clvc be recognized by the desktop a .desktop needs to be created:

and put in ~/.local/share/applications.

sudo update-desktop-database -q

Warning: I had to put it in /usr/share/applications/ for GNOME 3.6 to be able to recognize it in Default Applications and Removable media. This is likely a bug.

To have all known video types that VLC knows and define them to cVLC as the default application do:

xdg-mime default cvlc.desktop $(grep -oP 'video.*?;' /usr/share/applications/vlc.desktop | tr ';\n' ' ')

Load on DVD Insertion

I have yet to find out how to do this. This probably isn’t the correct way to do it, but it should work (note: my install is busted a bit right now so unable to test). Put in /usr/share/applications/clvc-dvd.desktop:)

[Desktop Entry]
Type=Application
Name=cVLC
GenericName=Media Player
GenericName[ca]=Reproductor multimèdia
GenericName[de]=Medienwiedergabe
GenericName[fr]=Lecteur multimédia
GenericName[it]=Lettore multimediale
GenericName[ja]=メディアプレーヤー
X-GNOME-FullName=Command Line VLC
Comment=Play movies and songs
Icon=vlc
TryExec=cvlc dvd://
Exec=cvlc dvd:// %U
Terminal=false
Type=Application
Categories=AudioVideo;Player;Recorder;
MimeType=video/dv;video/mpeg;video/x-mpeg;video/msvideo;video/quicktime;video/x-anim;video/x-avi;video/x-ms-asf;video/x-ms-wmv;video/x-msvideo;video/x-nsv;video/x-flc;video/x-fli;video/x-flv;video/vnd.rn-realvideo;video/mp4;video/mp4v-es;video/mp2t;application/ogg;application/x-ogg;video/x-ogm+ogg;audio/x-vorbis+ogg;application/x-matroska;audio/x-matroska;video/x-matroska;video/webm;audio/webm;audio/x-mp3;audio/x-mpeg;audio/mpeg;audio/x-wav;audio/x-mpegurl;audio/x-scpls;audio/x-m4a;audio/x-ms-asf;audio/x-ms-asx;audio/x-ms-wax;application/vnd.rn-realmedia;audio/x-real-audio;audio/x-pn-realaudio;application/x-flac;audio/x-flac;application/x-shockwave-flash;misc/ultravox;audio/vnd.rn-realaudio;audio/x-pn-aiff;audio/x-pn-au;audio/x-pn-wav;audio/x-pn-windows-acm;image/vnd.rn-realpix;audio/x-pn-realaudio-plugin;application/x-extension-mp4;audio/mp4;audio/amr;audio/amr-wb;x-content/video-vcd;x-content/video-svcd;x-content/video-dvd;x-content/audio-cdda;x-content/audio-player;application/xspf+xml;x-scheme-handler/mms;x-scheme-handler/rtmp;x-scheme-handler/rtsp;
X-KDE-Protocols=ftp,http,https,mms,rtmp,rtsp,sftp,smb
Keywords=Player;Capture;DVD;Audio;Video;Server;Broadcast;
NoDisplay=True

and then point to it in Removable Media > DVD.

YouTube videos

VLC has it’s own parser to be able to extract URL’s from YouTube so running is all that is needed to get the job done:

cvlc "http://www.youtube.com/..."

Convert Videos to PSP



I’m a TED video junkie. I always have videos on my PSP ready to watch. I also like to put YouTube videos on there. I did this enough that I created a script for it that makes putting videos on my PSP real easy:

 pspvidconv <d*> <video(s)> - Convert videos to PSP (d to use directory)

The PSP allows use of a single-depth directory. The directory option (when using d flag) will ask if the user wants to create a new directory, if the answer is no, it will present the existing ones.

Warning: Currently h264 encoding isn’t working. The PSP will report that it is an unknown codec, so mp3g4-xvid is the only option with ffmpeg.

h264enc

Because I’ve found that options and settings change frequently with encoding tools, it is better to have an expert be able to handle them (otherwise, I will spend more time looking options up again). A good program to use is h264enc. It’s a shell script (perl, I believe) and well done; not good for many files as all settings will have to be re-entered but does a good job.

Handbrake

For Handbrake GUI I found this post. I have yet to find any handbrake-cli lines that work.

YouTube from the command line

How to play YouTube videos became a question to me because flash in Linux is all but abandoned and knowing of flash security concerns. Good news is that most videos now are being converted to WebM (Firefox HTML 5 video) but for some unknown reason I find most of them that the sound won’t play. I really enjoyed watching YouTube videos so since I’ve gone to using youtube-dl which is a great command line program (there is also youtube-viewer).

I wrote a wrapper script do that to be able to download a number of varying videos:

youdl 
 youdl "youtube.com/url" # quotes necessary, not spaces

youtube-dl

I like youtube-dl quite a bit too but it takes more setting up. When using youtube-dl I put these in my ~/.bashrc to simplify the process:

utube-view () {
  mplayer -cache 200 -really-quiet $(youtube-dl -g --max-quality mp4 "$@" )     
}

youtube-viewer

youtube-viewer directly invokes mplayer:

youtube-viewer "http://youtube.com/video-url"

And it works great! The quotes are necessary to avoid bash interpretation of specialcharacters. youtube-viewer can also download the video too:

youtube-viewer -d "http://youtube.com/video-url"

MPlayer Keyboard Shortcuts

Got this from here:

Older Computer: Streaming Media Servers

Recently I had a notion after I bought my PS3 about media servers. The PlayStation 3 is pretty neat. Being just a little computer (with a big graphic card) it is able play audio, videos, and display pictures. The PS3 has categories of its’ differing abilities: Music, Video, Game, Network… On the Music, Video and Picture categories I noticed there is an option to find ‘Media Servers’. This got me intrigued: I have a basic wired/wireless home network that connects my PS3, Laptop and Printer (this also is pretty neat, a minuature Cisco router does this seamlessly) and I wondered if the media I had on my laptop could be shared with my PS3. With it I’d be better able to view/listen my media by using my TV, but would it be able to run decently on an eight year old laptop?… Yes.

MediaTomb

This is what I was recommended first when I first asked about media servers. I think this may have been because it is the most commonly used media server on Linux. MediaTomb was easy to install, configure (all three media servers I tried are just basic daemons with easy to edit configurations), and didn’t bog down my system when it ran normally. MediaTomb does provide nice thumbnail support and after editing the configuration and restarting the daemon it showed up immediately on my PS3. After running MediaTomb for awhile though however, I gave up using MediaTomb because at times it would get heady. MediaTomb appears to rescan the library from time to time and then it appears to do some parsing of files. Doing this would run up my fan on my laptop which is generally reserved for heavier tasks like working with ffmpeg.

uShare

Not sure I want to mention much here as it probably isn’t worth the time. A bit after installing uShare (a day) I discovered it wasn’t being developed anymore. uShare ran nice for one day but after adding a video that wasn’t support (or maybe just a new start to the PS3) The PS3 gave a “A DLNA Protocol Error (501)” that I could never fix. I tried waiting for the library to fully scan on my laptop before turning on the PS3, removed any questionable media files (unsupported codecs, DRMm have reported to cause problems) with no luck. uShare has not been maintained since 2007. When it did run, it ran well and light. uShare does not have support for thumbnails, and it does not monitor (or rescan) directories while running (the daemon will need to be restarted if you add new music for instance).

miniDLNA

Never got this to work, but I heard it is fast and cool.

Notes

Since I’ve written this article I’ve been using Rygel which is an ok media server. At least it is doing the trick now.

Apple Trailers Fix

HeaderAs some of you may have found out or read about, Apple trailer downloads for Linux are currently broken. Apple has implemented a Quicktime user agent check prior to downloading. Personally I agree with the decision because Apple is concerned about the quality of reproduction (though Apple trailers still play with an odd hue on Windows – think this has to do with Quicktime not correctly reading Window’s color setting – but I’m getting off topic). This means that movie players plugins for web browsers (like gecko-mediaplayer and totem) will no longer work. Until gstreamer gets a patch that fix’s this, here’s a script that can download them manually. To use the script, right-click on the download link and copy it to the clipboard then append it after the atget script.

You can comment wget line and uncomment the mplayer line to directly play the trailer. The mplayer line needs to have a cache to be sure the video is downloaded before it start or errors will occur (200MB should be enough for just about and video on the site).

Credits

  • Thanks to Ian on stack overflow, who help me figure out how to prepend a regex search.
Follow

Get every new post delivered to your Inbox.

Join 52 other followers