Search code examples
pythonvideoffmpegvideo-processingh.264

How can I cut/drop specific undecoded h.264 (Key-)frames from a video using FFmpeg?


I want to purposely "destroy" the video by deleting a keyframe so the following P-Frames reference the wrong Keyframe. This is also known as Datamoshing, and while there are already tools to do that for me I want to programm it myself.
From my understanding my best attempt is using bitstream filtering, but this doesnt work:

ffmpeg -i Input.mp4 -c copy -bsf:v noise=drop='gt(t\,30)*key' output.mp4

It does work with not(key)

It would be even better if I was able to split the video into its undecoded frames.
And then being able to reassemble it into a video with specific frames missing or other ones added.

For this Method I have only found this:

ffmpeg -i input.h264 -c:v libx264 -filter:v "select=gte(n\,25)" -frames:v 1 -f h264 frame.h264

But it only does one frame at a time, and I dont know if it actually keeps its frametype, since (correct me if I am wrong) its de- and encoded with this command. Any help is appreciated! Even completely different approaches.


Solution

  • Sorry, my mistake. I didn't add t as a direct variable. Use pts*tb in its place.

    ffmpeg -i Input.mp4 -c copy -bsf:v noise=drop='gt(pts/tb\,30)*key' output.mp4