From f25d25179aeae0c825b2e431c9d3b86c27db51fb Mon Sep 17 00:00:00 2001 From: xufuji456 Date: Fri, 9 Sep 2022 18:17:56 +0800 Subject: [PATCH] Feature: support push rtmp stream with http url --- app/src/main/cpp/ff_http_pusher.cpp | 2 ++ .../com/frank/ffmpeg/activity/PushActivity.kt | 32 +++++++------------ app/src/main/res/values-en/strings.xml | 4 +-- app/src/main/res/values/strings.xml | 4 +-- 4 files changed, 18 insertions(+), 24 deletions(-) diff --git a/app/src/main/cpp/ff_http_pusher.cpp b/app/src/main/cpp/ff_http_pusher.cpp index f1548d4..6f56473 100644 --- a/app/src/main/cpp/ff_http_pusher.cpp +++ b/app/src/main/cpp/ff_http_pusher.cpp @@ -23,6 +23,8 @@ int FFHttpPusher::open(const char *inputPath, const char *outputPath) { return ret; } + // Flv video: h264 audio: aac/mp3 + // If not h264, should transocde to h264 for (int i = 0; i < inFormatCtx->nb_streams; ++i) { AVStream *in_stream = inFormatCtx->streams[i]; const auto *codec = in_stream->codec->codec; diff --git a/app/src/main/java/com/frank/ffmpeg/activity/PushActivity.kt b/app/src/main/java/com/frank/ffmpeg/activity/PushActivity.kt index c7ae323..d24bf46 100644 --- a/app/src/main/java/com/frank/ffmpeg/activity/PushActivity.kt +++ b/app/src/main/java/com/frank/ffmpeg/activity/PushActivity.kt @@ -12,12 +12,12 @@ import com.frank.ffmpeg.R import java.io.File /** - * Using FFmpeg to push stream + * Using FFmpeg to push http-flv stream * Created by frank on 2018/2/2. */ class PushActivity : BaseActivity() { - private var editFilePath: EditText? = null + private var editInputPath: EditText? = null private var editLiveURL: EditText? = null @@ -32,30 +32,22 @@ class PushActivity : BaseActivity() { } private fun initView() { - editFilePath = getView(R.id.edit_file_path) - editLiveURL = getView(R.id.edit_live_url) - editFilePath!!.setText(FILE_PATH) + editInputPath = getView(R.id.edit_file_path) + editLiveURL = getView(R.id.edit_live_url) + editInputPath!!.setText(INPUT_PATH) editLiveURL!!.setText(LIVE_URL) initViewsWithClick(R.id.btn_push_stream) } private fun startPushStreaming() { - //TODO the video format is flv - val filePath = editFilePath!!.text.toString() - val liveUrl = editLiveURL!!.text.toString() - Log.i(TAG, "filePath=$filePath") - Log.i(TAG, "liveUrl=$liveUrl") + val filePath = editInputPath!!.text.toString() + val liveUrl = editLiveURL!!.text.toString() if (!TextUtils.isEmpty(filePath) && !TextUtils.isEmpty(filePath)) { - val file = File(filePath) - if (file.exists()) { - Thread(Runnable { - FFmpegPusher().pushStream(filePath, liveUrl) - }).start() - } else { - showToast(getString(R.string.file_not_found)) - } + Thread(Runnable { + FFmpegPusher().pushStream(filePath, liveUrl) + }).start() } } @@ -71,8 +63,8 @@ class PushActivity : BaseActivity() { companion object { - private val TAG = PushActivity::class.java.simpleName - private const val FILE_PATH = "storage/emulated/0/hello.flv" + // storage/emulated/0/beyond.mp4 + private const val INPUT_PATH = "http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" private const val LIVE_URL = "rtmp://192.168.17.168/live/stream" } } diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index 0b8ad52..ca8b782 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -30,8 +30,8 @@ Audio handle Media handle Video handle - Video pusher - Video living + Http-flv stream + RTMP living Media mux Audio extract diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index afe25c9..53bc35d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -30,8 +30,8 @@ 音频处理 音视频处理 视频处理 - 本地推流直播 - 实时推流直播 + http-flv推流 + rtmp推流直播 音视频合成 提取音频