linux视频拼接工具,linux中使用ffmpeg 无损剪切/拼接视频程序

# change this to what you need !!!

EXTRA_OPTIONS='-vcodec libx264 -crf 23 -preset medium -acodec aac -strict experimental -ac 2 -ar 44100 -ab 128k'

################################################################################

#

# NO NEED TO TOUCH ANYTHING AFTER THIS LINE!

#

################################################################################

# the version of the script

VERSION=1.3

# location of temp folder

TMP=/tmp

################################################################################

echo "MultiMedia Concat Script v$VERSION (mmcat) - A script to concatenate multiple multimedia files."

echo "Based on FFmpeg - www.ffmpeg.org"

echo "Don't forget to edit this script and change EXTRA_OPTIONS"

echo ""

################################################################################

# syntax check (has to have at least 3 params: infile1, infile2, outfile

################################################################################

if [ -z $3 ]; then

echo "Syntax: $0 ... "

exit 1

fi

################################################################################

# get all the command line parameters, except for the last one, which is output

################################################################################

# $first  - first parameter

# $last   - last parameter (output file)

# $inputs - all the inputs, except the first input, because 1st input is

#           handled separately

################################################################################

first=${@:1:1}

last=${@:$#:1}

len=$(($#-2))

inputs=${@:2:$len}

# remove all previous tmp fifos (if exist)

rm -f $TMP/mcs_*

################################################################################

# decode first input differently, because the video header does not have to be

# kept for each video input, only the header from the first video is needed

################################################################################

mkfifo $TMP/mcs_a1 $TMP/mcs_v1

ffmpeg -y -i $first -vn -f u16le -acodec pcm_s16le -ac 2 -ar 44100 $TMP/mcs_a1 2>/dev/null

ffmpeg -y -i $first -an -f yuv4mpegpipe -vcodec rawvideo $TMP/mcs_v1 2>/dev/null

# if you need to log the output of decoding processes (usually not necessary)

# then replace the "2>/dev/null" in 2 lines above with your log file names, like this:

#ffmpeg -y -i $first -vn -f u16le -acodec pcm_s16le -ac 2 -ar 44100 $TMP/mcs_a1 2>$TMP/log.a.1

#ffmpeg -y -i $first -an -f yuv4mpegpipe -vcodec rawvideo $TMP/mcs_v1 2>$TMP/log.v.1

################################################################################

# decode all the other inputs, remove first line of video (header) with tail

# $all_a and $all_v are lists of all a/v fifos, to be used by "cat" later on

################################################################################

all_a=$TMP/mcs_a1

all_v=$TMP/mcs_v1

i=2

for f in $inputs

do

mkfifo $TMP/mcs_a$i $TMP/mcs_v$i

ffmpeg -y -i $f -vn -f u16le -acodec pcm_s16le -ac 2 -ar 44100 $TMP/mcs_a$i 2>/dev/null

{ ffmpeg -y -i $f -an -f yuv4mpegpipe -vcodec rawvideo - 2>/dev/null $TMP/mcs_v$i ; } &

# if you need to log the output of decoding processes (usually not necessary)

# then replace the "2>/dev/null" in 2 lines above with your log file names, like this:

#ffmpeg -y -i $f -vn -f u16le -acodec pcm_s16le -ac 2 -ar 44100 $TMP/mcs_a$i 2>$TMP/log.a.$i

#{ ffmpeg -y -i $f -an -f yuv4mpegpipe -vcodec rawvideo - 2>$TMP/log.v.$i $TMP/mcs_v$i ; } &

all_a="$all_a $TMP/mcs_a$i"

all_v="$all_v $TMP/mcs_v$i"

let i++

done

################################################################################

# concatenate all raw audio/video inputs into one audio/video

################################################################################

mkfifo $TMP/mcs_a_all

mkfifo $TMP/mcs_v_all

cat $all_a > $TMP/mcs_a_all &

cat $all_v > $TMP/mcs_v_all &

################################################################################

# finally, encode the raw concatenated audio/video into something useful

################################################################################

ffmpeg -f u16le -acodec pcm_s16le -ac 2 -ar 44100 -i $TMP/mcs_a_all \

-f yuv4mpegpipe -vcodec rawvideo -i $TMP/mcs_v_all \

$EXTRA_OPTIONS \

$last

################################################################################

# remove all fifos

################################################################################

rm -f $TMP/mcs_*

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值