简体   繁体   English

如何从android流式传输到ffserver

[英]How to stream to ffserver from android

I need to stream from an android camera/ file to a remote ffserver which will broadcast my video. 我需要从一个Android摄像头/文件流到一个远程ffserver,它将播放我的视频。 I can do this on the desktop in ubuntu by issuing a command like: 我可以通过发出如下命令在ubuntu的桌面上执行此操作:

ffmpeg -f video4linux2 -s 640x480 -r 25 -i /dev/video0 http://192.168.0.20:8090/cam1.ffm

or stream a file like this: 或流式传输这样的文件:

ffmpeg -i /home/kev/share/movie.mp4 http://192.168.0.20:8090/cam1.ffm

So basically i want to be able to do the above from android. 所以基本上我希望能够从android做到以上。 After several searches this is what i've done so far - i came across this link http://bambuser.com/opensource from which i downloaded the ffmpeg source and built it. 经过几次搜索,这是我到目前为止所做的 - 我遇到了这个链接http://bambuser.com/opensource ,我从中下载了ffmpeg源并构建了它。 The build outputs several things: 1. shared libs [libavcodec, libavcore, libavdevice, libavfilter,libavformat,libavutil,libswscale] 2. executables [ffmpeg,ffprobe] 构建输出了几件东西:1。共享库[libavcodec,libavcore,libavdevice,libavfilter,libavformat,libavutil,libswscale] 2.可执行文件[ffmpeg,ffprobe]

Not sure how to plug my functionality with these resources this is what i've tried so far: 1. loaded the libs in my Activity using System.loadLibrary() then copied the ffmpeg executable to the assets folder which at runtime i copied to my application's "files" directory i then set permissions for the executable using Runtime.getRuntime().exec(). 不知道如何使用这些资源插入我的功能这是我到目前为止所尝试的:1。使用System.loadLibrary()将libs加载到我的Activity中,然后将ffmpeg可执行文件复制到assets文件夹,在运行时我将其复制到my应用程序的“文件”目录然后我使用Runtime.getRuntime()。exec()设置可执行文件的权限。 then the last step was to execute it in java with the following statement: 然后最后一步是在java中使用以下语句执行它:

Runtime.getRuntime().exec("ffmpeg -i file:///android_asset/movie.mp4http://<server>:8090/cam1.ffm");

2. copied ffmpeg.c,the shared libraries and the "include" folder that was generated by the build to my jni folder and added a jni function that wraps around the main() function in ffmpeg.c. 2.复制ffmpeg.c,共享库和构建到我的jni文件夹生成的“include”文件夹,并添加了一个包装ffmpeg.c中main()函数的jni函数。 With this approach i've found myself having to copy several header files from the ffmpeg source for the ndk-build to succeed and i highly doubt if this is the way to go. 通过这种方法,我发现自己必须从ffmpeg源复制几个头文件才能使ndk-build成功,我非常怀疑这是否可行。

The above two approaches havnt worked for me, i'm not sure where i'm going wrong, so any help on how to do a simple ffmpeg streaming like an mp4 file from android would be highly appreciated. 以上两种方法对我有用,我不知道我哪里出错了,所以任何有关如何做一个简单的ffmpeg流式传输的帮助就像来自android的mp4文件一样,将受到高度赞赏。

I got it working by using apporach 2, this is what i did. 我通过apporach 2使用它,这就是我所做的。 1. copied ffmpeg.c,the "include" folder and the shared libraries to my project's jni folder. 1.将ffmpeg.c,“include”文件夹和共享库复制到我项目的jni文件夹中。

  1. modified ffmpeg.c with reference to this blog post http://demo860.blogspot.com/2010/07/android-ffmpeg-dynamic-module-jni.html 修改了ffmpeg.c并参考了这篇博客文章http://demo860.blogspot.com/2010/07/android-ffmpeg-dynamic-module-jni.html

  2. there were several errors while building with ndk so i just added the missing dependencies until finally the build succeeded. 使用ndk构建时出现了几个错误,所以我只是添加了缺少的依赖项,直到最终构建成功。

At first the app would start and then immediately exit, this was due to a couple of things i forgot to do so make sure you've done the following to save yourself some hours and hair loss: - set internet permission on manifest(if media file is in sdcard, set write external storage permission and make sure the sdcard is mounted) - make sure the remote ffserver is running and configured correctly. 起初应用程序会启动,然后立即退出,这是由于我忘了做的一些事情,所以请确保你已经完成以下操作以节省一些时间和脱发: - 在清单上设置互联网权限(如果媒体文件在sdcard中,设置写入外部存储权限并确保已安装sdcard) - 确保远程ffserver正在运行并正确配置。 you can confirm by streaming from a desktop - make sure you have the correct params passed 您可以通过桌面流媒体确认 - 确保您已通过正确的参数

Now i can stream from an mp4 file in my sdcard to a remote ffserver, havnt tried streaming from the device camera yet. 现在我可以从我的SD卡中的mp4文件流式传输到远程ffserver,havnt尝试从设备摄像头流式传输。

