Yearly Archives: 2007

Halfviking get’s videos (ffmpeg, convert, flvmdi, flvplayer)

I’ve always wanted my online gallery export script to handle videos and last weekend, I bit the bullet and wrote it. I used quite a few Open source projects to accomplish this which means that PEAExport has a few dependencies but I think it’s worth it. My Canon Ixus takes AVI movies. The sizes of the movies range from 1MB to 50MB. To upload these would just be silly and each viewer would have to have an AVI viewer, which probably wouldn’t load in the browser. I really like flash movies players like those found on YouTube and Google Video so I anted to find a free one to use, I found the wonderful flvplayer @ http://www.jeroenwijering.com/. It’s an excellent player and free for non-commercial use.

So at this stage, I have my Videos in AVI format and a flash video (flv) player. I need to transcode them from AVI to FLV to work with the player. In work a few weeks ago we came across the SUPER application. This is a GUI front end to FFMPEG which is an absolutely wonderful utility, It handles tens of formats and hundreds of options. I used the FFMPEG.exe bundled with SUPER to tanscode them from AVI to FLV

ffmpeg.exe -i 'video.avi' -y -ab 64 -ar 22050 -b 200 -r 25 -s 650*450 'video.flv'

The options above (full list of options):

  • -i ‘video.avi’= input file is video.avi
  • -y = overwrite existing file if it exists
  • -ab 64 = audio bitrate is 64 kbit/s
  • -ar 22050 = audio sampling rate is 22050 Hz
  • -b 200 = video bitrate is 200 kbit/s
  • -r 25 = frame rate is 25Hz
  • -s 650*450 = rame size is 650 pixels by 450 pixels (WxH)
  • ‘video.flv’ = output file

Running this converts the hefty AVI video to a lightweight (relatively) FLV video. I then need to get the flvplayer playing this newly generated FLV.

<object data=”flvplayer.swf” type=”application/x-shockwave-flash”>
<param value=”file=video.flv&image=medium.jpg&linkfromdisplay=true&link=../14″ name=”flashvars” />
<param name=”movie” value=”flvplayer.swf?file=video.flv&image=medium.jpg&linkfromdisplay=true&link=../14″ />
</object>

There are many options for the flvplayer (full list of options). I only needed a few –

  • file=video.flv = input file is video.flv
  • image=medium.jpg = the loading image before you press play is medium.jpg
  • linkfromdisplay=true = when the user clicks directly on the movie area then they will be redirected to another page
  • link=../14 = when they click on the video, they will be redirected to the relative link “../14”

This plays fine but the progressbar isn’t running, This is a known limitation of FFMPEG (it’s fixed in the SVN version), FFMPEG does not write the metadata like video length etc to the FLV file. To do this, I was able to use another free utility called FLVMDI

flvdmi.exe video.flv video.flv

Running this inserts all the required metadata into the FLV video. The progress Bar now works perfectly.

You’ll notice that in the options for the flvplayer, I included “image=medium.jpg”. I could have used any image here but I wanted to use a frame from the video. Fortunately FFMPEG can do this.

ffmpeg.exe -i 'video.avi' -y -vcodec png -vframes 1 -an -f rawvideo -s 650x450 'videoimage.png'

The options above (full list of options):

  • -i ‘video.avi’= input file is video.avi
  • -y = overwrite existing file if it exists
  • -vcodec png = force video codec to png
  • -vframes 1 = set the number of video frames to one
  • -an = disable audio
  • -f rawvideo = force format to rawvideo
  • -s 650*450 = frame size is 650 pixels by 450 pixels (WxH)
  • ‘videoimage.png’ = output file

This results in a PNG file, quite a big one, taken from the first frame of the video. The file was too big for web use so I needed to convert it to JPEG. I could have used the Python image library PIL to do this (PEAExport already uses PIL) but I was already using some command utilities utilites to create videos and images. I thought, there’s no harm in another. That other was Convert.exe from the ImageMagick Library.

convert.exe -quality 75 videoimage.png videoimage.jpg

The options above (full list of options):

  • -quality 75 = compression level set to 75%
  • videoimage.png = videoimage.png is the input file
  • videoimage.jpg = videoimage.jpg is the output file

