Insert text using FFMPEG, but only in a portion of the video

2

I use the code below to generate new videos (from the respective folder) by entering the student's name and CPF in each video.

However, compilation takes a long time, since the compilation time is the time of the video. I need something faster, I want the text to be inserted only from the 5th to the 10th second of the video and then stop.

As if you split the video, enter the text. No need to compile the whole video. I believe it is necessary first to make a copy of the videos and then a code that only inserts the text in time.

The script I use is:

#!/bin/bash

echo "Nome do aluno"
read nome;
echo "CPF do aluno"
read cpf;

mkdir $cpf;

echo “iniciando a compilação para o aluno $nome”

[ "$1" ] && cd "$1"

ls -1 *.mp4
[ "$?" -ne 0 ] && echo 'Sem arquivos mp4 nesse diretório' && exit 0
for ARQUIVO in $(ls -1 *.mp4)
do
    ARQ_DESTINO="${ARQUIVO%%.mp4}.mp4"
    echo "Convertendo $ARQUIVO para $ARQ_DESTINO"
    ffmpeg -i "$ARQUIVO" -strict experimental -vf "drawtext=fontfile='/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf':text='Liberado para $nome - $cpf':x=200:y=10:fontsize=16:enable='between(t,5,10)'" /var/www/Arquivos/videos/$cpf/"$ARQ_DESTINO"
done

As I will sell videos online, I have set up a server to create these videos. However, each lesson package is about 6 hours long. If 4 people buy per day my server will work all day to assemble these new videos. So it's impractical, is there a faster solution?

    
asked by anonymous 04.10.2015 / 00:28

1 answer

0

See if this solution suits you. I created some temporary files to put the text in only one part.

#!/bin/bash

echo "Nome do aluno"
read nome;
echo "CPF do aluno"
read cpf;

mkdir $cpf;

echo “iniciando a compilação para o aluno $nome”

[ "$1" ] && cd "$1"

ls -1 *.mp4
[ "$?" -ne 0 ] && echo 'Sem arquivos mp4 nesse diretório' && exit 0
for ARQUIVO in $(ls -1 *.mp4)
do
    ARQ_DESTINO="${ARQUIVO%%.mp4}.mp4"
    echo "Convertendo $ARQUIVO para $ARQ_DESTINO"

    # Arquivo s temporários do início meio e fim do vídeo
    ffmpeg -i "$ARQUIVO" -c copy -ss 00:00:00 -to 00:00:05 -avoid_negative_ts 1  inicio.mp4
    ffmpeg -i "$ARQUIVO" -c copy -ss 00:00:05 -to 00:00:10 -avoid_negative_ts 1  meio.mp4
    ffmpeg -i "$ARQUIVO" -c copy -ss 00:00:10  -avoid_negative_ts 1  fim.mp4

    # Inserindo texto na parte do meio
    ffmpeg -i meio.mp4 -vf "drawtext=fontfile='/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf':text='Liberado para $nome - $cpf':x=200:y=10:fontsize=16" -avoid_negative_ts 1   meio-texto.mp4

    # Montando lista para concatenar os arquivos
    echo -e "file 'inicio.mp4'\nfile 'meio-texto.mp4'\nfile 'fim.mp4'" > lista.txt

    # Concatenando os arquivos
    ffmpeg -f concat -i lista.txt -c copy  "/var/www/Arquivos/videos/$cpf/$ARQ_DESTINO"

    # Removendo arquivos temporários utilizados
    rm inicio.mp4 meio.mp4 fim.mp4 meio-texto.mp4 lista.txt

done
    
21.03.2017 / 20:47