[英]Android - Choosing between MediaRecorder, MediaCodec and Ffmpeg
[英]Android - MediaRecorder output to stream for ffmpeg
我正在尝试将屏幕内容流式传输到rtmp服务器,并且我相信最简单/最好的方法是使用ffmpeg。
所以,这就是我到目前为止所拥有的:
try {
Socket socket = new Socket(url, port);
ParcelFileDescriptor fileDescriptor = ParcelFileDescriptor.fromSocket(socket);
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.SURFACE);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mMediaRecorder.setOutputFile(fileDescriptor.getFileDescriptor());
mMediaRecorder.setVideoSize(DISPLAY_WIDTH, DISPLAY_HEIGHT);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setVideoEncodingBitRate(512 * 1000);
mMediaRecorder.setVideoFrameRate(30);
int rotation = getWindowManager().getDefaultDisplay().getRotation();
int orientation = ORIENTATIONS.get(rotation + 90);
mMediaRecorder.setOrientationHint(orientation);
mMediaRecorder.prepare();
} catch (IOException e) {
e.printStackTrace();
}
在这里,重要的部分是
Socket socket = new Socket(url, port);
ParcelFileDescriptor fileDescriptor = ParcelFileDescriptor.fromSocket(socket);
mMediaRecorder.setOutputFile(fileDescriptor.getFileDescriptor());
因此,当我将其放置在Asynctask中时,我可以使其尝试发送某些内容,但会收到UnknownHostException
java.net.UnknownHostException: Unable to resolve host "rtmps://rtmp-api....": No address associated with hostname
因此,有人告诉我应该改用ffmpeg,但是我不知道如何从MediaRecorder中获取原始流并将其传递给ffmpeg。
如果我理解正确,则将ffmpeg用作:
-i original_stream rtmps://rtmp-api...
因此,如何获得可以在ffmpeg中用于流式传输的格式的MediaRecorder输出内容(而不用于保存的文件)。
谢谢!
无法评论,所以我将其作为答案,即使为时已晚,但该项目应该是您想要的: https : //github.com/danielkucera/ZidoStreamer
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.