有没有办法做到这一点?
我想以全屏模式运行 VLC 并自动加载播放列表。播放列表可以是一个文件夹,比如/home/user/videos
白天,我想使用此播放列表将一些电影上传到运行 VLC 的计算机。我将一部电影上传到/home/user/videos
现在我需要重新加载/重新启动 VLC 以使更改在播放列表中生效。
有没有办法在不重启 VLC 的情况下刷新播放列表?也许让它每隔 X 分钟检查一次新文件之类的?
答案1
我首先研究了编写 VLC LUA 扩展的可能性,发现这似乎非常有可能。
我查看了这个扩展:http://addons.videolan.org/CONTENT/content-files/140699-addsimilar.lua
它具有我们需要的所有功能。因此对其进行大量修改是可以正常工作的,但对于这个项目来说,这似乎太费力了。
于是我又在 Google 上搜索了一下,偶然发现了这个网站: http://www.cenolan.com/2013/03/looping-video-playlist-omxplayer-raspberry-pi/
事实证明,这个 bash 脚本可以轻松修改为使用 VLC 或 cvlc。
所以我这样做了,结果如下:
#!/bin/sh
# get rid of the cursor so we don't see it when videos are running
setterm -cursor off
#Time
TIME=$(date +%H)
# set here the path to the directory containing your videos
VIDEOPATH="/home/user/videos"
# you can normally leave this alone
SERVICE="cvlc"
# now for our infinite loop!
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
sleep 0;
else
for entry in $VIDEOPATH/* # You could add .mkv to the end of this or any other file extention, to only play specific extentions
do
cvlc --play-and-exit --no-video-title -f "$entry" > /dev/null
done
fi
done
我需要此功能的原因是为了像项目这样的信息亭视频屏幕,其中视频可以随时上传和删除。
此解决方案的一个缺点是 VLC 仍然需要在播放每个视频后打开和关闭,这是使用此脚本实现的。因此,运行脚本的 PC 需要有一个空白桌面(已删除 GUI)和黑色背景。这样,您只会在每个视频片段之间看到大约 0.5 - 1 秒的黑屏。
该脚本仍在进行中,因为我将向其中添加更多功能,因此如果您发现它有用并且想要我的最终脚本,请发表评论,我会更新答案。
如果您有更好的解决方案,甚至是 LUA 解决方案,请发布它 - 我会接受答案 - 但目前这对我的项目有用。
干杯
应 TheFrost 要求更新
这是我的最终脚本,我将在下面进行简要描述: 玩转
#!/bin/bash
xsetroot
# Set the path to the directory containing your videos
VIDEOPATH="/home/pi/vids/"
# Time & day
set_TIME() {
TIME=$(date +%H)
DAY=$(date +%u)
}
set_TIME
# Normally leave this alone
SERVICE="omxplayer"
# Get rid of the cursor so we don't see it when videos are running
setterm -cursor off
# # #
#
# Play files with omxplayer and close the player when the video is finished
#
# # #
play_files () {
for entry in $1*
do
set_TIME
# Dont try to play dirs
if [ ! -d "$entry" ]; then
omxplayer -p -o hdmi "$entry" > /dev/null
fi
done
}
# # #
#
# Check if its time to play files
# $1 = hour now, $2 = begin hour, $3 = End hour, $4 = folder with video files
#
# # #
check_if_time_to_play() {
# Make sure the arguments are interpreted as *decimal* integers
# by evaluating them in an arithmetic context (-i) with prefix '10#',
# indicating number base 10.
# (A leading '0' would cause intepretation as *octal*.)
local -i hourNow=10#$1 startHour=10#$2 endHour=10#$3 play
local dir=$4
# Make sure the folder is not empty.
if ! find "$dir" -mindepth 1 -print -quit | grep -q .; then
return # It's empty! Don't play the non-existing clips.
fi
# Determine if current hour is between begin and end time.
play=0
if (( startHour < endHour )); then
if (( hourNow >= startHour && hourNow < endHour )); then
play=1
fi
else # startHour > endHour: overnight hours
if (( hourNow >= startHour || hourNow < endHour )); then
play=1
fi
fi
if (( play )); then
# Play the clips
play_files "$dir"
else
: # Current hour is not in range, don't play the clips.
fi
}
# Now for our infinite loop!
while true; do
if ps ax | grep -v grep | grep $SERVICE > /dev/null
then
sleep 0;
else
# # #
#
# First we check the Video folder if it has any subfolders.
# If it doesn't, play the files in the folder.
# If subfolders exists, and follow the naming standard do as the commanded.
#
# A folder named: 18-22 means start at 18 o clock, end at 22, everyday.
# A folder named: 18-22-07 means start at 18 o clock, end at 22, only during Sunday.
#
# 01 = Monday, 02 = Tuesday and so on, thats why 07 is Sunday.
#
# Files in subfolders will be playd according to the folders name.
#
# If for some reason there is an empty folder or it doesn't follow the standard above, we ignore it.
#
# # #
cd $VIDEOPATH
shopt -s nullglob
FOLDERS=(*/)
shopt -u nullglob # Turn off nullglob to make sure it doesn't interfere with anything later
# Check if there is no subfolders
if (( !${#FOLDERS[@]} )); then
play_files "$VIDEOPATH"
else
play_files "$VIDEOPATH"
for entry in "${FOLDERS[@]}";
do
TEMPVAR=${entry::-1} # Remove trailing /
IFS='-' read -a PLAYTIME <<< "$TEMPVAR" # PLAYTIME array [0] = Begin time, [1] = End time, [2] = Day
if (( ${#PLAYTIME[@]} )); then
#check if day is not set
if (( !${#PLAYTIME[2]} )); then
check_if_time_to_play $TIME "${PLAYTIME[0]}" "${PLAYTIME[1]}" "$VIDEOPATH/$entry"
else # Day is set
if [ $DAY -eq "${PLAYTIME[2]}" ]; then
check_if_time_to_play $TIME "${PLAYTIME[0]}" "${PLAYTIME[1]}" "$VIDEOPATH/$entry"
else
continue # Not today..
fi
fi
fi
done;
fi
fi
done
因此,正如评论中所述,我切换到了 OMXplayer - 但 VLC 也可以正常工作。只需在 SERVICE= 和函数中对其进行更改即可play_files()
。
因此,脚本将播放位于中的文件VIDEOPATH
,如果此路径有子文件夹,它将检查文件夹是否使用为此发明的命名约定。阅读脚本中的注释 - 基本上,您可以创建一个名为 StartTime-EndTime 的文件夹(即,将文件夹命名为22-23
),并且此文件夹中的剪辑将仅在晚上 10 点到晚上 11 点播放。如果您只想在一周中的特定一天播放剪辑,请创建一个名为 StartTime-EndTime-DayOfWeek 的文件夹(即,名为 的文件夹22-23-01
),此文件夹中的剪辑将仅在星期一晚上 10 点到晚上 11 点播放。如果它在 02 结束,那么它将在星期二、03 星期三等等。
我认为其余部分已在脚本的评论中解释,否则如果您有任何问题,请随时提问。也请分享任何改进 :)
我让这个脚本在不同位置的 50 多个不同的 Raspberry PI 上运行。它们全天候运行,运行非常稳定。我已从 PI 中删除所有可见的 GUI。它们都运行一个 cronjob,每 15 分钟与主服务器进行 rsync,我的同步脚本如下所示: 同步脚本
#!/bin/sh
#MountFTP
echo "RASPERRYPIROOTPASSWORD" | sudo umount /home/pi/ftp/
sleep 5
echo "RASPERRYPIROOTPASSWORD" | sudo curlftpfs www-data:[email protected] /home/pi/ftp -o allow_other
#Sync Videos
rsync -avztr --delete /home/pi/ftp/data/files/CURRENTRASPBERRYPI/ /home/pi/vids/
#sync scripts (so we can remotely update the scripts)
rsync -avztr /home/pi/ftp/data/files/Scripts/syncscript/CURRENTRASPBERRYPI/sync.sh /home/pi #is this script
rsync -avztr /home/pi/ftp/data/files/Scripts/play.sh /home/pi #is they play videos script
chmod +x *.sh
#Write to log
IP="$(curl -s http://whatismyip.akamai.com/)"
DATE="$(date +%d-%m-%Y-%X)"
echo $DATE " - " $IP " - CURRENTRASPBERRYPI " >> /home/pi/CURRENTRASPBERRYPI.txt
cp /home/pi/CURRENTRASPBERRYPI.txt /home/pi/ftp/logs/
我会为运行该脚本的每台计算机手动更改上述脚本中的大写字母。
我在服务器上使用了一款基于 Web 的文件管理器,名为 AJAX explorer,现在称为 Pydio。这样,最终用户就可以轻松地将视频上传到他们想要的每台计算机/位置 (/ftp/data/files/CURRENTRASPBERRYPI/)。