Scott Hanselman

How to rotate an AVI or MPEG file taken in Portrait

February 11, 2007 Comment on this post [7] Posted in Musings | Tools
Sponsored By

I've got a little Casio Exilim that I use to make little videos to post on this blog. Sometimes, though, I rotate the camera and end up creating a video that's, well, rotated in portrait, not landscape, and I want to rotate the Video to a vertical orientation.

There's an open source tool called MPlayer out of Hungary that you can download. Get the MPlayer 1.0rc1 Windows package, NOT the Windows GUI package. We're not looking for a Video Player here  but rather a utility called MEncoder that comes with the MPlayer package.

This command-line tool is rather obscure, as it seems is the whole culture of video wonks, but I just want to do my work and move on. If you like, however, there's a whole world of Unofficial Packages that sit in front of this obscure tool and do the hard work for you.

Here's the magic I used to rotate my video 90 degrees to the right:

C:\Users\Scott\Desktop\mplayer>
mencoder -vf rotate=1 -o OUTPUT.AVI -oac copy -ovc lavc INPUT.AVI

The -vf is for "Video Filter" and you can chain them, like -vf rotate=1,flip,scale=640:480 if you like. The -oac and -ovc are the audio and video outputs. In this case, I "copy" the audio over, and use the "libavcodecs" for the output. You can do mencoder -ovc help to get a list of choices or read the massive docs.

At this point, I have a really tall 480x640 video, since it used to be at 640x480. Certainly I can leave it there, or I can expand it to a more regular 4:3 ratio. As it's now 640 tall, it'll need to be 853x640 to be 4:3.

C:\Users\Scott\Desktop\mplayer>
mencoder -vop expand=853:640 -oac copy ovc lavc -lavcopts vcodec=mjpeg  OUTPUT.AVI -o BIGOUTPUT.AVI

Notice that the portrait is now centered between black bars like a vertical DVD. The aspect ratio is correctish now and we have a vertically oriented video inside a horizontally oriented "container."

I probably (and you as well) should use "raw" as your output format as you move through these steps, as we're making copies of copies here and the quality is getting worse and worse. You'll end up with gigabyte-size temp files, for a bit, but your output will be much better.

Next I'll just scale the video back to 640x480 for posting on the web.

C:\Users\Scott\Desktop\mplayer>
mencoder -ovc lavc -lavcopts vcodec=mjpeg -vop scale=640:480 -oac copy BIGOUTPUT.AVI -o FINAL.AVI

Again, pick the codec that is right for you in order to tune your output size and quality.

UPDATE: Someone emailed saying that the AVI format made by mencoder doesn't always work on Windows Media. (I use VLC Player, works fine) and they suggested the final encoding pass be done by FFMPEG, rather than mencoder:

C:\Users\Scott\Desktop\mplayer>
c:\utils\ffmpeg_mp2.exe" -i finaltest.avi -sameq -acodec pcm_u8 -vcodec mjpeg FFMPEGOUTPUT.AVI

Worked for me.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Yahoo Pipes - Simultaneously Brilliant and Dumb

February 10, 2007 Comment on this post [1] Posted in Javascript | Musings | Web Services | XML
Sponsored By

Folks continue to blow me away with what can be done with JavaScript and Ajax. Seriously. Yahoo Pipes is amazing. Truly.

I always look at things like this with my non-technical family in mind. Things like DabbleDB are easy enough to use that my Dad or Wife - to be clear, experts in their fields of FireFighting and International Business respectively - could be very productive, very quickly. The same is true with anything that 37Signals does, and other very UX (User Experience) focused Ajax apps. It took a bit to convince my wife that Gmail was the Second Coming of email, but now she's convinced. Anyway.

I saw Yahoo Pipes and immediately had these thoughts (this is the one-sided conversation I had in my head):

Here's Technical Me:

"This is the beginning of that Semantic Web we've heard so much about. All I have to do is teach folks that URLs point to stuff that has some structure - like a database in the sky via hackable URLs - and they can go from there."

Here's Not-Technical Me, pretending to be a Web Enthusiast, like my Dad or Wife. This person knows that Feeds exist at URLs.

"Hm, so it looks like Yahoo Pipes likes to consume Feeds so I'll make a unified Feed for both my blog and my podcast."

"Ok, drag a Fetch here, and paste in the URL http://feeds.feedburner.com/ScottHanselman. Nice. Now another with http://feeds.feedburner.com/Hanselminutes, Cool."

"Now, how do I combine them?"

"Ah, Union, ok, under Operators. I had to look for that one. Not combine, but OK, drag a Union over here, how do I connect...Oh, wow. That's cool, just drag a line."

"Now I need to sort them by the date they were published, so new stuff is first."

"Drag a Sort over. Cool, so now click the drop-down...I figure pubDate must be Publication Date. I wish there was a Data Dictionary that would have made that easier to guess."

"So now I drag a line to Output. Cool, I see the output at the bottom."

"Wait. The order is all wrong. Hm...did I Sort wrong?"

I'll save you the carnage, but at this point the Non-Technical User of Yahoo Pipes is what we call in the Technical world "Screwed" because the Technical User realizes by looking at the source of the pipes resulting RSS here that the Sort widget sorted the Dates in alphabetical order.

This is lame, dear reader, for two reasons, in my opinion.

One, it reminds me how frustrated I was, and still am, when I realized that the <pubDate> element in RSS is based in the 1982 RFC822 Date Format (Sat, 07 Sep 2002 00:00:01 GMT) rather than the ISO 8601 Date Format the most XML formats conform too. Can't do much about that.

