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

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/*  [email protected]:/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/*  [email protected]:/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/*  [email protected]:/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

 

 

 

 

 

 

你可能感兴趣的:(Date,upload,脚本,File,delete,System)