简单介绍

Vlc for android是一款开源安卓播放器。具备播放多媒体文件、光盘、设备以及网络流媒体协议等功能,支持ARMv7 CPU或一个x86 CPU的设备,全部播放控制特性都已经开发完整。

以下将介绍怎样获代替码、编译、vlc原理、缩小延迟、加入截图和录制视频、多路播放等。

具体解释
1、获代替码

官网源代码下载:http://mirror.us.leaseweb.net/videolan/

git获取:clone from git://git.videolan.org/vlc-ports/android.git

补丁:https://patches.videolan.org/

2、编译

1、搭配环境
AndroidSDK:adt-bundle-linux-x86-20130522
JDK:jdk-7u25-linux-i586
NDK:android-ndk-r8e-linux-x86

2、安装工具
apt-get install gcc
apt-get install g++
apt-get build-dep vlc 
apt-get install git 
apt-get install wget 
apt-get install autoconf
apt-get install libtool
apt-get install subversion 
apt-get install cmake
apt-get install ant

3、配置信息

export ANDROID_NDK=/home/mythou/android-dev/android-ndk-r8e
export NDKR5C=/home/mythou/ndkr5c
export NDKR6B=/home/mythou/ndkr6b
PATH=$PATH:$NDKR6B:$ANDROID_NDK

export ANDROID_ABI=armeabi-v7a

export JAVA_HOME=/home/mythou/android-dev/jdk/jdk1.7.0_25
export JRE_HOME=/home/mythou/android-dev/jdk/jdk1.7.0_25/jre
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
export ANT_HOME=/home/mythou/android-dev/apache-ant-1.8.0
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH:$HOME/bin:$ANT_HOME

export ANDROID_SDK=/home/mythou/android-dev/adt-bundle-linux-x86-20130522/sdk
PATH=$PATH:$ANDROID_SDK/tools:$ANDROID_SDK/platform-tools

4、编译

sh compile.sh   or    sh compile.sh release

5、辅助库

因为某些原因,有些库无法获得。请手动下载放入便可。

3、vlc播放原理

