Skipping a frame without re-encoding H.264 video

1

1

I have an mp4/h.264 video which only contains I-Frames. I want to skip one of those I-frame without re-encoding the entire video. I tried this:

ffmpeg -i "file.mp4" -vf select='not(eq(n\,10))' "out.mp4"

But of course this actually does a re-encoding.

I would prefer if the solution will use ffmpeg, but any program which runs on Linux is fine.

Just to be clear: the video does not contain any P or B frame.

jellyjoe

Posted 2015-02-22T11:37:23.317

Reputation: 13

Answers

2

If you want to remove a single I-frame, you have to extract the bitstream to an Annex B format (e.g. ffmpeg -i input.mp4 -c:v copy -an output.h264, and then find the bytes that represent the NAL unit(s) containing the frame(s) you want to remove. Remove those bytes until the next start code, and save the stream.

Or, you could splice the video by using the -frames:v option to extract the first n frames:

ffmpeg -i input.h264 -c:v copy -frames:v n output.h264

Then, using the -ss parameter, you could seek to the position where you want to start again, and cut from there the same way. You could find out the position by multiplying n+1 times the framerate.

There is no simpler way I know of if you do not want to re-encode.

slhck

Posted 2015-02-22T11:37:23.317

Reputation: 182 472

Maybe I wasn't enough clear in my question. The video does NOT contain any P or B frames. Is there any "automatic" way to remove the frame? – jellyjoe – 2015-02-22T21:34:06.920

Oops, sorry, I wrote this too hastily. Will revise my answer tomorrow, but in essence, no. You could splice the video using the -frames:v option and then glue it back together. – slhck – 2015-02-22T21:47:43.027