HLS/m3u8视频相关操作入门(ffmpeg)

mp4转ts
ffmpeg -i inputfile   -codec copy -bsf h264_mp4toannexb outputfile
ts转MP4
ffmpeg -i inputfile  -acodec copy -vcodec copy -bsf aac_adtstoasc  outputfile
hls(m3u8)下载并转mp4
ffmpeg -i https://xxx.xxx.xxx/xxx.m3u8 -c copy -absf aac_adtstoasc output.mp4
ts(多个ts文件)转mp4
ffmpeg -y -f concat -i mp4list.txt -c copy asddaas.mp4

其中,mp4list.txt文件内容格式如下:

mp4list.txt文件内容: 
file “1.ts” 
file “2.ts” 
file “3.ts”
下载hls中的多个ts片段
#获取所有ts片段的url
def getAllUrl(url):
    url_list = []
    html = requests.get(url)
    file_url = html.text.split('\n')
    for url in file_url:
        if len(url) > 0 and url[0] != '#':
            url_list.append(url)
    return url_list
 
url = 'https://xxx.xxx.xxx/xxx.m3u8'
file_path = './' 
file_url = getAllUrl(url):  
base_url = '/'.join(url.split('/')[0:-1])
for u in file_url:
        url = base_url + '/' + u
        print('url', url)
        if os.path.exists(file_path + '/' + u):
            continue

        with open(file_path + '/' + u, 'wb') as f:
            f.write(requests.get(url).content)
        f.close()
多个ts片段合并

[shell]

for i in `ls *.ts`; do cat $i >> output.ts; done

[python]

import subprocess
read_file = ["1.ts","2.ts","3.ts"]
for i in read_file:
    str_c = 'cat ' +i+  ' >> ' + outputfile.strip()
    print(str_c)
    subprocess.getstatusoutput(str_c)

参考文献:
https://blog.csdn.net/weixin_34296641/article/details/91925392

hls视频打开方式
https://blog.csdn.net/saddyyun/article/details/85157709

<<<未完待续

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值