How to crossfade 3 videos using ffmpeg? - ffmpeg

I am currently using below command that is working fine for 2 videos but how to crossfade for 3 videos:
ffmpeg -report -i "video2.mp4" -i "video3.mp4" -an \
-filter_complex \
"[0:v]trim=start=0:end=9,setpts=PTS-STARTPTS[firstclip]; \
[1:v]trim=start=1,setpts=PTS-STARTPTS[secondclip]; \
[0:v]trim=start=9:end=10,setpts=PTS-STARTPTS[fadeoutsrc]; \
[1:v]trim=start=0:end=1,setpts=PTS-STARTPTS[fadeinsrc]; \
[fadeinsrc]format=pix_fmts=yuva420p,fade=t=in:st=0:d=1:alpha=1[fadein]; \
[fadeoutsrc]format=pix_fmts=yuva420p,fade=t=out:st=0:d=1:alpha=1[fadeout]; \
[fadein]fifo[fadeinfifo]; \
[fadeout]fifo[fadeoutfifo]; \
[fadeoutfifo][fadeinfifo]overlay[crossfade]; \
[firstclip][crossfade][secondclip]concat=n=3" \ outputname.mp4
Thanks!

Related

How to increase line-height of text using drawtext with FFMPEG?

I'm using the current code to create a video with some text of several lines. When executed I'm receiving a video with the text joined vertically because of lacking space. How do I do to add line-height space?
ffmpeg -i videoInput.mp4 \
-vf drawtext="./font/Roboto/Roboto-Bold.ttf: \
text='testing text \ntesting text \ntesting text':\
fontcolor=yellow:\
fontsize=36:\
box=1:\
boxcolor=black#0.5: \
boxborderw=160:\
x=(w-text_w)/2:\
y=(h-text_h)/2"\
-codec:a copy \
videoOutput.mp4
To increase the line-height add a line_spacing parameter to the command,(http://ffmpeg.org/ffmpeg-filters.html#drawtext-1)
So it looks like:
ffmpeg -i videoInput.mp4 \
-vf drawtext="./font/Roboto/Roboto-Bold.ttf: \
text='testing text \ntesting text \ntesting text':\
line_spacing=30:\
fontcolor=yellow:\
fontsize=36:\
box=1:\
boxcolor=black#0.5: \
boxborderw=160:\
x=(w-text_w)/2:\
y=(h-text_h)/2"\
-codec:a copy \
videoOutput.mp4
Or
Some trick is to append a double breakline on the desired text. It would look like:
text='testing text \n\ntesting text \n\ntesting text'
ffmpeg -i videoInput.mp4 \
-vf drawtext="./font/Roboto/Roboto-Bold.ttf: \
text='testing text \n\ntesting text \n\ntesting text':\
fontcolor=yellow:\
fontsize=36:\
box=1:\
boxcolor=black#0.5: \
boxborderw=160:\
x=(w-text_w)/2:\
y=(h-text_h)/2"\
-codec:a copy \
videoOutput.mp4

How to generate tile with video thumbnails with right timecode

I'm using FFMPEG library for generating video thumbnails every 5 sec with time codes using following command:
ffmpeg \
-i 20051210-w50s.flv \
-y \
-frames 1 \
-vf " \
select=not(mod(t\,5)), \
scale=320:-1, \
drawtext=fontfile=/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: \
timecode='00\\:00\\:00\\:00': r=25: fontcolor=white: x=220: y=220: box=1: boxcolor=black#0.5, \
tile=5x2" \
-vsync 0 \
out.jpg
It gererate right thumbnails tile, but timecodes is wrong. How to solve this issue?
The drawtext filter is not referencing the timestamp. It uses a simple counter that increments the timecode for each new frame. So, the way to do this is to draw each timecode and then drop frames.
ffmpeg \
-i 20051210-w50s.flv \
-y \
-frames 1 \
-vf " \
scale=320:-1, \
drawtext=fontfile=/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: \
timecode='00\\:00\\:00\\:00': r=25: fontcolor=white: x=220: y=220: box=1: boxcolor=black#0.5, \
select=not(mod(t\,5)), \
tile=5x2" \
-vsync 0 \
out.jpg
Drawing text for each frame before selecting the useful ones solves the problem but also introduces performance losses. I made an experiment about it, and the result confirmed my guess.
A better solution would be keeping calling "select" first and using text='%{pts:hms}' instead of timecode.
ffmpeg \
-i 20051210-w50s.flv \
-y \
-frames 1 \
-vf \
"select=not(mod(t\,5)), \
scale=320:-1, \
drawtext=text='%{pts:hms}': fontfile=/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: \
fontcolor=white: x=220: y=220: box=1: boxcolor=black#0.5, \
tile=5x2" \
-vsync 0 \
out.jpg

ffmpeg live stream only outputting 240p

I am having trouble rescaling the resolution of a video with complex filters to 720p, adding the scale to reference the video seems to cause an error
ffmpeg -re -i "https://mnmedias.api.telequebec.tv/m3u8/29880.m3u8" -i
./public/images/ACE.png -i ./public/images/logo2.jpg -i
./public/images/crunchy.png -i ./public/images/red.jpg -filter_complex "
[0]scale=1280:720[ovrl0], [va][ovrl0][v0];[1]scale=40:40[ovrl1], [v0]
[ovrl1] overlay=580:10:enable='lt(mod(t,40),10)'[v1];[2]scale=40:40[ovrl2],
[v1][ovrl2] overlay=580:10:enable='between(mod(t,40),10,20)'[v2];
[3]scale=40:40[ovrl3], [v2][ovrl3]
overlay=580:10:enable='gt(mod(t,40),20)'[v3];[4]scale=40:40[ovrl4], [v3]
[ovrl4] overlay=580:10:enable='gt(mod(t,40),30)'" -acodec aac -vcodec
libx264 -f flv "rtmp://a.rtmp.youtube.com/live2/2222-2222-2222-2222"
error output is [AVFilterGraph # 0x7f964163e9a0] No such filter: ''
Your filtergraph is malformed:
, [va][ovrl0][v0] appears to be a typo and is not applied to any filter.
Your first scale filter is referencing [v0] but [v0] does not exist (other than the orphaned declaration in the typo).
, is use to join linear filters to create a filterchain. ; is used to separate distinct filterchains. You're using , instead of ; in some locations. See FFmpeg Filter Syntax.
I'm guessing you want something like:
-filter_complex \
"[0]scale=1280:720[ovrl0]; \
[1]scale=40:40[ovrl1]; \
[2]scale=40:40[ovrl2]; \
[3]scale=40:40[ovrl3]; \
[4]scale=40:40[ovrl4]; \
[ovrl0][ovrl1] overlay=580:10:enable='lt(mod(t,40),10)'[v1]; \
[v1][ovrl2] overlay=580:10:enable='between(mod(t,40),10,20)'[v2]; \
[v2][ovrl3] overlay=580:10:enable='gt(mod(t,40),20)'[v3]; \
[v3][ovrl4] overlay=580:10:enable='gt(mod(t,40),30)'"

ffmpeg - overlay multiple fading texts with different colors

I have problem with this ffmpeg command, it works fine if the fading text is in white font color, but if I change the fontcolor to something else (for example black), the fading text will not appear, any ideas?
ffmpeg -i ./based_video/480/clip3.mp4 -filter_complex "color=black:100x100[c]; [c][0]scale2ref[ct][mv0]; \
[ct]setsar=1,split=3[t1][t2][t3]; \
[t1]drawtext=fontfile=/usr/share/fonts/truetype/roboto/Roboto-Bold.ttf:text='\$30,000.0':fontsize=40:fontcolor=white,split[text1][alpha1]; \
[text1][alpha1]alphamerge,fade=t=in:st=1:d=1:alpha=1,fade=t=out:st=5:d=1:alpha=1[txta1]; \
[t2]drawtext=fontfile=/usr/share/fonts/truetype/roboto/Roboto-Bold.ttf:text='\$30,000.0':fontsize=40:fontcolor=white,split[text2][alpha2]; \
[text2][alpha2]alphamerge,fade=t=in:st=1:d=1:alpha=1,fade=t=out:st=5:d=1:alpha=1[txta2]; \
[t3]drawtext=fontfile=/usr/share/fonts/truetype/roboto/Roboto-Bold.ttf:text='\$30,000.0':fontsize=40:fontcolor=white,split[text3][alpha3]; \
[text3][alpha3]alphamerge,fade=t=in:st=1:d=1:alpha=1,fade=t=out:st=5:d=1:alpha=1[txta3]; \
[mv0][txta1]overlay=x='100':y='200':shortest=1[mv1]; \
[mv1][txta2]overlay=x='300':y='200':shortest=1[mv2]; \
[mv2][txta3]overlay=x='500':y='200':shortest=1" \
-c:v libx264 -c:a copy ./output_video/testnew-clip3-output.mp4
full log is here :
https://docs.google.com/document/d/1y9Dnn0Df75J8P_hZ6LjHTX2dk-8z97UnTjlX8dnc0v0/edit?usp=sharing
Thanks in advance
You're feeding the plane with the drawn text as the alpha. If the text is black, then the alpha is black and so the text won't appear. You can skip the alpha creation and merging altogether.
ffmpeg -i ./based_video/480/clip3.mp4 -filter_complex "color=black#0:100x100,format=yuva444p[c]; [c][0]scale2ref[ct][mv0]; \
[ct]setsar=1,split=3[t1][t2][t3]; \
[t1]drawtext=fontfile=/usr/share/fonts/truetype/roboto/Roboto-Bold.ttf:text='\$30,000.0':fontsize=40:fontcolor=white,fade=t=in:st=1:d=1:alpha=1,fade=t=out:st=5:d=1:alpha=1[txta1]; \
[t2]drawtext=fontfile=/usr/share/fonts/truetype/roboto/Roboto-Bold.ttf:text='\$30,000.0':fontsize=40:fontcolor=white,fade=t=in:st=1:d=1:alpha=1,fade=t=out:st=5:d=1:alpha=1[txta2]; \
[t3]drawtext=fontfile=/usr/share/fonts/truetype/roboto/Roboto-Bold.ttf:text='\$30,000.0':fontsize=40:fontcolor=white,fade=t=in:st=1:d=1:alpha=1,fade=t=out:st=5:d=1:alpha=1[txta3]; \
[mv0][txta1]overlay=x='100':y='200':shortest=1[mv1]; \
[mv1][txta2]overlay=x='300':y='200':shortest=1[mv2]; \
[mv2][txta3]overlay=x='500':y='200':shortest=1" \
-c:v libx264 -c:a copy ./output_video/testnew-clip3-output.mp4

FFMPEG | AVFilterGraph error WINDOWS and DEBIAN

I trying to use FFMPEG for modify a vidéo.
I have this command on this forum but I have some error
ffmpeg -i input -filter_complex \
"[0:v]crop=iw/2:ih/2:0:0[lt]; \
[0:v]crop=iw/2:ih/2:ow:0[rt]; \
[0:v]crop=iw/2:ih/2:0:oh[lb]; \
[0:v]crop=iw/2:ih/2:ow:oh[rb]; \
[lb][lt]hstack[top]; \
[rt][rb]hstack[bottom]; \
[top][bottom]vstack" \
-c:a copy output
Error windows : [AVFilterGraph # 00000000035ecc20] No such filter: '\'
Error Debian : [AVFilterGraph # 0xe152ceab4e0] No such filter: ' '
Any solution to fix it ? Thx !
I have the solution ! Just remove all \ an all in single line !
ffmpeg -i big_buck_bunny.mp4 -filter_complex "[0:v]crop=iw/2:ih/2:0:0[lt]; [0:v]crop=iw/2:ih/2:ow:0[rt]; [0:v]crop=iw/2:ih/2:0:oh[lb]; [0:v]crop=iw/2:ih/2:ow:oh[rb]; [lb][lt]hstack[top]; [rt][rb]hstack[bottom]; [top][bottom]vstack" -c:a copy test.mp4

Resources