Oct. 27, 2008Noah
http://wayback.archive-it.org/1193/20081022045239/http://ash-v315.ash.youtube.com/get_video?video_id=YAt-3Yk2u80&ip=207.241.228.140&signature=9ADED9ECF4E6E4A0FE90D9A7868B948C53D9B88F.90615F113D10480E53ACBC293B989DB81C208853&sver=2&expire=1224661955&key=yt4&ipbits=2
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!
Oct. 28, 2008kLink
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
Oct. 28, 2008Noah
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?
Oct. 28, 2008kLink
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/
Oct. 29, 2008Noah
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?
Oct. 29, 2008kLink
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.
Oct. 29, 2008Noah
> 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.
Oct. 29, 2008kLink
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.
Oct. 29, 2008Noah
> 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.
Oct. 29, 2008kLink
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.
Oct. 30, 2008Noah
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.
Oct. 30, 2008kLink
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.
Nov. 05, 2008JeroenW
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.
Nov. 05, 2008Noah
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?
Nov. 19, 2008JeroenW
Yes I see. So YouTube also does aspectratio detection now. But this video indeed has width/height set in the metadata.
Nov. 25, 2008ShaddyShow
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...
Nov. 25, 2008ShaddyShow
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.
Jan. 29, 2009William
@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.
Jan. 29, 2009lefTy
@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: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.
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, 480x360, 25.00 tb(r)
Stream #0.1: Audio: mp3, 44100 Hz, stereo, s16, 128 kb/s
At least one output file must be specified
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";
?>
Apr. 30, 2009Michael Griffin
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:
<code>
/** 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;
</code>
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.
Apr. 30, 2009Michael Griffin
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);
};
}
}
Apr. 30, 2009Michael Griffin
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!!!
Sep. 23, 2009Sammy
Michael,
Do you have this separately builded version somewhere on-line?
Oct. 03, 2009Dave
Thanks Micheal Griffin
Oct. 04, 2009Dave
thanks micheal g
Nov. 04, 2009Steve
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!
Here are some helpful links to learn more about the JW Player™:
Earn money with ads from LongTail's AdSolution. Watch our demos and sign up now!
If you don’t buy a commercial license, you cannot use a JW Player™ on (i) a site that has ads; (ii) a corporate site; or a (iii) CMS. Our licenses are very inexpensive, so what are you waiting for? Buy a license today.