使用ffmpeg从m3u8地址下载mp4视频文件-linux脚本(bash)

1.使用说明

$ m3u8-download
usage: m3u8-download M3U8_ADDRESS {OUTPUT_FILENAME}

如图:
使用ffmpeg从m3u8地址下载mp4视频文件-linux脚本(bash)

2.脚本如下:
注意: 将第一行#!/usr/bin/env bash修改为你的bash的绝对路径.

#!/usr/bin/env bash

# Title: m3u8-download
# Description: This script will download video from m3u8 address
# Author: William Chanrico
# Date: 08-Nov-2017

echo " _____________________    "
echo "/ hello, who's there? \\  "
echo "\\ william said hi...  /  "
echo " ---------------------    "
echo "       \\   ,__,          "
echo "        \\  (..)____      "
echo "           (__)    )\     "
echo "              ||--|| *    "
echo -e "Download video from m3u8 address using ffmpeg\n"

if [[ -z $1 ]]; then
	echo -e "usage: m3u8-download M3U8_ADDRESS {OUTPUT_FILENAME}\n";
	exit;
fi

m3u8_filename=$(basename "$1")

if [[ -z $2 ]]; then
	output_filename="${m3u8_filename%.*}"
else
	output_filename="$2"
fi

echo -e "Downloading $(tput bold)$m3u8_filename$(tput sgr0) as $(tput bold)$output_filename.mp4$(tput sgr0)\n"

if [ -e "$output_filename.mp4" ]; then
	read -p "Overwrite $(tput bold)$output_filename.mp4$(tput sgr0)? [y/N] " input

	[[ ! $input =~ [yY] ]] && exit;
fi


counter=0

# Parsing ffmpeg stderr and stdout for cleaner terminal output
ffmpeg -y -hide_banner -loglevel info -i $1 -c copy -bsf:a aac_adtstoasc "$output_filename.mp4" 2>&1 \
	| while read -r OUTPUT || [ -n "$OUTPUT" ]; do

	if [ $counter = 4 ]; then
		while [[ $counter -gt 0 ]]; do
			tput cuu1;
			tput el;
			let counter=counter-1;
		done
	fi

	echo "${OUTPUT:0:$(tput cols)}"
	let counter=counter+1
done

echo -e "Done\n"

参考:m3u8_download

上一篇:【实验】爬取m3u8视频


下一篇:猫抓插件