簡體   English   中英

Android-MediaRecorder輸出流到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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM