Answer the question
In order to leave comments, you need to log in
ffmpeg loop video how?
The task is to glue 5 sec mp4 + minute mp3
The output naturally turns out 5 sec mp4 with music. I don’t understand how to loop a video but at the same time that mp3 does not loop.
I made a separate mp4 by looping it like this printf \"file '%s'\n\" tmp.mp4 >> tmp/list.txt
. Next, the gluing itself
ffmpeg -f concat -i tmp/list.txt -c copy tmp/loop.mp4 -y
ffmpeg -i "loop.mp4" -i "file.mp3" -shortest "file_audio_video.mp4"
Answer the question
In order to leave comments, you need to log in
Perhaps mp4 does not allow simple file concatenation, so when merging it is decoded and compressed again.
It's faster to decompress the video once into .ts
a format that you can then simply glue together.
I did something similar to assemble mp3 + pictures into a static video.
More or less like this:
# из mp4 сделать ts
TMPVIDEO="tmp_video.ts"
ffmpeg \
-i "short.mp4" \
-bsf:v h264_mp4toannexb \
-an \
-f mpegts \
-y -hide_banner \
"$TMPVIDEO"
# до этого определить, сколько раз повторить фрагмент,
# чтобы покрыть длину mp3
REPEATS=5
LONGVIDEO="long_video.ts"
N=1
while [ $N -le $REPEATS ]; do
ffmpeg -i "concat:$TMPVIDEO|$TMPVIDEO" \
-c:v copy \
-y -hide_banner \
"$LONGVIDEO"
local STATUS=$? ; if [ $STATUS -ne 0 ]; then return $STATUS; fi
rm -f "$TMPVIDEO"
mv "$LONGVIDEO" "$TMPVIDEO"
local N=$[$N << 1]
echo "N: $N"
done
# получили длинное видео с запасом
# подрезать длину, чтобы точно соответствовала
FFMPEG -i "$TMPVIDEO" \
-c:v copy \
-t $MUSIC_LENGTH \
-y -hide_banner \
"$LONGVIDEO"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question