I used this command ffmpeg -i thevideo.mp4 -c:a copy -vf 'drawbox= : x=0 : y=0 : color=invert:enable=between(t\,11\,39)' output.mp4 but it runs very slow.

So, I took another approach, I copy first and last part and run "drawbox" only on selected length, and then adding them all together.

ffmpeg -i thevideo.mp4 -ss 00:00:00 -to 00:00:10 -c copy cut.mp4

ffmpeg -i thevideo.mp4 -ss 00:00:11 -to 00:00:39 -c:a copy -vf 'drawbox= : x=0 : y=0 : color=invert' cut2.mp4

ffmpeg -i thevideo.mp4 -ss 00:00:40 -c copy cut3.mp4

ffmpeg -f concat -i mylist.txt -c copy output.mp4

content of mylist.txt:

file 'cut1.mp4'
file 'cut2.mp4'
file 'cut3.mp4'

Can I run it in one command and have the same speed or even faster but without cutting and concatenating the parts of the video?

  • You could always write a script. Look at something like libav.org/faq.html#How-can-I-join-video-files_003f (i'm sure there are similar classic ffmpeg approaches)
    – v010dya
    May 4 '15 at 7:00
  • @Volodya The question involves ffmpeg, not avconv which does not even have a concat demuxer (or at least last time I checked; they probably haven't decided to re-invent the wheel yet). Perhaps you meant this link? ffmpeg.org/faq.html#How-can-I-join-video-files_003f
    – llogan
    May 4 '15 at 7:05
  • @LordNeckbeard Which is why i have said "i'm sure there are similar classic ffmpeg approaches".
    – v010dya
    May 4 '15 at 7:07
  • @Volodya I was not attempting to offend you, but my point is still valid: avconv != ffmpeg.
    – llogan
    May 4 '15 at 7:09
  • @LordNeckbeard Ok, let's leave it at "It cannot be scripted due to classic ffmpeg not having concat demuxer" then.
    – v010dya
    May 4 '15 at 7:11

Your current method using the concat demuxer while stream copying is probably the fastest (I'm just counting the ffmpeg time and not any time you take to enter the additional commands). Unfortunately, you have to perform several steps, but the advantage is that your non-filtered segments are not being re-encoded which preserves quality and results in fast processing.

It is possible to do it all in one command with the trim, atrim, and concat filters, but this will re-encode everything and possibly be slower. You will have to test. However, it may create a more "stable" output if you find your current method to be problematic (which would likely be fairly obvious upon playback). The filter is generally used instead of the demuxer when all streams are being filtered.

Example using concat filter:

ffmpeg -i input.mp4 -filter_complex \
"[0:v]trim=end=10[v0]; \
 [0:a]atrim=end=10[a0]; \
 [0:v]trim=10:40,drawbox=color=invert[v1]; \
 [0:a]atrim=10:40[a1]; \
 [0:v]trim=start=40[v2]; \
 [0:a]atrim=start=40[a2]; \
 [v0][a0][v1][a1][v2][a2]concat=n=3:v=1:a=1[v][a]" \
-map "[v]" -map "[a]" -movflags +faststart output.mp4


  • If you get a weird output refer to the setpts, asetpts filters (search for PTS-STARTPTS).

  • If it is still too slow use a faster x264 preset. See FFmpeg Wiki: H.264 Video Encoding Guide.

  • I assume you're using OS X with the "tessus" build of ffmpeg from your previous FFmpeg question. The default AAC encoder for the tessus build is libvo_aacenc. The native FFmpeg AAC encoder is generally regarded as being slightly better. If you want to use it add -c:a aac -strict experimental. If you want the best supported AAC encoder, libfdk_aac, then use homebrew to compile ffmpeg. See FFmpeg Wiki: AAC Encoding Guide.

  • Really, great answer, thank you very much for your great explanation, you did help me a lot.
    – whitesiroi
    May 4 '15 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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