1

I know how to launch a video in VLC from the shell under Android as follows:

am start -n org.videolan.vlc/org.videolan.vlc.gui.video.VideoPlayerActivity -a android.intent.action.VIEW -d file:////storage/emulated/0/VideoToPlay.mp4

However, I also have a SubStation Alpha subtitles file which goes along with this video, which in this example could be called subtitles.ssa.

Is there any way using the "am start" command (or any other Android shell command, for that matter) where I can tell VLC to launch the VideoToPlay.mp4 video also with the subtitles.ssa subtitles?

This is do-able in Linux by adding a --sub-file /path/to/subtitles.ssa argument to the shell command line which would launch a video via VLC, and I'm wondering if there's some way to do this in the shell in Android, as well.

Thank you in advance.

1

1 Answer 1

1

I thought of a way to get an Android script to accomplish this:

(1) create an empty "work" directory;

(2) copy the VideoToPlay.mp4 file into that work directory;

(3) copy the *.ssa file into the same directory under the name "VideoToPlay.ssa";

(4) run the "am start" command I posted above, pointing to the VideoToPlay.mp4

This works because as long as there is an .ssa file in the same directory as the video and with the same base name as the video, VLC will apply the subtitles in that .ssa file to the specified video.

Here is my script to accomplish this:

#!/system/bin/sh                                                                                                                                      

workdir=/sdcard/vidwork
amstart=( /system/bin/am start -n org.videolan.vlc/org.videolan.vlc.gui.video.VideoPlayerActivity -a android.intent.action.VIEW -d )
amstop=( /system/bin/am force-stop org.videolan.vlc )

# If VLC is running, kill it.
"${amstop[@]}" 1>/dev/null 2>&1

[[ $# -lt 1 ]] && {
  echo "                                                                                                                                              
usage: ${0##*/} video-to-play [ subtitle-file ]                                                                                                       
"
  exit 1
}

videopath="${1}"
shift

[[ -r "${videopath}" ]] ||  {
  echo "                                                                                                                                              
Video doesn't exist: ${videopath}                                                                                                                     
"
  exit 1
}

videoname="${videopath##*/}"

case "${videoname}" in
*.mp4|*.mkv)
  ;;
*) 
  echo "                                                                                                                                              
Video must be mp4 or mkv                                                                                                                              
"
  exit 1
  ;;
esac
  
videobasename="$( echo "${videoname}" | /system/bin/sed -e 's/\.mp4$//i' -e 's/\.mkv$//i' )"

/system/bin/rm -rf "${workdir}" 1>/dev/null 2>&1
/system/bin/mkdir -p "${workdir}" 1>/dev/null 2>&1
    
[[ $# -gt 0 ]] && {
  subpath="${1}"
  shift
  [[ -r ${subpath} ]] || {
    echo "                                                                                                                                            
Subtitle file doesn't exist: ${subpath}                                                                                                               
"
    exit 1
  }
  /bin/cp "${subpath}" "${workdir}/${videobasename}.ssa"
}

/bin/cp "${videopath}" "${workdir}"

cmd=( "${amstart[@]}" "file:///${workdir}/${videoname}" )

{
  "${cmd[@]}"
} 1>/dev/null 2>&1

exit 0

PS: This script needs to run as root in order for the /system/bin/am force-stop ... command to function properly.

Therefore, assuming this script is stored as /sdcard/runvid.sh, it needs to be run on a rooted device as follows ...

/system/bin/su -c /sdcard/runvid.sh path-to-video-file [ path-to-subtitle-file ]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .