Watermark Video in FFMPEG without vhook

It has always been that with ffmpeg, if you want to watermark a video, you needed vhook. vhook as we all know is old and not very useful to windows users and in the newer ffmpeg builds has been replaced with video filters, or –vf.

One of the filters in the new –vf format is a watermark filter, allowing you to watermark your videos during the transcoding procedure.

An example would be: –vf “overlay:10:10” which would tell the overlay to position 10 pixels from the top of the main video, and 10 pixels from the left.

But what if we want to position from the right? Or from the bottom? Or centre the overlay? This is where main_w (main video width), main_h (main video height), overlay_w (overlay video width) and overlay_h  (overlay video height) comes in. You can use these variables to represent the certain set sizes of the video and the overlay.

So what if we wanted to position 10 pixels from the right and 10 pixels from the bottom? We would the use: –vf “overlay:main_w-overlay_w-10:main_h-overlay_h-10”.

So how do we specify the overlay? What we do is use the “movie” video filter which would take our png or jpg and convert that into a movie which is then overlaid on top of our existing movie.

See example below:

ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]" outputvideo.flv

Or if you are planing to use your video with a newer version of flash that supports h264 encoded videos, you could use:

ffmpeg.exe -i input.avi -sameq -vcodec libx264 -acodec libfaac -vf "movie=logo.png [watermark]; [in][watermark] overlay=(main_w-overlay_w)/2:main_h-overlay_h-10 [out]" -threads 0 "output-slow.mp4"

qt-faststart.exe output-slow.mp4 output-fast.mp4

Thus giving you a watermarked MPEG4 h264 + AAC file capable of streaming with a flash player.

Search and Replace in Linux Command Line

I wanted to search and replace every file in a directory tree and find a URL that linked to /web-design and remove that part of the URL, and i also wanted to find the phrase “Web Design” in a link and replace it with “Affordable Web Design”.

Usually i would have to go through each individual file via SSH or FTP and then open the file, make the edits, save the file and re-upload the file. The problem with that is, i needed to do this for over 15,000 files on over 3000 web sites, and that isn’t something i wanted to do.

Firstly, i needed to find all the html files that could possibly have these two defects, so i went with “find”, its simple, and easy, and crawls sub directories as default.

Find all files with the extension “.html” in the current directory and all sub directories:
find . -iname '*.html'

The problem i had then was, web sites that are still being worked on are in a private directory that i do not want to alter, so i needed to exclude these directories:
find . -iname '*.html' -not -path '*private*'

This now gives me a list of everything that i need to do a search and replace on.

For this next part, you can use either “sed” or “perl”. I chose to go with perl as i know perl better than sed.

This cold should replace “/web-design” with “” in a file called “index.html” in the current folder. (Follows the format “s/what to find/what to replace with/g”):
perl -pi -w -e 's/\/web-design//g;' index.html

So what we need to do now is use xargs to combine the two parts and make the search and replace in all files:
find . -iname '*.html' -not -path '*private*' | xargs perl -pi -w -e 's/\/web-design//g;' -sl

This code should now look in the current directory, and all sub-directories contained within for any html file not in a private folder, and remove the text “/web-design” and replace it with nothing.

The next bit was a simple modification to replace the phrase “Web Design” with “Affordable Web Design”, though we needed to take into account that we only wanted to replace content within a A HREF tag, so we need to search for “>Web Design<”
find . -iname '*.html' -not -path '*private*' | xargs perl -pi -w -e 's/\>Web Design\</\>Affordable Web Design\</g;' -sl

Make sure that when you are creating your regular expressions, you escape any special characters such as \ / < > and friends.

The Advantages of Secure Passwords

Secure passwords are random strings of letters (both upper case and lower case), numbers, and special symbols. Rather than simply using a dictionary word.

All passwords should be stored as a hash, so that nobody with access to the database they are stored in can simply see all the plain text passwords.

The advantage is that a totally random password can only be broken by a brute force method, which means a program has to generate random strings and create the hash for that string, and compare it to what is in the database. Once it finds something that matches, that is the password.

On a powerful computer, a well written program can run through around 17 billion different generations, hashes and checks per hour. (2 * (2^33))

The longer the password is, the longer it takes to crack the password via the brute force method. See below for examples.

Upper or Lower Case Only

No. Characters 1 Compter 100 Computers 1,000 Computers (small botnet)
8 6.08 hours 0.06 hours 0.006 hours
10 4,108.5 hours 41.085 hours 4.1084 hours
12 2,777,348.18 hours 27,773.48 hours 2,777.35 hours

Mixed Case and Numbers