Two, while Dave Winer thinks that Yahoo Pipes are something that only a technical user would care about, I personally think that it's time to make the web more accessible. That means I shouldn't have to know JavaScript to make a Mashup. The idea behind Pipes is wonderful. That enthusiastic and creative folks who know that a URL can point to a Feed and that Feeds have Good Stuff™ can make Better Stuff™ that is greater than the sum of its parts.

So, Number Two is basically that it's pretty amazing that, even in Beta, an application that speaks RSS and intends to produce RSS at its core doesn't understand one of the most fundamental data types - a date and a time.

That said, I'd still say Yahoo Pipes is going places. This is a silly stumble out of the dates, I mean, gates, but seriously, go check it out. Their developers know this is icky and say it's on their ToDo List.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

How to force all cookies to Secure under ASP.NET 1.1

February 10, 2007 Comment on this post [0] Posted in ASP.NET
Sponsored By

Just a quick tip here. Thanks to John Batdorf for bringing it up. In order to prevent Session Hijacking, when you've got a secure site, it's a good idea to mark your cookies as "secure," meaning that they can't be accessed over HTTP. This prevents folks from being issued cookies over HTTPS then switching to HTTP in order to access the cookie with sniffers or other evil.

There's a few ways to do this in ASP.NET 1.1, here's an easy one. Under 2.0 you can say requireSSL="true" as well and avoid this code altogether (see below). For 1.1, add a handler for End_Request to your Global.asax.

This chunk of code is multipurpose, so don't blindly copy-paste. Note that it code also sets the Forms Auth cookie and Session cookie to HttpOnly, but that's not required.  If you have JavaScript DOM code that accesses cookies, you won't want those marked HttpOnly.

protected override void Application_EndRequest(Object sender, EventArgs e) 
{
      string authCookie = System.Web.Security.FormsAuthentication.FormsCookieName;
      foreach (string sCookie in Response.Cookies) 
      {
            if (sCookie == authCookie || sCookie == "ASP.NET_SessionId")
            { 
                  if(System.Environment.Version.Major<2)
                  {
                        // Force HttpOnly to be added to the cookie header under 1.x
                        Response.Cookies[sCookie].Path += ";HttpOnly";
                  }
            }
            //Force all cookies to SSL regardless of web.config settings!
            Response.Cookies[sCookie].Secure = true;
      }
}

The check if we're running under 2.0 is to prevent doubling up on the HttpOnly attribute if code compiled under 1.1 is run under 2.0 and you've set  httpOnlyCookies to true.

<httpCookies httpOnlyCookies="true" requireSSL="true" domain="" />

If you're using older versions of IIS, make sure you have this hotfix (274149) to ensure that IIS respects your secure cookies, or better yet, don't serve traffic on port 80.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Hanselminutes Podcast 50 - OpenID/Microsoft Announcement

February 09, 2007 Comment on this post [1] Posted in Identity | Podcast
Sponsored By

My fiftieth podcast is up. This one was about the OpenID/Microsoft Annoucement and how OpenID will affect Identity 2.0 possibly more than CardSpace - certainly in the short term.

ACTION: Please vote for us on Podcast Alley!

Links from the Show

My OpenID (lu2)
ZDNET on the Announcement (lu7)
OpenID Screencast (lu3)
Historical Background (lu8)
Notes on Bill Gates’ Identity Keynote (luc)
OpenID Explained (lu4)
CardSpace / OpenID Collaboration Announcement (lu9)
TailRank on OpenID (lud)
Identity 1.0 (lu5)
Scott Kveton on CardSpace and OpenID (lua)
Integrating OpenID and Infocard - Part 1 (lue)
OpenID Commentary (lu6)

Subscribe: Feed-icon-16x16 Subscribe to my Podcast in iTunes

Do also remember the archives are always up and they have PDF Transcripts, a little known feature that show up a few weeks after each show.

Our sponsors are /n software and the .NET Dev Journal.

As I've said before this show comes to you with the audio expertise and stewardship of Carl Franklin. The name comes from Travis Illig, but the goal of the show is simple. Avoid wasting the listener's time. (and make the commute less boring)

  • The basic MP3 feed is here, and the iPod friendly one is here. There's a number of other ways you can get it (streaming, straight download, etc) that are all up on the site just below the fold. I use iTunes, myself, to listen to most podcasts, but I also use FeedDemon and it's built in support.
  • Note that for now, because of bandwidth constraints, the feeds always have just the current show. If you want to get an old show (and because many Podcasting Clients aren't smart enough to not download the file more than once) you can always find them at http://www.hanselminutes.com.
  • I have, and will, also include the enclosures to this feed you're reading, so if you're already subscribed to ComputerZen and you're not interested in cluttering your life with another feed, you have the choice to get the 'cast as well.
  • If there's a topic you'd like to hear, perhaps one that is better spoken than presented on a blog, or a great tool you can't live without, contact me and I'll get it in the queue!

Enjoy. Who knows what'll happen in the next show?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Web 2.0 Explained in Video by Michael Wesch

February 09, 2007 Comment on this post [12] Posted in Musings
Sponsored By

It moves fast, so pay attention, but this is the single best 5-minute explanation of Web 2.0 I've seen. It was created by Michael Wesch, Assistant Professor of Cultural Anthropology at Kansas State University.

It's absolutely worth your five minutes.

I'm personally interested in what your spouses and parents thinks about it.

Too fast? Too intense? To many concepts too fast? Or does it open their eyes and help them to "get" Web 2.0? 

Dad, what do you think?

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook bluesky subscribe
About   Newsletter
Hosting By
Hosted on Linux using .NET in an Azure App Service

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.