ffmpeg下载m3u8流媒体

安装

编译好的windows可用版本的下载地址(官网中可以连接到这个网站,和官方网站保持同步): http://ffmpeg.zeranoe.com/builds/

该版本为FFMPEG的Static,Static里面只有3个应用程序:ffmpeg.exe,ffplay.exe,ffprobe.exe,每个exe的体积都很大,相关的Dll已经被编译到exe里面去了。

使用

ffmpeg.exe

ffmpeg是用于转码的应用程序

命令行进入bin目录,输入以下命令即可将m3u8下载为指定格式的文件

C:\01-python\59-ffmpeg\ffmpeg\bin\ffmpeg -i http://vodcdn.yst.vodjk.com/201909191433/2afc693f2edda43e677598144b12a31e/company/1/2019/8/1/18852t5bfe/sd/a84ccae0440549398f8080f6d336075b.m3u8 .\video\1416.mp4


# C:\01-python\59-ffmpeg\ffmpeg\bin\ffmpeg    ffmpeg.exe路径
# http://vodcdn.yst.vodjk.com/201909191433/2afc693f2edda43e677598144b12a31e/company/1/2019/8/1/18852t5bfe/sd/a84ccae0440549398f8080f6d336075b.m3u8    m3u8视频url
# .\video\1416.mp4  存放路径是当前文件夹下的video   名称为1416.mp4

ffplay.exe

ffplay是用于播放的应用程序。

ffplay .\3029.mp4

ffprobe.exe

ffprobe是用于查看文件格式的应用程序。

更多高级用法的文档: http://blog.csdn.net/leixiaohua1020/article/details/12751349

 

示例

import json, pymysql, requests, os, time, ffmpeg, asyncio, aiohttp, aiomysql, hashlib


class yibao(object):
    def __init__(self):
        self.db = pymysql.connect(host='localhost', port=3306, database='cfda', user='root', password='root',
                                  charset='utf8')
        self.cursor = self.db.cursor()
        self.headers = {
            "user-agent": "com.xinma.yst/YST/5.5.3",
            "referer": "app.yst.vodjk.com",
            'Content-Type': 'application/x-www-form-urlencoded'
        }
        self.url = 'https://api.yst.vodjk.com/v1/course?keyid=1004&time=1568774753613&userid=294066&app_version=5.5.3&appid=100004&uutp=android&uuid=ffffffff-dfe4-a66d-24b0-59af559c6620&usertoken=9390faed9a5a0db2818c2233e6c2ffc9&ip=172.17.100.15'
        self.parse_page()

    def parse_page(self):
        self.cursor.execute('SELECT id, parent_id, title, url FROM yaoshitong_class_3 where id > 1386 and id < 1401')
        for data in self.cursor.fetchall():
            data_list = {
                "keyid": '1004',
                "time": '1568774753613',
                "userid": '294066',
                "app_version": '5.5.3',
                "appid": '100004',
                "uutp": 'android',
                "uuid": 'ffffffff-dfe4-a66d-24b0-59af559c6620',
                "usertoken": '9390faed9a5a0db2818c2233e6c2ffc9',
                "ip": '172.17.100.15',
                # ----------------------
                "pagesize": '20',
                # "modules": 'info:5,comments:1',
                "modules": 'info%3A5%2Ccomments%3A1',
                # "courseid": '376',
                "courseid": str(data[1]),
                "page": '1',
            }
            dict2 = sorted(data_list)
            a = ''
            for key in dict2:
                if key != 'time':
                    a += key + '=' + data_list[key] + '&'
            m = hashlib.md5()
            m.update(a[:-1].encode('utf-8'))
            md1 = m.hexdigest()

            data2 = md1 + 'e2fae2b4e226e878e7f81e4e7e39c9da' + data_list['time']
            m = hashlib.md5()
            m.update(data2.encode('utf-8'))
            md2 = m.hexdigest()
            re_data = {
                "sign": md2,
                "pagesize": "20",
                "courseid": str(data[1]),
                "modules": "info:5,comments:1",
                "page": "1",
            }
            html = requests.post(url=self.url, headers=self.headers, data=re_data).content.decode('utf-8')
            print(html)
            data_json = json.loads(html)
            u3m8_url = data_json['data']['info']['catalog'][0]['lesson'][0]['video']['url']
            try:
                name = str(data[0]) + '-' + data[1]
                print("C:\\01-python\\59-ffmpeg\\ffmpeg\\bin\\ffmpeg -i {} .\\video\\{}.mp4".format(u3m8_url, data[0]))
                os.system("C:\\01-python\\59-ffmpeg\\ffmpeg\\bin\\ffmpeg -i {} .\\video\\{}.mp4".format(u3m8_url, data[0]))
                print('*' * 100)
            except:
                pass
            time.sleep(1)

        # self.db.commit()


if __name__ == '__main__':
    yibao()

  

 

转载于:https://www.cnblogs.com/yoyo1216/p/11549174.html

你可能感兴趣的:(ffmpeg下载m3u8流媒体)