0

I've created command, which connects video file with music, use shortest(video) duration, and output this to result file

 ffmpeg \
-i ./source/video/women/1.mp4 \
-i ./source/audio/women.mp3 -y \
-filter:v drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=1:boxcolor=black@1:y=280,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=a0:[email protected]:enable='between(t,0,6.5)':y=700,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=a1:[email protected]:enable='between(t,0,6.5)':y=800,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=a2:[email protected]:enable='between(t,0,6.5)':y=900,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=a3:[email protected]:enable='between(t,0,6.5)':y=1000,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=b0:[email protected]:enable='between(t,7,10)':y=1000,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=b1:[email protected]:enable='between(t,7,10)':y=1100,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=b2:[email protected]:enable='between(t,7,10)':y=1200,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=b3:[email protected]:enable='between(t,7,10)':y=1300,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=b4:[email protected]:enable='between(t,7,10)':y=1400,drawtext=fontsize=30:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=c:enable='between(t,10.2,inf)':boxcolor=black@1:y=1500,drawtext=fontsize=30:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=d:enable='between(t,10.2,inf)':boxcolor=black@1:y=1550 \
-map 0:v:0 \
-map 1:a:0 \
-shortest out2/_.mp4

If I add second output, it works, but without audio and drawtext. How could I fixe this and get draw text works on both outputs?

UPD 1:

ffmpeg -i ./source/video/kids/1.mp4 -i ./source/audio/kids.mp3 -y \
-filter_complex drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=Facts about children:boxcolor=black@1:y=280:text='Facts about children':boxcolor=black@1:y=280,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=Facts about children:boxcolor=black@1:y=280:text='a0':[email protected]:y=700:enable='between(t,0,6.5)',drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=Facts about children:boxcolor=black@1:y=280:text='a1':[email protected]:y=800:enable='between(t,0,6.5)',drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=Facts about children:boxcolor=black@1:y=280:text='a2':[email protected]:y=900:enable='between(t,0,6.5)',drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=Facts about children:boxcolor=black@1:y=280:text='a3':[email protected]:y=1000:enable='between(t,0,6.5)',split=2[o0][o1] \
-map [o0] -map 1:a:0 -shortest 1.mp4 \
-map [o1] 2.mp4

now it works almost correctly, but gives the following error:

