Friday, April 1, 2011

find files bigger than certain size and scp over to another server

— SkyHi @ Friday, April 01, 2011
Files can be found under Linux in many different ways. Using the find tool is one of the best ways to find files. The find tool has a huge number of parameters which can be set so that Linux finds exactly those files that you were searching for. Many users use the find tool with just the basic parameters. They get the results that they were looking for. Unfortunately most of the users don't spend time to learn all about find. If they do, they can make excellent use of this tool and I am sure you would be surprised at the possibilities.

In case you just want to know where a particular file exists on your system, and nothing else is required, then use locate tool. Article No.20 explains how to use locate.


Here are a few ways to use find

-

$ find / -name 'program.c' 2>/dev/null
$ find / -name 'program.c' 2>errors.txt
/
Start searching from the root directory (i.e / directory)
-name
Given search text is the filename rather than any other attribute of a file
'program.c'
Search text that we have entered. Always enclose the filename in single quotes.. why to do this is complex.. so simply do so.

Note : 2>/dev/null is not related to find tool as such. 2 indicates the error stream in Linux, and /dev/null is the device where anything you send simply disappears. So 2>/dev/null in this case means that while finding for the files, in case any error messages pop up simply send them to /dev/null i.e. simply discard all error messages.

Alternatively you could use 2>error.txt where after the search is completed you would have a file named error.txt in the current directory with all the error messages in it.

-

$ find /home/david -name 'index*'
$ find /home/david -iname 'index*'
The 1st command would find files having the letters index as the beginning of the file name. The search would be started in the directory /home/david and carry on within that directory and its subdirectories only.
The 2nd command would search for the same, but the case of the filename wouldn't be considered. So all files starting with any combination of letters in upper and lower case such as INDEX or indEX or index would be returned.

-

$ find -name met*
The above command would start searching for the files that begin with the letters 'met' within the current directory and the directories that are present within the current directory. Since the directory is not specified as the the second parameter, Linux defaults to using the current directory as the one to start the search in.

-

$ find /mp3collection -name '*.mp3' -size -5000k
$ find / -size +10000k
The 1st command would find within a directory called /mp3collection, only those mp3 files that have a size less than 5000 Kilobytes ( < 5MB) The 2nd command would search from the / directory for any file that is larger than 10000k (> 10MB)

-

$ find /home/david -amin -10 -name '*.c'
$ find /home/david -atime -2 -name '*.c'
$ find /home/david -mmin -10 -name '*.c'
$ find /home/david -mtime -2 -name '*.c'

The 1st commmand searches for those files that are present in the directory /home/david and its subdirectoires which end in .c and which have been accessed in the last 10 minutes.
The 2nd command does the same but searches for those files that have been accessed in the last 10 hours.
The 3rd and the 4th commands do the same as the 1st and 2nd commands but they search for modified files rather than accessed files. Only if the contents of the files have been modified, would their names be returned in the search results.

-

$ find / -mount -name 'win*'
This command searches for files starting with the letters 'win' in their filenames. The only difference is that the mounted filesystems would not be searched for this time. This is useful when you have your Windows partitions mounted by default. And a search for 'win' might return many files on those partitions, which you may not be really interested in. This is only one use of -mount parameter.

-

$ find /mp3-collection -name 'Metallica*' -and -size +10000k
$ find /mp3-collection -size +10000k ! -name "Metallica*"
$ find /mp3-collection -name 'Metallica*' -or -size +10000k
Boolean operators such as AND, OR and NOT make find an extremely useful tool.
The 1st command searches within the directory /mp3-collection for files that have their names beginning with 'Metallica' and whose size is greater than 10000 kilobytes (> 10 MB).
The 2nd command searches in the same directory as above case but only for files that are greater than 10MB, but they should not have 'Metallica' as the starting of their filenames.
The 3rd command searches in the same directory for files that begin with 'Metallica' in their names or all the files that are greater than 10 MB in size.

-

The exec option is probably the most important feature of the find tool. The exec command allows you to execute a particular command on the results of the find command. A simple demonstration of this feature is shown below. Its upto your imagination to make maximum use of this feature. Suppose you wanted to see the details of the files (read, write, execute permission, file size, owner etc..) that have been returned as a search result you could do the following

