您的位置:首页 > 移动开发 > Android开发

vlc-android截屏以及录像功能的实现

2015-01-27 17:18 701 查看
这里讲的是vlc-android截屏以及录像功能的实现,如果单纯想编译vlc-android的源码请移步至:/article/1765977.html

1、首先按照上面编译文档的流程配置好ubuntu下的android环境

2、安装好一大堆工具:

sudo apt-get install ant autoconf automake autopoint cmake gawk gcc g++ libtool m4 patch pkg-config ragel subversion yasm git
切换vlc android 版本到 0.1.x-bugfix(这一步不要忘记,一开始忘记了导致重新下了一次源码)
git clone git://git.videolan.org/vlc-ports/android.git
cd android
git branch -r
git checkout 0.1.x-bugfix
3、修改部分文件:
1)android/configure.sh进行修改 删掉其中的-disable-sout

2) 另外保存图片为png格式,需要让ffmpeg增加-enable-encoder=png的编码器(在android/vlc/contrib/src/ffmpeg/rules.mak中修改)

有一行:
else

FFMPEGCONF += --disable-encoders --disable-muxers
改成FFMPEGCONF += --disable-encoders --enable-encoder=png --disable-muxers

4、编译源码:直接在android目录执行 sh compile.sh
编译过程中不知道为啥遇到好几次停顿,每次都是touch **;反正不是报错,没管它继续重新执行sh compile.sh。
最后报错了:../vlc/android/modules/.libs/libvorbis_plugin.a(libvorbis_plugin_la-vorbis.o): in function OpenEncoder:../../modules/codec/vorbis.c:758:
error: undefined reference to 'vorbis_encode_setup_vbr‘
解决办法:将下面的红色部分修改
修改vlc-android/jni/Android.mk

[java]
view plaincopy





LOCAL_LDLIBS := -L$(VLC_CONTRIB)/lib \
$(VLC_MODULES) \
$(VLC_BUILD_DIR)/lib/.libs/libvlc.a \
$(VLC_BUILD_DIR)/src/.libs/libvlccore.a \
$(VLC_BUILD_DIR)/compat/.libs/libcompat.a \
-ldl -lz -lm -llog \
-ldvbpsi -lebml -lmatroska -ltag \
-logg -lFLAC -ltheora -lvorbis -lvorbisfile -lvorbisenc \
-lmpeg2 -la52 \
-lavformat -lavcodec -lswscale -lavutil -lpostproc -lgsm -lopenjpeg \
-lliveMedia -lUsageEnvironment -lBasicUsageEnvironment -lgroupsock \
-lspeex -lspeexdsp \
-lxml2 -lpng -lgnutls -lgcrypt -lgpg-error \
-lnettle -lhogweed -lgmp \
-lfreetype -liconv -lass -lfribidi -lopus \
-lEGL -lGLESv2 -ljpeg \
$(CPP_STATIC)


-logg -lFLAC -ltheora -lvorbis

后添加

-lvorbisfile -lvorbisenc

继续编译,结果有报错了:
error: undefined reference to 'vlc_entry__access_output_udp'

出现这个错误,修改一下/vlc/modules/access_output目录下的

Modules.am 文件就可以编译过了。

修改方法:将下面的红色部分修改(晕死,红色都加不上,加上代码就变了,大家自己对比哪里不同吧,添加了两行,注释了三行)

[java]
view plaincopy





SOURCES_access_output_dummy = dummy.c
SOURCES_access_output_file = file.c
SOURCES_access_output_udp = udp.c
SOURCES_access_output_http = http.c bonjour.c bonjour.h
SOURCES_access_output_shout = shout.c

access_output_LTLIBRARIES += \
libaccess_output_dummy_plugin.la \
libaccess_output_file_plugin.la \
libaccess_output_udp_plugin.la \
libaccess_output_http_plugin.la

#libaccess_output_udp_plugin_la_SOURCES = udp.c
#libaccess_output_udp_plugin_la_LIBADD = $(SOCKET_LIBS) $(LIBPTHREAD)
#access_output_LTLIBRARIES += libaccess_output_udp_plugin.la

libaccess_output_livehttp_plugin_la_SOURCES = livehttp.c
libaccess_output_livehttp_plugin_la_CFLAGS = $(AM_CFLAGS) $(GCRYPT_CFLAGS)
libaccess_output_livehttp_plugin_la_LIBADD = $(GCRYPT_LIBS) -lgpg-error
if HAVE_GCRYPT
access_output_LTLIBRARIES += libaccess_output_livehttp_plugin.la
endif

ok,到这里问题解决可以成功编译源码了。最后的库文件在vlc-android/libs/arm**中
5、添加截屏以及录像功能代码(这一步可以在第四步编译的时候就加上):
8月1日更新
其实需要修改的文件不只是下面这两个,最好能够看懂patch文件,自行添加patch包,也就是打补丁。
文件的大概内容请看:https://patches.videolan.org/patch/606/
8月1日更新结束
1)修改vlc/include/vlc/libvlc_media_player.h,在文件最后两行:
/** @} audio */

/** @} media_player */

之间添加代码:

[cpp]
view plaincopy





LIBVLC_API bool libvlc_media_player_is_recordable( libvlc_media_player_t *p_mi );

LIBVLC_API bool libvlc_media_player_is_recording( libvlc_media_player_t *p_mi );

LIBVLC_API int libvlc_media_player_record_start( libvlc_media_player_t *p_mi, const char *psz_filename );

LIBVLC_API int libvlc_media_player_record_stop( libvlc_media_player_t *p_mi );

2)在vlc/lib/media_player.c最后添加:

[cpp]
view plaincopy





bool libvlc_media_player_is_recordable( libvlc_media_player_t *p_mi )
{
input_thread_t *p_input_thread;
bool b_can_record;

p_input_thread = libvlc_get_input_thread( p_mi );
if( !p_input_thread )
return false;

b_can_record = var_GetBool( p_input_thread, "can-record" );

vlc_object_release( p_input_thread );
return b_can_record;
}
bool libvlc_media_player_is_recording( libvlc_media_player_t *p_mi )
{
input_thread_t *p_input_thread;
bool b_record;

p_input_thread = libvlc_get_input_thread( p_mi );
if( !p_input_thread )
return false;

b_record = var_GetBool( p_input_thread, "record" );

vlc_object_release( p_input_thread );
return b_record;
}
int libvlc_media_player_record_start( libvlc_media_player_t *p_mi, const char* psz_filename )
{
input_thread_t *p_input_thread;

p_input_thread = libvlc_get_input_thread( p_mi );
if( !p_input_thread )
return -1;

var_SetString( p_input_thread, "input-record-path", psz_filename );
var_SetBool( p_input_thread, "record", true );

vlc_object_release( p_input_thread );
return 0;
}
int libvlc_media_player_record_stop( libvlc_media_player_t *p_mi )
{
input_thread_t *p_input_thread;

p_input_thread = libvlc_get_input_thread( p_mi );
if( !p_input_thread )
return -1;

var_SetBool( p_input_thread, "record", false );

vlc_object_release( p_input_thread );
return 0;
}

,ok修改完毕,重新sh compile.sh
3)在LibVLC.java中添加:

[java]
view plaincopy





public native boolean takeSnapShot( int num, String file, int width, int height);

public native boolean videoRecordStart(String path);

public native boolean videoRecordStop();

public native boolean videoIsRecording();

public native boolean videoIsRecordable();

public native int getState();

public boolean takeSnapShot(String file, int width, int height) {
return takeSnapShot(0, file, width, height);
}

即可调用java接口takeSnapShot实现截屏功能了,录像功能的接口:viceoRecordStart,videoRecordStop。
很快就可以编译出最新的库文件。到这里便实现了截屏跟录像的功能。给一个最后截屏跟录像的实例吧:

下载链接:费了老大劲才传上去,注意下载后源码要自己修改成适合自己的url,(这里测试的是rtsp的)http://download.csdn.net/detail/a358763471/7702397
本文参考文章:
/article/2949920.html#
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: