Jan 262010

You may have noticed that I am using the super slick SuperSlider-Login plugin on this site.  You can see it in the top right corner of the page.
SuperSlider Login

I noticed that it works perfectly in FireFox but IE8 just refused to render the CSS properly.  Anyhow, under the SuperSlider plugin settings, I chose the black appearance and vertical display. The plugin worked as expected in FF but under IE8, when I clicked on “Log In” button, IE8 would only drop the slider about 10px and not display anything else.

To fix this issue, I had to edit the black_vertical.css file under the /wp-content/plugins/superslider-login/plugin-data/superslider/ssLogin/black/

In the .css file, find the #loginpanel section and simply add Height: 240px; or whatever height you want to give it. I chose 240px but you can play with it to fit your needs. This fix doesn’t seem to affect Firefox. It may or may not work for you, but that’s what I did and now it seems to display properly.

Jan 242010

Okay so it’s been a year since my last post, sue me!

So lately I’ve been preoccupied with learning Ruby.  Ruby is a very sweet language, I won’t go into the reasons why, that’s what google is for.  This post is about my first attempt at coding in Ruby. Here’s the scenario, I have an external Hard Drive with around 1TB(1602 files) of AVI files.  These files are in sub directories named by date.  The AVI’s are from my security DVR system and as such are not compressed very well.  Each file takes up between 500mb to 1 gig of space.  I have been transcoding them with FFmpeg manually for the last few days, and knew I could write a simple Bash script to do it for me.  Since I have been bored with doing things the easy way, I thought “Let’s learn a new language just for this task!”.  Stupid, huh?  Anyways,  So I set out to learn Ruby.  Now, I am certainly no expert and I know my coding will probably make Ruby guru’s gag, but it works for me and you are more than welcome to use it at your own risk.  I take no responsibility in you deleting all your files or formatting your system.

GOAL: Recursively find and transcode all files matching the user inputted file extension.


Linux (I personally use CentOS 5.4)
FFmpeg compiled with h.264 and libfaac (which is beyond the scope of this post)

ProgressBar library for ruby

Now on to the Code:

Okay, so these first four lines are pretty self explanatory. If not, then you need to start learning Ruby or any language for that matter.
Fire up your favorite editor and insert the following:

#!/usr/bin/env ruby
require 'ftools'
require 'progressbar'
require 'find'

This tells ruby to clear the screen, Let’s start with a blank screen.
system ('clear')

Let’s create some functions:
The first function simply converts a measurement of time in seconds to days, hours, minutes, and seconds are returns a string with these values.
The second one simply defines three variables, start_time, end_time. and elapsed_time. The yield statement basically tells ruby to pause this function after defining the start_time variable, continue processing the main code (which we’ll get to in a second), and come back here once we’re done below.

def secs_to_days (secs)
  days = ((secs / 60) / (60 * 24)).floor
  hours = (((secs / 60) % (60 *24)) / 60).floor
  minutes = (secs / 60) % 60
  seconds = secs % 60
 "Conversion took #{days.to_s} days, 
  #{hours.to_s} hours 
  #{minutes.to_s} minutes 
  and #{seconds.to_s} seconds."

def elapsed_time
  start_time = Time.now
  end_time = Time.now  
  elapsed_time = end_time.to_i - start_time.to_i

This function simply presents the user with some questions and gathers the responses into an array and returns the array.

def user_input
  responses = Array.new
  recurse, delete = nil
  print "What type of file are we going to look for? "
  filetype = gets.chomp!
  responses.push filetype
  print "What is the full path where we should begin searching? "
  basedir = gets.chomp!
  responses.push basedir
  print "Should we search recursively? (y/n) "
  recurse = gets.chomp!
  if /y/i =~ recurse
    recurse = true
    recurse = false
  responses.push recurse
  print "Delete the original files after conversion? (y/n) "
  delete = gets.chomp!
  if /y/i =~ delete
    delete = true
    delete = false
  responses.push delete

  return responses

Now we’re getting to the meat and bones. The find_files function does exactly that. It is passed our array from the previous function, uses our responses to set our starting directory, the type of file we are looking for and to either search only the current directory or to search recursively.

def find_files(criteria)
  puts "Beginning Filesystem Search for specified files..."
  puts "We will search for all files with an extension of #{criteria[0]}"
  puts "Beginning in the directory named #{criteria[1]} and will"
  if criteria[2] == true
    puts "Search Recursively"
    puts "NOT Search Recursively"

  file_stack = Array.new

  if criteria[2] == true
    Find.find(criteria[1]) do |filename|
      if File.extname(filename) == criteria[0]
        file_stack.push filename
  elsif criteria[2] == false
    puts Dir.glob("*#{criteria[0]}")
    file_stack = Dir.glob("*#{criteria[0]}")

    puts "Oops, I broke!"

  return file_stack

Okay, now this is the main function. The first two lines setup our progress bar. Then we start a loop to process our array of found files and transcode each one in turn using FFmpeg into an h.264 video and depending on our responses, will either delete the original file or not. I am also dumping all output from FFmpeg into log files, so if a problem arises, I can see what happened. After each file is transcoded, we tell our progress bar to update. Then, when our loop has reached the end, we tell our progress bar that we are done. One thing to note… my FFmpeg command line is predetermined. Meaning, I already know how many streams my AVI files have and how I want to process them. You will need to modify the FFmpeg command line to suit your needs.

def convert_video(filename, criteria)
  pbar = ProgressBar.new("Conversion",100)
  pbar_step = 100 / filename.nitems
  filename.each do |video|
    myfile_extension = File.extname(video)
    myfile_basename = File.basename(video,myfile_extension)
    myfile = File.dirname(video)+"/"+myfile_basename
    system "ffmpeg -y -i #{video} -map 0.0 -map 0.1 -map 0.2 -map 0.3 \ 
      -acodec libfaac -ab 64k -ac 2 -vcodec libx264 -r 29.97 -s 640x480 \
      -vpre hq -crf 22 -threads 0 -f mp4 #{myfile}.mp4 -vcodec libx264 \
      -r 29.97 -s 320x240 -vpre hq -crf 22 -newvideo -acodec libfaac \
      -ab 64k -ac 2 -newaudio 2>> ffmpeg.log 1>> ffmpeg.error.log" 
    system "rm -rf #{video}" if criteria[3] == true

This is where the main execution of our program starts. We have a variable named criteria which is initialized with our function user_input. The same goes for the variable named file_stack, except that the find_files function is passed our criteria variable. Then we just print out a line indicating how many files our little program found.

criteria = user_input()

file_stack = find_files(criteria)

puts "Looks like we\'ve found #{file_stack.nitems}"

And this last bit of code ties it all together. If we have files to process, then let the transcoding begin, if not, We’re Done!

if file_stack.nitems > 0
  print "Press Enter to begin Transcoding or CTRL-C to cancel."
  convert = elapsed_time {
    convert_video(file_stack, criteria)
puts secs_to_days(convert)

  puts "Sorry, I couldn't find any files to process... Exiting!"

Now save your file. You can name it anything you want with an .rb extension. chmod +x it. Now run it.

Click here to see the entire source code. Use it as you will, but at your own risk.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Welcome BrainYang.com

Log in

Lost your password?

Register For This Site


Join us as we spread the word.