[FFmpeg-user] Cut part of a video, crop it and blackout parts of it

Cecil Westerhof Cecil at decebal.nl
Mon Apr 5 13:54:40 EEST 2021


Cecil Westerhof via ffmpeg-user <ffmpeg-user at ffmpeg.org> writes:

> I have to cut out a part of a video, crop it and blackout two parts.
> I do this with:
>     ffmpeg -y                                      \
>            -ss 00:19:49                            \
>            -i  2021-03-25ToastmastersClubAvond.mp4 \
>            -to 442                                 \
>            -vf "
>                 crop = 1440:1080:240:0
>                 ,
>                 drawbox=enable='between(t, 0, 2)'     :
>                    color     = black                  :
>                    w         = in_w                   :
>                    h         = in_h                   :
>                    thickness = fill
>                 ,
>                 drawbox=enable='between(t, 339, 342)' :
>                    color     = black                  :
>                    w         = in_w                   :
>                    h         = in_h                   :
>                    thickness = fill
>            "                                       \
>            -acodec copy                            \
>            -vcodec libx264                         \
>            -crf    23                              \
>            speechClean2.mp4

With the help of this mailing list I changed it to:
    ffmpeg -y                                      \
           -ss 00:19:49                            \
           -i  2021-03-25ToastmastersClubAvond.mp4 \
           -to 442                                 \
           -vf "
                crop = 1440:1080:240:0
                ,
                drawbox=enable='bitor(between(t, 0, 2),between(t, 339, 342))' :
                   color     = black                                          :
                   w         = in_w                                           :
                   h         = in_h                                           :
                   thickness = fill
           "                                       \
           -acodec copy                            \
           -vcodec libx264                         \
           -preset veryfast                        \
           -crf    28                              \
           speechClean3.mp4

The input quality is probably poor, that is why I switched to crf 28.
I do not see a difference in quality.

I use veryfast because that probably gives (counter-intuitively) the
smallest size.


> The reason I do -to in the output is that in this way the metadata
> concerning the video length is less out of whack.
>
> I was wondering if this is a good way, or that it could be done
> better?
> Also, beside the timestamps the parameters for drawbox are the same.
> Is there a way that I do not have to repeat them?
>
> I started the crf with 16, then 20 and lastly 23.
>
> The input file has:
>     Stream #0:1(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1920x1080, 2070 kb/s, 25 fps, 25 tbr, 30k tbn, 60k tbc (default)
>
> With crf 16 I get:
>     Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1440x1080, 5541 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
>
> With crf 20 I get:
>     Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1440x1080, 3538 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
>
> And with crf 23 I get:
>     Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1440x1080, 2444 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)

With crf 28 and preset veryfast I get:
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1440x1080, 1056 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)


When I have better quality video I should maybe change crf back to 23.

-- 
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof


More information about the ffmpeg-user mailing list