Monday, October 11, 2010

Simple MPEG Trickery

In a previous life I occasionally created MPEG files from still images. I recently found some notes I'd taken and printed out. Since cloud services are all the rage these days, and because this may actually be useful to someone else (who knows?) I thought I'd save the notes here.

Disclaimer: I assume no responsibility for the horrendous formatting of blogger.com.



How to Convert Images to MPEG



Method 1

cat <file>               \
 | anytopnm              \
 | ppmtoy4m -n <n> -r    \
 | mpeg2enc -F 4 -q 1 -Q 5 -H -a 1 -2 1 -4 1 -o <file>.mpg


Explanation:
  1. Convert the file to a pnm (portable anymap)
  2. Convert the pnm to a y4m (YUV4MPEG2) stream.
    • -n: Output a total of <n> frames.
    • -r: Repeat last frame until <n>.
  3. Convert the stream to MPEG
    • -F 4: Format 4: Standard SVCD
    • -q 1: Quantization (1..31; 1 is best quality)
    • -Q 5: Quantization Reduction (0.0..5.0; 5 for sharp images)
    • -H: Keep as much High Frequency information as possible.
    • -a 1: Aspect ratio (1=1:1; 2=4:3; 3=16:9; 4=2.21:1)
    • -4 1: Initial 4x4 subsample search quality (1..4; 1 for best quality)
    • -2 1: Secondary 2x2 subsample quality (1..4; 1 for best quality)

Sadly, that's not as clean as it could be. It would seem that the quality settings do not affect the initial image. The longer the clip, the clearer the MPEG gets, until the new GOP, at which point it resets. I think it's a bug. The following produces larger images and is more complicated, but they are crystal clear. There must be an easier way to do this as well, preferably with a pipe. Transcode is just a wrapper ... I should be able to turn on debugging and find out what it is really doing under the hood.


Method 2


Step 1:
  • Create the input source
cat <file>| anytopnm | ppmtoy4m -n <n>-r > <file>.y4m

Step 2:
  • Transcode the Y4M to MPEG
transcode -C 3 -y ffmpeg,null -F mpeg1 -Q 5 -V -k -i <file>.y4m -o <file>

This creates <file>.m1v. MPEG1 produces slightly smaller files with no appreciable difference in quality.

Explanation
  1. Convert the file to a pnm (portable anymap)
  2. Convert the pnm to a y4m (YUV4MPEG2) stream.
    • -n: Output a total of <n> frames.
    • -r: Repeat last frame until <n>.
  3. Convert the stream to MPEG
    • -C 3: Anti-alias mode 3: Process Full Frame
    • -y ffmpeg,null: Use ffmpeg video codec, no audio codec
    • -F mpeg1: Option to tell ffmpeg to use mpeg1 encoder
    • -Q 5: Encoding quality (0=fastest, 5=best)
    • -V: Use YV12/I420 as internal video codec (fastest processing)
    • -k: Swap red/blue (Cr/Cb) in video. Without this, people get blue faces
    • -i: Input file name
    • -o: Output file form (.m1v or other extension automatically appended).


Method 3


This looks like a very promising method (needs to be fleshed out)

cat <file>.y4m | ffmpeg -f yuv4mpegpipe -i - -target vcd -f mpeg1video -y <output>

or something like


ffmpeg [-f (yuv4mpegpipe)] -i <file> -target vcd [-f mpeg1video]? -y <output>

Explanation
  1. Start with y4m (see above to create)
  2. -target vcd seems to be the magic
  3. -y is force overwrite


Method 4

This is a pretty good way to extend (loop) an MPEG. First, convert it to a YUV stream:


transcode -i <file> -o output -y yuv4mpeg -k

  • The -k is the chroma conversion we need with YUV video

Next, there are two ways to proceed. mpeg2enc is slower, a little less quality, but better compression. ffmpeg is faster, better quality, and the commandline arguments make sense, but it produces bigger files.

Both of these work with yuv4mpeg streams as created in the steps above. The yuv4mpeg stream is text-based, and contains one line at the beginning of the file that need to be removed for looping. Repeat the sed command in the examples below to extend the MPEG duration.

  1. mpeg2enc
    • (cat <file>; sed 1d <file>) | mpeg2enc -v 1 -I 0 -f 8 -F 4 -n <n> -a 2 -o <ouput>
  2. ffmpeg
    • (cat <file>; sed 1d <file>) | ffmpeg -f yuv4mpegpipe -i - -target dvd -b 2000 -y <ouput>

Note: the '-b 2000' overrides the default bitrate to 2mbit. Raising the bitrate gives better quality video at the expense of larger file sizes.


Method 5

This is an all-in-one shot that I've been using with success:


cat <input>               \
 | anytopnm               \
 | pnmtoy4m -r -n 100     \
 | ffmpeg -f yuv4mpegpipe -i - -target vcd -f mpeg1video -y <output>.mpg



Converting Short MPEGs into Long MPEGs


Method 1

This is really just extracting a still frame and then extending it into an MPEG using Method 5 above:

  1. Extract the first frame:

    transcode -i <short_mpeg> -o <framename> -y ppm -c 0-1

  2. Convert it into an MPEG:

    cat <framename>000000.ppm            \
     | ppmtoy4m -r -n ((<seconds> * 30)) \
     | ffmpeg -f yuv4mpegpipe -i - -target vcd -f mpeg1video -y <output>.mpg

Friday, July 30, 2010

My Toaster is Amazing

So here's a simple example that shows my continuing childlike wonder .... or something.

My toaster is amazing.  Not that there's anything special about my toaster - it's a 2-slice Toastmaster.  I expect I bought it some 15 years ago for $15 or less, and most likely at Walmart.  I suppose what I find amazing about it, aside from toasters being one of the most reliable devices you'll ever buy, is that I don't really know how they work.

Now, I generally understand the electricity makes heat part, but the "brownness" selector is something of a mystery.  I always assumed that this was tied to a variable resistor that affected some timer.  Not so.

I don't really care to go shopping.  You may wonder if my brain just skipped the tracks.  A reasonable assumption but bear with me:  Because I don't care to shop, I tend to avoid it.  This means that I tend to "stock up" when I do go shopping.  Long story short, this means I have lots of bread in my freezer.

One day I thought I'd defrost some bread by popping it into the toaster.  It may be uneven and a bit crisp on the edges, but I can deal with that - or so I thought.  It turns out that the toaster toasts my bread to perfection even when it's initially frozen solid.  Clearly, this toaster is a more complex device than I had imagined.


In an assuredly unrelated topic, turkey and cheese on frozen wheat bread - 3 stars; turkey and cheese on toasted wheat bread - 11 !

Thursday, July 22, 2010

A word-game riddle