视频播放的基本步骤:
    1、acess 訪问(获取视频数据)
    2、demux 解复用(音频、视频分离)  
    3、decode 解码(音频和视频的解码)
    4、output 输出(音频和视频的输出(aout和vout)

如图:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYmFua2V0cmVl/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />

4、缩小延迟

改动延迟的方法有两种:1、直接用Java代码实现;2、在vlc库中改动。

涉及延迟的參数有:file-caching(文件缓存)、live-caching(直播缓存)、network-caching(网络缓存)、sout-mux-caching(输出缓存)。

Java代码实现例如以下:

			options.add(":file-caching=1500");//文件缓存
options.add(":network-caching=1500");//网络缓存 options.add(":live-caching=1500");//直播缓存
options.add(":sout-mux-caching=1500");//输出缓存 options.add(":codec=mediacodec,iomx,all");

vlc库实现例如以下:

查找目标文件vlc/src/libvlc-module.c  改动相应的參数

    add_integer( "file-caching", DEFAULT_PTS_DELAY / 3000,
CACHING_TEXT, CACHING_LONGTEXT, true )
add_integer( "live-caching", DEFAULT_PTS_DELAY / 3000,
CAPTURE_CACHING_TEXT, CAPTURE_CACHING_LONGTEXT, true )
add_integer( "network-caching", CLOCK_FREQ / 3000,
NETWORK_CACHING_TEXT, NETWORK_CACHING_LONGTEXT, true )
add_integer( "sout-mux-caching", 1000, SOUT_MUX_CACHING_TEXT,
SOUT_MUX_CACHING_LONGTEXT, true )

把分母数据增大,缓存的数据就越小,延迟就降低,流畅性就降低,相反。分母数据降低,缓存的数据就越大,延迟就添加,流畅性就添加。

測试结果,延迟明显降低。

5、加入截图和录制视频

官方已给出补丁实现截图和录制视频

1、截图

改动文件: android/configure.sh  搜索内容 -disable-sout   并删除

改动文件:android/vlc/contrib/src/ffmpeg/rules.mak  添加-enable-encoder=png的编码器 实现png格式截图

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

源代码又一次编译便可

编译过程中可能会出现例如以下问题:

./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

 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

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 内容覆盖便可

相关源代码加入:

在libvlcjni.c中添加函数:

boolean Java_org_videolan_libvlc_LibVLC_takeSnapShot(JNIEnv *env, jobject thiz,jint number, jstring path, jint width,jint height)
{
jboolean isCopy;
libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
/* Get C string */
const char* psz_path = (*env)->GetStringUTFChars(env, path, &isCopy); if (mp)
if(libvlc_video_take_snapshot(mp, (int)number,psz_path , (int)width,(int)height)==0)
return JNI_TRUE;
return JNI_FALSE; }

LibVlc.java中添加native函数的接口和调用方法:

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

2、录制视频

录制补丁  https://patches.videolan.org/patch/606/

补丁内容例如以下:

diff --git a/include/vlc/libvlc_events.h b/include/vlc/libvlc_events.h
index 2cfedbf..25a16ea 100644
--- a/include/vlc/libvlc_events.h
+++ b/include/vlc/libvlc_events.h
@@ -72,6 +72,8 @@ enum libvlc_event_e {
libvlc_MediaPlayerSnapshotTaken,
libvlc_MediaPlayerLengthChanged,
libvlc_MediaPlayerVout,
+ libvlc_MediaPlayerRecordableChanged,
+ libvlc_MediaPlayerRecordingFinished, libvlc_MediaListItemAdded=0x200,
libvlc_MediaListWillAddItem,
@@ -165,6 +167,14 @@ typedef struct libvlc_event_t
} media_player_pausable_changed;
struct
{
+ int new_recordable;
+ } media_player_recordable_changed;
+ struct
+ {
+ char *psz_filename;
+ } media_player_recording_finished;
+ struct
+ {
int new_count;
} media_player_vout; diff --git a/include/vlc/libvlc_media_player.h b/include/vlc/libvlc_media_player.h
index aefef02..8ddef37 100644
--- a/include/vlc/libvlc_media_player.h
+++ b/include/vlc/libvlc_media_player.h
@@ -1628,6 +1628,121 @@ LIBVLC_API int libvlc_audio_set_delay( libvlc_media_player_t *p_mi, int64_t i_de /** @} audio */ +/**
+ * Can the media player record the current media? + *
+ * Media must be buffering or playing before it can be recorded.
+ *
+ * The media player event manager will emit a libvlc_MediaPlayerRecordableChanged event
+ * when the recordable state changes after starting media playback. The event data will
+ * describe the new recordable state, so invocation of this API method is not strictly
+ * necessary to determine when recording can be started.
+ *
+ * A libvlc_MediaPlayerRecordableChanged event will not be emitted if the media is
+ * stopped (notified by a libvlc_MediaPlayerStoppedEvent) or finishes normally (notified
+ * by a libvlc_MediaPlayerFinished event).
+ *
+ * A calling application should therefore register an event callback for those events
+ * so that it may query the new recordable state and manage recording at the appropriate
+ * time.
+ *
+ * \param p_mi media player
+ * \return true if the media player can record, false if it can not
+ * \version LibVLC 2.1.0 or later
+ */
+LIBVLC_API bool libvlc_media_player_is_recordable( libvlc_media_player_t *p_mi );
+
+/**
+ * Is the current media being recorded?
+ *
+ * \param p_mi media player
+ * \return true if recording, false if not
+ * \version LibVLC 2.1.0 or later
+ */
+LIBVLC_API bool libvlc_media_player_is_recording( libvlc_media_player_t *p_mi );
+
+/**
+ * Start recording the current media.
+ *
+ * Media must be buffering or playing before it can be recorded. A calling application
+ * can begin recording immediately on receipt of a libvlc_MediaPlayerRecordableChanged
+ * event sent via the media player event manager (if recording is possible for the
+ * currently playing media), and any time thereafter until the media stops.
+ *
+ * Media will be saved to the file path denoted by the psz_filename parameter if it is
+ * supplied. Any such supplied filename should not include a file extension as the
+ * correct file extension will automatically be appended when the file is created. This
+ * filename may denote a full path name, but each directory in the path must already
+ * exist or recording will silently fail. If the calling application chooses to specify
+ * the filename then it is the responsibility of that application to take account of
+ * this and itself make sure any needed directories are created.
+ *
+ * Alternatively, a calling application need not supply a filename and so instead let
+ * vlc automatically generate a unique filename. This will cause vlc to create a new
+ * file in the appropriate media directory for the user - for example "~/Videos". The
+ * actual filename used will be sent in an event when the recording is complete.
+ *
+ * When recording has finished and the new file has been completely saved, a
+ * libvlc_MediaPlayerRecordingFinished event will be sent via the media player event
+ * manager. The event data will contain the filename of the newly recorded file - this
+ * will either be the filename as specified by the calling application or a filename
+ * generated by vlc if the application did not supply a filename. In either case, this
+ * filename will include the automatically appended file extension.
+ *
+ * The saved media file will not be immediately available or visible until recording
+ * has completely finished and the libvlc_MediaPlayerRecordingFinished event has been
+ * received, or the media has stopped or finished normally.
+ *
+ * Recording can be stopped and started on-the-fly once the recordable state is set;
+ * each time recording is stopped and restarted a new file will be created so a calling
+ * application should take care to provide unique filenames, or defer to vlc to create
+ * unique filenames.
+ *
+ * Recording will be stopped when the media stops playing, and must be explicitly
+ * started again to restart recording, i.e. the recording state is not automatically
+ * preserved when playing media subsequently.
+ *
+ * Media player functionailty such as next/previous chapter, set time or position and
+ * so on are ineffective when recording is enabled. However, pausing the media is
+ * possible and will pause the recording; unpausing the media will resume playback and
+ * recording.
+ *
+ * Recording of the primary media or sub-items is possible.
+ *
+ * \param p_mi media player
+ * \param psz_filename name of the file to save the media to, not including any file extension,
+ * or NULL if vlc should generate the filename automatically
+ * \return 0 if recording was started, -1 on error
+ * \version LibVLC 2.1.0 or later
+ */
+LIBVLC_API int libvlc_media_player_record_start( libvlc_media_player_t *p_mi, const char *psz_filename );
+
+/**
+ * Stop recording the current media.
+ *
+ * This method requests that the recording stop, and will return immediately. Recording
+ * will not stop immediately.
+ *
+ * When the recording actually stops some short time later and the new file has
+ * finished being written, a libvlc_MediaPlayerRecordingFinished event will be sent via
+ * the media player event manager. The newly recorded file will not be visible or
+ * available until after this event has been sent.
+ *
+ * The event data will contain the full name of the file that was created. The filename
+ * will either be that as was specified by the calling application on invoking
+ * libvlc_media_player_record_start(), or the filename that vlc automatically generated
+ * if the calling application did not supply its own filename. In either case the
+ * filename will contain the automatically appended file extension.
+ *
+ * There is no need to invoke this method to stop the recording if the media is stopped
+ * or finishes playing normally.
+ *
+ * \param p_mi media player
+ * \return 0 if recording was stopped, -1 on error
+ * \version LibVLC 2.1.0 or later
+ */
+LIBVLC_API int libvlc_media_player_record_stop( libvlc_media_player_t *p_mi );
+
/** @} media_player */ # ifdef __cplusplus
diff --git a/lib/event.c b/lib/event.c
index c71a48a..7ef4abd 100644
--- a/lib/event.c
+++ b/lib/event.c
@@ -279,6 +279,8 @@ static const event_name_t event_list[] = {
DEF(MediaPlayerSnapshotTaken)
DEF(MediaPlayerLengthChanged)
DEF(MediaPlayerVout)
+ DEF(MediaPlayerRecordableChanged)
+ DEF(MediaPlayerRecordingFinished) DEF(MediaListItemAdded)
DEF(MediaListWillAddItem)
diff --git a/lib/libvlc.sym b/lib/libvlc.sym
index 42dad5c..3ff67ef 100644
--- a/lib/libvlc.sym
+++ b/lib/libvlc.sym
@@ -137,6 +137,8 @@ libvlc_media_player_get_title
libvlc_media_player_get_title_count
libvlc_media_player_get_xwindow
libvlc_media_player_has_vout
+libvlc_media_player_is_recordable
+libvlc_media_player_is_recording
libvlc_media_player_is_seekable
libvlc_media_player_is_playing
libvlc_media_player_new
@@ -146,6 +148,8 @@ libvlc_media_player_set_pause
libvlc_media_player_pause
libvlc_media_player_play
libvlc_media_player_previous_chapter
+libvlc_media_player_record_start
+libvlc_media_player_record_stop
libvlc_media_player_release
libvlc_media_player_retain
libvlc_media_player_set_agl
diff --git a/lib/media_player.c b/lib/media_player.c
index a41b8c7..6573197 100644
--- a/lib/media_player.c
+++ b/lib/media_player.c
@@ -64,6 +64,10 @@ input_pausable_changed( vlc_object_t * p_this, char const * psz_cmd,
vlc_value_t oldval, vlc_value_t newval,
void * p_userdata );
static int
+input_recordable_changed( vlc_object_t *p_this, char const *psz_cmd,
+ vlc_value_t oldval, vlc_value_t newval,
+ void *p_userdata );
+static int
input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
vlc_value_t oldval, vlc_value_t newval,
void * p_userdata );
@@ -72,6 +76,10 @@ static int
snapshot_was_taken( vlc_object_t *p_this, char const *psz_cmd,
vlc_value_t oldval, vlc_value_t newval, void *p_data ); +static int
+file_recording_finished( vlc_object_t *p_this, char const *psz_cmd,
+ vlc_value_t oldval, vlc_value_t newval, void *p_data );
+
static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi ); /*
@@ -132,6 +140,8 @@ static void release_input_thread( libvlc_media_player_t *p_mi, bool b_input_abor
input_seekable_changed, p_mi );
var_DelCallback( p_input_thread, "can-pause",
input_pausable_changed, p_mi );
+ var_DelCallback( p_input_thread, "can-record",
+ input_recordable_changed, p_mi );
var_DelCallback( p_input_thread, "intf-event",
input_event_changed, p_mi ); @@ -227,6 +237,25 @@ input_pausable_changed( vlc_object_t * p_this, char const * psz_cmd,
} static int
+input_recordable_changed( vlc_object_t *p_this, char const *psz_cmd,
+ vlc_value_t oldval, vlc_value_t newval,
+ void *p_userdata )
+{
+ VLC_UNUSED(p_this);
+ VLC_UNUSED(psz_cmd);
+ VLC_UNUSED(oldval);
+
+ libvlc_media_player_t *p_mi = p_userdata;
+ libvlc_event_t event;
+
+ event.type = libvlc_MediaPlayerRecordableChanged;
+ event.u.media_player_recordable_changed.new_recordable = newval.b_bool;
+
+ libvlc_event_send( p_mi->p_event_manager, &event );
+ return VLC_SUCCESS;
+}
+
+static int
input_event_changed( vlc_object_t * p_this, char const * psz_cmd,
vlc_value_t oldval, vlc_value_t newval,
void * p_userdata )
@@ -357,6 +386,23 @@ static int snapshot_was_taken(vlc_object_t *p_this, char const *psz_cmd,
return VLC_SUCCESS;
} +static int file_recording_finished(vlc_object_t *p_this, char const *psz_cmd,
+ vlc_value_t oldval, vlc_value_t newval, void *p_data )
+{
+ VLC_UNUSED(p_this);
+ VLC_UNUSED(psz_cmd);
+ VLC_UNUSED(oldval);
+
+ libvlc_media_player_t *p_mi = p_data;
+ libvlc_event_t event;
+
+ event.type = libvlc_MediaPlayerRecordingFinished;
+ event.u.media_player_recording_finished.psz_filename = newval.psz_string;
+
+ libvlc_event_send(p_mi->p_event_manager, &event);
+ return VLC_SUCCESS;
+}
+
static input_thread_t *find_input (vlc_object_t *obj)
{
libvlc_media_player_t *mp = (libvlc_media_player_t *)obj;
@@ -480,6 +526,10 @@ libvlc_media_player_new( libvlc_instance_t *instance )
var_Create (mp, "amem-set-volume", VLC_VAR_ADDRESS);
var_Create (mp, "amem-format", VLC_VAR_STRING | VLC_VAR_DOINHERIT);
var_Create (mp, "amem-rate", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT);
+
+ var_Create (mp, "recording-finished", VLC_VAR_STRING);
+ var_AddCallback (mp, "recording-finished", file_recording_finished, mp);
+
var_Create (mp, "amem-channels", VLC_VAR_INTEGER | VLC_VAR_DOINHERIT); mp->p_md = NULL;
@@ -515,6 +565,9 @@ libvlc_media_player_new( libvlc_instance_t *instance )
register_event(mp, TitleChanged);
register_event(mp, PausableChanged); + register_event(mp, RecordableChanged);
+ register_event(mp, RecordingFinished);
+
register_event(mp, Vout); /* Snapshot initialization */
@@ -566,6 +619,8 @@ static void libvlc_media_player_destroy( libvlc_media_player_t *p_mi )
var_DelCallback( p_mi->p_libvlc,
"snapshot-file", snapshot_was_taken, p_mi ); + var_DelCallback( p_mi, "recording-finished", file_recording_finished, p_mi );
+
/* No need for lock_input() because no other threads knows us anymore */
if( p_mi->input.p_thread )
release_input_thread(p_mi, true);
@@ -732,12 +787,14 @@ int libvlc_media_player_play( libvlc_media_player_t *p_mi ) var_AddCallback( p_input_thread, "can-seek", input_seekable_changed, p_mi );
var_AddCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
+ var_AddCallback( p_input_thread, "can-record", input_recordable_changed, p_mi );
var_AddCallback( p_input_thread, "intf-event", input_event_changed, p_mi ); if( input_Start( p_input_thread ) )
{
unlock_input(p_mi);
var_DelCallback( p_input_thread, "intf-event", input_event_changed, p_mi );
+ var_DelCallback( p_input_thread, "can-record", input_recordable_changed, p_mi );
var_DelCallback( p_input_thread, "can-pause", input_pausable_changed, p_mi );
var_DelCallback( p_input_thread, "can-seek", input_seekable_changed, p_mi );
vlc_object_release( p_input_thread );
@@ -1409,3 +1466,62 @@ void libvlc_media_player_next_frame( libvlc_media_player_t *p_mi )
vlc_object_release( p_input_thread );
}
}
+
+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;
+}
diff --git a/modules/stream_out/record.c b/modules/stream_out/record.c
index de6d32e..40ddfea 100644
--- a/modules/stream_out/record.c
+++ b/modules/stream_out/record.c
@@ -110,6 +110,8 @@ struct sout_stream_sys_t
int i_id;
sout_stream_id_t **id;
mtime_t i_dts_start;
+
+ char *psz_record_file;
}; static void OutputStart( sout_stream_t *p_stream );
@@ -158,6 +160,8 @@ static int Open( vlc_object_t *p_this )
p_sys->i_dts_start = 0;
TAB_INIT( p_sys->i_id, p_sys->id ); + p_sys->psz_record_file = NULL;
+
return VLC_SUCCESS;
} @@ -172,6 +176,19 @@ static void Close( vlc_object_t * p_this )
if( p_sys->p_out )
sout_StreamChainDelete( p_sys->p_out, p_sys->p_out ); + if( p_sys->psz_record_file ) {
+ for( vlc_object_t *p_mp = p_stream->p_parent; p_mp; p_mp = p_mp->p_parent )
+ {
+ if( var_Type( p_mp, "recording-finished" ) )
+ {
+ var_SetString( p_mp, "recording-finished", p_sys->psz_record_file );
+ break;
+ }
+ }
+
+ free( p_sys->psz_record_file );
+ }
+
TAB_CLEAN( p_sys->i_id, p_sys->id );
free( p_sys->psz_prefix );
free( p_sys );
@@ -352,7 +369,10 @@ static int OutputNew( sout_stream_t *p_stream,
} if( psz_file && psz_extension )
+ {
+ p_sys->psz_record_file = strdup( psz_file );
var_SetString( p_stream->p_libvlc, "record-file", psz_file );
+ } free( psz_file );
free( psz_output );
diff --git a/src/input/var.c b/src/input/var.c
index 9613fe2..04f33b9 100644
--- a/src/input/var.c
+++ b/src/input/var.c
@@ -210,6 +210,9 @@ void input_ControlVarInit ( input_thread_t *p_input )
text.psz_string = _("Subtitles Track");
var_Change( p_input, "spu-es", VLC_VAR_SETTEXT, &text, NULL ); + /* ES Out */
+ var_Create( p_input, "input-record-path", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
+
/* Special read only objects variables for intf */
var_Create( p_input, "bookmarks", VLC_VAR_STRING | VLC_VAR_DOINHERIT );

下载补丁,并把文件放到vlc文件夹中,运行命令patch -p1 < xxxx.patch。因为版本号不一样有些地方会失败。请打开补丁自己检查手动改动。

补丁中主要相关函数:

+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;
+}

