Playing Flv Files in Ruby On Rails (Part 1)

Ruby On Rails No Comments »

Playing Flv Files in Ruby On Rails (Part 1) 

Rails has been a great and powerful framework for me since I have got in touch with. This time in order to test the power of Rails framework, I choose to play with the flash based video playback for web apps using the rails framework.

 

Before we actually get our hands dirty in writing the core programs of video playback, we first need to check out the requirement and the basic knowledge of the requirements that are actually required as a part of the development process.

 

The following listing provides the basic tools and equipments that should be in our hand before we start off with the development

 

1.Flash Player Helper Plugin:

This is the first most important tool which we require for playing the video file.

You can Install the plugin into your Rails App from the following site:

ruby script/plugin install svn://rubyforge.org/var/svn/flashplayrhelpr

 

For actually integrating the plugin into your application use the rake:

rake flash_player:install

That’s gonna install the falsh player into your application.

 For more information regarding the plugin please visit :

http://www.jroller.com/abstractScope/entry/flash_mp3_imageslideshow_media_player

And not forgetting a thanks to farooq ali for a great tutorial regarding the integration of the plugin into the rails app.

 

 

2 .File Column Plugin for File Upload:

 You can download and  install the file column plugin from the following location:

ruby script/plugin install http://opensvn.csie.org/rails_file_column/
   plugins/file_column/trunk

 

For more information of the plugin and its usage please visit:

http://www.kanthak.net/opensource/file_column/

 

3.Mplayer/Mencoder:

The basic task of a mencoder which comes bundled with the mplayer, is mainly used for the conversion of  the a movie file(basics format .WMV,.AVI …etc). into .FLV(Flash Video) format .

In order to download the mencoder(MPlayer 1.0rc1 Windows), please refer to the instruction on the following site

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

 

We will discuss the integration of mencoder into our Rails app in the second part of this tutorial

 

 

 

4.Video Codecs:

These are the most important role playing stuff when it comes to video conversion from one format to the other.

You can download the latest version of the codecs(Windows x86 20071007) from the following location:

http://www4.mplayerhq.hu/homepage/design6/dload.html#binary_codecs

 

Configuration of codecs in Mplayer/Mencoder 

When you download the codec pack from the mplayer site .You will find that the codecs are mere dll files. So in order to use these codecs ,what we have to do is copy the all the dll files into the codecs folder in the mplayer directory

 

NOTE: Please create a codecs folder if not present and do not forget to read the readme in the mplayer source directory for more information

 

With these basic configuration in hand we can now move to develop a Rails app for flash Video playback in the upcoming part

 

           

 

 

 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • blogmarks
  • Book.mark.hu
  • co.mments
  • Technorati
  • YahooMyWeb
  • IndianPad
  • DZone

Validating XSD against XML In Ruby On Rails.(Part 2)

Ruby On Rails 5 Comments »

 Before I actually run into the development of the xsd helper, I would like to express some few points regarding how this helper will actually work:

1.The input to the xsd helper will be an xml file and an xsd file against which the ml is supposed to be validated

2. the Output will be the a message indicating the validation status.

So, here goes the actual helper i.e Xsd_Helper.rb

module XsdHelper

I require the fileutils and tempfile libs for file object manipulation

  require ‘fileutils’

  require ‘tempfile’

I define the FILE_HOME  and the XML_STARTLET HOME.In the file home, I create 2 files finalxsd.xsd and finalxml.xml which we are going to see later.In the xmlstartlet home I keep the xmlstartlet library.Here I have kept the library in the public folder of our app.

    FILE_HOME = “#{RAILS_ROOT}/public/temp”

    XMLSTARTLET_HOME =”#{RAILS_ROOT}/public/xmlstartlet”

Now , we write the actual method which validates the xml against the xsd. We pass 2 parameters to the method i.e the xsdfile and the xmlfile

   def validate_xml_to_xsd(xsdfile,xmlfile)

@temp_xsd =validate(xsdfile)

            @temp_xml =validate(xmlfile)

We have to validate the xmlfiles and xsdfiles type in this case since in rails files below the size of 10kb are passed as a STRINGIO object and files above 10kb are passed as the TempFile Object . So, This validate method converts the STRINGIO object into the TEMPFILE object .

   

     finalxsd = File.new(FILE_HOME+”/finalxsd.xsd”,”w”)

     finalxml = File.new(FILE_HOME+”/finalxml.xml”,”w”)