A while ago I came up with a simple riddle while driving (no, I don't need a cell phone to be distracted, TYVM).  I haven't really figured out the best way to describe it, but this is the premise:

There exist sets of five words (in english) such that the only difference between the words is that one of the letters can be replaced by each of the five vowels.  As an example, the pattern "b_g" expands into "bag", "beg", "big", "bog", and "bug".  I believe all the three letter combinations are that plus "f_r", "p_p", "p_t", and "t_n".

I know of a similar set consisting of words of seven letters.  The challenge is to find it.  Is it the longest?

A secondary challenge is to simply find other sets, of any length.

Sunday, June 27, 2010

Newspaper Clippings

Since living in Florida I've often wondered if the sun makes people insane.

I don't have much of a cohesive thought behind this, but I've recently been reading the local newspaper's website.  For lack of any better commentary, I'll simply quote the thoughts of those from my community.

The paper reports a story regarding raccoons becoming acclimated to humans and behaving aggressively.  Apparently they are being fed, either directly or indirectly by the people who feed the local feral cats, and as state law prevents the raccoons from being relocated, they will be trapped and chemically euthanized.  Among the 45 comments to the story are these gems:

Momekit writes:  "Did you know that Racoons also carry TB along with rabies --and they are also know for loving to eat your cats and killing your dog if they can.-They will attack you--as I have been almost run down by a pack. If they run away I say relocate them WAAAAAAAY out in no mans land. f they stand their ground --put them down- I had them try to rip into my camping tent with me and my two cats inside. I do not like them anymore -ever no not ever..WE had cats killed by them I know what I say as true along with 28 chickens -and a couple of geese..I know of a lady police woman tht had one for a pet that snapped 3 of her finger off before she could get them away from it. Some pet. Wild animals when wrown are dangerous and they will always be WILD. My kitties had a riht to life along with the chicken-of which some were down right pets--Now they are all dead becasue of racoons-Racoons do not belong around people or their pets.By the way they climb and sleep in trees eat N baby birds- squirls N kittens"

kittengirl replies:  "Momekit, Also watch out for the coyotes. They are now in our area. They have migrated to all over the Southern U.S. and Florida. They eat cats, dogs, raccoons, chickens, ducks, and children. One cornered me in my yard while I was gardening one time, and was sneaking up on me silently with a demon-like grin on his face. I barely got in my house in time. They run in large packs and you and your pets or children DO NOT STAND A CHANCE of getting away from them unhurt if the pack attacks.Even if you are in a camping tent, that will be no protection from them. They are far more dangerous than raccoons, and carry rabies.They should all be removed from our area."

I'd like to think that kittengirl was exercising her sharp wit here, but I'm not convinced that's the case.  What's more, the paper carries a ranking system of sorts, and these are the highest "Recommend"ed comments on the page.

Of course, there are also interesting threads about the feral cat problem.  Freelens has the problem solved:  "I bet if people stop feeding the feral cat colonies there would be a lot more birds laying a lot more eggs that the racoons could be eating."

Sadly, it appears that the feral cats are actually zombies.  From imqwerty: "Google "Florida feral cat attacks" for more...
VOLUSIA COUNTY, Fla. — The Volusia County Health Department issued a rabies alert for 60 days Friday, following two unprovoked attacks on humans by feral cats within the past month.
In one case, a cat wandered into a house and attacked a woman inside. In the other, passing motorists who stop to aid a cat that had been hit by a car were attacked."

Elsewhere in the news, there is a community blog site.  rodrinck3 posts the following entry titled "Toe nail fungus": "A natural colon cleansing method is sure to make you healthier, boost your energy levels.Find how toe nail fungus treatment works.for more details go to genital warts"

Indeed.

Thursday, March 18, 2010

Microsoft Security Essentials (SOLVED: 0x8004ff01)

Initially published 2010/03/18; updated 2013/05/01 to edit title in a poor-man's SEO effort

So ... ignoring the whole I'm actually installing Windows thing for a moment, in order to look at some software I'm installing Windows XP (XP because apparently I bought something that came with a license for it) in a virtual machine.

So I installed XP and then upgraded to service pack 3 via Windows Update.  It seemed like the right thing to do.  Meanwhile, Windows is complaining about my not having antivirus software installed.

I find something called Microsoft Security Essentials that can be installed for free, but it keeps failing with error code 0x8004ff01.  There's a link that can be clicked for help, but no help is to be found by following it.  The site even provides a search box but it knows nothing about the error code.

I figure maybe if I installed IE8 it would pull in whatever was hip and cool, but no such luck - the same error continues to manifest itself. While searching around on the web for how to solve this I find all sort of abstruse instructions involving editing the registry and rebooting a dozen times.  Ahh, Windows, how I never missed you.


However, using the gray stuff in my head (aka: taking a SWAG) I found the the answer is relatively straightforward: Download MSI 4.5 (the Windows Installer), which can be retrieved from here:  http://www.microsoft.com/downloads/details.aspx?FamilyId=5A58B56F-60B6-4412-95B9-54D056D6F9F4&displaylang=en

Clicky-clicky and away you go.  Your Windows XP with Service Pack 3 (SP3) gets a fancy new icon in the system tray, the antivirus warning icon goes away, and your computer is apparently suitably inoculated for travel to the internets.

Saturday, March 13, 2010

Flash (savior of the universe?)

This morning I looked at my Watt's Up? meter and it read 160 watts.  I was expecting it to read around 110 based on my baseline measurement the other day.  I noticed that "Shockwave Flash" was consuming some 80% of my CPU so I killed it.  Now the meter reads about 97 watts.

Because I may be taking a trip soon I went to the Travelocity website.  They have a banner advertising their own service (thanks - I never would have heard of you otherwise) that for some reason just HAD to be done in flash.  Because, you know, you can't make a 4 frame GIF or something.

My Watt's Up? meter now reads 110 watts again.

Fight global warming: disable Flash.

Thursday, March 11, 2010

Illuminating

I recently bought a Watt's Up? power meter and plugged my computer station into it.  Looking at the readout, it consumes about 110 Watts.

Wow, I thought, that seems like a lot.  Because, you know, it's over 100.  In some scales that could boil water.

Then one evening I turned on my little desk lamp and glanced at the power meter.  It read 150 Watts.  Wow again.  That seems like almost 50% more (though it's closer to 1/3)!

So I look, and the little lamp only has a 40 Watt bulb in it (at least that part of the math works out).

That seems ... disproportionate.

With 110 Watts, I can power a computer with its associated CPU, Hard Disks, Graphics Card, etc, a pair of speakers with a powered subwoofer, a 22" LCD, a cable modem, a wireless router, a keyboard and optical mouse, and recharge the battery in my UPS.  Using these I can talk to almost anyone in the world virtually instantaneously, watch movies, play music, learn about the world, and almost anything else intangible.

With 40 Watts, I can illuminate a small corner of my bedroom.


My bathroom lighting fixture has three bulbs: a 100 Watt and two 75s.  250 Watts to illuminate the smallest room in the house.  I could put a computer with 6 22" LCDs there instead, saving power and upgrading the lighting to a giant virtual seizure-inducing disco ball or psychedelic Lava® lamp wall.

Or I could save all that energy and just comb my hair in the dark.