FFMPEG add keyframes without reencoding

12,415

Solution 1

How can I add keyframes for FLV files without reencoding?

You can't.

A keyframe, or I-frame, is a frame that stands on it's own - it doesn't require any frames before or after in order to be decoded. Other frames are P-frames (which require one or more previous frames to be decoded, and base their contents on changes made to the previous frame rather than forming a complete picture in isolation) and B-frames (the same as P-frames, but reference frames both before and after them).

In order to change a P- or B-frame to an I-frame, you need to decode and then re-write the video stream. So you can't add keyframes without re-encoding.

Have a look at the x264 encoding guide on the ffmpeg wiki for some tips on how to get a good-looking encode.

Solution 2

When you do -vcodec copy, you are entirely copying the video codec. Then no parameters can affect the video, so also the GOP size isn't parsed again.

Try just using the gopsize, without a video codec copy:

ffmpeg -i file.flv -acodec copy -g 1 -sameq -y tmp.flv

Note the -sameq parameter means same quantizer, which should only be used when you are decoding and encoding using the same codec (like MPEG-2 to MPEG-2), like in your case where you don't want to change the codec.

Share:
12,415

Related videos on Youtube

Zoltán
Author by

Zoltán

Updated on September 18, 2022

Comments

  • Zoltán
    Zoltán almost 2 years

    How can I add keyframes for FLV files without reencoding? I try to use this command, but do nothing:

    ffmpeg -i file.flv  -vcodec copy -acodec copy -g 0 -y tmp.flv && yamdi -i tmp.flv -o out.flv
    

    The (source and this) result is not seekable corretly with flash player. I have a lot of flv to "repair".

  • Zoltán
    Zoltán about 11 years
    it's made a bigger file with wrong quality. :( so there is no way without reencoding?
  • evilsoup
    evilsoup about 11 years
    The reason why this command will give poor results is because of ffmpeg's terrible default settings. If you use -c:v libx264 -crf 22 or something similar, you'll get a decent-looking picture (see the links in my answer for more information)
  • Alvin Wong
    Alvin Wong about 11 years
    @NickvanTilborg IIRC, newer versions has explicitly disabled -sameq since it was mistaken as "same quality". Do you know what the replacement is in newer versions?
  • slhck
    slhck about 11 years
    @AlvinWong There is no replacement for -sameq because most people abused it, and it never worked properly. See: What is the “sameq” or “same_quant” option in FFmpeg? Does it mean “same quality”?