COMMUNITY

[SOLVED] Sys.stdin() not reading stdout

I’m trying to pipe data into my app. I’m using Process to run a command which outputs to stdout.

If I try to read that output, using the methods available to Sys.stdin(), the app becomes unresponsive, seemingly waiting for keyboard input in the terminal. It does not seem to be receiving the piped stdout data from ffmpeg.

I’ve produced a simplified example that reproduces the issues. In this example, ffmpeg is reading from a video file, transcoding it to mjpeg (-c:v mjpeg -f mjpeg) and outputting it to stdout (pipe:1).

package;

import openfl.utils.Assets;
import openfl.display.Sprite;
import openfl.events.Event;
import sys.io.Process;

class Main extends Sprite {

	public function new() {
		super();
		
		trace(Assets.exists('assets/bbb_sunflower_1080p_30fps_normal.mp4')); // true
		var process:Process = new Process('ffmpeg -i assets/bbb_sunflower_1080p_30fps_normal.mp4 -an -c:v mjpeg -f mjpeg pipe:1');
		addEventListener(Event.ENTER_FRAME, enterFrameHandler);
	}
	
	private function enterFrameHandler(e:Event):Void {
		try {
			trace(Sys.stdin().readByte());
		} catch (e:haxe.io.Eof) {
			trace("done!");
		}
	}
}

Command:

openfl test neko -debug
openfl test cpp -debug
  • Targeting: cpp (final) and neko (testing)
  • System: Linux 64bit (Arch based)
  • Haxe: [4.2.4]
  • hxcpp: [4.2.1]
  • OpenFL: [git]

To get the output of ffmpeg you need to read process.stdout.
Sys.stdin() refers to stdin of your openfl-compiled app and just waits for user input.

1 Like

Ah! Thank you @RealyUniqueName.

A simple fix too, and I’m getting data now.

For the sake of completeness, here’s the code including that correction.

package;

import openfl.display.Sprite;
import openfl.events.Event;
import sys.io.Process;

class Main extends Sprite {
	var process:Process;

	public function new() {
		super();
		
		process = new Process('ffmpeg -i assets/bbb_sunflower_1080p_30fps_normal.mp4 -an -c:v mjpeg -f mjpeg pipe:');
		addEventListener(Event.ENTER_FRAME, enterFrameHandler);		
	}
	
	private function enterFrameHandler(e:Event):Void {		
		try {	
			trace(process.stdout.readByte());			
		} catch (e:haxe.io.Eof) {
			trace("done!");
		}
	}
}
1 Like