AS3 - how to change speed of FLVPlayBack - actionscript-3

i need to play FLVPlayback Video at different speeds , can i do this by changing frame-rate of FLVPlayBack and how can i achieve this using as3?
Or is there any other method to do the same? Please Suggest me.
Meghana

There's no way to change the framerate of a video in AS3, it will be always rendered at the video's native framerate.
The only way I can think to do it is to write some sort of function that calculates how to move the playhead, but I cannot guarantee the result of this approach.....
EDIT:
As you ask in your comment, YES, you can do it by controlling the NetStream. Here you have the solution: http://younsi.blogspot.it/2009/03/how-to-play-video-in-flash-in-slow.html

Chiming in a bit late, but there's actually a way to play an FLV in slow motion without constantly seeking or playing/pausing repeatedly. It's just extremely involved.
If you open the .flv file using a URLStream then you can access the bits. Scan for the timestamp, re-write it, then pass the new ByteArray to a NetStream in data generation mode. Using this you can play video at any frame rate - although the ability to play audio in slow / fast motion depends on the codec being used. The layout of an FLV packet is something like:
"FLV"
packet length
packet type (audio / video / metadata)
timestamp
additional headers
data
To change the audio sample rate you would need to muck with the data - much more convoluted than just changing timestamps. I know, for instance, that AAC data has a header which specifies the sample rate as an index into an array:
[ 96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 7350 ]
So if you had 44.1 kHz audio (sample rate index = 4) you could play at half speed by declaring the sample rate to be 22.05 kHz (sample rate index = 7)

//set your framerate here whatever you want
stage.frameRate = 30;
var FRAMERATE : Number = stage.frameRate;
btnActual.addEventListener(MouseEvent.CLICK, videoSpeed);
btn15.addEventListener(MouseEvent.CLICK, videoSpeed);
btn5.addEventListener(MouseEvent.CLICK, videoSpeed);
function videoSpeed (myEvent:Event):void{
var newFrameRate = Number(myEvent.target.value);
stage.frameRate = newFrameRate;
}

Related

In pyaudio, how can I get a stream to 'consistently' produce sound?