库调用方法函数例如以下:

jboolean Java_org_videolan_libvlc_LibVLC_takeSnapShot(JNIEnv *env, jobject thiz,jint number, jstring path, jint width,jint height)
{
jboolean isCopy;
libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
/* Get C string */
const char* psz_path = (*env)->GetStringUTFChars(env, path, &isCopy); if (mp)
if(libvlc_video_take_snapshot(mp, (int)number,psz_path , (int)width,(int)height)==0)
return JNI_TRUE;
return JNI_FALSE; } jboolean Java_org_videolan_libvlc_LibVLC_videoRecordStart(JNIEnv *env, jobject thiz,jstring path)
{
jboolean isCopy;
libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
/* Get C string */
const char* psz_path = (*env)->GetStringUTFChars(env, path, &isCopy);
//const char* psz_filename=(*env)->GetStringUTFChars(env, filename, &isCopy);
if (mp)
if(libvlc_media_player_record_start(mp,psz_path)==0)
return JNI_TRUE;
return JNI_FALSE;
} jboolean Java_org_videolan_libvlc_LibVLC_videoRecordStop(JNIEnv *env, jobject thiz)
{
jboolean isCopy;
libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
/* Get C string */
if (mp)
if(libvlc_media_player_record_stop(mp)==0)
return JNI_TRUE;
return JNI_FALSE;
} jboolean Java_org_videolan_libvlc_LibVLC_videoIsRecording(JNIEnv *env, jobject thiz)
{
jboolean isCopy;
libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
if (mp)
if(libvlc_media_player_is_recording(mp))
return JNI_TRUE;
return JNI_FALSE;
}
jboolean Java_org_videolan_libvlc_LibVLC_videoIsRecordable(JNIEnv *env, jobject thiz)
{
jboolean isCopy;
libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
if (mp)
if(libvlc_media_player_is_recordable(mp))
return JNI_TRUE;
return JNI_FALSE;
} jint Java_org_videolan_libvlc_LibVLC_getState(JNIEnv *env, jobject thiz)
{
libvlc_media_player_t *mp = getMediaPlayer(env, thiz);
if (mp){
libvlc_state_t state=libvlc_media_player_get_state(mp);
return (jint)state;
}
else
return -1;
}
6、实现多路播放

使用process属性实现

总结

接触vlc for android 是帮助朋友完毕一个外单,即实现认证播放器的封装(即加入播放网络视频的认证)。传地址便可播放。

经測试vlc无法播放swf文件,为了弥补这已缺陷,准备加入swfdec到android平台以支持swf文件。

推荐博客站点:http://flavienlaurent.com/

博客站点:http://flavienlaurent.com/

Vlc for Android 全面阐述的更多相关文章

  1. 基于 VLC 的 Android 多媒体解决方案

    前段时间项目中需要在 Android 中播放视频.流媒体.查看监控,就研究了一下 Android 多媒体解决方案. 查找了一下,大致有如下几种: Android MediaPlayer FFmpeg ...

  2. Android : VLC for Android 环境搭建及编译

    一.下载VLC源码: git clone https://code.videolan.org/videolan/vlc-android.git 编译apk:   sh compile.sh -a ar ...

  3. VLC for Android 编译过程

    首先,给一个VLC的官网链接:VLC-AndroidCompile 上面有编译所需要安装的插件,环境变量的配置等等信息:虽然是英语,但也挺好理解,这里就不再详述:此文主要记录我在编译的过程中遇到的一些 ...

  4. VLC for Android编译

    编译环境是ubuntu 64bit 全程参考https://wiki.videolan.org/AndroidCompile/ 一:环境准备 1.安装系统 尽量使用最新的ubuntu系统 可以省去很多 ...

  5. Linux下编译VLC for Android源代码总结

    转:http://blog.chinaunix.net/uid-26611383-id-3678766.html 由于项目需要,需要一个在android平台能够支持RTSP协议的播放器,由于之前没有a ...

  6. VLC For Android Ubuntu14.04编译环境搭建

    VLC多媒体播放器(英语:VLC media player,最初为VideoLAN Client.是VideoLAN计划的开放源码多媒体播放器.)支持众多音频与视频解码器及文件格式,并支持DVD影音光 ...

  7. 【转】vlc android 代码编译

    转自:http://blog.csdn.net/asircao/article/details/7734201 系统:ubuntu12.04代码:git://git.videolan.org/vlc- ...

  8. Android高手速成--第一部分 个性化控件(View)

    第一部分 个性化控件(View) 主要介绍那些不错个性化的View,包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView.Pro ...

  9. Android 多媒体视频播放一( 多媒体理解与经验分享)

    前言 说到android的多媒体,一把辛酸一把泪,当初听说会多媒体的比较牛掰,公司也有需求,于是乎我也积极的加入研究android多媒体的行列,记得以前刚接触的时候,最开始还是比较头大的,主要是但是很 ...

