Order Now AdSolution Sign Up | Login » Bits on the Run Sign Up | Login »

Forums

/

aspect ratio not detected

30 replies [Last post]

http://wayback.archive-it.org/1193/20081022045239/http://ash-v315.ash.youtube.com/get_video?video_id...

This is a youtube video that we have archived. The original watch page is: http://www.youtube.com/watch?v=YAt-3Yk2u80

Totem (http://www.gnome.org/projects/totem/) finds and plays the correct dimensions: 320x180 (16:9 aspect ratio), so they must be in there somewhere, and the youtube player also finds them. JW Player plays at 4:3 aspect ratio.

I would love to see this work correctly!

 
The sad reality is, "Your video has no size data".

So... they were guessing.

Magic: FLV
Version: 1
Has audio: yes
Has video: yes
Offset: 9
--- Tag #1 at 0xD (13) ---
Tag type: Meta
Body length: 6516
Timestamp: 0
* Metadata event name: onMetaData
* Metadata contents: {
    'duration' => 675.030000
    'videodatarate' => 328.893957
    'lastkeyframetimestamp' => 674.760000
    'lastkeyframelocation' => 27748999.000000
    'creator' => 'YouTube, Inc.'
    'metadatacreator' => 'YouTube Metadata Injector.'
    'flvsource' => 'cdbp'
    'haskeyframes' => true
    'hasmetadata' => true
    'keyframes' => {
        'times': [
            0.000000
            2.040000
            4.000000
            ..........
            670.840000
            672.800000
            674.760000
        ]
        'filepositions': [
            6544.000000
            154348.000000
            221286.000000
            ...............
            27675848.000000
            27720016.000000
            27748999.000000
        ]
        '': 0.000000
        '': 0.000000
    }
}
* Missing: 28 bytes
Previous tag size: 0
--- Tag #2 at 0x1990 (6544) ---
Tag type: Video
Body length: 2627
Timestamp: 0
* Video codec: Sorensen H.263
* Video frame type: keyframe
Previous tag size: 2638
--- Tag #3 at 0x23E2 (9186) ---
Tag type: Audio
Body length: 209
Timestamp: 0
* Sound type: Mono
* Sound size: 16 bits
* Sound rate: 22 kHz
* Sound format: MP3
Previous tag size: 220
......................
--- Tag #42717 at 0x1A78D98 (27757976) ---
Tag type: Audio
Body length: 210
Timestamp: 675030
* Sound type: Mono
* Sound size: 16 bits
* Sound rate: 22 kHz
* Sound format: MP3
Previous tag size: 221

kLink: thank you for the response!

What tool did you use to dump this info?

Using "flvtool2 -P" on linux I can confirm that dimensions are not reported, whereas they are for videos like the jw player test video http://www.jeroenwijering.com/upload/bunny.flv

I'm not convinced it's guessing though. When I run totem with --gst-debug=*:5 the first log line I can find indicating the dimensions is this:

0:00:31.907767646 14439 0x8577b80 DEBUG ffmpeg gstffmpegdec.c:937:gst_ffmpegdec_negotiate:<ffdec_flv0> Renegotiating video from 0x0@ -1/-1 fps to 320x180@ -1/0 fps

When I run totem the same way on bunny.flv, I see a very similar line:

0:00:06.056908444 14685 0x8160698 DEBUG ffmpeg gstffmpegdec.c:937:gst_ffmpegdec_negotiate:<ffdec_flv0> Renegotiating video from 0x0@ -1/-1 fps to 320x176@ -1/0 fps

Which seems to hint that it's finding the dimensions on the two videos in a similar way.

Could the dimensions be coming from metadata buried inside the payload inside the flv container, or something like that?

Well, if you use ffmpeg, you can find out anything, because it can decipher the encoded video and audio. That's what I use serverside to get video information such as size (WxH) and duration.

I used flvdump from here: http://code.google.com/p/flvmeta/

kLink, thanks again for the very helpful response.

But, so, flash deciphers the encoded video and audio too, right? So why can't it get the dimensions and other info?

Flash can do that, after it has loaded the file, but thata's too late to be useful for most applications.

You need to know the size in advance for some re-sizing, etc.

> after it has loaded the file

Not sure what you mean by this. Totem figures out the size while still buffering, and same with the youtube player.

http://www.youtube.com/watch?v=YAt-3Yk2u80

You can see youtube adjust the aspect ratio in the first split second, long before the entire video is buffered.

Well, I don't know about the Flash players, but I need the size long before the video file is loaded, to size and position the page elements, etc. Maybe Jeroen's player could do that also, although I don't see any need for it, since the video container file should have the proper metadata created and injected when it is created.

> Maybe Jeroen's player could do that also,

Maybe Jeroen's player *could* do that! Jeroen, would you like to weigh in?

> although I don't see any need for it, since the video container file should have the proper metadata created and injected when it is created.

I think I've demonstrated the need for it already. I have videos that I did not create and can't modify, but I want to be able to play them properly. It seems to me that this would be a very common use case.

Why can't you modify the videos?

I downloaded the video from the link that you posted. If I wanted to, I could create and inject the metadata or transcode it to H.264 in an MP4 container or rotate it upslide down or run it backwards; there's no limitation. There's no need for the player to become an encoder/post-processor just because the original video wasn't properly encoded and post-processed.

For us specifically, the reason we can't modify the videos is that we are an archive, we store artifacts in their original form and do not modify them, for historical integrity. See http://www.archive.org/about/about.php for more info.

I'm quite familiar with your organization, having gotten quite a few videos from your archives.

So, what are you going to do in a couple of years when no one can play an FLV video because Flash and the players don't support it anymore, having moved on to better formats, like H.264. You will have to develop proxy transcoders that read the old formats and serve them in a currently supported format. Or, in the case of the video that we're discussing, add the metadata (or whatever is needed) so the video is playable.

The player indeed does read the width/height metadata of FLV files (if they are in the file) and stretches accordingly. If there's no metadata, a default of 4x3 is used.

There's no other way for Flash-based players to detect video width/height. The YouTube player actually doesn't do any dimension-checking: it simply displays always as 4:3.

Totem, being not Flash-based, can actually look inside the decoded video chunks and do better estimations on the filesize there.

If you do not want to change the original videos, it'd be best to always presume a 4:3 resolution. If there's metadata, the video will scale correctly.

Alternatively, you could use a tool like Totem / FFMPEG / Mplayer to detect the width/height of the player and save it as separate metadata. Next, you make sure the display of the player has the right dimensions and then set the "stretching=exactfit" flashvar. Now the player stretches the video to the display, regardless of what the metadata says.

Hey JeroenW, thanks for that explanation.

> There's no other way for Flash-based players to detect video width/height. The YouTube player actually doesn't do any dimension-checking: it simply displays always as 4:3.

But take a look here at the original youtube video: http://www.youtube.com/watch?v=YAt-3Yk2u80
For me, the video, at first for a split second, appears to take up the full 4:3 area of the player. Then it adjusts to the correct 16:9. Do you see this behavior?

Yes I see. So YouTube also does aspectratio detection now. But this video indeed has width/height set in the metadata.

I am also "working" on this.

The Flvplayer will detect the HQ quality videos with the correct size - as it seems.
The MP4 files (&fmt=18) seem to have correct metadata.

The Flvplayer does not detect right the SQ quality videos.
At the moment I found no way how to play the SQ videos in the right format.

And YouTube has now changed their player generally to widescreen, so there will soon be the same number of widescreen as standard screen videos and it is URGENT to be able to play in the right format...

But... how to detect the right format...

Follow this topic: http://www.jeroenwijering.com/?thread=13704 and look at Bouke Regnerus posting on 23.10.2008.

With this code you get all videos in high quality and correct aspect ratio.

@Shaddyshow, it seems to me you're trying to do a different thing.

You want to link to the HQ youtube video from your site, correct?

What I'd like to know, just like Noah, is how to recognise and then correctly convert a 4:3 or 16:9 video which has been uploaded to my website.

@William,

The best, quickest way to find out the video file's native size is to use ffmpeg, available from sourceforge.net.

ffmpeg -i video.flv will return this information:

C:\wget>ffmpeg -i video.flv
FFmpeg version SVN-r16043-Sherpya, Copyright (c) 2000-2008 Fabrice Bellard, et a
l.
  libavutil     49.12. 0 / 49.12. 0
  libavcodec    52. 6. 1 / 52. 6. 1
  libavformat   52.23. 1 / 52.23. 1
  libavdevice   52. 1. 0 / 52. 1. 0
  libavfilter    0. 1. 0 /  0. 1. 0
  libswscale     0. 6. 1 /  0. 6. 1
  libpostproc   51. 2. 0 / 51. 2. 0
  built on Dec 10 2008 18:25:26, gcc: 4.2.5 20080919 (prerelease) [Sherpya]

Seems stream 0 codec frame rate differs from container frame rate: 1000.00 (1000
/1) -> 25.00 (25/1)
Input #0, flv, from 'video.flv':
  Duration: 00:03:14.43, start: 0.000000, bitrate: 128 kb/s
    Stream #0.0: Video: flv, yuv420p, <strong>480x360</strong>, 25.00 tb(r)
    Stream #0.1: Audio: mp3, 44100 Hz, stereo, s16, 128 kb/s
At least one output file must be specified

which you can parse to get the size. You can run ffmpeg in a serverside script, PHP or whatever, to get the size for whatever you want to do with the file.

This script is meant to return the size information for informational purposes only, but could easily be enhanced to do whatever file manipulation you want to do.
ffmpeg_get_width_height.php:

<?php

// get video width and height - 10-14-07
// for testing call with: ffmpeg_get_width_height.php?file=video.flv

$videofile = (isset($_GET['file'])) ? strval($_GET['file']) : 'video.flv';

ob_start();
passthru("ffmpeg-10141.exe -i \"". $videofile . "\" 2>&1");
$size = ob_get_contents();
ob_end_clean();

preg_match('/(\d{2,4})x(\d{2,4})/', $size, $matches);
$width = $matches[1];
$height = $matches[2];

print "  Size: " . $size   . "<br />\n";
print
" Width: " . $width  . "<br />\n";
print
"Height: " . $height . "<br />\n";

?>

HAH HAH HAH HAH HAH. I'm soooo happy right now. I had the same problem as everyone else: trying to set a specific screen aspect ratio, in the player as well as full screen. I finally figured out how to do it. Ok let me first off let you know what I was trying to do specifically. I had a video that was 704x480 pixels. It was anamorphic and therefore when it was stretched out it looked correct, but as it was it looked squished. The aspect ratio which i wanted it to play at was 16/9. I set the dimensions of the player to 853x480 and set stretching to exactfit. This worked only in the player whilst it was not in full screen. When the fullscreen button was pressed, the video would distort to the dimensions of the screen as expected, but this is obviously not what I wanted, as some of the people who would be watching my videos would obviously not have widescreen devices. After a little digging I determined where the actionscript was that fed the stretching settings into the player. I examined it and decided to add some code. Here's what I did:

I added a new variable and its respective case where the other variables and cases were in the stretcher.as file:

/** Stretches the clip to fit the widescreen format. **/
public static var WIDESCREEN:String = "widescreen";

case 'widescreen':
clp.width = wid;
clp.height = (wid/16)*9;
break;

And BAM! After exporting the player.fla... It works!!! Basically it adjusts the height based upon the aspect ratio of 16/9. Let me know what you think. I'll paste in the code for the modified stretcher.as file so you can use it if you wish... Of course the possibilities are limitless. Thankyou so much Jeroen for making this player open source! And by the way I have no actionscripting experience so this problem solving took me about fifteen minutes, figuring out where it was and then modifying it.

As promised here's the modified file:

/**
* Simple class that handles stretching of displayelements.
**/
package com.jeroenwijering.utils {

import flash.display.DisplayObject;

public class Stretcher {

/** Stretches the clip nonuniform to fit the container. **/
public static var EXACTFIT:String = "exactfit";
/** Stretches the clip uniform to fill the container, with parts being cut off. **/
public static var FILL:String = "fill";
/** No stretching, but the clip is placed in the center of the container. **/
public static var NONE:String = "none";
/** Stretches the clip uniform to fit the container, with bars added. **/
public static var UNIFORM:String = "uniform";
/** Stretches the clip to fit the widescreen format. **/
public static var WIDESCREEN:String = "widescreen";

/**
* Resize a displayobject to the display, depending on the stretching.
*
* @param clp The display element to resize.
* @param wid The target width.
* @param hei The target height.
* @param typ The stretching type.
* **/
public static function stretch(clp:DisplayObject,wid:Number,hei:Number,typ:String='uniform'):void {
var xsc:Number = wid/clp.width;
var ysc:Number = hei/clp.height;
switch(typ.toLowerCase()) {
case 'exactfit':
clp.width = wid;
clp.height = hei;
break;
case 'fill':
if(xsc > ysc) {
clp.width *= xsc;
clp.height *= xsc;
} else {
clp.width *= ysc;
clp.height *= ysc;
}
break;
case 'none':
clp.scaleX = 1;
clp.scaleY = 1;
break;
case 'uniform':
if(xsc > ysc) {
clp.width *= ysc;
clp.height *= ysc;
} else {
clp.width *= xsc;
clp.height *= xsc;
}
break;
case 'widescreen':
clp.width = wid;
clp.height = (wid/16)*9;
break;
}
clp.x = Math.round(wid/2 - clp.width/2);
clp.y = Math.round(hei/2 - clp.height/2);
clp.width = Math.ceil(clp.width);
clp.height = Math.ceil(clp.height);
};

}

}

Oh BTW I'll have a link to my site soon so you can check out a working example. For those of you who don't want to re-encode videos, but specify a certain aspect ratio I think my solution is a must. The great thing about it is that you can make as many custom variables for the stretching flashvar as you want, and then assign them to specific files. Hope this helps people!!!

Michael,

Do you have this separately builded version somewhere on-line?

Thanks Micheal Griffin

thanks micheal g

Michael, this is the exact solution that i have been looking for. Could you let me know where to input this script?

Or, could anyone let me know how to do this?

Thanks so much! :)