Stderr output: frame=    0 fps=0.0 q=0.0 q=0.0 size=       0kB time=-577014:32:22.77 bitrate=  -0.0kbits/s speed=N/A
Stderr output: frame=    0 fps=0.0 q=0.0 q=0.0 size=       0kB time=-577014:32:22.77 bitrate=  -0.0kbits/s speed=N/A
Stderr output: frame=    8 fps=6.2 q=28.0 q=28.0 size=       0kB time=00:00:00.20 bitrate=   1.9kbits/s speed=0.156x
Stderr output: frame=   14 fps=7.7 q=28.0 q=28.0 size=       0kB time=00:00:00.44 bitrate=   0.9kbits/s speed=0.242x
Stderr output: frame=   22 fps=9.3 q=28.0 q=28.0 size=       0kB time=00:00:00.76 bitrate=   0.5kbits/s speed=0.321x
Stderr output: frame=   30 fps= 10 q=28.0 q=28.0 size=       0kB time=00:00:01.12 bitrate=   0.3kbits/s speed=0.389x
Stderr output: frame=   39 fps= 11 q=28.0 q=28.0 size=       0kB time=00:00:01.44 bitrate=   0.3kbits/s speed=0.424x
Stderr output: frame=   50 fps= 12 q=28.0 q=28.0 size=       0kB time=00:00:01.88 bitrate=   0.2kbits/s speed=0.462x
Stderr output: frame=   57 fps= 12 q=28.0 q=28.0 size=       0kB time=00:00:02.20 bitrate=   0.2kbits/s speed=0.478x
Stderr output: frame=   67 fps= 13 q=28.0 q=28.0 size=       0kB time=00:00:02.56 bitrate=   0.1kbits/s speed=0.496x
Stderr output: frame=   75 fps= 13 q=28.0 q=28.0 size=       0kB time=00:00:02.88 bitrate=   0.1kbits/s speed=0.502x
Stderr output: frame=   83 fps= 13 q=28.0 q=28.0 size=       0kB time=00:00:03.20 bitrate=   0.1kbits/s speed=0.507x
Stderr output: frame=   92 fps= 13 q=28.0 q=28.0 size=       0kB time=00:00:03.56 bitrate=   0.1kbits/s speed=0.52x
Stderr output: frame=  100 fps= 14 q=28.0 q=28.0 size=       0kB time=00:00:03.88 bitrate=   0.1kbits/s speed=0.527x
Stderr output: frame=  108 fps= 14 q=28.0 q=28.0 size=       0kB time=00:00:04.20 bitrate=   0.1kbits/s speed=0.533x
Stderr output: frame=  117 fps= 14 q=28.0 q=28.0 size=       0kB time=00:00:04.56 bitrate=   0.1kbits/s speed=0.534x
Stderr output: frame=  126 fps= 14 q=28.0 q=28.0 size=       0kB time=00:00:04.92 bitrate=   0.1kbits/s speed=0.543x
Stderr output: frame=  134 fps= 14 q=28.0 q=28.0 size=       0kB time=00:00:05.24 bitrate=   0.1kbits/s speed=0.547x
Stderr output: frame=  142 fps= 14 q=28.0 q=28.0 size=       0kB time=00:00:05.56 bitrate=   0.1kbits/s speed=0.551x
Stderr output: frame=  151 fps= 14 q=28.0 q=28.0 size=       0kB time=00:00:05.92 bitrate=   0.1kbits/s speed=0.559x
Stderr output: frame=  158 fps= 14 q=28.0 q=28.0 size=       0kB time=00:00:06.20 bitrate=   0.1kbits/s speed=0.558x
Stderr output: frame=  165 fps= 14 q=28.0 q=28.0 size=     256kB time=00:00:06.52 bitrate= 321.7kbits/s speed=0.559x
Stderr output: frame=  174 fps= 14 q=28.0 q=28.0 size=     512kB time=00:00:06.84 bitrate= 613.3kbits/s speed=0.559x
Stderr output: frame=  184 fps= 14 q=28.0 q=28.0 size=     768kB time=00:00:07.24 bitrate= 869.0kbits/s speed=0.568x
Stderr output: frame=  193 fps= 15 q=28.0 q=28.0 size=    1024kB time=00:00:07.60 bitrate=1103.8kbits/s speed=0.571x
Stderr output: frame=  252 fps= 16 q=-1.0 Lq=-1.0 size=    8271kB time=00:00:09.96 bitrate=6802.6kbits/s speed=0.626x
Stderr output: video:16476kB audio:28kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown
Stderr output: [libx264 @ 0xffffa27d79f0] frame I:2     Avg QP:23.97  size: 87068
Stderr output: [libx264 @ 0xffffa27d79f0] frame P:80    Avg QP:24.66  size: 47762
Stderr output: [libx264 @ 0xffffa27d79f0] frame B:170   Avg QP:25.98  size: 26117
Stderr output: [libx264 @ 0xffffa27d79f0] consecutive B-frames:  1.2% 23.0% 10.7% 65.1%
Stderr output: [libx264 @ 0xffffa27d79f0] mb I  I16..4: 12.8% 74.6% 12.6%
Stderr output: [libx264 @ 0xffffa27d79f0] mb P  I16..4: 12.3% 44.9%  2.2%  P16..4: 24.9%  7.9%  2.0%  0.0%  0.0%    skip: 5.7%
Stderr output: [libx264 @ 0xffffa27d79f0] mb B  I16..4:  6.4% 15.8%  0.4%  B16..8: 35.7%  7.8%  1.1%  direct: 4.7%  skip:28.2%  L0:48.4% L1:46.8% BI: 4.8%
Stderr output: [libx264 @ 0xffffa27d79f0] 8x8 transform intra:73.1% inter:88.7%
Stderr output: [libx264 @ 0xffffa27d79f0] coded y,uvDC,uvAC intra: 43.3% 71.1% 18.0% inter: 20.2% 36.8% 0.9%
Stderr output: [libx264 @ 0xffffa27d79f0] i16 v,h,dc,p: 32% 22% 10% 37%
Stderr output: [libx264 @ 0xffffa27d79f0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 17% 19%  5%  7%  7%  6%  7%  5%
Stderr output: [libx264 @ 0xffffa27d79f0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 19% 12%  5% 11% 10%  7%  7%  4%
Stderr output: [libx264 @ 0xffffa27d79f0] i8c dc,h,v,p: 45% 21% 25%  9%
Stderr output: [libx264 @ 0xffffa27d79f0] Weighted P-Frames: Y:0.0% UV:0.0%
Stderr output: [libx264 @ 0xffffa27d79f0] ref P L0: 63.6% 17.3% 14.5%  4.6%
Stderr output: [libx264 @ 0xffffa27d79f0] ref B L0: 89.1%  9.4%  1.5%
Stderr output: [libx264 @ 0xffffa27d79f0] ref B L1: 97.7%  2.3%
Stderr output: [libx264 @ 0xffffa27d79f0] kb/s:6694.37
Stderr output: [aac @ 0xffffa26739b0] Qavg: 530.098
Stderr output: [libx264 @ 0xffffa21358d0] frame I:2     Avg QP:23.97  size: 87068
Stderr output: [libx264 @ 0xffffa21358d0] frame P:80    Avg QP:24.66  size: 47762
Stderr output: [libx264 @ 0xffffa21358d0] frame B:170   Avg QP:25.98  size: 26117
Stderr output: [libx264 @ 0xffffa21358d0] consecutive B-frames:  1.2% 23.0% 10.7% 65.1%
Stderr output: [libx264 @ 0xffffa21358d0] mb I  I16..4: 12.8% 74.6% 12.6%
Stderr output: [libx264 @ 0xffffa21358d0] mb P  I16..4: 12.3% 44.9%  2.2%  P16..4: 24.9%  7.9%  2.0%  0.0%  0.0%    skip: 5.7%
Stderr output: [libx264 @ 0xffffa21358d0] mb B  I16..4:  6.4% 15.8%  0.4%  B16..8: 35.7%  7.8%  1.1%  direct: 4.7%  skip:28.2%  L0:48.4% L1:46.8% BI: 4.8%
Stderr output: [libx264 @ 0xffffa21358d0] 8x8 transform intra:73.1% inter:88.7%
Stderr output: [libx264 @ 0xffffa21358d0] coded y,uvDC,uvAC intra: 43.3% 71.1% 18.0% inter: 20.2% 36.8% 0.9%
Stderr output: [libx264 @ 0xffffa21358d0] i16 v,h,dc,p: 32% 22% 10% 37%
Stderr output: [libx264 @ 0xffffa21358d0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 17% 19%  5%  7%  7%  6%  7%  5%
Stderr output: [libx264 @ 0xffffa21358d0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 19% 12%  5% 11% 10%  7%  7%  4%
Stderr output: [libx264 @ 0xffffa21358d0] i8c dc,h,v,p: 45% 21% 25%  9%
Stderr output: [libx264 @ 0xffffa21358d0] Weighted P-Frames: Y:0.0% UV:0.0%
Stderr output: [libx264 @ 0xffffa21358d0] ref P L0: 63.6% 17.3% 14.5%  4.6%
Stderr output: [libx264 @ 0xffffa21358d0] ref B L0: 89.1%  9.4%  1.5%
Stderr output: [libx264 @ 0xffffa21358d0] ref B L1: 97.7%  2.3%
Stderr output: [libx264 @ 0xffffa21358d0] kb/s:6694.37

In result I need one video with all draw text + audio from input trimmed by video duration (I use shortest for this, maybe I'm wrong), and a second video with all draw text and without any audio.

1 Answer 1

2

You need to split the drawtext output and then map a split result for each output.

ffmpeg \
-i ./source/video/women/1.mp4 \
-i ./source/audio/women.mp3 -y \
-filter_complex drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=1:boxcolor=black@1:y=280,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=a0:[email protected]:enable='between(t,0,6.5)':y=700,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=a1:[email protected]:enable='between(t,0,6.5)':y=800,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=a2:[email protected]:enable='between(t,0,6.5)':y=900,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=a3:[email protected]:enable='between(t,0,6.5)':y=1000,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=b0:[email protected]:enable='between(t,7,10)':y=1000,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=b1:[email protected]:enable='between(t,7,10)':y=1100,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=b2:[email protected]:enable='between(t,7,10)':y=1200,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=b3:[email protected]:enable='between(t,7,10)':y=1300,drawtext=fontsize=80:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=b4:[email protected]:enable='between(t,7,10)':y=1400,drawtext=fontsize=30:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=c:enable='between(t,10.2,inf)':boxcolor=black@1:y=1500,drawtext=fontsize=30:fontcolor=white:x=(w-tw)/2:box=1:boxborderw=20:fontfile=./OpenSans-Light.ttf:text=d:enable='between(t,10.2,inf)':boxcolor=black@1:y=1550,split=2[o0][o1] \
-map [o0] \
-map 1:a:0 \
-shortest out1/_.mp4
-map [o1] \
-map 1:a:0 \
-shortest out2/_.mp4
7
  • Thanks, it's almost what I need, but not final. I've added update to question
    – kRicha
    Commented Aug 1, 2023 at 20:14
  • ffmpeg logs to stderr and I don't see any error in the log. To not have audio in 2nd output, remove -map 1:a:0 and also -shortest
    – Gyan
    Commented Aug 2, 2023 at 4:07
  • yes, I've done this and get error) error is in question section.
    – kRicha
    Commented Aug 2, 2023 at 19:19
  • I looked at the log and there's no error indicated, only encoding progress and stats.
    – Gyan
    Commented Aug 3, 2023 at 4:24
  • seems something wrong, because music stops after 1st second in first video.
    – kRicha
    Commented Aug 3, 2023 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.