I am using an endless while loop to convert byte data (used in single chunks), to an integer value (in order to 'manipulate' those values and then reconvert the values back to bytes again and write the bytes to the PyAudio stream (for sound).
Everything plays smoothly until I write a complex function that takes up too much processing time. Then, I hear a bunch of pops, snaps and clicks over the audio. I notice that the reason for this happening, is because (between the time that the program loops to play the next chunk of streamed data provided to the PyAudio stream), there is a 'transition' of silence as there is a 'wait' for the loop to repeat... and that is what creates the pops between each chunk being played if the loop is 'too slow'.
Is there a way to make the 'voltage' going to the speakers at 'constant' based on the last data value provided to the PyAudio's stream? This would be a great way to smoothen out the 'pops', 'snaps' and 'clicks' when playing sound, instead of there being silence until the next value is passed to the stream. The reason I don't use a chunk greater than 1, is because I want to do many 'creative' things with PyAudio (through an endless loop), and have values inside the loop determine the 'voltage level' going to the speakers.

What governs playback speed when encoding with Android's MediaCodec + mp4parser?

I'm trying to record, encode and finally create a short movie on Android (using API 16) with a combination of MediaCodec and Mp4Parser (to encapsulate into .mp4).
Everything is working just fine, except for the duration of the .mp4: its always 3 seconds long - and runs at about twice the 'right' speed.
The input to encoder is 84 frames (taken 100ms apart).
The last frame sets the 'end of stream' flag.
I set the presentation time for each frame on queueInputBuffer
I've tried to tweak every conceivable parameter - but nothing seems to make a difference - the film is always 3 seconds long - and always played way too fast.
So what governs the playback seepd? how do I generate a film with 'natuarl' speed?
I figured it out: When encapsulating with mp4parser (needed if you target API<18), you need to set the speed in mp4parser's API. The presentation time you provide to queueInputBuffer appearently make no difference if you're not using Android's built-in muxer (available only from API18).
I stumbled on this question on github, which indicates the following is required:
new H264TrackImpl(new FileDataSourceImpl(rawDataFile), "eng", 100, 10);
the last two parameters (timeScale and frameTick) set the playback speed to 'noraml'.

Can Media Source API appended buffer(range) be overwritten?

I did little investigation into Media Souce Extension/API but I haven't found a way for specific buffer to be overwritten. Lets say I have watched first 30 seconds with lower quality and player switched to higher quality after that, so 30-60 sec is HQ. So... when I seek back to seconds 0-30 I would get lower quality video (one already buffered), but I would like to re-append newly requested same range with higher quality and watch that. I've seen on existing players (MSE showcases) this is not the case.
I guess MSE determines where to append buffer based on (I cannot recall now for the name) start date time? So, is it possible to override some appended range/buffer in Media Source API ?
Yes, it's possible. Before you call appendBuffer() on a source buffer, set timestampOffset to the time in seconds you wish to start overwriting. For example:
var mediaSource = new MediaSource();
mediaSource.addEventListener('sourceopen', function() {
var sourceBuffer = mediaSource.addSourceBuffer('video/webm; codecs="vorbis,vp8"');
/* ...code to fetch low quality binary... */
sourceBuffer.appendBuffer(lowQualityBinary);
/* ...later fetch higher quality binary and overwrite
* entire video starting at the beginning...
*/
sourceBuffer.timestampOffset = 0;
sourceBuffer.appendBuffer(highQualityBinary);
});
Note that if the user is playing the video and you overwrite starting at a time prior to their current play time, the current behavior on Chrome is to continue showing the original appended video. If it's overwritten later, or they seek around, they'll see the new video.

x264 rate control modes

Recently I am reading the x264 source codes. Mostly, I concern the RC part. And I am confused about the parameters --bitrate and --vbv-maxrate. When bitrate is set, the CBR mode is used in frame level. If you want to start the MB level RC, the parameters bitrate, vbv-maxrate and vbv-bufsize should be set. But I don't know the relationship between bitrate and vbv-maxrate. What is the criterion of the real encoding result when bitrate and vbv-maxrate are both set?
And what is the recommended value for bitrate? Equals to vbv-maxrate?
Also what is the recommended value for vbv-bufsize? Half of vbv-maxrate?
Please give me some advice.
bitrate address the "target filesize" when you are doing encoding. It is understandably confusing because it applies a "budget" of certain size and then tries to apportion this budget on the frames - that is why the later parts of a movie get a smaller amount of data which results in lower video quality. For example, if you have 10 seconds of complete black images followed by 10 second of natural video - the final encoded file will be very different than if the order was the opposite.
vbv-bufsize is the buffer that has to be completed before a "transmission" would occur say in a streaming scenario. Now, let's tie this to I-frames and P-frames: the vbv-bufsize will limit the size of any of your encoded video frames - most likely the I-frame.

How do I amplify sounds by a specified number of decibels in AS3?

A few days ago, this was my question, and I found the answer. Maybe this will help someone else.
A. The first part of the problem: can you amplify sound using Flash? The AS3 documentation for SoundTransform says this about the volume attribute:
"The volume, ranging from 0 (silent) to 1 (full volume).
At face value, this means you can only make sounds quieter. In fact, if you supply a value greater than one (1.0), sounds will be amplified. You risk saturating the sound and getting poor quality, but you can do it, and for voice, you can get away with a lot. (Music is less forgiving, so experiment. This method does not do dynamic compression, which is better suited to music.)
B. The second part of the problem: the order in which you do things.
RIGHT:
soundTransform = new SoundTransform();
soundTransform.volume = volume * volumeAdjustment;
audioChannel.soundTransform = soundTransform;
WRONG:
soundTransform = new SoundTransform();
audioChannel.soundTransform = soundTransform;
soundTransform.volume = volume * volumeAdjustment;
I did some testing in CS3 and CS4, and got different results. In CS3, I could set the volume on the transform AFTER "audioChannel.soundTransform = soundTransform;" and everything was fine. But in CS4 it had no effect. I suspect that CS3 used pass by reference to set the soundTransform, while CS4 uses pass by value semantics and copies the object passed into it. The CS4 approach is better designed, but did break my code that worked fine in CS3.
C. The last question, is how to convert a decibel value to a factor that can be multiplied by the volume to amplify (or quiet) the sound by the desired amount.
var multiplier:Number = Math.pow(10, decibels / 20); // Power vs. amplitude
Note that "decibels" may be a positive number (to amplify) or a negative number (to make quieter). If decibels is zero, no change occurs.
A value for decibels of 3 will (to a close approximation) double the amplitude.
A value of 10 decibels will increase the volume tenfold (exactly).
Your decibel calculation should actually use 20, not 10:
var multiplier:Number = Math.pow(10, decibels / 20);
Digital audio is amplitude, not power (it's a representation of sound pressure, not sound power).