Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers 2

up vote 5 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
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.