I'm looking for the same thing too, anyone got a working build with the widescreen variable?

After some cursing I managed to get it compiled myself. Never compiled anything before so it was really only guesswork and changing stuff here and there trying to make sense of error messages, to make it easier for anyone searching for the same thing here the compiled player.swf file with "widescreen" as a stretching option. Thanks to Michael Griffin.

http://www.multiupload.com/DIH8Q416WD

I am having a problem with 16:9 aspect ratio FLV playing back as 4:3. Unfortunately the JWPlayer is installed on someone else's server so I don't have access to the source code. My vid is encoded with ffmpegX but have not been able to get it to work in terminal mode and so haven't been able to check the FLV container for the size/aspect ratio meta-data as suggested by kLink 2 years ago. . .

is anyone willing to download my file and let me know if the meta-data is complete?

http://soundings.com/flvtest.html

Thanks,
Phil
Soundings of the Planet
heaven at soundings.com

Can you provide a link to where the JW Player is running?

your file has none of the extra metadata...

your file:

Magic: FLV
Version: 1
Has audio: yes
Has video: yes
Offset: 9
--- Tag #1 at 0xD (13) ---
Tag type: Video
Body length: 23861
Timestamp: 0
* Video codec: Sorensen H.263
* Video frame type: keyframe
Previous tag size: 23872
--- Tag #2 at 0x5D51 (23889) ---
Tag type: Audio
Body length: 183
Timestamp: 0
* Sound type: Stereo
* Sound size: 16 bits
* Sound rate: 22 kHz
* Sound format: MP3
Previous tag size: 194
   ...