随机推荐

  1. git的0基础使用

    1.申请一个git帐号 2.项目开发者将你增加这个项目 3.在终端随意一个目录克隆 该项目地址 git clone 该项目地址 4.进nginx配置 5.更新的时候进入项目目录 git pull

  2. hdu 1240 Asteroids! (三维bfs)

    Asteroids! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  3. 常用的50条linux 命令

    从今天起,咱开始正式学习python了,于是遍整理了50条linux的常用命令. 1 线上查询帮助命令 :man   遇到什么不会的命令可以 man +你想要查询的命令 (需要有网),因为是英文的所以 ...

  4. MySQL的一些语法总结

    初学MySQL,今天遇到了一个问题,然后汇总了一下MySQL的一些语法 1. date和datetime类型是不同的 date只记录日期(包括年月日),datetime记录日期和时间(包括年月日时分秒 ...

  5. ASP.NET中实现Ajax分页

    在页面中指定一个div容器来接收动态生成的分页数据: <div id="div_menu"> </div> 使用jQuery来请求并处理Json格式数据: ...

  6. oracle to_char()及to_date()函数使用

    to_char(x[,format]) :将x转换成字符串,可以使用format参数来格式化字符串输出. to_date(x[,format]) :将字符串x转换成日期,可以使用format匹配要转换 ...

  7. DTO学习系列之AutoMapper(四)

    本篇目录: Mapping Inheritance-映射继承 Queryable Extensions (LINQ)-扩展查询表达式 Configuration-配置 Conditional Mapp ...

  8. Effective C++ 第二版 5)new和delete形式 6) 析构函数里的delete

    内存管理 1)正确得到: 正确调用内存分配和释放程序; 2)有效使用: 写特定版本的内存分配和释放程序; C中用mallco分配的内存没有用free返回, 就会产生内存泄漏, C++中则是new和de ...

  9. jade的基本语法

    - for (var i=0;i<3;i++) li scnu-learn //这里的=,默认会转义内容 p= "Welcome scnu <strong>good< ...

  10. js 按元素向数组中最佳删除元素

    追加::: var a = [];// 创建数组 a.push(1); // 添加到最后 a.unshift(); // 添加到第一个位置 删除:::如果你没有使用第三方框架,有类似的扩展功能可以根据 ...