Excellent, I now have a lightweight flv video but I want a thumbnail to display in my gallery index pages. I ran the FFMPEG fram grap command but with “-s 250×186” to reduce the size to thumbnail size. I also want to indicate that it’s a video that the users is going to see and not another photo. So I need to Annotate it with the word “Video”

convert.exe -quality 75 -gravity South -font C:WINDOWSFontsGOTHICB.TTF -pointsize 50 -fill black -annotate +1+1 Video -fill white -annotate +0+0 Video videoimage.png videoimage.jpg

The options above (full list of options):

  • -quality 75 = compression level set to 75%
  • -gravity South = direction primitive gravitates to when annotating the image – In this case, we want the annotation loacted in the South of the image
  • -font C:\\WINDOWS\\Fonts\\GOTHICB.TTF = The font for the annotation. In this case I am using Century Gothic Bold
  • -pointsize 50 = The font size is set to 50 points
  • -fill black = The fill of the annotation is to be black
  • -annotate +1+1 Video = Annotate the word “Video” plus one pixel in both directions from the base position of “South”
  • -fill white = The fill of the next annotation is to be white
  • -annotate +0+0 Video = Annotate the word “Video” plus zero pixels in both directions from the base position of “South”
  • videoimage.png = videoimage.png is the input file
  • videoimage.jpg = videoimage.jpg is the output file

This creates a thumbnail image with the word “Video” in white with a black drop shadow, in Century Gothic Bold font, size 50 points.

thumbnail image with the word Video

And that my friends is it. Enjoy all my vidoes @ http://www.halfviking.com. I have also created a new page @ http://www.halfviking.com/videos using flvplayer’s playlist feature. My favourite single video is Bobby very bemused as to what on earth is planted in the ground at Crosby beach north of Liverpool.

Australia Day 2007

Australia Day 2004 It’s been a whole three years since I was in Sydney celebrating Australia day. I’ve done a lot since then but so much of me wishes I was back there waving my paper flags. Those were good times . It’s also nice to see the Aussies kicking England’s ass in the cricket once again. I don’t watch cricket as it’s hellishly boring, I only heard it on the news.

British Gas suck ass

British Gas suck assChurchill might kick ass but British Gas definitely sucks ass. I joined British Gas for my electricity in June of last year to try and save a few quid as Scottish Power Manweb was costing a fortune and I got a price fix untill the end of 2009. I have a direct debit of £64 going to British Gas every month as we estimated that is what my monthly bill would be. I now have £480 credit on my electricity account. The idiots have yet to bill me. I have had numerous phone calls with them, supervisors and managers and am awaiting a call from their hit squad support team (that was about 2 weeks ago I was told that). I abhor bad customer service. I pay £98 (gas and electric) a month to British Gas, they sure as hell better start looking after me or I’ll be on to watchdog. Am I going to get a big bill when they finally get around to it or will I get a refund. I have absolutely no idea.

Churchill kick ass

Churchill kick assGill’s car insurance is up for renewal and the renewal quote she got from Diamond was £495 including breakdown cover. That’s a bit steep so we set about lowering it and in true Philroche fashion (actually Gill did it), we got it down to £336 with Churchill.

It always pays to shop around.

Sweet Memories

A good buddy of mine sent me this in email format – well worth a read. It’ll make you think.

Ah I remember them well Way back…. I’m talking about Hide and seek in the park The shop down the road, Hopscotch, Donkey, skipping, handstands, stuck in the mud, football with an old can, Dandy, Beano, Twinkle and Roly Poly, Hula Hoops, Jumping the stream, Building a swing from a tyre and a piece of rope tied to a tree, (If you live in Dublin the lampost) building tree-houses, climbing up onto roofs,Tennis on the street, the smell of the sun and fresh cut grass,Hubba Bubba bubble gum and 2p Flogs, macaroon bars and woppas, 3p refreshers and wham bars, golf ball chewing gums and liquorice whips,desperate dan and roy of the rovers, sherbit dips and mr. freezes,marathon bars and everlasting gobstoppers, An ice cream cone on a warm summer night from the van that plays a tune, chocolate or vanilla or strawberry or maybe neopolitan

