Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

NetStream and SAMPLE_DATA

Advisor ,
May 08, 2018 May 08, 2018

Hi,

is there a special way to use SampleDataEvent with NetStream.play() ?

I would like to apply my own audio effect to NetStream thanks

TOPICS
ActionScript
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2018 May 09, 2018

if you're using felarca's flvencoder, you're using the bitmapdata class to create the flv.

and i had no trouble, using his class, creating an flv using a loaded sound and graphics generated by computespectrum, http://kglad.com/Files/forums/test.flv

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 17, 2018 May 17, 2018

I use leelib classes I modified. didn't know felarca flvencoder, I will take a look soon.

sorry for the delay, I'm so busy to debug other things... will be back soon

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 04, 2018 Aug 04, 2018

Hi Keith, sorry for the long delay,

do you have any link about felarca flvencoder to try computeSpectrum audio grab?

my goal is to grab all audio played int the swf (sounds as well as netstream)

the mix it into a bytearray to save it as an flv.

thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2018 Aug 04, 2018

i'm not sure what you're asking.

i gave a link to an flv created using the flvencoder class.  the flv shows a brief snippet of queen's bohemian rhapsody and a visual created using computespectrum.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 04, 2018 Aug 04, 2018

for a graphic representation computeSpectrum() is ok, but my goal is to grab

the raw audio data from it and save the audio only in a wave file

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2018 Aug 05, 2018

how do you extract the audio from the data?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 05, 2018 Aug 05, 2018

like that

package{

  

    import flash.display.Sprite;

    import flash.display.Graphics;

    import flash.events.Event;

    import flash.events.NetStatusEvent;

    import flash.events.AsyncErrorEvent;

    import flash.events.TimerEvent;

    import flash.media.Sound;

    import flash.media.Video;

    import flash.media.SoundChannel;

    import flash.media.SoundMixer;

    import flash.net.NetConnection;

    import flash.net.NetStream;

    import flash.utils.ByteArray;

    import flash.utils.Endian;

    import flash.utils.Timer;

    import flash.text.TextField;

    public class SoundMixer_computeSpectrumExample extends Sprite{

      

        private var audioResult:Sound;

        private var server:String = "rtmp://myservert/vod";

        private var stream:String = "mp4:sample1_150kbps.f4v";

        private var nc:NetConnection;

        private var ns:NetStream;

        private var audioTimer:Timer;

        private var recTimer:Timer;

        private var bytes:ByteArray = new ByteArray();

        private var wavArray:ByteArray = new ByteArray();

        private const CHANNEL_LENGTH:uint = 256;

        public function SoundMixer_computeSpectrumExample(){

            nc = new NetConnection();

            nc.connect(server);

            nc.addEventListener(NetStatusEvent.NET_STATUS,onNetStatus);

            nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR,function(event:AsyncErrorEvent):void{trace(event.toString())});

            nc.client = this;  

            audioTimer = new Timer(86.1328125);

            audioTimer.addEventListener(TimerEvent.TIMER,audioTimerHandler);

            recTimer = new Timer(10000,1);

            recTimer.addEventListener(TimerEvent.TIMER,recTimerHandler);

            //wavArray.endian = Endian.LITTLE_ENDIAN;

        }

      

        private function onNetStatus(event:NetStatusEvent):void{

            var code:String = event.info.code;

            trace(code);

            switch(code){

                case "NetConnection.Connect.Success":

                    ns = new NetStream(nc);

                    ns.client = this;

                    ns.bufferTime = 0;

                    ns.addEventListener(NetStatusEvent.NET_STATUS,onNetStatus);

                    ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR,function(event:AsyncErrorEvent):void{});

                    ns.play(stream);

                break;

                case "NetStream.Play.Start":

                    audioTimer.start();

                    recTimer.start();

                break;

                case "NetStream.Buffer.Flush":

                    if(last_status == "NetStream.Play.Stop"){

                        audioTimer.stop();

                    }

                break;

            }

            last_status = code;

        }

        public function onBWDone(){

            //

        }

        private function audioTimerHandler(event:TimerEvent):void{

            SoundMixer.computeSpectrum(bytes,true,1);

            for(var i:uint=0;i<CHANNEL_LENGTH; i++){

                wavArray.writeByte(bytes.readByte());

            }

            for(i=CHANNEL_LENGTH;i>0;i--){

                wavArray.writeByte(bytes.readByte());

            }

        }

        private function recTimerHandler(event:TimerEvent):void{

            ns.close();

            audioTimer.stop();

            wavArray.position = 0;

            // TODO: how to replay the audio?

        }

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 05, 2018 Aug 05, 2018

you need to extract the audio from the video.  i don't know how to do that.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Aug 05, 2018 Aug 05, 2018
LATEST

on computeSpectrum doc it says "raw sound data", can be PCM but wav is LITTLE_ENDIAN as I know

my main goal being to grab all audio playing in the swf (netstream,sound object etc...)

into a bytearray and convert it in wav.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
May 08, 2018 May 08, 2018

What I need to do is to catch on every frame or timer the audio data

to save it on a file locally in FLV as PCM. Everything is working well but the audio, samples are too short

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines