Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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".

share|improve this question
up vote 8 down vote accepted

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.

share|improve this answer

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|improve this answer
it's made a bigger file with wrong quality. :( so there is no way without reencoding? – Zoltán Apr 25 '13 at 12:45
True, the file is bigger, since I-frames are actually JPEG-images (sort of). The other keyframes are predictions to generate a picture, to shrink the filesize. And no, you MUST reencode if you change the GOP-size. If you see quality loss, you must adjust the quality factor. This is the only case where you can use the -sameq parameter, because you will use the same codec. – Nick van Tilborg Apr 25 '13 at 12:50
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) – evilsoup Apr 25 '13 at 12:54
@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? – Alvin Wong Apr 25 '13 at 12:57
@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”? – slhck Apr 25 '13 at 12:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .