Skip to content

Instantly share code, notes, and snippets.

@gMan1990
Last active May 12, 2022 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gMan1990/b4585ead146c92fe74d59a84cb3942fd to your computer and use it in GitHub Desktop.
Save gMan1990/b4585ead146c92fe74d59a84cb3942fd to your computer and use it in GitHub Desktop.
ffmpeg ysl to a live
#!/bin/bash
cd "$(dirname "$0")" || exit 1
DIR=$(pwd)
OUTFILE="-f flv rtmp://js.live-send.acg.tv/live-js/?streamname=*&key=*"
while :; do
#./ffmpeg -re -i "Bailey No Ordinary Cat.mp4" -c copy $OUTFILE
cd "$DIR/YSL" || exit 1
for name1 in *; do
if [ -d "$DIR/YSL/$name1" ]; then
cd "$DIR/YSL/$name1" || exit 1
for name2 in *; do
if [ -f "$DIR/YSL/$name1/$name2" ]; then
if [ -z "$mp3Fir" ] && [ "mp3" = "${name2##*.}" ]; then
mp3Fir=$name2
if [ -n "$jpgFir" ]; then
break
fi
continue
fi
if [ -z "$jpgFir" ] && [ "jpg" = "${name2##*.}" ]; then
jpgFir=$name2
if [ -n "$mp3Fir" ]; then
break
fi
continue
fi
fi
done
if [ -n "$mp3Fir" ]; then
cd "$DIR" || exit 1
echo "$name1/$mp3Fir" > textfileYSL.txt
if [ -n "$jpgFir" ]; then
imgFile=YSL/$name1/$jpgFir
echo "$jpgFir" >> textfileYSL.txt
else
imgRandom=$(ls YSLImg | sort -R | head -n 1)
imgFile="YSLImg/$imgRandom" # 随机背景图存放文件夹
echo "$imgRandom(RANDOM)" >> textfileYSL.txt
fi
truncate -s "$(( $(stat -c "%s" textfileYSL.txt) - 1 ))" textfileYSL.txt
# 暂定超3分钟的不循环(估计值)
sloop=$((4 * 1024 * 1024 / $(stat -c "%s" "YSL/$name1/$mp3Fir")))
./ffmpeg -re -stream_loop "$((sloop > 10 ? 10 : sloop))" -i "YSL/$name1/$mp3Fir" -loop 1 -i "$imgFile" -c:v libx264 -c:a copy -shortest -vf "scale=iw: -2, drawtext=textfile=textfileYSL.txt: fontcolor=Black: x=w-tw: box=1: boxcolor=White" -threads 2 $OUTFILE
mp3Fir=
fi
jpgFir=
fi
done
done
@gMan1990
Copy link
Author

gMan1990 commented Nov 28, 2020

# split in files of given max duration, https://unix.stackexchange.com/questions/1670
ffmpeg -hide_banner -i input.mp4 -c copy -f segment -segment_time 0:00:50 -reset_timestamps 1 output-%d.mp4

# split in files of given max size, see GPAC-MP4Box

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment