commiestream/stream.sh

58 lines
1.9 KiB
Bash
Executable File

#!/bin/bash
#commiestream - a simple script to stream mkv files to commie.club
#Copyright (C) 2019 oneseveneight
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <https://www.gnu.org/licenses/>.
video_file="$1"
vid_info=$(ffmpeg -i "$video_file" 2>&1)
audio_stream_num=""
subtitle_stream_num=""
audio_streams=$(echo "$vid_info" | grep "Stream .*: Audio: ")
subtitle_streams=$(echo "$vid_info" | grep "Stream .*: Subtitle: ")
ffmpeg_filter=""
[ -z "$1" ] && echo "No mkv file provided" && exit
[ -z "$2" ] && echo "No stream name provided" && exit
#Setting scale, this should be made an option at some point,
#but for now you can change "1080" to whatever you like
ffmpeg_filter="[vid]scale=-1:1080[vid2]"
echo "Which audio stream would you like to use?"
echo "$audio_streams"
echo -n "Input the stream number, eg. '0:3' : "
read -r audio_stream_num
echo "Which subtitles would you like to use? (Enter for none)"
echo "$subtitle_streams"
echo -n "Input the stream number, eg. '0:3' : "
read -r subtitle_stream_num
[ -n "$subtitle_stream_num" ] \
&& ffmpeg_filter="[0:v][$subtitle_stream_num]overlay[vid];$ffmpeg_filter"
echo "Filter set: '$ffmpeg_filter'"
echo "Press enter to continue"
read -r
ffmpeg \
-y \
-i "$1" \
-filter_complex "$ffmpeg_filter" \
-map "$audio_stream_num" \
-map "[vid2]" \
-f flv \
"./$2.flv" & sleep 3
ffmpeg -re -i "./$2.flv" -f flv -c copy "$2"