自动切割视频文件脚本及改进

1.原始方式:

Lai-Mac:shelltest laijingli$ more autosegmenter
#!/bin/bash
### This is a shell to auto segmente,mkdir,rename

## get the will be segmented detail file name list
 ls -l ../macftp/ > ftp.txt

## get the file name list only include the name and Extension
 awk '{print $9}' ftp.txt > filelist.txt

## delelte the first null line删除第一行
 sed -i -e '1d' filelist.txt

## make new dir with the file name,and segmente the files in the filelist.txt,and put them into their own dir

##根据文件名生成目录,并将切好的文件放到和文件名对应的文件夹里,并且根据日期生成日志文件
 awk -F'.' '{system("mkdir  /Users/laijingli/video/"$1) system("mediafilesegmenter -b http://192.168.206.160/"$1 "  -f /Users/laijingli/video/"$1 " -l $(date +%Y%m%d%H)_seglog.log   -i index.m3u8 -B "$1"-" " /Users/laijingli/macftp/"$1".ts")}' filelist.txt

 ## when segmente finished,this script will auto upload the segmented files to web server
 scp -r /Users/laijingli/video/*  root@192.168.206.160:/data/iphonevideo/.

## when all the segmented files finished upload,delete the segmented files and the dir
 rm -fr /Users/laijingli/video/*

 

 

2.管道方式:

 Lai-Mac:shelltest laijingli$ more pipe
#!/bin/bash
### This is a shell to auto segmente,mkdir,rename

 ls -l ../macftp/ |awk '{print $9}'|awk -F'.' '{system("mkdir  /Users/laijingli/video/"$1) system("mediafilesegmenter -b http://192.168.206.160/"$1"  -f /Users/laijingli/video/"$1 " -l $(date +%Y%m%d%H)_seglog.log  -i index.m3u8 -B "$1"-" " /Users/laijingli/macftp/"$1".ts")}'

## when segmente finished,this script will auto upload the segmented files to web server
 scp -r /Users/laijingli/video/*  root@192.168.206.160:/data/iphonevideo/.

## when all the segmented files finished upload,delete the segmented files and the dir
 rm -fr /Users/laijingli/video/*

 

 

文件的内容:

Lai-Mac:shelltest laijingli$ more ftp.txt
total 128848
-rw-r--r--  1 laijingli  staff  39364944 Mar 16 14:58 3sframe.ts
-rw-r--r--  1 laijingli  staff  26600496 Mar 16 14:58 bmw.ts

 

Lai-Mac:shelltest laijingli$ more filelist.txt
3sframe.ts
bmw.ts

 

 

3.用以上方式切割的ts视频拖拽有问题,改用mediastreamsegmenter切割效果很好,切完后的文件大小和源ts视频大小相当

Lai-Mac:shelltest laijingli$ more autosegmenter
#!/bin/bash
### This is a shell to auto segmente,mkdir,rename

## get the will be segmented detail file name list
 ls -l ../macftp/ > ftp.txt

## get the file name list only include the name and Extension
 awk '{print $9}' ftp.txt > filelist.txt

## delelte the first null line
 sed -i -e '1d' filelist.txt

## make new dir with the file name,and segmente the files in the filelist.txt,and put them into their own dir
 awk -F'.' '{system("mkdir  /Users/laijingli/video/"$1) system("cat /Users/laijingli/macftp/"$1".ts |mediastreamsegmenter -b http://192.168.206.160/aim/ts/"$1 "  -f /Users/laijingli/video/"$1 " -l seglog_$(date +%Y%m%d).log -s 2000  -i index_video.m3u8 -B "$1"-")}' filelist.txt


awk -F'.' '{system("cp /Users/laijingli/shelltest/index.m3u8  /Users/laijingli/video/"$1) system("cat /Users/laijingli/macftp/"$1".ts |mediastreamsegmenter -b http://192.168.206.160/aim/ts/"$1 "  -f /Users/laijingli/video/"$1 " -l seglog_$(date +%Y%m%d).log -s 2000  -a  -i index_aac.m3u8 -B " "aac-"$1"-")}' filelist.txt

## when segmente finished,this script will auto upload the segmented files to web server
# scp -r /Users/laijingli/video/*  root@192.168.206.160:/data/iphonevideo/.

## when all the segmented files finished upload,delete the segmented files and the dir
# rm -fr /Users/laijingli/video/*

 

 

4.m3u8文件---》提供高低码流的自动切换的m3u8文件

Lai-Mac:gaoxiao2 laijingli$ more index.m3u8
#EXTM3U
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=350000
index_video.m3u8
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=64000, CODECS="mp4a.40.5"
index_aac.m3u8

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值