diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8c09a83 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +test/test_out diff --git a/pdf2video b/pdf2video index e04c013..2d4454f 100755 --- a/pdf2video +++ b/pdf2video @@ -17,7 +17,7 @@ common_params=( ) sound_params=( - "i|input|Входной текстовый файл.|:||" + "i|input|Входной файл.|:||" "e|emotion|Эмоциональный настрой говорящего. Может принимать значения 'neutral', 'good', 'evil'. По умолчанию '!DEFAULT!'.|:|'neutral'|" "s|speaker|Голос говорящего. Может принимать значения 'oksana','jane','omazh','zahar','ermil','silaerkan','erkanyavas','alyss', 'nick'. По умолчанию '!DEFAULT!'.|:|'erkanyavas'|" "S|speed|Скорость озвучки. По умолчанию '!DEFAULT!'.|:|'1.0'|" @@ -49,8 +49,7 @@ all_params=("${common_params[@]}" "${sound_params[@]}" "${video_params[@]}") function GetExec { local exec_file_name="$1" - exec="$exec_file_name" - [ ! -f "$exec" ] && exec="./$exec_file_name" + exec="./$exec_file_name" [ ! -f "$exec" ] && exec="~/$exec_file_name" echo "$exec" @@ -77,7 +76,7 @@ $(ProcessParams video_params Params2Help) # Расширенный вывод pdf2video -i in.pdf -o out.mp4 -V # Первые 10 страниц -pdf2video -i in.pdf -o out.mp4 -r {1..10} +pdf2video -i in.pdf -o out.mp4 -r '{1..10}' # Хронометраж pdf2video -i in.pdf -o out.mp4 -T timing.txt @@ -152,6 +151,7 @@ function MakeVideo { [ $verbose ] && echo "ffmpeg $?" local play_time=$(PlayTime "${page_mp3_file}") + play_time_plus1=$(( $play_time + 1 )) local time_opt="-c:a copy" if [ ${minimum_time_on_page} -ge $(( ${play_time} )) ]; then local add_time="$minimum_time_on_page" # $(( 5 - ${play_time} )) @@ -164,11 +164,11 @@ function MakeVideo { if [ $split = 'time' ]; then cur_water_mark="; [out]${water_mark}[out]" 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]${cur_water_mark}\" -map \"[out]\" -map \"2:a\" -t '${play_time}'" + 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]${cur_water_mark}\" -map \"[out]\" -map \"2:a\" -t '${play_time_plus1}'" elif [ $split = 'half' ]; then cur_water_mark="; [out]${water_mark}[out]" 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]${cur_water_mark}\" -map \"[out]\" -map \"2:a\" -t '${play_time}'" + 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]${cur_water_mark}\" -map \"[out]\" -map \"2:a\" -t '${play_time_plus1}'" else video_filter="-filter_complex \"${water_mark}\" -map \"1:a\"" fi diff --git a/test/run_test b/test/run_test new file mode 100755 index 0000000..865829d --- /dev/null +++ b/test/run_test @@ -0,0 +1,31 @@ +#!/bin/bash +# Общественное достояние, 2024, Алексей Безбородов (Alexei Bezborodov) + +in_file_name='test/Наставление А.В.Суворова.pdf' +out_file_name_prefix='test/test_out/Наставление А.В.Суворова' +start_text='Файл для теста.' + +mkdir 'test_out' + +cd .. + +function MakeVideoWithSplit { + local split=$1 + local speaker=$2 + ./pdf2video -i "${in_file_name}" -t "${split}" -o "${out_file_name_prefix}_${speaker}_${split}.mp4" --timing_file "${out_file_name_prefix}_${speaker}_${split}.txt" -s "${speaker}" -V +} + +MakeVideoWithSplit 'time' 'erkanyavas' +MakeVideoWithSplit 'half' 'zahar' +MakeVideoWithSplit 'full' 'oksana' + +./pdf2video -i "${in_file_name}" -r '{1..1}' -o "${out_file_name_prefix}_{1..1}.mp4" -V + +./pdf2video -i "${in_file_name}" -a '${start_text}' -o "${out_file_name_prefix}_start_text.mp4" -V + +./pdf2video -i "${in_file_name}" -W '640' -H '480' -o "${out_file_name_prefix}_640*480.mp4" -V + +./pdf2video -i "${in_file_name}" --speaker -split 'time' 'oksana' -o "${out_file_name_prefix}_oksana.mp4" -V + +./pdf2video -i "${in_file_name}" -speaker 'oksana' -e 'good' -o "${out_file_name_prefix}_oksana_good.mp4" -V + diff --git a/test/Наставление А.В.Суворова.odt b/test/Наставление А.В.Суворова.odt new file mode 100644 index 0000000..e812805 Binary files /dev/null and b/test/Наставление А.В.Суворова.odt differ diff --git a/test/Наставление А.В.Суворова.pdf b/test/Наставление А.В.Суворова.pdf new file mode 100644 index 0000000..b70b050 Binary files /dev/null and b/test/Наставление А.В.Суворова.pdf differ diff --git a/txt2mp3 b/txt2mp3 index 3c07249..8ea92dc 100755 --- a/txt2mp3 +++ b/txt2mp3 @@ -35,8 +35,7 @@ all_params=("${common_params[@]}" "${sound_params[@]}") function GetExec { local exec_file_name="$1" - exec="$exec_file_name" - [ ! -f "$exec" ] && exec="./$exec_file_name" + exec="./$exec_file_name" [ ! -f "$exec" ] && exec="~/$exec_file_name" echo "$exec" @@ -82,13 +81,13 @@ fi source_text=$(cat "${input_file}") # Удаляем все пробелы в начале и в конце строк и заменяем два и более пробелов на один, удаляем все непечатаемые символы -source_text="$(echo "${source_text//[$'\t\r\n']/' '}" | sed 's/^ *//;s/[ ^]*$//;s/ */ /;s/[^[:blank:][:print:]]//g')" +source_text="$(echo "${source_text//[$'\t\r\n']/' '}" | sed 's/^ *//;s/[ ^]*$//;s/ */ /;s/__*/_/;s/[^[:blank:][:print:]]//g')" #[ $verbose ] && echo "Исходный текст $source_text" >> "out.txt" ping -c 3 ya.ru &>/dev/null || { echo "Интернет недоступен."; exit; } -split_size=1450 +split_size=1400 [ $verbose ] && echo "Длина текста ${#source_text}: Разбиваем на части по $split_size" txt_array=() @@ -116,7 +115,7 @@ done audio_file_names_array=() # Если текст пустой, то всё равно создаём выходной файл -[ ${#txt_array[@]} -le 0 ] && { txt_array+="."; } +[ ${#txt_array[@]} -le 0 ] && { txt_array+="-."; } SAVE_IFS=$IFS IFS=""