First you need to know the parameters of the video file:
ffmpeg -i file.avi I have this:
Input #0, avi, from 'file.avi': Metadata: encoder : Lavf56.36.100 Duration: 00:10:38.49, start: 0.000000, bitrate: 814 kb/s Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 672 kb/s, 25 fps, 25 tbr, 25 tbn, 50 tbc Stream #0:1: Audio: aac (LC) ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, fltp, 128 kb/s .avi from .MTS get this:
for invideo in *.MTS; do ffmpeg -i "$invideo" -s hd720 -c:v libx264 -crf 23 -c:a aac -strict -2 "Converted/${invideo%%.MTS}.avi"; done; Next, you need to make a video of the pictures with the same parameters.
In the graphical editor, create pictures Begin.png and End.png with a resolution of 1280x720.
Create a video from pictures:
ffmpeg -loop 1 -i Начало2.png -pix_fmt yuv420p -vframes 501 -vf "fade=out:899:1:alpha=1" -sar 1:1 -aspect 16:9 -s hd720 -c:v libx264 -crf 23 -c:a aac -strict -2 Начало2.avi ffmpeg -loop 1 -i Окончание2.png -pix_fmt yuv420p -vframes 501 -vf "fade=out:899:1:alpha=1" -sar 1:1 -aspect 16:9 -s hd720 -c:v libx264 -crf 23 -c:a aac -strict -2 Окончание2.avi Overlay audio track:
ffmpeg -i 00019.wav -i Начало2.avi -s hd720 -c:v libx264 -crf 23 -c:a aac -strict -2 Начало_звук.avi ffmpeg -i 00019.wav -i Окончание2.avi -s hd720 -c:v libx264 -crf 23 -c:a aac -strict -2 Окончание_звук.avi For simplicity, I took the audio track from a video file recorded by the same video camera in silence:
ffmpeg -i 00019.MTS -c:a pcm_s16le -vn 00019.wav We cut to the desired duration:
ffmpeg -i Начало_звук.avi -ss 00:00:00 -t 00:00:10 -s hd720 -c:v libx264 -crf 23 -c:a aac -strict -2 Начало_10с.avi ffmpeg -i Окончание_звук.avi -ss 00:00:00 -t 00:00:10 -s hd720 -c:v libx264 -crf 23 -c:a aac -strict -2 Окончание_10с.avi Glue to all files in the current directory:
for invideo in *.avi; do ffmpeg -i concat:"info/Начало_10с.avi|$invideo|info/Окончание_10с.avi" -s hd720 -c:v libx264 -crf 23 -c:a aac -strict -2 "${invideo%%.avi}_mod.avi"; done; I had errors when sticking because of different SAR, DAR and audio codec of the video files being glued.
I thank the distinguished Sergiks for the tips.