$ find / - name 'Metallica*' -exec ls -l {\}\ \;

This command would find all the files on your system that begin with the letters 'Metallica' and would then execute the 'ls -l' command on these files. So basically you would be able to see the details of the files that were returned according to your search criteria.

The words following the -exec option is the command that you want to execute i.e. ls -l in this case.
{\}\ is basically an indicator that the filenames returned by the search should be substituted here.
\; is the terminating string, and is required at the end of the command


find test -type f  | xargs -i scp  '{}' root@192.168.0.1:'{}'
find ./test -type f  | xargs -i scp  '{}' root@192.168.0.1:~/'{}'
###60MB
find . -size +60000k -type f |xargs -i scp '{}' web1@dump.sample.net:~/
There is a difference between those two commands. The 1st just use the full path of the found file and copies it to the same path.
/etc/myapp/test.txt --> /etc/myapp/test.txt

The second will copy the full path to the home dir.
/etc/myapp/test.txt --> ~/etc/myapp/test.txt

Thanks for your help. Problem sovled



REFERENCES
http://www.codecoffee.com/tipsforlinux/articles/21.html
http://www.unix.com/shell-programming-scripting/113925-find-exec-scp-2.html

Thursday, March 31, 2011

File extension search and copy

— SkyHi @ Thursday, March 31, 2011
find ./ -name "*.txt" -exec cp {} newfolder \;


But need to to find both .txt and .csv files
find ./ -name "*.[ct][sx][vt]" -exec cp {} newfolder \;
This command recursively finds from the current directory and subdirectories, files with names as per the below criteria.

After . the first character must be c or t (For .csv and .txt files)
After . the second character must be s or x (For .csv and .txt files)
After . the third character must be v or t (For .csv and .txt files)

Anyway, other combinations will also match (like .cxt) which I mentioned in my previous reply.

The exec in the above command copies all the found files (i.e, all .csv and .txt files we need) to the directory called newfolder.


ni@Januty:$ find . -iname "*.txt" -mtime -0.1 -exec cp {} ch5 \;


REFERENCES
http://www.unix.com/unix-advanced-expert-users/58363-file-extension-search-copy-3.html

Wednesday, March 23, 2011

top - Linux command line to see the running processes in real time

— SkyHi @ Wednesday, March 23, 2011
When you need to see the running processes on your Linux in real time, you have top as your tool for that.
top also displays other info besides the running processes, like free memory both physical and swap
Usage
top [options]
Options
-d ss.tt
Delay -- Specifies the seconds and tenths of seconds of delay between the updates of the info showed on the screen, being the default 3 seconds
-i
Starts top with the last remembered 'i' state reversed. When this toggle is Off, tasks that are idled or zombied will not be displayed.
-n n
Specifies the maximum number of iterations, or frames, top should produce before ending.
-p n
Monitor only processes with specified process IDs. This option can be given up to 20 times, or you can provide a comma delimited list with up to 20 pids. Co-mingling both approaches is permitted. This is a command-line option only. And should you wish to return to normal operation, it is not necessary to quit and and restart top -- just issue the '=' interactive command.
-s
- Secure - Runs top in secure mode, restricting the commands you can use while top is running even for root
-S (Sum)
Starts top with the last remembered 'S' state reversed. When 'Cumulative mode' is On, each process is listed with the cpu time that it and its dead children have used. See the 'S' interactive command for additional information regarding this mode.
Description of the fields
a: PID -- Process Id
The task's unique process ID, which periodically wraps, though never restarting at zero.
b: PPID -- Parent Process Pid
The process ID of a task's parent.
c: RUSER -- Real User Name
The real user name of the task's owner.


d: UID -- User Id




The effective user ID of the task's owner.


e: USER -- User Name




The effective user name of the task's owner.


f: GROUP -- Group Name




The effective group name of the task's owner.


g: TTY -- Controlling Tty




The name of the controlling terminal. This is usually the device (serial port, pty, etc.) from which the process was started, and which it uses for input or output. However, a task need not be associated with a terminal, in which case you'll see '?' displayed.


h: PR -- Priority




The priority of the task.


i: NI -- Nice value




The nice value of the task. A negative nice value means higher priority, whereas a positive nice value means lower priority. Zero in this field simply means priority will not be adjusted in determining a task's dispatchability./dd>


j: P -- Last used CPU (SMP)




A number representing the last used processor. In a true SMP environment this will likely change frequently since the kernel intentionally uses weak affinity. Also, the very act of running top may break this weak affinity and cause more processes to change CPUs more often (because of the extra demand for cpu time).


k: %CPU -- CPU usage




The task's share of the elapsed CPU time since the last screen update, expressed as a percentage of total CPU time. In a true SMP environment, if 'Irix mode' is Off, top will operate in 'Solaris mode' where a task's cpu usage will be divided by the total number of CPUs. You toggle 'Irix/Solaris' modes with the 'I' interactive command.


l: TIME -- CPU Time




Total CPU time the task has used since it started. When 'Cumulative mode' is On, each process is listed with the cpu time that it and its dead children has used. You toggle 'Cumulative mode' with 'S', which is a command-line option and an interactive command. See the 'S' interactive command for additional information regarding this mode.


m: TIME+ -- CPU Time, hundredths




The same as 'TIME', but reflecting more granularity through hundredths of a second.


n: %MEM -- Memory usage (RES)




A task's currently used share of available physical memory.


o: VIRT -- Virtual Image (kb)




The total amount of virtual memory used by the task. It includes all code, data and shared libraries plus pages that have been swapped out.

VIRT = SWAP + RES.

p: SWAP -- Swapped size (kb)




The swapped out portion of a task's total virtual memory image.


q: RES -- Resident size (kb)




The non-swapped physical memory a task has used.
RES = CODE + DATA.

r: CODE -- Code size (kb)




The amount of physical memory devoted to executable code, also known as the 'text resident set' size or TRS.


s: DATA -- Data+Stack size (kb)




The amount of physical memory devoted to other than executable code, also known as the 'data resident set' size or DRS.


t: SHR -- Shared Mem size (kb)




The amount of shared memory used by a task. It simply reflects memory that could be potentially shared with other processes.


u: nFLT -- Page Fault count




The number of major page faults that have occurred for a task. A page fault occurs when a process attempts to read from or write to a virtual page that is not currently present in its address space. A major page fault is when disk access is involved in making that page available.


v: nDRT -- Dirty Pages count




The number of pages that have been modified since they were last written to disk. Dirty pages must be written to disk before the corresponding physical memory location can be used for some other virtual page.


w: S -- Process Status




The status of the task which can be one of:
'D' = uninterruptible sleep
'R' = running
'S' = sleeping
'T' = traced or stopped
'Z' = zombie Tasks shown as running should be more properly thought of as 'ready to run' -- their task_struct is simply represented on the Linux run-queue. Even without a true SMP machine, you may see numerous tasks in this state depending on top's delay interval and nice value.


x: Command -- Command line or Program name




Display the command line used to start a task or the name of the associated program. You toggle between command line and name with 'c', which is both a command-line option and an interactive command. When you've chosen to display command lines, processes without a command line (like kernel threads) will be shown with only the program name in parentheses, as in this example:
( mdrecoveryd )
Either form of display is subject to potential truncation if it's too long to fit in this field's current width. That width depends upon other fields selected, their order and the current screen width.
Note: The 'Command' field/column is unique, in that it is not fixed-width. When displayed, this column will be allocated all remaining screen width (up to the maximum 512 characters) to provide for the potential growth of program names into command lines.


y: WCHAN -- Sleeping in Function




Depending on the availability of the kernel link map ('System.map'), this field will show the name or the address of the kernel function in which the task is currently sleeping. Running tasks will display a dash ('-') in this column. Note: By displaying this field, top's own working set will be
increased by over 700Kb. Your only means of reducing that overhead
will be to stop and restart top.


z: Flags -- Task Flags