Here,I create 2 new files in the FILE_HOME named finalxsd.xsd and finalxml.xsd.the purpose of these 2 files is, since, xmlstartlet library takes does not support the tempfile object

  FileUtils.copy(”#{@temp_xsd.path}”,”#{finalxsd.path}”)

  FileUtils.copy(”#{@temp_xml.path}”,”#{finalxml.path}”)

Here I copy the two file content from the temporary file to the respective xml and xsd file command_line=”#{XMLSTARTLET_HOME}/xml val -s “+ “#{finalxsd.path}” +’ ‘+”#{finalxml.path}”

  result_string = %x[#{command_line}] 

Then , I pass the two files to the xmlstratlet commandline utility for the actaual validation of the xml file

 assess_validation_result(result_string)

The access validation result takes the result string as the input and customizes the output which is returned to our rails controller as a Boolean output

   end

 

  private

 

  def assess_validation_result(result_string)

                        if (result_string=~/.+xml - invalid/).nil? then

                  true

                        else

                    raise result_string 

                        end

  end

       

def validate(file)

  @file = file

  # @file should contain file uploaded by HTTP

  # it is either StringIO object (if file was smaller than 10Kb)

  # or Tempfile (otherwise)

  if not (@file.kind_of? StringIO or @file.kind_of? Tempfile)

       return

  end

   if @file.kind_of? StringIO

    # Yes, if @file is StringIO, create new Tempfile and copy everything to it

     @real_file = Tempfile.new(”tempofile”)

    while not @file.eof?

      @real_file.write @file.read

    end

  else

   # Most uploads will be Tempfiles

    @real_file = @file

  end

   return @real_file

end

end

So,finally in the controller action, You can call the validate_xml_to_xsd(xsdfile,xmlfile) as ashoen below:

def input
    if request.post? && !params.nil?    
        @validate_output = validate_xml_to_xsd(params[’fileinfo’][’xsd_file’],params[’fileinfo’][’xml_file’])

if(@validate_output == true)

             flash[:notice] =”Your xml has been successfully validated”

end

render :action =>  ‘output’
      else
        render :action => ‘input’

       flash[:notice] = “Failed to validate the xml file”
          end
     end
end

 

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • blogmarks
  • Book.mark.hu
  • co.mments
  • Technorati
  • YahooMyWeb
  • IndianPad
  • DZone

Validating XSD against XML In Ruby On Rails.(Part 1)

Ruby On Rails No Comments »

Validating XSD against XML In  Ruby On Rails.(Part 1)

XMLSchema Validator Helper For Ruby on Rails

Introduction to XSD/XMLSchema

Before I get into the actual implementation of XMLSchema Validation, I would like to give a brief introduction to what is XSD and why do we actually need to validate the xml against its XSD. 

XML Schema can be used to express a schema: a set of rules to which an XML document must conform in order to be considered ‘valid’ according to that schema. However, unlike most other schema languages, XML Schema was also designed with the intent of validation resulting in a collection of information adhering to specific datatypes, which can be useful in the development of XML document processing software, but which has also provoked criticism.For more info…you can check out the w3c based standards for the Xml Schema at the following link:

http://www.w3.org/XML/Schema

The Xml support for our rails framework is not up to the expectations, with  REXML library providing some kind of support doing some basic xml operations which does not support xml validate which generally tend to go slow when the app is exposed to the production environment.

So, after 2 hours of  hardcore googling, I finally came up with the xmlstratlet command line utility.

XMLStarlet is a command line XML toolkit which can be used to transform,

query, validate, and edit XML documents and files using  simple set of shell

commands in similar way it is done for plain text files  using grep/sed/awk/

tr/diff/patch.

For more info, you can reach the xmlstartlet utility at the following website:

http://xmlstar.sourceforge.net/

You can download the latest version of  the xmlstartlet library at the following location:

http://xmlstar.sourceforge.net/download.php

 

So, with this base knowledge in our brains, we can now move to the core validation of xml using xsd in oour next part

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • blogmarks
  • Book.mark.hu
  • co.mments
  • Technorati
  • YahooMyWeb
  • IndianPad
  • DZone

WordPress Theme & Icons by N.Design Studio. Packaged by Edublogs - education blogs.
Entries RSS Comments RSS Login