--- Tag #3532 at 0x6CD909 (7133449) ---
Tag type: Audio
Body length: 183
Timestamp: 70217
* Sound type: Stereo
* Sound size: 16 bits
* Sound rate: 22 kHz
* Sound format: MP3
Previous tag size: 194

what it should look like:

Magic: FLV
Version: 1
Has audio: yes
Has video: yes
Offset: 9
--- Tag #1 at 0xD (13) ---
Tag type: Meta
Body length: 942
Timestamp: 0
* Metadata event name: onMetaData
* Metadata contents: {
    'duration' => 70.242000
    'lasttimestamp' => 70.217000
    'lastkeyframetimestamp' => 69.333000
    'videocodecid' => 2.000000
    'audiocodecid' => 2.000000
    'audiodelay' => 0.000000
    'canSeekToEnd' => false
    'width' => 1280.000000
    'height' => 720.000000
    'videodatarate' => 0.000000
    'audiodatarate' => 0.000000
    'framerate' => 12.000000
    'creationdate' => 'unknown'
    'metadatacreator' => 'Manitu Group FLV MetaData Injector 2'
    'metadatadate' => Thu, 02 Dec 2010 15:59:12 Pacific Standard Time
    'keyframes' => {
        'filepositions': [
            970.000000
            992487.000000
            1029413.000000
            1054366.000000
            1080249.000000
            1268288.000000
            1367015.000000
            2169531.000000
            2592341.000000
            2750303.000000
            3632225.000000
            3919360.000000
            4109471.000000
            4858571.000000
            5650960.000000
            6118744.000000
            6262704.000000
            6453973.000000
            6591755.000000
            6994063.000000
            7022075.000000
            7048940.000000
            7074402.000000
            7099245.000000
        ]
        'times': [
            0.000000
            10.417000
            10.750000
            10.833000
            10.917000
            12.500000
            13.917000
            18.750000
            23.000000
            25.750000
            31.833000
            33.667000
            35.500000
            43.000000
            50.000000
            54.583000
            56.583000
            59.917000
            62.000000
            69.000000
            69.083000
            69.167000
            69.250000
            69.333000
        ]
    }
    'filesize' => 7134642.000000
    'videosize' => 6598908.000000
    'audiosize' => 534726.000000
    'datasize' => 995.000000
}
Previous tag size: 953
--- Tag #2 at 0x3CA (970) ---
Tag type: Video
Body length: 23861
Timestamp: 0
* Video codec: Sorensen H.263
* Video frame type: keyframe
Previous tag size: 23872
--- Tag #3 at 0x610E (24846) ---
Tag type: Audio
Body length: 183
Timestamp: 0
* Sound type: Stereo
* Sound size: 16 bits
* Sound rate: 22 kHz
* Sound format: MP3
Previous tag size: 194
   ...
--- Tag #3534 at 0x6CDCEC (7134444) ---
Tag type: Audio
Body length: 183
Timestamp: 70217
* Sound type: Stereo
* Sound size: 16 bits
* Sound rate: 22 kHz
* Sound format: MP3
Previous tag size: 194