I'm trying to generate a video file out of 3 files: file #1 and #2 are both dynamically generated image list file; file #3 is a dynamically generated pcm file;
I need to slow down or speed up the final video based on user input, for this I use setpts
and asetrate
, so for example the commands below generates a final file called video3.mp4, which is exactly what I need:
ffmpeg -f concat -safe 0 -i file1.txt -f s16le -ar 11025 -ac 1 -i file3.pcm -filter_complex "[0:v]setpts=PTS/0.4[final], [1:a]asetrate=4410[audio]" -c:v libx264 -preset veryslow -crf 0 -map "[final]" -map "[audio]" video.mp4 -y
ffmpeg -i video.mp4 -f concat -safe 0 -stream_loop -1 -i file2.txt -filter_complex "[0:v][1:v]overlay=shortest=1[final]" -map "[final]" -c:v libx264 -preset veryslow -crf 0 -map 0:a video2.mp4 -y
ffmpeg -i video2.mp4 -filter_complex "[0:v]scale=480:-1:flags=neighbor[final]" -map "[final]" -c:v libx264 -preset veryslow -crf 0 -map 0:a video3.mp4 -y
as I said, the final output (video3.mp4) is exactly what I need but I didn't want to run 3 separated commands to get it, so I tried to combine it all into a single command but it does not output what I need. The issue I have is that the overlaid file (file2.txt) is out of timing.
For example, this is the content of file2.txt:
file 'image1.png'
duration 1
file 'image25.png'
duration 1
file 'image37.png'
duration 1
file 'image75.png'
duration 1
...
so it basically needs to overlay a new image every 1 second but if I combine the commands it gets completely out of timing...
this is the command I I have:
ffmpeg -f concat -safe 0 -i file1.txt -f concat -safe 0 -stream_loop -1 -i file2.txt -f s16le -ar 11025 -ac 1 -i file3.pcm -filter_complex "[0:v]setpts=PTS/0.4[setpts],[2:a]asetrate=4410[audio];[setpts][1:v]overlay=shortest=1[overlay];[overlay]scale=480:-1:flags=neighbor[final]" -c:v libx264 -preset veryslow -crf 0 -map "[final]" -map "[audio]" video.mp4 -y
so do I really need to run separated commands or am I missing something in the combined one?