「Linux」- 爬取网站视频、合并 TS 文件




How to Install and Use FFmpeg on CentOS 7 | Linuxize

curl -O http://example.com/[0-9].ts

### 安装 ffmpeg 命令
yum install epel-release
yum localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm
yum install ffmpeg ffmpeg-devel

cat $(/bin/ls -w 1 *.ts | sort --version-sort ) >> .tmp.ts
ffmpeg -i .tmp.ts -acodec copy -vcodec copy .tmp.ts.mp4

实现:下载、合并、解码 TS 文件

command line – Use ffmpeg copy codec to combine *.ts files into a single mp4 – Super User


for i in $(seq 0 1000)
    # 计算
    fragment_name=$(basename $request_fragment)
    echo "\n####### $2 $i ${request_fragment}\n"
    # 下载
    curl -O "${request_fragment}"
    # 检查
    file "${fragment_name}" | grep HTML && rm -rfv "${fragment_name}" && break
    # 休息
    # sleep 0.3

# 合并 
cat $(/bin/ls -w 1 *.ts | sort --version-sort ) >> .tmp.ts

# 转化
ffmpeg -i .tmp.ts -acodec copy -vcodec copy .tmp.ts.mp4

# 清理
rm -rf *.ts .tmp.ts

# 重命名
mv .tmp.ts.mp4 "$2".mp4

HTTP Live Streaming and M3U8

M3U8 VLC | How to Play M3U8 Stream and Download M3U8 to MP4 in VLC?

除了常见的媒体播放外,VLC 还支持用于各种服务器之间的媒体流传输的流协议 HTTP。 HTTP Live Streaming 播放列表的文件扩展名为 .m3u8,通常以直播 IPTV 链接的形式提供。

在 VLC 中,能够直接播放 .m3u8 链接

在 VLC 中,同时能够将 .m3u8 转为为 .mp4 文件:
Step 1. Open VLC and click on Media to choose “Open Network Stream…”.
Step 2. Input the .m3u8 playlist link to the box and then click on Convert from the drop-down menu of Play at the right bottom.
Step 3. Choose the output format as MP4 from the drop-down menu of Profile. Then, click on Browse to choose the destination folder and rename your file.
Step 4. After saving, just click on “Start” to converting the .m3u8 stream to MP4 with M3U8 player VLC.