Wait…… Watching Saturday Morning cartoons…short commercials, battle of the Planets, Road Runner, He-Man, Swapshop, and Why Don’t You, Transformers, how do you do?, bosco, forty-coats, the littlest hobo and lassie, chucklevision, little house on the prairie and highway to heaven, Or staying up for Knight Rider, Airwolf or V when around the corner seemed far away and going into town seemed like going somewhere A million midge bites, sticky fingers and mud all over you, knee-pads on your jeans, Cops and Robbers, Rounders,tip the Can, Climbing trees, spin the bottle, Building igloos out of snow banks Walking to school, no matter what the weather, Running till you were out of breath Laughing so hard that your stomach hurt, Jumping on the bed. Pillow fights, Spinning around, getting dizzy and falling down was cause for giggles.Being tired from playing.. Remember that?

The worst embarrassment was being picked last for a team, Water balloons were the ultimate weapon Football cards in the spokes transformed any bike into a motorcycle I’m not finished just yet… Eating raw jelly, orange squash ice pops Remember when… There were two types of sneakers – girls and boys and Dunlop Green Flash and the only time you wore them at school, was for “P.E.”,! gola football boots It wasn’t odd to have two or three “best” friends, when nobody owned a purebred dog, when 25p was decent pocket money when you’d reach into a muddy gutter for a penny,when nearly everyone’s mum was at home when the kids got there,when it was considered a great privilege to be taken out to dinner at a real restaurant with your parents,when any parent could discipline any kid, or feed him or use him to carrygroceries and nobody, not even the kid, thought a thing of it,when being sent to the head’s office was nothing compared to the fate that awaited a misbehaving student at home Basically, we were in fear for our lives but it wasn’t because of muggings, drugs, gangs, etc. Our parents ! and grandparents were a much bigger threat! and some of us are still afraid of them!!!

Remember when…. Decisions were made by going “eeny- meeny- miney-mo.” Mistakes were corrected by simply exclaiming, “do over!” “Race issue” meant arguing about who ran the fastest Money issues were handled by whoever was the banker in “Monopoly” the game of life and connect four, atari 2600’s and commadore 64’s, The worst thing you could catch from the opposite sex was germs It was unbelievable that Kerbs wasn’t an Olympic event Having a weapon in school, meant being caught with a biro barrel pea shooter or an elstic band, Scrapes and bruises were kissed and made better Taking drugs meant orange-flavored chewable vitamins,Ice cream ! was considered a basic food group,Getting a foot of snow was a dream come true Abilities were discovered because of a “double dare” Older siblings were the worst tormentors, but also the fiercest protectors If you can remember most or all of these, then you have LIVED!!!!

Those were the good times – when we didn’t know what a mortgage was, or a what a looming deadline meant.

Geek resolutions

As it’s new year and my motivation is at an all time low, I think a list of TODOs (or new years resultions) is needed. Some of those listed are techy and some are not but all of them are aimed at improving my life.

I will

  • Finish the new design of this site – as you can see, it’s still a work in progress
  • Comment my code
  • Finish projects I have started
  • Document my code properly
  • Use UML – even if it’s just in my head
  • Move to Ubuntu on my home machine
  • Caption all my photos – all 8500 of them
  • Read all the books I bought
  • Read non-techy books too
  • Cook more
  • Eat less
  • Eat healthier
  • Find some way of feeling healthier that I can actually stick to (Gym is a bit too much commitment)
  • Start to budget my outgoings properly
  • Stop calling my dog “the rodent”
  • Learn that Friday does not have to equal “getpissedday”
  • Stop watching soap operas – comedy series like King of Queens and Scrubs will remain on my Sky+ planner though
  • Contribute to an open source project
  • Help fellow developers more
  • Always keep in mind that I know only a fraction of what I think I know
  • Be in a good mood
  • Write another useful Firefox extension that uses a custom XPCOM component
  • Use Patterns in code more
  • Stop driving like an idiot just so I can get home quicker
  • Go to Ireland to see my friends and family more
  • Go to the summer house in Norway
  • Save money
  • And finally – keep this blog up to date

There’s quite a few there so I think it’s more of a two year plan. I have been working on an eight year plan with Gill too, but it’s still a bit up in the air but very exciting – as along as all goes well –

I will also (I thought of some more)

  • Move to IMAP instead of POP email
  • Backup more
  • Learn how to use SVN properly
  • Go to LinuxWorld in London (as long as it’s not on Gill’s birthday like last year)
  • Get a whiteboard at home
  • ……..I’ll add some more as I think of them