我正在开发一款Android应用程序,通过移动相机记录和直播视频。 现在,我正在两者之间切换。我想同时录制和流式传输。
正在记录文件时,无法使用ffmpeg进行流式传输,因为MP4文件信息中的MOV ATOM尚未插入文件中(最终会进入)。
ffmpeg有没有办法:
修改
我决定尝试使用ffmepg通过命令行直接访问摄像机来尝试不同的方法。如果有效,我可以同时录制视频和流。我开始尝试使用FFMPEG library for android:在MainActivity中使用以下代码:
final FFmpeg ffmpeg = FFmpeg.getInstance(getApplicationContext());
try {
ffmpeg.loadBinary(new LoadBinaryResponseHandler() {
@Override
public void onStart() {}
@Override
public void onFailure() {
}
@Override
public void onSuccess() {}
@Override
public void onFinish() {}
});
} catch (FFmpegNotSupportedException e) {
// Handle if FFmpeg is not supported by device
Log.e("FFMEPG","error", e);
}
try {
// to execute "ffmpeg -version" command you just need to pass "-version"
ffmpeg.execute(" -y -f video4linux2 -s 320x240 -r 25 -i /dev/video0 /testing.mp4", new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
Log.d("FFMEPG","start");
}
@Override
public void onProgress(String message) {
Log.d("FFMEPG",message);
}
@Override
public void onFailure(String message) {
Log.e("FFMEPG",message);
}
@Override
public void onSuccess(String message) {
Log.d("FFMEPG",message);
}
@Override
public void onFinish() {
Log.d("FFMEPG","finish");
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
// Handle if FFmpeg is already running
Log.e("FFMEPG","error", e);
}
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
ffmpeg.killRunningProcesses();
}
}, 10000);
并在AndroidManifest.xml中提供必要的权限:
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
我只是想从相机录制一个简单的10秒mp4文件,但是我收到以下错误:
03-05 12:52:29.391 22004-22004/test.testcameraffmpeg E/FFMEPG﹕ WARNING: linker: /data/data/test.testcameraffmpeg/files/ffmpeg has text relocations. This is wasting memory and is a security risk. Please fix.
ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers
built on Oct 7 2014 15:08:46 with gcc 4.8 (GCC)
configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/armeabi-v7a-neon --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -mfpu=neon' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
libavutil 54. 7.100 / 54. 7.100
libavcodec 56. 1.100 / 56. 1.100
libavformat 56. 4.101 / 56. 4.101
libavdevice 56. 0.100 / 56. 0.100
libavfilter 5. 1.100 / 5. 1.100
libswscale 3. 0.100 / 3. 0.100
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 0.100 / 53. 0.100
[video4linux2,v4l2 @ 0x424bad30] Cannot open video device /dev/video0: Permission denied
/dev/video0: Permission denied
我必须是root才能访问相机吗?有人试过这种方法吗?