how to make an output of one ffmpeg process input to the other?
I need to merge text, audio, and video in one mp4 file. In order to do it, I use these two commands in .bat file
ffmpeg -i %video_file% -i %audio_file% -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 %output_file_name% -shortest
ffmpeg -i %output_file_name% -vf "drawtext=fontfile=font.ttf:text='Powered by SANTA ltd.':fontcolor=white:fontsize=96:box=1:[email protected]:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2" -c:a copy output_font.mp4
So, the first one merges audio + video, and the second one binds a text in the middle of the screen.
The question is - how to make a pipe from these two commands? So, instead of using two commands, I'll use just one?
UPD
I tried to use this command
ffmpeg -i %video_file% -i %audio_file% -c:v copy -c:a aac -map 0:v:0 -map 1:a:0 -vf "drawtext=fontfile= /windows/fonts/font.ttf:text='Powered by SANTA ltd.':fontcolor=white:fontsize=96:box=1:[email protected]:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2" -shortest %output_file_name%
There is an error I got:
Filtergraph 'drawtext=fontfile= /windows/fonts/font.ttf:text='Powered by SANTA ltd.':fontcolor=white:fontsize=96:box=1:[email protected]:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2' was defined for video output stream 0:0 but codec copy was selected. Filtering and streamcopy cannot be used together.
Solution 1:
Merging The 2 commands into one should work fine. That is how video filters work in ffmpeg. Note that I am suggesting the answer for a bat file as given by you, but I work in the shell where the syntax is slightly different.
ffmpeg -i %video_file% -i %audio_file% -c:v libx264 -c:a aac -map 0:v:0 -map 1:a:0 \
-vf "drawtext=fontfile= /windows/fonts/font.ttf:text='Powered by \
SANTA ltd.':fontcolor=white:fontsize=96:box=1:boxcolor=\
[email protected]:boxborderw=5:x=(w-text_w)/2:y=(h-text_h)/2" -shortest %output_file_name%
Note that if you use a video filter such as drawtext, an encoding must take place. In other words you cannot use -c:v copy, which means no encoding. If you do not explicitly use/state a codec, ffmpeg will use a default codec. It's best to use a codec and set bitrates explicitly. See below.
What I have tested in a bash shell was with an image and this works fine:
ffmpeg -y -loop 1 -f image2 -i image.png -i audio.wav -s 1280x720 -strict -2 -acodec \
aac -b:a 128k -vcodec libx264 -pix_fmt yuv420p -vf "drawtext=fontfile= /Windows/fonts/courier.ttf:text=\
'Powered by SANTA ltd.':fontcolor=white:fontsize=96:box=1:[email protected]:boxborderw=\
5:x=(w-text_w)/2:y=(h-text_h)/2" -threads 4 -crf 25 -refs 1 -bf 0 -coder 0 -g 25 -keyint_min 15 \
-shortest -movflags +faststart test.mp4
Note that in Windows you will need to provide path to the font, with forward slashes.