Tuesday, July 26, 2011

How to Create a Web-Based Video Converter

My wife teaches cooking classes near Boston and blogs about food. Recently, she's become interested in video. She's already made a few videos using Windows Movie Maker (WMM), like this one on how to dice an onion. But, she's finding that free movie editing software just doesn't cut it. The kicker was when she published a video, learned that the volume was too low and couldn't find any way to raise the volume in WMM---it only allows limited volume adjustment.

She had already started researching video software options and settled on Sony Vegas. Yes, people complain that it crashes and/or runs slowly, but those same people are trying to process relatively large movies. My wife is looking to publish 5 minute non-HD videos on YouTube. So far, Sony Vegas has worked well for her. The one problem she's encountered is that Sony Vegas can't import Flip Video AVI files. She found a free Windows-based converter. But, it leaves a blatant watermark and screwed-up a half-second of the audio track.

I figured this would be an easy problem to solve with Linux software. Sure enough, a bit of searching and I discovered ffmpeg, which is available in Debian. After a few minutes of man-page reading, I had a command-line to perform the conversion:

ffmpeg -i myvideo.avi -target ntsc-vcd myvideo.mpg
Note that this generates NTSC video. If you're in Europe, you might want PAL, which you'd get by changing the target to pal-vcd.

But, this wouldn't cut it. My wife didn't want to have to copy to Linux, convert, then copy back or wait for me to get home just so she could start editing a video. So, I set to work on creating a web-based converter. Creating a script to upload the video is straightforward and easy to find. Here's an example of file upload HTML and PHP. But, what this page doesn't tell you about are the hard limits PHP has on file and memory sizes. Here is a PHP "bug" which describes the max file size ("exceeds the limit of 8388608 bytes") problem I quickly encountered. Sniper provides the config settings that need to be edited:

post_max_size = 256M
upload_max_filesize = 256M
memory_limit = 256M
I modified these settings in /etc/php5/apache2/php.ini, restarted my web server, and then was able to upload video files larger than 8 megs. The final question was how to push the converted video back to my wife's web browser. For some reason, all the pages I found on how to upload a file didn't mention anything about the possibility of pushing binary data back to the user. Finally, I stumbled upon the PHP readfile function. Occasionally, PHP is nice in that it provides tools and examples for what you probably want to do, like push an entire file to a user's web browser. The readfile manual page provides a full example for how to do this, including the necessary HTTP headers and proper output buffer management.

Here's what I ended-up with. Note that this script is unsafe due to the fact that it executes a shell command. Also, it relies on /tmp being the usual "temp" directory and can fail if a file already exists with the name $outfile. But, it serves it's purpose for me.

if ($_FILES["video"]["name"]) {
  $pattern = '/(.+)\.avi$/i';
  $replacement = '${1}.mpg';
  $outfile = preg_replace($pattern, $replacement, basename($_FILES["video"]["name"]));
  $cmd = "ffmpeg -i " . $_FILES["video"]["tmp_name"] . " -target ntsc-vcd " . $outfile;
  header('Content-Type: application/octet-stream');
  header('Content-Disposition: attachment; filename=' . $outfile);
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  header('Pragma: public');
  header('Content-Length: ' . filesize($outfile));
} else {
<form enctype="multipart/form-data" action="video.php" method="POST">
Choose a file to upload: <input name="video" type="file" /><br />
<input type="submit" value="Upload Video" />

Tuesday, July 19, 2011

How to Create a GMail Filter Based on Reply-To

Today, I found myself trying to filter a message in Gmail based on the "Reply-to:" header. "Reply-to:" was the only user-friendly header that clearly distinguished it from other types of messages I receive. I knew that Gmail allows list-based filtering using a "list:" prefix in the "Has the words:" field. But, I haven't found a resource to tell you what, if any, other prefixes are allowed. I tried "reply-to:" without success. Then, I searched and found another poor soul with the same dilema. A bit more futzing and I discovered that "replyto:" was the correct prefix. Unfortunately, the Google help forum won't let me post a reply (!) So, I am hoping that romadatnvwisp will read this post and learn how easy it is to filter based on the "Reply-to:" header. Maybe he's figured it out himself?

To recap... lets say you want to filter messages with a Reply-to: address of "me@sample.com". Here's how you do it:

  1. Click the gear icon in the upper-right-hand-corner of Gmail, then select "Mail settings"
  2. Click the "filters" tab, scroll to the bottom and click "Create a new filter"
  3. Type "replyto:me@sample.com" in the "Has the words" field
  4. Click "Next Step" and finish creating the filter; note that matching messages should appear below after clicking "Next Step"

Sunday, July 10, 2011

How to Add Share Buttons in Blogger

Google has redesigned the Blogger administration interface.  As a result, the instructions posted by Blogger a month ago on how to add the "+1" button are no longer valid.  "Design >  Page Elements" no longer exists.  Instead, you need to click "Layout" then click the tiny "Edit" link at the bottom right-hand corner of the "Blog Posts" box.  This will give you a list of post option.  Make sure the "Show Share Buttons" checkbox is checked, then scroll to the bottom and hit "Save".

Didn't work?  That's expected if your blogger has existed for a while (more than 1 year?).  Fortunately, this Blogger Templates post on how to add share buttons describes how to hack it (scroll down).  This trick worked nicely for all but one of the blogs I administer.  Unfortunately, for my wife's Beyond Salmon blog which was created six years ago, it only sort-of worked---the buttons came out very small and the "+1" button didn't appear (even after I moused over the other share buttons, which was the only way "+1" would appear on some other blogs).  Bleh.

Friday, July 1, 2011

I Want My Old Google Calendar Back!

My wife woke up this morning to discover that her Google Calendar had been transformed via Google's effort to evolve the Google design and experience.  I fail to see how this effort is a good idea.  The result is that my wife can see fewer events on her "Month" calendar (which is the primary view she uses).  She used to be able to see six events per day.  Now she can see four and she has to click the "more" link to see all events on a day with 5 or 6 events.  It seems that this is due to wasted space.  There is more padding/spacing around everything, including day-of-the-week names and date numbers.  What's the point of spreading-out everything in the display if it distances you from useful information without improving usability?  I'm at a loss.  Fortunately, it's easy to revert to the old UI---click the gear icon in the upper-right-hand-corner, then select "Use the classic look".

Disclosure: I joined Google via the ITA Software acquisition and have no involvement in the above-discussed UI redesign.

Update 7/4/11: Apparently, I'm not the only one who thinks the Google Calendar redesign is a bad idea.