FFmpeg av_seek_frame规律详解

本帖最后由 TangMonk 于 2016-7-27 10:26 编辑

1 av_seek_frame对视频进行跳转规律
1.1 flags参数
#define AVSEEK_FLAG_BACKWARD 1 ///< seek backward,若你设置seek时间为1秒,但是只有0秒和2秒上才有I帧,则时间从0秒开始。 #define AVSEEK_FLAG_BYTE 2 ///<seeking based on position in bytes #define AVSEEK_FLAG_ANY 4 ///< seek toany frame, even non-keyframes,若你设置seek时间为1秒,但是只有0秒和2秒上才有I帧,则时间从2秒开始。 #defineAVSEEK_FLAG_FRAME 8 ///< seeking based on frame number,若你设置seek时间为1秒,但是只有0秒和2秒上才有I帧,则时间从2秒开始。
1.2 seek不成功的原因
1.2.1 格式问题

[td]  
   
格式
   
   
AVSEEK_FLAG_BYTE
   
   
AVSEEK_FLAG_ANY
   
  
mp4
  
  
不可以
  
  
可以
  
  
flv
  
  
可以
  
  
不可以
  
  
avi
  
  
可以,但是显示下一个pos
  
  
可以
  
  
ogv
  
  
可以
  
  
可以
  
  
webm
  
  
可以
  
  
可以
  
1.2.2 ffmpeg版本问题
有的版本可以满足上面的格式关系
1.3 flv
对于flv格式,pkt->pos指向该packet的h264数据位置
1.4 MP4
有些mp4的片段的最后一个packet的pos为packet.pos,那么该mp4在seek的时候需要用到文件pos-50000位置的数据,不同的视频该偏移不同
1.5 av_seek_frame到40.0秒处,av_read_frame读到的第一个packet可能不是40秒处的视频packet,可能是之前的音频packet

遇到的问题及解决
2.1 probe size[flv @ 0x608380] Packet mismatch 0 7474
[flv @ 0x608380] Could not find codec parameters for stream 0 (Video:h264, none, 502 kb/s): unspecified size Consider increasing the value for the'analyzeduration' and 'probesize' options [flv @ 0x608380] Could not find codecparameters for stream 1 (Audio: aac, 44100 Hz, stereo, 32 kb/s): unspecifiedsample format Consider increasing the value for the 'analyzeduration' and'probesize' options
2.1.1 原因是自定义IO的probe size参数设置的过小
2.2 mp4文件执行时打印错误: [mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fff340008c0] error reading header
原因: 头的大小过小,分配大一点的头解决
2.3 mp4文件执行到avformat_open_input,报[mov,mp4,m4a,3gp,3g2,mj2@ 0x7fff340008c0] moov atom not found
别人那里没问题 原因:头太小,10M才可以,5M都不行
原文地址:https://www.cnblogs.com/elesos/p/11777496.html