static int stream_has_enough_packets(AVStream *st, int stream_id, PacketQueue *queue) { return stream_id < 0 || queue->abort_request || (st->disposition & AV_DISPOSITION_ATTACHED_PIC) || queue->nb_packets > MIN_FRAMES && (!queue->duration || av_q2d(st->time_base) * queue->duration > 1.0); }
这是 ffplay.c 源码中的一个函数,用于校验是否有必要继续向缓冲区中添加 AVPacket
。但是 “道理我都懂”,可是,st->disposition & AV_DISPOSITION_ATTACHED_PIC
是个什么骚操做,为何这个操做能够决定是否有必要继续向缓冲区中添加内容?html
【注:】你能够直接跳过 化原 过程,直接到最后看结果。c++
果真,还真有介绍。连接在这:AV_DISPOSITION_ATTACHED_PICshell
The stream is stored in the file as an attached picture/"cover art" (e.g.
APIC frame in ID3v2). The first (usually only) packet associated with it will > be returned among the first few packets read from the file unless seeking > takes place. It can also be accessed at any time in AVStream.attached_pic.
好吧,感受只能意会不能言传。json
它和mp3文件有关,是一个流的标志。 -- 大佬less
ffprobe
仍是乖乖使用 ffprobe
查看文件的 streams
和 packets
信息吧。ide
查看 streams
函数
# 使用 ffprobe -show_streams -i quliulang.mp3 能够查看更详细的流信息 ffprobe -i quliulang.mp3
获得了下面的结果:
能够看到,一个 *.mp3 文件也能够有 Video Stream
。是的,还能够看到它的 codec type
是 png
。结合 查文档 中给出的文档的解释,有没有明白些什么?再来看下 packets
。工具
查看 packets
spa
ffprobe -show_packets -of json -i quliulang.mp3 > packets.json
输出结果以下:.net
通过上述的分析,能够获得的结果是:AV_DISPOSITION_ATTACHED_PIC
是一个标志。若是一个流中含有这个标志的话,那么就是说这个流是 *.mp3 文件中的一个 Video Stream
。而且该流只有一个 AVPacket
,也就是 attached_pic
。这个 AVPacket
中所存储的内容就是这个 *.mp3 文件的封面图片。
所以,也能够很好的解释了文章开头提到的为何 st->disposition & AV_DISPOSITION_ATTACHED_PIC
这个操做能够决定是否能够继续向缓冲区中添加 AVPacket
。这里能够回答,是由于,若是这个流中包含这个标志的话,说明这个流是 *.mp3 文件中的 Video Stream
。不是传统意义上的视频流。它只存放了封面信息,在播放或者导出时,不须要这个数据。所以咱们可使用这个标志很好的区分这个特殊的 Video Stream
。而且经过判断,屏蔽该流,不对其进行操做。