No. Characters 1 Compter 100 Computers 1,000 Computers (small botnet)
8 6,354.53 hours 63.55 hours 6.35 hours
10 24,426,826.45 hours 244,268.26 hours 24,426.83 hours
12 93,896,720,861.02 hours 938,967,208.61 hours 93,896,720.86 hours

Mixed Case, Numbers and Special Symbols

No. Characters 1 Compter 1,000 Computers 100,000 Computers
8 177,407.91 hours 177.41 hours 1.77 hours
10 1,567,576,296.21 hours 1,567,576.30 hours 15,675.76 hours
12 13,851,104,153,269.40 hours 13,851,104,153.27 hours 138,511,041.53 hours

As you can see, not only is the character space (upper case/lower
case/numbers/symbols) important, but also string length. e.g. an 8 character,
totally random string using mixed case, numbers and symbols could be cracked in
less than two hours on a larger botnet, and it is likely that the person
stealing this information has access to something like this, but for a 12
character string, this would take over 15,800 years on a 100,000 computer
botnet.

p.s. A 32 character mixed case, numbers and sybol password would take upto
45,839,513,591,436,800,000,000,000,000,000,000,000,000 years on 100,000,000 (100 million) computers,
to brute force which is one-million-trillion-trillion times longer than the universe has existed.

Reset The Internet

The following is an example of the sort of work it would take to back up the data on the internet. Destroy the current implementation, and create a new one.

Where to start?

Assuming that all parties involved in something as large scale as resetting the entire internet have agreed to actually doing this, and doing so at no extra cost to the customer (me and you) we would first need to consider how, and where, all the data that is currently on the internet will be backed up.

The shear scale of the internet as it currently stands is unimaginable, the number of domain names registered globally now totals more than 138 million, according to the second quarter 2007 Domain Name Industry Brief published by VeriSign, a provider of digital infrastructure for the networked world.

The largest top-level domains (TLD) in terms of total base of registrations are .com, .de (Germany), .net, .uk (United Kingdom), .cn (China) and .org.

Backing up the domain name database

Let us work out how much space a raw database would take up to simply store the records of the domain name, two domain name servers, and for arguments sake, a 32bit signed integer to represent the unix timestamp of when the domain was registered, and for now, we will forgo all the other information we know domain names carry. Say we stick to the maximum 63 characters originally set out for domain names and use 8 bit characters.

63characters x 8bits per character = 504 bytes

Now we add on the 32 bits for the date first registered.

504 + 32 = 536

We now need to make sure we have enough room to store two domain name servers from 0.0.0.0 to 255.255.255.255, so we need a field that can hold 15 characters, or, we can use another 32 bit integer for each of the domain name servers and store it in its address format.

536 + (32 x 2) = 600

So now we have 600 bits per row to store this information. Now we need to find out what that would be in real terms of storing 138 million domain names.

600 x 138,000,000 = 82,800,000,000bits

82,800,000,000 / 8 = 10,350,000,000bytes

10350000000 / 1024 / 1024 = 9870.5mb

So we have over 9000mb of information just stored in those fields, the central database would also have to store the owner, the address of the owner, the technical contact, and the administrative contact. The ISP that was used to register the domain name would also have to be stored along with the last renewal date and various others. With this extra data we could increase this figure by quite an amount.

Backing up the web

To give some context to the size of just the World Wide Web (only one of the services that currently runs on the internet), the BBC currently has 5.43 million pages indexed in Google, ranging from their homepage at 120kb to a media rich news page of around 250kb so if we take an average of half way between (185kb) to work this out, everyone can be happy:

185kb x 5,340,000 = 987,900,000kb = 964,746mb = 942gb

Say we were to back up all that data on to a set of DVD’s, an standard DVD claims 4.7gb storage on the front of the disk, where it is actually closer to 4.4gb. To make this easier we assume that the BBC have not compressed any of their data, but have packaged it into a set of 4.4gb files (multi-part rar files or multi part tar files) so that we do not run into the problem caused by having a lot of small files.

942gb / 4.4gb = 214.1 DVD’s

So we would need 215 DVD’s to simply back up bbc.co.uk (since we cant have 0.1 of a DVD), and this assumes that we are simply storing the data hoping that nothing goes wrong with any of the discs, so a recovery record of 5% in WinRAR could be added which would be sufficient enough to recover all text based data within the files, this would push the 942gb to 989gb.

989gb / 4.4gb = 224.7 DVD’s

Now we need 225 DVD’s in order to back up the BBC and ensure that we have some sort of recovery record in case of data corruption because of a bad copy or a scratched disc.

To be continued…