Search code examples
actionscript-3ffmpegyoutubeencode

FFMPEG gets in never ending condition while live streaming on YouTube


I have been working in AS3 to stream 1080P video on YouTube and video gets start uploading and almost 4-5 minutes of the video has been uploaded successfully and afterwards YouTube shows that stream has been ended, but FFMPEG will never hits on "Exit" or any other method even after waiting for next 10 minutes.

Below is the method I am using.

public var _nativeProcessStartupInfo:NativeProcessStartupInfo;
public var _processArgs:Vector.<String>;
public var _process:NativeProcess;
protected function StartVideo_clickHandler(event:MouseEvent):void
{
    _nativeProcessStartupInfo.executable = File.applicationStorageDirectory.resolvePath("ffmpeg.exe Path");
    _processArgs.push('-re');
    _processArgs.push('-i');
    _processArgs.push(VideoPath);
    _processArgs.push('-vcodec');
    _processArgs.push('copy');
    _processArgs.push('-acodec');
    _processArgs.push('copy');
    _processArgs.push('-maxrate');
    _processArgs.push('4500k');
    _processArgs.push('-bufsize');
    _processArgs.push('9000k');
    _processArgs.push('-pix_fmt'); 
    _processArgs.push('yuv422p');
    _processArgs.push('-preset');
    _processArgs.push('fast');
    _processArgs.push('-ac'); 
    _processArgs.push('2');
    _processArgs.push('-r'); 
    _processArgs.push('30');                            
    _processArgs.push('-g');
    _processArgs.push('60');                            
    _processArgs.push('-ar');
    _processArgs.push('44100');
    _processArgs.push('-f');
    _processArgs.push('flv');                   
    _processArgs.push(streamurl+'/'+streamname);
    _nativeProcessStartupInfo.arguments = _processArgs;
    _process = new NativeProcess();
    _process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
    _process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, progress);
    _process.addEventListener(NativeProcessExitEvent.EXIT, onExit);
    _process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOErrorNativeProcess);
    _process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOErrorNativeProcess);
    _process.start(_nativeProcessStartupInfo);
}
public function onIOErrorNativeProcess(event:IOErrorEvent):void
{
    trace(event.toString());
}
public function onOutputData(event:ProgressEvent):void
{
    trace("Got: ", _process.standardOutput.readUTFBytes(_process.standardOutput.bytesAvailable)); 
}
public function progress(e:ProgressEvent):void 
{
    trace(e);
}
public function onExit(e:NativeProcessExitEvent):void
{
    trace(e);
}

I have tried with 720P video too by changing bit rate from 4500k to 2500k which is as per YouTube and it is working fine but with 1080P something not went as per expectation.

Here are the video details: Resolution : 1920*1080 Data Rate : 3220kbps FrameRate : 20 Video Description

Thanks in advance


Solution

  • There is two problem with the following code.

    1. In the "progress" function I am not reading actual log of the FFMPEG, have to update progress event like below.

      public function progress(e:ProgressEvent):void 
      {
          trace("Progress: ", _process.standardOutput.readUTFBytes(_process.standardOutput.bytesAvailable));
      }
      
    2. For now I have just traced the log and code is working properly in Debug mode after creating build issue has been happening and after that I have logged all the data in file and then even after creating build everything is working fine.

    I don't know the exact reason behind it, but this solution help me for now.

    Thanks