Skip to content

android 读取摄像头和麦克风,使用rtmp推流

Notifications You must be signed in to change notification settings

taoboy/AndroidFFmpeg

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

90 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

推流 所在项目 Streaming

推流

左边是推流端,右边是播放端, 由于gif图片过大,如果加载不出来,请查看art/streaming.gif

感谢

支持如下功能:

  • Android mini API 16.
  • H.264/AAC 硬编.
  • H.264/AAC 软编.
  • 前后摄像头切换.

编译

clone libx264extra目录,执行 sh tools/compile-x264.sh all 生成libx264.a静态库 导入Streaming到Android Studio

使用方式:

encoder = new Encoder.Builder()
				// 是否使用软编
                .setSoftEncoder(Encoder.SOFT_ENCODE)
                // 设置CameraView
                .setCameraView(mCameraView)
                .build();

释放资源 调用代码如下:

encoder.stop();



FFmpeg Library for Android
Building
export ANDROID_NDK=you_ndk_path

因为arm64和x86,x86-64使用了yasm,所以需要安装yasm,由于我使用的是mac,所以使用brew安装,brew install yasm,brew安装文档brew

然后在终端运行

./build-android.sh

会去下载ffmpeg和x264的源码,编译完成之后会在tools目录下的ffmpeg-build下生成对应的libffmpeg.so,编译完成之后把项目导入Android Studio就可以了.

使用

压缩

压缩

FFmpeg ffmpeg = FFmpeg.getInstance();
ffmpeg.setInputDataSource("you input path");
ffmpeg.setOutputDataSource("you output path");
//视频的宽
int videoWidth = ffmpeg.getVideoWidth();
//视频的高
int videoHeight = ffmpeg.getVideoHeight();
//视频的角度,90,180,270,360
doule roation = ffmpeg.getRotation();
int result = ffmpeg.setCompress(需要缩放的宽,需要缩放的高);
ffmpeg.release();
//result >= 0 success
if (result < 0) {
    //error
}

裁剪

下面是裁剪的效果图

FFmpeg ffmpeg = FFmpeg.getInstance();
ffmpeg.setInputDataSource("you input path");
ffmpeg.setOutputDataSource("you outpu path");
int result = ffmpeg.crop(x, y, width, height);
ffmpeg.release();
// result >= 0 success
if (result < 0) {
    //error
}

播放

采用FFmpeg + SDL2来进行解码和播放

note 目前还没有做快进和暂停操作,还有一些细节操作需要调整,不建议用在项目中

播放状态

About me:

wlanjie, 联系方式:qq:153920981 微信:w153920981

About

android 读取摄像头和麦克风,使用rtmp推流

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 50.0%
  • C 47.0%
  • Objective-C 1.8%
  • Java 0.9%
  • Perl 0.2%
  • CMake 0.1%