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

1.使用说明

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

如图:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值