From 2951cc596bd499a5646a501aa18218aee8608fc6 Mon Sep 17 00:00:00 2001 From: Alexei Bezborodov Date: Mon, 8 Jan 2024 21:47:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D1=80=D1=83=D0=B3=D0=BE=D0=B9=20=D1=80?= =?UTF-8?q?=D0=B5=D0=B6=D0=B8=D0=BC=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=8B?= =?UTF-8?q?=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D0=B0=20=D0=B4=D0=B5=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D1=82=D1=80=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=86=D1=8B=20=D0=BF=D0=BE=D0=BF=D0=BE=D0=BB=D0=B0=D0=BC.=20?= =?UTF-8?q?=D0=92=D1=81=D1=91=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20?= =?UTF-8?q?=D0=B4=D0=B5=D0=BB=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D1=87=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=B7=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D1=8B?= =?UTF-8?q?=20ffmpeg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pdf2video | 81 +++++++-------------------------------------------------------- 1 file changed, 8 insertions(+), 73 deletions(-) diff --git a/pdf2video b/pdf2video index 36ee335..b2abc1a 100755 --- a/pdf2video +++ b/pdf2video @@ -137,6 +137,9 @@ function MakeVideo { if [ $split = 'time' ]; then float_image="-i \"${resized_page_image_file}\"" video_filter="-filter_complex \"[1:v]scale=${video_width}*2:${video_height}*2[scale1]; [0:v][scale1]overlay=enable='between=(t,0,${play_time})':x=-w/4:y=-t/(${play_time})*h/2[out]\" -map \"[out]\" -map \"2:a\" -t '${play_time}'" + elif [ $split = 'half' ]; then + float_image="-i \"${resized_page_image_file}\"" + video_filter="-filter_complex \"[1:v]scale=${video_width}*2 - ${video_width}/20:${video_height}*2 - ${video_height}/20[scale1]; [1:v]scale=${video_width}*2 - ${video_width}/20:${video_height}*2 - ${video_height}/20[scale2]; [0:v][scale1]overlay=enable='between=(t,0,${play_time}/2)':x=-w/(4*1.026):y=0[out]; [out][scale2]overlay=enable='between=(t,${play_time}/2,${play_time})':x=-w/(4*1.026):y=-h/(2*1.026)[out]\" -map \"[out]\" -map \"2:a\" -t '${play_time}'" fi cmd="ffmpeg -y ${ffmpeg_pre_options} -i \"${resized_page_image_file}\" ${float_image} -i \"${page_mp3_file}\" ${video_filter} ${ffmpeg_options} ${time_opt} \"${page_mp4_file}\"" @@ -152,28 +155,6 @@ function MakeVideo { rm "${resized_page_image_file}" } -function SplitText { - local out_array_name=$1[@] - local source_text=$2 - local split_size=$3 - out_array=("${!out_array_name}") - - local space_char=" " - local cur_text="" - for ((i=1;i<=${#source_text};i++)); do - local cur_char=${source_text:$i-1:1} - cur_text="${cur_text}${cur_char}" - if [ "$cur_char" = "$space_char" ] && [ ${#cur_text} -ge $split_size ] || [ $i = ${#source_text} ]; then - SAVE_IFS=$IFS - IFS="" - split_source_text_array+=(${cur_text}) - IFS=$SAVE_IFS - - cur_text="" - fi - done -} - [ $verbose ] && echo "Всего страниц $page_count" for ((page=1;page<=${page_count};page++)); do @@ -206,61 +187,15 @@ for ((page=1;page<=${page_count};page++)); do source_text="$(cat "${page_text_file}")" - if [ "$split" = "half" ] && [ ${#source_text} -ge $minimum_text_on_page ]; then + page_mp3_file=$(mktemp -t "pdf2video_page_mp3_file_XXXXXXXXXXX.mp3") - split_size=$(( ${#source_text} / 2 + 2)) # Половина с небольшим запасом - split_source_text_array=() + Text2mp3 "$page_text_file" "$page_mp3_file" - SplitText split_source_text_array "$source_text" $split_size - - page_mp3_file_half1=$(mktemp -t "pdf2video_page_mp3_file_half1_XXXXXXXXXXX.mp3" -) - page_mp3_file_half2=$(mktemp -t "pdf2video_page_mp3_file_half2_XXXXXXXXXXX.mp3" -) - - Text2mp3 <( echo "${split_source_text_array[0]}" ) "$page_mp3_file_half1" - Text2mp3 <( echo "${split_source_text_array[1]}" ) "$page_mp3_file_half2" - - width=$(identify -format "%w" "$page_image_file")> /dev/null - height=$(identify -format "%h" "$page_image_file")> /dev/null - - height_half=$(( $height / 2 + $height / 20 )) - - page_image_file_half1=$(mktemp -t "pdf2video_page_image_file_half1_XXXXXXXXXXX.png" -) - page_image_file_half2=$(mktemp -t "pdf2video_page_image_file_half2_XXXXXXXXXXX.png" -) + page_mp4_file="${input_file}_${page}.mp4" - # convert format (widthxheight+left+top / wxh+l+t) - convert "$page_image_file" -crop ${width}x${height_half}+0+0 "${page_image_file_half1}" - convert "$page_image_file" -crop "${width}x${height_half}+0+$(( $height - $height_half ))" "${page_image_file_half2}" - - page_mp4_file_half1="${input_file}_${page}_half1.mp4" - page_mp4_file_half2="${input_file}_${page}_half2.mp4" - - MakeVideo "${page_image_file_half1}" "$page_mp3_file_half1" "$page_mp4_file_half1" "$split" - - MakeVideo "${page_image_file_half2}" "$page_mp3_file_half2" "$page_mp4_file_half2" "$split" - - rm "$page_image_file_half1" - rm "$page_image_file_half2" - - rm "$page_mp3_file_half1" - rm "$page_mp3_file_half2" - - else - page_mp3_file=$(mktemp -t "pdf2video_page_mp3_file_XXXXXXXXXXX.mp3") - - Text2mp3 "$page_text_file" "$page_mp3_file" - - page_mp4_file="${input_file}_${page}.mp4" - - MakeVideo "$page_image_file" "$page_mp3_file" "$page_mp4_file" "$split" - - rm "$page_mp3_file" - - fi + MakeVideo "$page_image_file" "$page_mp3_file" "$page_mp4_file" "$split" + rm "$page_mp3_file" rm "$page_image_file" rm "$page_text_file"