Friday, July 27, 2012

Command-Line Media Conversion

Tired of searching for those ever-changing media converter applications, or for an online conversion site that is actually working at any one time?

Search no more!! Install ffmpeg (and sox too) and learn how to convert media from most formats into most other formats... easily-peasily!

Common usage:

ffmpeg -i input.mp4 out.mkv
Done! Give it whichever input file in any format, tell it which file to output to (with the appropriate extension), and press [ENTER]! You'll have your toasty new file in a few seconds, minutes, hours, days, months, or years, depending on your computational power, file size, network speed (if applicable). Most likely a few seconds will suffice. Convert AVI-MP3, MP3-WAV, AVI-MKV, MOV-AVI, MKV-MP3, MOV-AIFF, or whatever you want! (Just make sure it makes sense - you can get audio out of video, but most probably not the other way around).

Also consider sox, an audio-specialized application with a wider spectrum of formats, precise control over channels, sample rates, dithering, and many other audio-specific attributes, effects, and synthesizers, plus other great tools like direct file playing and recording:
  • Play a music file: play musicFile.mp3
  • Recording yourself into a wave file: rec myRecording.wav
  • Convert all the .raw files in your current directory to wave files: for f in *.raw; do sox -r 16000 $f ${f/.raw/.wav}; done

There ya go! Apply and enjoy! Credits due:

VI Capitalization

Have you found yourself in the need to either capitalize or de-capitalize a large amount of text, and realized that your text editor did not have that capability, so you proceeded to re-type all of your text in your desired capitalization?

Re-type no more!!! vi will save you, as it has save many others so often before!!

  1. Open your file in vi.
  2. To convert all to uppercase, press gggUG
  3. To convert all to lowercase, press ggguG
  4. Done!
Alternatively, you can type in either of these longer vi commands:
  • <ESC>:%s/.*/\L&/
  • <ESC>:%s/.*/\U&/
though surely variations of these allow you much greater flexibility for more precise and/or complex substitutions.
Enjoy!

And of course, credits due to:


http://www.lefred.be/?q=node/75

Thursday, July 26, 2012

Finding/opening your smallest/largest images/files

So I have a folder of about 14K pictures and videos, and I decided to try to find the smallest images in my set (I was actually looking for the darkest ones, and it kinda worked). So I made up this command, and it works out nicely:

open $(find . | grep JPG | xargs ls -all | sed 's/  */ /g' | cut -f 5- -d' ' | sort -nr | tail -n 500 | cut -f 5 -d' ')



Logical steps:
  1. find . : Shows all files inside the current directory, and recursively inside all subdirectories.
  2. grep JPG : Remove all no-JPG files from the list (folders, system files, video files, etc).
  3. xargs ls -all : Re-list all the files, this time with all file attributes (size, permissions, etc).
  4. sed 's/ */ /g' : Replace all space sequences with a single space.
  5. cut -f 5- -d' ' : Grab only the attributes starting from the file size column (this might vary depending on your ls default attributes. Tweak the "5" to accomodate your own settings).
  6. sort -nr : Sort descendingly by file size.
  7. tail -n 500 : Grab only the 500 last files (I didn't want to open ALL of them).
  8. cut -f 5 -d' ' : Grab only the actual filename (remove all other attributes).
  9. open : Open them in Preview! (Or whatever your default image-viewing application is).
  10. View!

Google Web Search Keyboard Navigation

A few days ago, I realized that Gmail has the best keyboard UI among all of the Google products. Its keyboard amenability is a highly desirable feature among users who like performing tasks without frequently switching over to the mouse.

So today I was telling a friend about this, and about how even Google Web Search does not have such a keyboard-friendly interface. I opened a Google Web Search window to demonstrate how one couldn't navigate up and down the searches with "j" and "k", and how one could not open a search result with "o". But then I thought maybe it was navigable with arrow keys. So I tried it, and sure enough, it works!!! Steps here:
  1. Search for something on Google.
  2. Press [TAB] to remove focus from the main search text box.
  3. Press [UP] and [DOWN] to move up and down the search results!
  4. Press [ENTER] to open that search result! This also replaces your current browser tab. OR...
  5. Press [Command]-[ENTER] to open the search result on a new tab! I imagine it works with [Ctrl]-[ENTER] on Windows machines.
Now I'm curious to see what other Google products I can find keyboard shortcuts for. I've noticed Google Play is notoriously lacking in these, but maybe YouTube and Maps have matured to the point of keyboard interactivity.

And... ENJOY!!

Wednesday, July 25, 2012

Bash Pause

How do you pause a bash script, either to prompt a keypress or to actually get some input into the program? Easy peasy, use the read -p command!

Such as:
read -p "Press [Enter] key to start backup..."

Thanks!:
http://www.cyberciti.biz/tips/linux-unix-pause-command.html