This column represents the task's current scheduling flags which are expressed in hexadecimal notation and with zeros suppressed. These flags are officially documented in . Less formal documentation can also be found on the 'Fields select' and 'Order fields' screens.
Interactive commands
While top is running you may issue some options that will interact immediately with top these options are:
h
Help, displays a summary of command that will modify the behavior of top
k
Kills a process, you will be able to kill only your own processes, unless you are running top as root
n
Once this command is entered top will ask you how many lines you want on your screen, if you enter 0 top will display as much as it can
q
Exits top
r
Change the priority of a process, as well as with k you will only be able to act on your own processes unless you are root
W
Writes the current configuration to your personal configuration file, which is $HOME/.toprc
Example
top - 22:29:04 up 7:16, 3 users, load average: 0.06, 0.08, 0.08
Tasks: 105 total, 2 running, 99 sleeping, 0 stopped, 4 zombie
Cpu(s): 2.5%us, 0.7%sy, 0.0%ni, 95.7%id, 1.0%wa, 0.2%hi, 0.0%si, 0.0%st
Mem: 1035196k total, 796652k used, 238544k free, 55680k buffers
Swap: 2650684k total, 0k used, 2650684k free, 432516k cached
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
4267 root 15 0 320m 45m 10m S 4 4.5 4:45.33 X
2865 haldaemo 17 0 5736 4136 1864 S 0 0.4 0:23.18 hald
1 root 15 0 744 288 240 S 0 0.0 0:01.15 init
2 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/0
3 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/0
4 root RT 0 0 0 0 S 0 0.0 0:00.00 migration/1
5 root 34 19 0 0 0 S 0 0.0 0:00.00 ksoftirqd/1
6 root 10 -5 0 0 0 S 0 0.0 0:00.12 events/0
7 root 10 -5 0 0 0 S 0 0.0 0:00.00 events/1
8 root 12 -5 0 0 0 S 0 0.0 0:00.00 khelper
9 root 10 -5 0 0 0 S 0 0.0 0:00.00 kthread
13 root 14 -5 0 0 0 S 0 0.0 0:00.00 kblockd/0
14 root 10 -5 0 0 0 S 0 0.0 0:00.00 kblockd/1
15 root 16 -5 0 0 0 S 0 0.0 0:00.00 kacpid
125 root 11 -5 0 0 0 S 0 0.0 0:00.00 cqueue/0
126 root 11 -5 0 0 0 S 0 0.0 0:00.00 cqueue/1
127 root 10 -5 0 0 0 S 0 0.0 0:00.02 kseriod
171 root 16 0 0 0 0 S 0 0.0 0:00.00 pdflush
172 root 15 0 0 0 0 S 0 0.0 0:00.06 pdflush
173 root 12 -5 0 0 0 S 0 0.0 0:00.00 kswapd0
174 root 12 -5 0 0 0 S 0 0.0 0:00.00 aio/0
175 root 13 -5 0 0 0 S 0 0.0 0:00.00 aio/1
435 root 12 -5 0 0 0 S 0 0.0 0:00.00 kpsmoused
847 root 10 -5 0 0 0 S 0 0.0 0:00.00 ata/0

Tuesday, March 22, 2011

MySQL: the Pros and Cons of MyISAM InnoDB Tables

— SkyHi @ Tuesday, March 22, 2011
Unlike the majority of database systems, MySQL offers a number of table types. Choosing the correct type can be critical for your web application, but few developers realise the implications until it is too late. In this article we examine MyISAM tables.MyISAM is the default MySQL table type. If you have never knowingly specified a type, your table will use the MyISAM engine. There are several reasons why that could be an advantage.

1. Simplicity
MyISAM tables are simple. If you are new to MySQL or databases in general, I would recommend you start with MyISAM tables.
In the following example, we will create a new database and table from the mysql> command prompt. (You do have MySQL installed, right? If not, take a look at How to Install MySQL.)

CREATE DATABASE mysqltest;
USE mysqltest;
CREATE TABLE mysqltest.articles (
id int UNSIGNED NOT NULL AUTO_INCREMENT,
title TEXT NOT NULL,
body MEDIUMTEXT,
PRIMARY KEY (id))
ENGINE = MyISAM;

