Skip to content

Commit

Permalink
完成MediaCodec编码并使用RTMPDump推流
Browse files Browse the repository at this point in the history
  • Loading branch information
eric committed Dec 28, 2017
1 parent dd559ba commit 7670dc0
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 22 deletions.
4 changes: 2 additions & 2 deletions rtmpfile/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".CameraActivity" />
<activity android:name=".PushFileRtmpActivity" />
<activity android:name=".CameraFFmpegPushRtmpActivity" />
<activity android:name=".FFmpegPushFileRtmpActivity" />
<activity android:name=".CameraMediaCodecActivity" />
<activity android:name=".CameraMediaCodecRtmpActivity" />
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
* Modified :
*/

public class CameraActivity extends Activity implements SurfaceHolder.Callback {
public class CameraFFmpegPushRtmpActivity extends Activity implements SurfaceHolder.Callback {
private MySurfaceView sv;
private final int WIDTH = 480;
private final int HEIGHT = 320;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,14 @@
import com.wangheart.rtmpfile.utils.LogUtils;

import java.io.IOException;

/**
* Author : eric
* CreateDate : 2017/11/6 10:57
* Email : ericli_wang@163.com
* Version : 2.0
* Desc : 摄像头操作类
* Modified :
*/
public class CameraInterface {
private Camera mCamera;
private boolean isPreviewing = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,11 @@ private void init() {
mFlvPacker.setPacketListener(new Packer.OnPacketListener() {
@Override
public void onPacket(final byte[] data, final int packetType) {
// IOUtils.write(mOutStream, data, 0, data.length);
pushExecutor.execute(new Runnable() {
@Override
public void run() {
int ret=RtmpHandle.getInstance().push(data, data.length);
LogUtils.w(data.length + " " + packetType + " ret:"+ret);
int ret = RtmpHandle.getInstance().push(data, data.length);
LogUtils.w("type:" + packetType + " length:" + data.length + " 推流结果:" + ret);
}
});
}
Expand Down Expand Up @@ -186,7 +185,7 @@ public void surfaceCreated(SurfaceHolder holder) {
@Override
public void run() {
int ret = RtmpHandle.getInstance().connect("rtmp://192.168.31.127/live");
LogUtils.w("connect ret " + ret);
LogUtils.w("打开RTMP连接: " + ret);
}
});
}
Expand All @@ -200,6 +199,8 @@ public void surfaceDestroyed(SurfaceHolder holder) {
mFlvPacker.stop();
CameraInterface.getInstance().stopPreview();
CameraInterface.getInstance().releaseCamera();
int ret = RtmpHandle.getInstance().close();
LogUtils.w("关闭RTMP连接:" + ret);
IOUtils.close(mOutStream);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* Modified :
*/

public class PushFileRtmpActivity extends Activity {
public class FFmpegPushFileRtmpActivity extends Activity {
private TextView tvPushInfo;

@Override
Expand Down
37 changes: 31 additions & 6 deletions rtmpfile/src/main/java/com/wangheart/rtmpfile/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,43 @@ private void initData() {
tvCodecInfo.setText(FFmpegHandle.getInstance().getAvcodecConfiguration());
}

public void btnCamera(View view) {
Intent intent = new Intent(this, CameraActivity.class);
/**
* FFmpeg推送视频文件
*
* @param view
*/
public void btnFFmpegPushFile(View view) {
Intent intent = new Intent(this, FFmpegPushFileRtmpActivity.class);
startActivity(intent);
}

public void btnPushFile(View view) {
Intent intent = new Intent(this, PushFileRtmpActivity.class);
/**
* FFmpeg推送摄像头采集的数据
*
* @param view
*/
public void btnCameraFFmpeg(View view) {
Intent intent = new Intent(this, CameraFFmpegPushRtmpActivity.class);
startActivity(intent);
}

/**
* MediaCodec编码摄像头数据并保存问flv格式到文件
*
* @param view
*/
public void btnMediaCodec(View view) {
Intent intent = new Intent(this, CameraMediaCodecActivity.class);
startActivity(intent);
}

public void librmtp(View view) {
new Thread(){
/**
* RTMPDump推送视频文件
*
* @param view
*/
public void btmRtmpdumpFile(View view) {
new Thread() {
@Override
public void run() {
super.run();
Expand All @@ -62,6 +82,11 @@ public void run() {
}.start();
}

/**
* MediaCodec编码摄像头数据并使用RTMPDump进行推流
*
* @param view
*/
public void btnMediaCodecRtmp(View view) {
Intent intent = new Intent(this, CameraMediaCodecRtmpActivity.class);
startActivity(intent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
* CreateDate : 2017/12/25 18:13
* Email : ericli_wang@163.com
* Version : 2.0
* Desc :
* Desc : RTMPDump调用类
* Modified :
*/

public class RtmpHandle {
public static RtmpHandle mInstance;
private static RtmpHandle mInstance;

private RtmpHandle() {
}
Expand Down
13 changes: 8 additions & 5 deletions rtmpfile/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,27 @@
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="btnPushFile"
android:text="推送文件RTMP流" />
android:onClick="btnFFmpegPushFile"
android:text="FFmpeg推送文件RTMP流" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="btnCamera"
android:onClick="btnCameraFFmpeg"
android:text="开启摄像头进行视频编码(FFmpeg)" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="btnMediaCodec"
android:text="开启摄像头进行视频编码(MediaCodec),存到flv文件" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="librmtp"
android:text="librmtp" />
android:onClick="btmRtmpdumpFile"
android:text="解析FLV文件通过librmtp推流" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 7670dc0

Please sign in to comment.