ffmpeg 영상 편집 스크립트


이 스크립트는 영상을 시간별로 자른뒤 병합하고 인코딩한다.

!/bin/bash

#파일 선택 받기
txtname=”vlist”date +%s“.txt”
IFS=$’\n’
for FILE in ls $1
do
let I=I+1
echo “$I) ‘$FILE’”
done

echo -n “파일을 선택 하십시요) “
read FILE_NUM

FILE_NAME=ls $1 | sed -n "$FILE_NUM"p

echo $FILE_NAME

#FILE_NAME=”${FILE_NAME// /}” #파일명 확장자 분리 fileName=”${FILE_NAME%.}” fileName=”${fileName// /}”
fileExtension=”${FILE_NAME##
.}”

#시간 입력 받기
TIME_LIST=()
while :
do
if ((${#TIME_LIST[@]} >0))
then
read -n 1 -p “시간을 추가 하시겠습니까?[y/n]:”
echo
if [[ $REPLY =~ ^[Nn]$ ]]; then
break
fi

fi

echo -e “시작 시간을 를 입력하세요: c “
read sp
TIME_LIST+=($sp)
echo -e “종료 시간을 를 입력하세요: c “
read ep
TIME_LIST+=($ep)

done

echo “###########################################################################################”
echo “##############################영상 자르기를 시작합니다..#########################################”
echo “###########################################################################################”

filecount=1
FILE_LIST=()
for ((i=0;i<${#TIME_LIST[@]};i+=2))
do
SEC1=date +%s -d ${TIME_LIST[$i+1]}
SEC2=date +%s -d ${TIME_LIST[$i]}

timediff=expr ${SEC1} - ${SEC2}
echo “${timediff}”
echo “시작시간: ${TIME_LIST[$i]}”
echo “종료시간: ${TIME_LIST[$i+1]}”
#영상 시간에 따라 분리하기
ffmpeg -i $FILE_NAME -ss ${TIME_LIST[$i]} -t ${timediff} -vcodec copy -acodec copy $fileName”“$filecount”.”$fileExtension FILE_LIST+=($fileName”“$filecount”.”$fileExtension)

files=\'$fileName"_"$filecount"."$fileExtension\'

#파일 인덱스 증가
((filecount++))

done
echo “###########################################################################################”
echo “##############################파일 찹치기를 시작합니다.#########################################”
echo “###########################################################################################”

for ((i=0;i<${#FILE_LIST[@]};i++)) do echo file ${FILE_LIST[$i]}>> $txtname
done

#for %%i in ${FILE_LIST[@]} do echo file ‘%%i’>> mylist.txt
#printf “%s\n” ${FILE_LIST[@]} > vidlist.txt
ffmpeg -f concat -safe 0 -i $txtname -c copy $fileName”_merge.”$fileExtension

#생성한 텍스트 파일 삭제
rm $txtname
#생성한 파트영상 삭제
for ((i=0;i<${#FILE_LIST[@]};i++))
do
rm ${FILE_LIST[$i]}
done

echo “###########################################################################################”
echo “##############################인코딩을 시작합니다.#########################################”
echo “###########################################################################################”

ffmpeg -i $fileName”_merge.”$fileExtension -c:v libx265 -crf 28 -c:a aac -b:a 128k $fileName”_kindtito.”$fileExtension
ffmpeg -i $fileName”_merge.”$fileExtension -max_muxing_queue_size 9999 -threads 16 -c:v libx264 -crf 23 -c:a copy $fileName”_kindtito.”$fileExtension
rm $fileName”_merge.”$fileExtension


답글 남기기

이메일 주소는 공개되지 않습니다.