This creates a new database, mysqltest, and a new table named articles with the columns id (an automatically generated number), title and body. Determining the best column data type is about as complex as it gets.

2. Speed
MySQL is fast. Really fast. Under normal conditions, benchmarks show that MyISAM tables beat every other general-purpose database and uses fewer system resources.

3. Full-text searching
Consider our table above. What if we need to search for keywords in both the title and the body? An easy solution is to add a fulltext index:

ALTER TABLE mysqltest.articles ADD FULLTEXT alltext (title, body);
We can now find all articles that feature the words “database” and/or “article” using:

SELECT * FROM mysqltest.articles
WHERE MATCH(title, body) AGAINST ('database article');
We can even order articles by the most relevant first to create a simple search engine:

SELECT *, MATCH(title, body) AGAINST ('database article') AS rel
FROM mysqltest.articles
ORDER BY rel DESC;

The disadvantages of MyISAM tables

There are several situations when MyISAM may not be suitable.
1. Poor data integrity
MyISAM tables do not support transactions or foreign key constraints.
Consider a banking application where you are transferring money. This would typically involve two SQL UPDATE statements; a debit from one account and a credit to another. If MySQL or the server failed at the wrong point, you could end up with money in both accounts or neither.

2. Poor crash recovery
MySQL is reliable, but MyISAM tables can become corrupt following a crash. The problem can usually be fixed using REPAIR TABLE but it is an additional administrative overhead.

3. Table locking
MyISAM uses table-level locking. When a row is inserted or updated, all other changes to that table are held up until that request has been completed.
It is not always easy to prove whether this will cause problems for your web application but, in general, if you are performing more inserts/updates than selects, MyISAM may not be the best table type to choose.

Should you use MyISAM?

MyISAM is an ideal choice if you are new to MySQL, your web application is simple, has to be fast, or use full-text searches. However, it should not be used when data integrity is a priority. Possible applications could include content management systems, online bookmarking tools, RSS readers, or simple search engines.
Note that you can mix table types within the same database. In practice, it may cause less developer confusion if you stick with a single table type.
See also:

MySQL: the Pros and Cons of InnoDB Tables

 Following on from our look at MyISAM tables, today we examine InnoDB tables.
InnoDB is less well known than the default MyISAM table type. However, there are several reasons why it could be better choice for your web application.

1. Data integrity and foreign key constraints
Foreign keys establish a relationship between columns in one table and those in another. For example, you might create a library application where books can be loaned to members. A foreign key constraint would ensure that a member existed before a book could be checked-out. Similarly, removing a user would not be possible until all their books were returned.
For further information about foreign keys and automating your database, refer to How to Use MySQL Foreign Keys for Quicker Database Development.

2. Transactions
InnoDB tables support transactions. A transaction allows multiple SQL commands to be treated as a single and reliable unit.
Consider a banking application where you are transferring money from one account to another. The transaction would only be committed if both accounts were altered successfully. If anything failed, the database would be rolled-back to a previous state.
In addition, InnoDB tables recover well from crashes. MySQL will analyze the log files to ensure the data is accurate so there is no need to repair tables.

3. Row-level locking
InnoDB uses row-level rather than table-level locking. If a row is being inserted, updated or deleted, only changes to the same row are held up until that request has completed. Tables that receive more updates than selects may be faster with InnoDB.

The disadvantages of InnoDB tables

There are a number of situations when InnoDB may not be suitable.
1. Increased complexity
Creating an InnoDB table is no more complex than MyISAM, e.g.

CREATE TABLE employee (
id smallint(5) unsigned NOT NULL,
firstname varchar(30),
lastname varchar(30),
PRIMARY KEY (id)
) ENGINE=InnoDB;
However, designing that database with foreign key relationships does require more effort. Database novices will find MyISAM easier because it has fewer features.

2. No full-text search
InnoDB tables do not support full-text searches; it is not easy to match one or more keywords against multiple columns.

3. Slower performance
If your application is primarily selecting data and performance is a priority, MyISAM tables will normally be faster and use fewer system resources.

