I'm using the FileReference class to upload flvs to a server.
Is it possible to check the flv length not size before allowing an upload?
Are you targeting Flash Player 10 alone or lower versions too? Because lower versions of Flash player (9 etc) do not allow the uploading SWF to read the contents of file (other than creationDate, creator (The Macintosh creator type of the file), modificationDate, name, size in bytes and type), so there is no way you are going to be able to do this on those players.
If you are targeting solely FP10 users, you can load the FLV into a ByteArray in your SWF and
Play it using an FLV player and read the duration property from the player. But I couldn't find an FLV player that takes a ByteArray as input - and after reading this thread in SO, it seems like that is not possible at all.
Parse the FLV file, and read the duration property from its metadata. The FLV file specification is open, but this isn't going to be easy.
Update to the comment:
Excerpts from the FLV file spec:
onMetaData
An FLV file can contain metadata with an “onMetaData” marker. Various stream properties
are available to a running ActionScript program via the NetStream.onMetaData property.
The available properties differ depending on the software used.
Common properties include:
duration: a DOUBLE indicating the total duration of the file in seconds
width: a DOUBLE indicating the width of the video in pixels
height: a DOUBLE indicating the height of the video in pixels
videodatarate: a DOUBLE indicating the video bit rate in kilobits per second
framerate: a DOUBLE indicating the number of frames per second
videocodecid: a DOUBLE indicating the video codec ID used in the file (see “Video
tags” on page 8 for available CodecID values)
audiosamplerate: a DOUBLE indicating the frequency at which the audio stream is
replayed
audiosamplesize: a DOUBLE indicating the resolution of a single audio sample
stereo: a BOOL indicating whether the data is stereo
audiocodecid: a DOUBLE indicating the audio codec ID used in the file (see “Audio
tags” on page 6 for available SoundFormat values)
filesize: a DOUBLE indicating the total size of the file in bytes
FLV file can contain metadata - it doesn't say it will contain metadata. It also says that available properties can vary based on the software used to create FLV. So I guess there is no guarantee (as per specs) that the duration property will be present. That said, duration is one of the basic properties of FLV and it would be safe to assume that any reasonable software would include it.
You can use Netstream.appendBytes to feed FileReference.data (after a call to browse, before a call to upload) to a NetStream used for playing a video. From there, the duration can be taken from the metadata, as described elsewhere on this thread. Note that at least Flash Player 10 is required for this approach.
Related
I am developing a application in c# by using Directshow.NET. I am using a virtual camera which will help to record desktop screen. So my graph is:
Virtual cam --->color space converter --->sample grabber ---> ASF writer.
While coding, I used a custom .prx which I generated by Windows Media Profile Editorand configured into IConfigAsfWriterusing WMCreateProfileManager.
In .prx file Mode is CBR, codec Windows Media Video 9 and frame rate 15fps with 759Kbps video bit rate, but still video looks so blurry. If I increase video bit rate like upto 5Mbps then this blurriness is not coming but increasing bit rate results into large file size (54 seconds of recording file size is 10MB).
I tried another graph using graphEdit virtual cam ---> AVI mux ---> File writer but this also generating large .avi file.
How can i record video without blur effect by keeping minimum file size, for eg. 1 minute of video size up to 2-3 MB?
Do i need to use any video compressor?
The quality depends on the codec you use, but also on the number of bits per pixel. You can calculate it this way:
bits/pixel = bitrate / (width * height * framerate)
(bitrate in bits/second and framerate is in frames/second)
So if you want to reduce the bitrate without getting blurry video, you also have to reduce the resolution or framerate. That way you keep the number of bits per pixel the same.
In my server two mp4 file is available. When I browse the video1.mp4 url from my browser, it started to play the video file in browser.
If I play video2.mp4 url from browser,it takes long to start playing.
At that time I had checked the browsers temp file, It downloads the full video then only it starts to play.
After clearing the temp file i had tried to play the video1. It takes some amount of file only.(Video1 size is 800 MB, temp memory has 50 MB only, Video2 size is 500 MB, temp memory also has the 500 MB)
What is the difference between two video files. Both are MP4 only. But one takes full video data and another one takes partial amount of video file, why ?
The two files are encoded differently. MP4 files are divided in packets called boxes, the box that describes the type of compression and the different tracks that are present in the video file is a 'moov' box, and traditionally it lives at the end of the file, but encoding software can be configured to generate it at the beginning.
For example, if you use ffmpeg you can use the qt-faststart option to enable putting the metadata at the beginning.
I have an original video coded at 20Mbps, 1920x1080, 30fps and want to convert it down to be 640x480 30fps at a range of (3 different) bitrates for use by Adobe Live Streaming.
Should I use ffmpeg to resize and encode at the 3 bitrates then use f4fpackager to create the f4m f4f and f4x files or just use ffmpeg to reduce the resolution and then f4fpackager to encode the relevant bitrates?
I've had several tries so far, but when encoded the videos seem to play at a much larger bitrate than they've been encoded at. For example, if I set up the OSMF to play from my webserver, I'd be expecting my best encoded video to play at 1,500kbps but it's way above that.
Has anyone had any experience of encoding for use like this?
I'm using the following options to f4fpackager
--bitrate=1428 --segment-duration 30 --fragment-duration 2
f4fpackager doesn't do any encoding, it does 2 things:
- fragment the mp4 files (mp4 -> f4f)
- generate a Manifest (f4m) file referencing all you fragmented files (f4f)
So the process is:
- transcode your source file in all the size/bitrate that you want to provide (eg: 1920x01080#4Mbps, 1280x720#2Mbps, etc)
- use f4fpackager to convert the mp4 to f4f (this is the fragmentation step)
- use f4fpackager to generate the Manifest.f4m referencing the files that you generated in the previous step
the --bitrate option of f4fpackager should match the value that you use with ffmpeg, this parameter is used to generate the manifest file with the correct bitrate value of each quality
the player uses a VideoDisplay
and i set the source like videoDisplay.source = "sourceStringURL"
and the vid doesn't play until it's fully loaded
If you are trying to play recorded MP4 then it will not play until you record it in Progressive format, and if you cant specify progressive format then you have to use this program QTIndexSwapper that will help you.
When you directly record MP4 format, the file size is unknown for the recorder so when you stop recording the recorded moves the MOOV atom which is beginning point of MP4 at the end of the file. This atom needs to be placed at the beginning for flash player to detect its length and where to start. QTIndexSwapper does it for you. You will also get lots of c based program to do that.
I am using the below jQuery plugin for playing mp3
www.happyworm.com/jquery/jplayer
However, there is a bug in Flash that the total play (track) time won't show up correctly UNTIL AFTER the whole mp3 is completed downloaded.
I wonder if there is a way to work around this to get the correct total time using either javascript / another flash / even backend library in ASP.NET. Any suggestion helps. Thanks
You sure that's a bug? Looking at the header definition for the MP3 format I don't see any values for the length of the file. Generally applications that play MP3s would have to calculate the time, and that may not be doable until the entire file is downloaded. So the behavior you're seeing from Flash might be expected.
Theoretically if it's a fixed bitrate file (as opposed to VBR) then knowing the bitrate (gotten from the header) and the total size of the file should be enough to calculate it. However, the server would have to report the size of the file in the response headers (and that's not guaranteed to be accurate).
My guess is you'd need some service on the server that could calculate the length and report that to you in a separate request.