Forcing video preview frame in YouTube

Many people noticed YouTube flash player is not so rich in options, and one of its the lacks is that it's not possible to choose the preview frame for an uploaded video; not a static image, neither a frame from the video itself. However, if you absolutely have the need to choose the preview frame, you should know YouTube takes as preview the frame at about the temporal half of the video. This is not an official information, but just the result of some observation: maybe for some videos the choosing "algorithm" is different.

In my expreriences (the most beautyful video I uploaded, that's nevertheless a poor one, is this), the frame at the exact half of total frames number is not the chosen preview; it seems that the algorithm is:

  1. Take the temporal length of the video;
  2. Divide by 2, and truncate to the shortest integer;
  3. Choose previous frame, or the current one if it's exactly the moment to change frame (if 1/framerate divides the length).
I made two videos to confirm this hypothesis, with labels in each frame indicating the current position:

As you can see, the choosen frame is not the exact half. 500 frames at 25 frames/second are 20 seconds, and 510 frames are 20.4 seconds. In both cases, frame number 251 (1-based) is choosen; 0.4 seconds more make no influence at all.
If you want to do more tests by yourself, you can use ImageMagick go generate the frames and MEncoder to merge them into a video. Here is the bash script I used to generate these videos.

Interlacing makes things more complicated, because there's no way to know in advance how YouTube converting engine will work; and, of course, we can not choose in advance useful video parameters (like deinterlacing method). So, try to upload an already deinterlaced video, if possible; Flash streams are progressive, and would be a good choice not to let YouTube decide how to deinterlace.

Update: by downloading again my same video, I noticed that its length has changed, though the original submission was already progressive. The conclusion is: I can't find out the algorithm YouTube uses to choose the preview, it would need more experiments and I don't have the time to do them.

But is this just a useless toy?
In my opinion, it's not just a toy, but a powerful trick. Consider, for example, this video:

The preview is absolutely arbitrary, and has *nothing* to do with the content of the video. During the first two hours after I uploaded it, 239 views were hit. Without this "special preview", the same video was viewed 2 times in a week... Tricks for cheating people apart, this technique can be used to set a decent preview to your videos; the default YouTube's algorithms produces lots of annoying previews, that just don't match well the real content of the videos. That was why I had the initial idea: in one of my videos, the chosen preview was a frame almost completely black, while the rest of the video was white.

As you probably noticed, poor seeking is another annoying fact in YouTube videos; this time, the injection of keyframes is related also to scene changes, so if you move the "preview frame" one or two or three position before, it's not the preview anymore but it's still a keyframe (I did this experiment). To do: upload a .flv video already encoded with many keyframes, to test if YouTube is going to delete some of them or not.

Now, if YouTube chose for your video an awful preview, you know how to force it to use a better one. Power to masses! But remember: from a great power, come great responsabilities... Try to imagine what spammers could do with this trick... Oouch!

1 comment:

Anonymous said...

Interesting post.. Found this on the search engine when I typed deinterlace youtibe video. On the learning curve right now, =).

Post a Comment