It seems to be a bit late to answer this question, but if you need a solution, here's one... 回答这个问题似乎有点迟了,但如果你需要一个解决方案,这里有一个......

Well, I had devised a workaround to the same problem but through the first approach that is using a compiled FFmpeg Binary rather than JNI ... 好吧,我已经为同样的问题设计了一个解决方法,但是通过使用编译的FFmpeg二进制而不是JNI的第一种方法......

First, as far as it seems to me, the builds provided by Bambuser are way too old and FFmpeg has a vicious development cycle... So I'd rather suggest to custom build your own binary from the latest FFmpeg Source... 首先,就我而言, Bambuser提供的版本太旧了, FFmpeg的开发周期也很恶劣......所以我宁愿建议从最新的FFmpeg Source自定义构建你自己的二进制文件......

Here's a script that could be used to generate one : 这是一个可用于生成一个脚本的脚本:

#!/bin/bash

echo ""
echo " ********** FFmpeg Android Build ********** "
echo ""

NDK=$HOME/android-ndk-r8d
PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86
PLATFORM=$NDK/platforms/android-14/arch-arm
PREFIX=$HOME/FFmpeg.Binaries.Android
FFMPEG_BASE=$HOME/FFmpeg.Build

if [ -d "$FFMPEG_BASE" ]; then
    rm -v -r -f $FFMPEG_BASE
fi
if [ -d "$PREFIX" ]; then
    rm -v -r -f $PREFIX
fi

mkdir $FFMPEG_BASE
mkdir $PREFIX

# x264 Installation
echo ""
echo " ********** libx264 Installation ********** "
echo ""

cd $FFMPEG_BASE
git clone --depth 1 git://git.videolan.org/x264
cd $FFMPEG_BASE/x264

./configure --prefix=$PREFIX \
--enable-static \
--enable-pic \
--disable-asm \
--disable-cli \
--host=arm-linux \
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
--sysroot=$PLATFORM

make
sudo make install
sudo ldconfig

#FFmpeg Installation
echo ""
echo " ********** FFmpeg (Android) Installation ********** "
echo ""
cd $FFMPEG_BASE
# git clone --depth 1 git://source.ffmpeg.org/ffmpeg
cd $FFMPEG_BASE/ffmpeg

./configure --target-os=linux --prefix=$PREFIX \
--enable-cross-compile \
--enable-runtime-cpudetect \
--disable-asm \
--arch=arm \
--cc=$PREBUILT/bin/arm-linux-androideabi-gcc \
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
--disable-stripping \
--nm=$PREBUILT/bin/arm-linux-androideabi-nm \
--sysroot=$PLATFORM \
--enable-nonfree \
--enable-version3 \
--enable-gpl \
--disable-doc \
--enable-avresample \
--enable-demuxer=rtsp \
--enable-muxer=rtsp \
--disable-ffserver \
--disable-ffprobe \
--enable-ffmpeg \
--enable-ffplay \
--enable-libx264 \
--enable-encoder=libx264 \
--enable-decoder=h264 \
--enable-protocol=rtp \
--enable-hwaccels \
--enable-zlib \
--extra-cflags="-I$PREFIX/include -fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -mfloat-abi=softfp -mfpu=vfpv3-d16 -marm -march=armv7-a" \
--extra-ldflags="-L$PREFIX/lib"

make -j4 install

$PREBUILT/bin/arm-linux-androideabi-ar d libavcodec/libavcodec.a inverse.o
$PREBUILT/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -L$PREFIX/lib  -soname libffmpeg.so -shared -nostdlib  -z,noexecstack -Bsymbolic --whole-archive --no-undefined -o $PREFIX/libffmpeg.so libavcodec/libavcodec.a libavfilter/libavfilter.a libavresample/libavresample.a libavformat/libavformat.a libavutil/libavutil.a libswscale/libswscale.a -lc -lm -lz -ldl -llog -lx264 --warn-once --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a

# rm -v -r -f $FFMPEG_BASE
clear
echo ""
echo "FFmpeg Android Build Successful..."
echo ""

ls -l -R $PREFIX

exit    

For the above script to work, Android NDK is required and could be downloaded from here . 要使上述脚本生效Android NDK是必需的,可以从这里下载。 Download the NDK and extract to your /home/<username> directory or else customize the script as per your needs... 下载NDK并解压缩到您的/home/<username>目录,或者根据您的需要自定义脚本...

And also avoid using the file:// protocol in the command line, just specify the absolute path of the input file. 并且还要避免在命令行中使用file:// protocol,只需指定输入文件的绝对路径即可。 And try to log the output from the FFmpeg process by gettin' instances of its stdout and stderr streams... 并尝试通过其stdoutstderr流的gettin'实例记录FFmpeg进程的stderr ...

You don't have to copy shared libraries and include folder. 您不必复制共享库和包含文件夹。 You can use the "PREBUILD_SHARED_LIBRARY" feature of Andriod.mk instead. 您可以使用Andriod.mk的“PREBUILD_SHARED_LIBRARY”功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM