0
I've come across some weird piece of MP4 video, where I-Frames are not marked as Key-Frames. This is messing with my video exporting script (seeking is way off and the video doesn't start at the right time). The script invokes the following command to export part of an MP4 (h264 AAC) video:
ffmpeg -ss <start_offset> -i input.mp4 -vcodec mpeg4 -acodec aac -q:v 5 output.mp4
which produces the following error:
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x2231480] seek_frame_generic failed as this stream seems to contain no keyframes after the target timestamp, 1002 non keyframes found.
I did run ffprobe to see where the key frames where in my input:
ffprobe -show_entries frames=key_frame,pict_type,pkt_pts_time -select_streams v -of compact -v 0 input.mp4
frame|key_frame=1|pkt_pts_time=0.00|pic_type=I
frame|key_frame=0|pkt_pts_time=0.15|pic_type=I
frame|key_frame=0|pkt_pts_time=3.52|pic_type=I
frame|key_frame=0|pkt_pts_time=6.89|pic_type=I
frame|key_frame=0|pkt_pts_time=10.26|pic_type=I
frame|key_frame=0|pkt_pts_time=13.63|pic_type=I
...
Why are all the I-Frames after the first one not key frames ? How can i seek to a given time (whatever the frame) rather that seeking to the closest key frame ?
Thanks a lot for your help.
1Will need to see file to diagnose. For now, shift -ss to after input name. – Gyan – 2019-08-12T15:56:13.320
Hey Gyan, thanks for your answer. I can't disclose the file as it belongs to a client. I'll gladly run commands on it and give you the output. – lieblo – 2019-08-13T06:40:43.663
Let's start with
ffprobe input -show_streams -report
– Gyan – 2019-08-13T08:19:01.663Report available at link
– lieblo – 2019-08-13T10:10:21.043ffmpeg -report -skip_frame nokey -i input -vf showinfo -an -f null -
– Gyan – 2019-08-13T10:31:15.190report – lieblo – 2019-08-13T11:24:41.573
ffmpeg -report -analyzeduration 100M -probesize 100M -skip_frame nokey -i input -vf showinfo -an -f null -
– Gyan – 2019-08-13T12:01:57.187report. Thanks a lot for your time ! – lieblo – 2019-08-13T12:47:11.213
The video appears to be encoded using periodic intra-refresh so only one KF at start. Use -ss after input for such files. – Gyan – 2019-08-13T13:08:05.507
Alright thank you. Post this as answer so that i may accept it ? – lieblo – 2019-08-13T13:19:07.217
Try
ffmpeg -seek2any 1 -ss <start_offset> -i input.mp4 -vcodec mpeg4 -acodec aac -q:v 5 output.mp4
– Gyan – 2019-08-13T13:54:31.460Ok this sort of works (apart from a few values that produce an error for a reason, but nothing i can't overcome). Post this and i'll accept it. – lieblo – 2019-08-14T07:00:06.397