Should you use InnoDB?

InnoDB is the best option if you need to create a reliable data-driven web application. In many ways, InnoDB is a better default choice than MyISAM:
  1. unless you have a significantly large or heavily-used system, the speed differences are likely to be negligible
  2. full-text searches can be implemented in other ways, e.g. more complex SQL or server-side search algorithms.
InnoDB is certainly the best choice for online shops, financial applications or any project where data integrity is essential. Defining tables is more complex, but your application will be more robust and may require less server-side code.
Note that you can mix table types within the same database. In practice, it may cause less developer confusion if you stick with a single table type.

REFERENCES
http://blogs.sitepoint.com/mysql-myisam-table-pros-con/

Monday, March 21, 2011

AttributeError: 'module' object has no attribute 'findall'

— SkyHi @ Monday, March 21, 2011
Code:
d@home$ cat re.py
import re
re_string = "{{(.*?)}}"
some_string = "this is a string with {{words}} embedded in {{curly brackets}} to show an {{example}} of {{regular expression}}"
for match in re.findall(re_string,some_string):
        print 'Match->', match


ERROR:
Traceback (most recent call last):
  File "re.py", line 1, in <module>
    import re
  File "/home/nikid/PythonSysadmin/re.py", line 4, in <module>
    for match in re.findall(re_string,some_string):
AttributeError: 'module' object has no attribute 'findall'
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 48, in apport_excepthook
    if not enabled():
  File "/usr/lib/python2.6/dist-packages/apport_python_hook.py", line 21, in enabled
    import re
  File "/home/nikid/PythonSysadmin/re.py", line 4, in <module>
    for match in re.findall(re_string,some_string):
AttributeError: 'module' object has no attribute 'findall'

Original exception was:
Traceback (most recent call last):
  File "re.py", line 1, in <module>
    import re
  File "/home/nikid/PythonSysadmin/re.py", line 4, in <module>
    for match in re.findall(re_string,some_string):
AttributeError: 'module' object has no attribute 'findall'




Solution:

rename the file re.py to another name


Another one

ERROR:

NameError: name 'randint' is not defined

Solution:
Rename the random.py to different name..

REFERENCES
http://www.willmer.com/kb/2007/12/attributeerror-module-object-has-no-attribute-blah/

Friday, March 18, 2011

ffmpeg Converting VOB or MP4 to FLV format

— SkyHi @ Friday, March 18, 2011
Using "mencoder" to create "flv" from "VOB" DVD video format files

Many websites nowadays are using swf and flv file formats to play videos hosted on their site or sites, it's advantage is clear in that the file itself is often in comparison to regular video format files, smaller and easier to upload so the site is able to hold and run more video content with much less bandwidth than would normally be required.

#> mencoder inputfile.VOB -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=150 -ofps 25 -oac mp3lame -lameopts abr:br=32 -srate 22050 -vf scale=720 -o outputfile.flv

In our first test video conversion format a file named VTS_01_2.VOB was successfully converted from a 776.9Mb file to a 17mb outputfile.flv although the video and audio was brilliant the file stopped short of it's actual completion target in other words outputfile.flv was considerably shorter than it should have been, we have concluded from this that the VOB file is corrupt and the conversion terminates at that point. Having obtained another dvd with which to copy from we tried again, you should not this recording was original obtained from a small video recorder and transfered to DVD which we then migrated to a flash video (flv). Below is how we archived it, please note the above mencoder script is different to the one below which did eventually work.

#> mplayer dvd://1 -dumpstream -dumpfile myvideo.vob
#> mencoder myvideo.vob -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=150 -ofps 25 -oac mp3lame -lameopts abr:br=32 -srate 8000 -vf scale=720 -o outputfile.flv

It is important to note the above "mplayer" command it does not play the file not visibly at least but dumps or rips 1 or more VTS_01_n.VOB files into a single "vob" extension file that can then be converted into a video file format you require. The input file has been altered to reflect the file output from mplayer and "-srate" has been altered to "8000". If you think a graphical user interface is the way to go you may be right it would take a lot of the guess work and fun out of using command line, but for now command line seems much better than "gui". Ahh problems with the above it turns out with an "-srate of 8000" you might get some rapid clicking when transfered to a website or you tube, through some investigation and some trial and error we came up with the following which you might think is much better.

#> mplayer dvd://1 -dumpstream -dumpfile myvideo.vob
#> mencoder myvideo.vob -of lavf -ovc lavc -lavcopts vcodec=flv:vbitrate=150 -ofps 25 -oac mp3lame -lameopts abr:br=32 -srate 44100 -vf scale=720 -o outputfile.flv

The "flv" format files can only support 8000, 22050 and 44100 I believe for the available -srate.

Converting MP4 to FLV
ffmpeg -i myvideo.mp4 -ar 44100 myvideo.flv

Converting FLV TO SWF

ffmpeg -i input.flv -acodec copy -vcodec copy output.swf

REFERENCES
http://ubuntuforums.org/showthread.php?t=1001642

How to Embed Flash Video on Your Web Page with a Control Bar

— SkyHi @ Friday, March 18, 2011
My last article described how to embed SWF in your web page. The main problem associated with this is that the flash video plays automatically. If the video is 10 minutes long viewers will need to wait patiently for it to finish or click out of the web page. This can be very frustrating and may turn off your visitors. It’s better to offer them a control bar.

One of the best solutions to this problem is to use the Flash Player named Flowplayer. It enables you to easily embed a flash video file in your web page and allow visitors to control the playing (ie start or stop the video).

To see how the flash media player looks on a web page visit:
Paul Koko Fashion Design Gallery

What is Flowplayer?

It’s a flash media player that allows you to easily play and control the video from your web page. It’s hosted on a global streaming network and allows extensive customization.

Video formats supported by Flowplayer include FLV, MP4 and H.264. To convert your original video to any of these formats use youconvertit.com…a free online service that converts media files to different formats.

The free version of Flowplayer is sufficient to play your flash video however you can purchase a commercial license if you don’t want the logo displayed at the beginning of the video. (I hardly noticed it).

How to embed flash video on your web page with a control bar

1. Download the flash video player (Flowplayer)
http://flowplayer.org/download/index.html

After downloading the zipped file, unzip it it to a folder on your hard drive
The Flowplayer folder contains all these files:

flowplayer-3.2.3.swf
flowplayer.controls-3.2.2.swf
example folder

2. Upload the Flowplayer folder to your server.

This will enable you to first test if the example video works on your server. After uploading the folder insert this URL in your browser ie http://www.yourdomain.com/flowplayer/example/index.html (replace yourdomain.com with your own domain).

If it doesn’t work check you uploaded all the files correctly and used the correct file paths.

3. Create folders on the server to play your own video

Create a folder on your server named “video” and put these 3 files inside it:

flowplayer-3.2.3.swf
flowplayer.controls-3.2.2.swf
video.flv (your own video file)

Create a folder named “js” and place this javascript file inside it (taken from the example folder)

flowplayer-3.2.3.min.js

Upload both these folders to your web server.

4. Insert javascript code in your web page

To include the javascript file: flowplayer-3.2.3.min.js in your web page place this code in the HEAD section:



5. Create the html code to add your video file and the flash media player (Flowplayer)

The center tags are to center the video on the web page.
Make sure you save the web page to retain your changes.

5. Upload the web page to your server

Your video won’t play correctly if the web page containing the code is not uploaded to the server.

6. Test your video

Enter the URL of your web page in your browser. It should play immediately and display a control bar underneath so your visitors can stop the video whenever they want.

7. Customization

For most users the default behavior is sufficient however Flowplayer allows you to further configure how the video displays on your web page. Customization options may include:

* changing the background color
* use a different control bar
* place a clock on the screen
* have a splash image displayed
* load playlists

Now you have no excuse to play a cool video on your web page.

Documentation

http://flowplayer.org/documentation/installation/index.html

Related articles
Embed SWF in Your Web Page

REFERENCES
http://www.drostdesigns.com/how-to-embed-flash-video-on-your-web-page-with-a-control-bar/