Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove all non key frames from video without re-encoding

I have a HEVC mkv video from which I need to remove all but key frames without re-encoding whole thing.

I found out that I can extra key frames using this

ffmpeg -i full.mkv -c:v copy -vf "select=eq(pict_type\,PICT_TYPE_I)" key.mkv

but I get:

Filtergraph 'select=eq(pict_type\,PICT_TYPE_I)' was defined for video output stream 0:0 but codec copy was selected.
Filtering and streamcopy cannot be used together.

What do I do?

like image 256
Teamol Avatar asked Aug 13 '26 18:08

Teamol


1 Answers

You'll have to use the bitstream filter filter_units for this:

ffmpeg -i test.mkv -c copy -map v -bsf:v "filter_units=pass_types=16-23|32-34" key.mkv

This will only pass through random access pictures from the HEVC stream. This should cover most of them but HEVC has more keyframes types than H.264 so I'll update the types above if there are some I've missed.

like image 133
Gyan Avatar answered Aug 20 '26 01:08

Gyan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!