FFmpeg 4.3 音视频-多路H265监控录放C++开发十五,解码相关,将h264文件进行帧分隔变成avpacket

前提

前面我们学习了 将YUV数据读取到AVFrame,然后将AVFrame通过 h264编码器变成 AVPacket后,然后将avpacket直接存储到了本地就变成了h264文件。

这一节课,学习解码的一部分。我们需要将 本地存储的h264文件进行帧分隔,也就是变成avpacket,前面直接将avpacket存储就能变成h264文件,那么为什么h264文件需要进行帧分隔才能变成avpacket 呢?

这其实很容易理解,我在编码的时候,由于h264编码器在将avframe变成avpacket的时候就是按照h264的格式进行编码的,因此存储下来的就是一个一个的h264格式的编码结构(也就是NALU结构),因此一个avpacket就是一个NALU或者多个NALU,那么直接存储成h264文件,是OK的。

那么如果是我们本地的h264文件要转化成avpacket,我们需要通过 读取文件的形式 将 h264中的一段数据先读取到内存,然后将这段内存转化成avpacket。

问题

读取多少内存才刚好是一个avpacket呢?

如果不是h264,而是h265文件呢?

实际上这个avpacket的大小是不好定义的,更加明确的说明应该是 avpacket中的data 和size 到底是多大,是不好定义的。

ffmpeg 的解决方案:

ffmpeg指定一块内存,比如4096个字节。

每次从h264文件中都读取4096个字节。

然后通过 解析器 来解析这段内存,假设第一个avpacket大小为10000,不够一个avpacket,这时候怎么办呢?实际上 解析器内部是有缓存的,不够10000个字节,就不生成avpacket,还是会读取10000个字节到 解析器内部的缓存。

然后循环再去读 h264文件的下一个4096字节,直到够了10000个字节,就会生成一个avpacket。

假设中间的第一个avpacket大小为100,那么4096个字节中可能有多个avpacket,因此在读取4096字节后,解析器会找到该4096中的第一个avpacket,还需要有一个循环,该循环就是从剩下的3996个字节,在解析

循环的时候,会减去一个avpacket的大小,然后将指针指向减去avpacket大小的位置,再去解析 剩下来的 内存。

代码 mian.cpp

#include <iostream>
#include <fstream>
using namespace std;
extern "C" {
	#include "libavcodec/avcodec.h"
}

char* const h264filename = (char* const)"1920_1080_25.h264";

//我们的目的是从 h264文件中 截取avpacket,,也就是对h264进行帧分隔
int main(int argc, const char *argv[]) {

	ifstream ifs = ifstream(h264filename,ios_base::binary);
	cout << "main start" << endl;

	//找到解码器
	AVCodec* avcodec = avcodec_find_decoder(AV_CODEC_ID_H264);

	//找到解码器上下文
	AVCodecContext* avcodecContext = avcodec_alloc_context3(avcodec);


	//找到解析器上下文
	AVCodecParserContext*  avcodecParserContext = av_parser_init(AV_CODEC_ID_H264);

	//打开解码器上下文
	avcodec_open2(avcodecContext, NULL, NULL);

	//这里要加一个 AV_INPUT_BUFFER_PADDING_SIZE,是为了某些解码器的buf fix,是ffmepg的要求,但是不会给 AV_INPUT_BUFFER_PADDING_SIZE 中写入数据
	unsigned char buf[4096+ AV_INPUT_BUFFER_PADDING_SIZE] = { 0 };
	AVPacket *avpacket = av_packet_alloc();
	while (!ifs.eof()) {
		ifs.read((char *)buf, 4096);//打算每次从h264文件中读取4096个字节
		int realbufreadcount = ifs.gcount(); // 真正读取的字节数
		if (realbufreadcount<=0) { //如果读取的数据是<=0的,说明整个h264文件已经读取完成了,或者读取h264文件的时候出现了错误了,那么就要直接退出
			cout << "已经读取到h264文件的最后" << endl;
			break;
		}

		//需要对真正读取的字节数进行解析,有可能这4096个字节中有多个avpacket,
		//因此要有一个判断决定是否解析完毕了这4096个字节.
		//这个判断条件就是 读取到的字节数的复制体。
		int parsebufcount = realbufreadcount;
		int parseret = 0;
		auto tempbuf = buf;//让 tempbuf 指向 buf的指针。这里为什么不直接用buf呢?从功能实现上直接用buf也是可以的,但是这是C语言的基本功,尽量不要用原始指针。而是找一个复制的指针。
		while (parsebufcount > 0 ) {
			///av_parser_parse2方法解析了多少个字节,从那个指针开始解析(第五个参数),解析多少个字节(第六个参数)
			parseret = av_parser_parse2(avcodecParserContext,
				avcodecContext,
				&avpacket->data,
				&avpacket->size,
				tempbuf,
				parsebufcount,
				AV_NOPTS_VALUE,
				AV_NOPTS_VALUE,
				0);
			cout << "realbufreadcount = " << realbufreadcount 
				<< "  parseret = " << parseret 
				<< " avpacket->size = " << avpacket->size 
				<< endl;
			parsebufcount = parsebufcount - parseret; //将解析过的字节减去
			tempbuf = tempbuf - parseret;//将指针指向还没有解析过的字节的最开始
		}
	}

	if (ifs) {
		ifs.close();
	}
	if (avpacket!=nullptr) {
		av_packet_free(&avpacket);
	}

	if (avcodecParserContext != nullptr) {
		av_parser_close(avcodecParserContext);
	}
	if (avcodecContext != nullptr) {
		avcodec_free_context(&avcodecContext);
	}
}

运行结果:

main start
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 1393 avpacket->size = 30065
realbufreadcount = 4096  parseret = 2703 avpacket->size = 0
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 297 avpacket->size = 3000
realbufreadcount = 4096  parseret = 594 avpacket->size = 594
realbufreadcount = 4096  parseret = 1188 avpacket->size = 1188
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 528 avpacket->size = 528
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 1056 avpacket->size = 1056
realbufreadcount = 4096  parseret = 433 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 1612 avpacket->size = 18429
realbufreadcount = 4096  parseret = 2484 avpacket->size = 0
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 956 avpacket->size = 3440
realbufreadcount = 4096  parseret = 1912 avpacket->size = 1912
realbufreadcount = 4096  parseret = 1228 avpacket->size = 0
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 255 avpacket->size = 1483
realbufreadcount = 4096  parseret = 752 avpacket->size = 752
realbufreadcount = 4096  parseret = 1504 avpacket->size = 1504
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 960 avpacket->size = 960
realbufreadcount = 4096  parseret = 625 avpacket->size = 0
realbufreadcount = 4096  parseret = 1393 avpacket->size = 2018
realbufreadcount = 4096  parseret = 2703 avpacket->size = 0
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 3390 avpacket->size = 6093
realbufreadcount = 4096  parseret = 706 avpacket->size = 0
realbufreadcount = 4096  parseret = 3097 avpacket->size = 3803
realbufreadcount = 4096  parseret = 999 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 3993 avpacket->size = 13184
realbufreadcount = 4096  parseret = 103 avpacket->size = 0
realbufreadcount = 4096  parseret = 2962 avpacket->size = 3065
realbufreadcount = 4096  parseret = 1134 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 1960 avpacket->size = 7190
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 409 avpacket->size = 409
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 818 avpacket->size = 818
realbufreadcount = 4096  parseret = 909 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 2940 avpacket->size = 12041
realbufreadcount = 4096  parseret = 1156 avpacket->size = 0
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 487 avpacket->size = 1643
realbufreadcount = 4096  parseret = 3609 avpacket->size = 0
realbufreadcount = 4096  parseret = 2448 avpacket->size = 6057
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 897 avpacket->size = 897
realbufreadcount = 4096  parseret = 751 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 460 avpacket->size = 5307
realbufreadcount = 4096  parseret = 920 avpacket->size = 920
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 1840 avpacket->size = 1840
realbufreadcount = 4096  parseret = 876 avpacket->size = 0
realbufreadcount = 4096  parseret = 2296 avpacket->size = 3172
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 745 avpacket->size = 745
realbufreadcount = 4096  parseret = 1055 avpacket->size = 0
realbufreadcount = 4096  parseret = 3746 avpacket->size = 4801
realbufreadcount = 4096  parseret = 350 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 2298 avpacket->size = 6744
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 747 avpacket->size = 747
realbufreadcount = 4096  parseret = 1051 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 380 avpacket->size = 9623
realbufreadcount = 4096  parseret = 1053 avpacket->size = 1053
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 2106 avpacket->size = 2106
realbufreadcount = 4096  parseret = 557 avpacket->size = 0
realbufreadcount = 4096  parseret = 2197 avpacket->size = 2754
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 646 avpacket->size = 646
realbufreadcount = 4096  parseret = 1253 avpacket->size = 0
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 3277 avpacket->size = 4530
realbufreadcount = 4096  parseret = 819 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 2107 avpacket->size = 7022
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 556 avpacket->size = 556
[h264 @ 017D6740] non-existing PPS 1 referenced
realbufreadcount = 4096  parseret = 1112 avpacket->size = 1112
realbufreadcount = 4096  parseret = 321 avpacket->size = 0
[h264 @ 017D6740] non-existing PPS 127 referenced
realbufreadcount = 4096  parseret = 283 avpacket->size = 604
realbufreadcount = 4096  parseret = 3813 avpacket->size = 0
realbufreadcount = 4096  parseret = 2298 avpacket->size = 6111
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 747 avpacket->size = 747
realbufreadcount = 4096  parseret = 1051 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 337 avpacket->size = 5484
realbufreadcount = 4096  parseret = 967 avpacket->size = 967
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 1934 avpacket->size = 1934
realbufreadcount = 4096  parseret = 858 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 3922 avpacket->size = 8876
realbufreadcount = 4096  parseret = 150 avpacket->size = 150
realbufreadcount = 4096  parseret = 24 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 1655 avpacket->size = 5775
realbufreadcount = 4096  parseret = 2441 avpacket->size = 0
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 1471 avpacket->size = 3912
realbufreadcount = 4096  parseret = 2625 avpacket->size = 0
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 3177 avpacket->size = 5802
realbufreadcount = 4096  parseret = 919 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 436 avpacket->size = 5451
realbufreadcount = 4096  parseret = 872 avpacket->size = 872
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 1744 avpacket->size = 1744
realbufreadcount = 4096  parseret = 1044 avpacket->size = 0
realbufreadcount = 4096  parseret = 2981 avpacket->size = 4025
realbufreadcount = 4096  parseret = 1115 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 3134 avpacket->size = 8345
realbufreadcount = 4096  parseret = 962 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 1134 avpacket->size = 6192
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 2268 avpacket->size = 2268
realbufreadcount = 4096  parseret = 694 avpacket->size = 0
realbufreadcount = 4096  parseret = 2872 avpacket->size = 3566
realbufreadcount = 4096  parseret = 1224 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 766 avpacket->size = 6086
realbufreadcount = 4096  parseret = 1852 avpacket->size = 1852
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 1067 avpacket->size = 1067
realbufreadcount = 4096  parseret = 411 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 2142 avpacket->size = 6649
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 591 avpacket->size = 591
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 1182 avpacket->size = 1182
realbufreadcount = 4096  parseret = 143 avpacket->size = 143
realbufreadcount = 4096  parseret = 38 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 16 avpacket->size = 4150
realbufreadcount = 4096  parseret = 329 avpacket->size = 329
realbufreadcount = 4096  parseret = 658 avpacket->size = 658
realbufreadcount = 4096  parseret = 1316 avpacket->size = 1316
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 768 avpacket->size = 768
realbufreadcount = 4096  parseret = 1009 avpacket->size = 0
realbufreadcount = 4096  parseret = 1189 avpacket->size = 2198
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 2378 avpacket->size = 2378
realbufreadcount = 4096  parseret = 529 avpacket->size = 0
realbufreadcount = 4096  parseret = 3621 avpacket->size = 4150
realbufreadcount = 4096  parseret = 475 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 3932 avpacket->size = 8503
realbufreadcount = 4096  parseret = 164 avpacket->size = 0
realbufreadcount = 4096  parseret = 0 avpacket->size = 160
[h264 @ 017D6740] non-existing PPS 2 referenced
realbufreadcount = 4096  parseret = 109 avpacket->size = 113
realbufreadcount = 4096  parseret = 511 avpacket->size = 511
realbufreadcount = 4096  parseret = 1022 avpacket->size = 1022
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 2044 avpacket->size = 2044
realbufreadcount = 4096  parseret = 410 avpacket->size = 0
realbufreadcount = 4096  parseret = 1913 avpacket->size = 2323
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 362 avpacket->size = 362
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 724 avpacket->size = 724
realbufreadcount = 4096  parseret = 1097 avpacket->size = 0
realbufreadcount = 4096  parseret = 3498 avpacket->size = 4595
realbufreadcount = 4096  parseret = 598 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 1626 avpacket->size = 6320
realbufreadcount = 4096  parseret = 2470 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 2310 avpacket->size = 8876
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 759 avpacket->size = 759
realbufreadcount = 4096  parseret = 1027 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 981 avpacket->size = 10200
realbufreadcount = 4096  parseret = 2326 avpacket->size = 2326
realbufreadcount = 4096  parseret = 789 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 1160 avpacket->size = 6045
realbufreadcount = 4096  parseret = 2936 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 1034 avpacket->size = 8066
realbufreadcount = 4096  parseret = 3062 avpacket->size = 0
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 2286 avpacket->size = 5348
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 735 avpacket->size = 735
realbufreadcount = 4096  parseret = 1075 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 462 avpacket->size = 5633
realbufreadcount = 4096  parseret = 924 avpacket->size = 924
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 1848 avpacket->size = 1848
realbufreadcount = 4096  parseret = 862 avpacket->size = 0
realbufreadcount = 4096  parseret = 2596 avpacket->size = 3458
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 1045 avpacket->size = 1045
realbufreadcount = 4096  parseret = 455 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 620 avpacket->size = 5171
realbufreadcount = 4096  parseret = 1240 avpacket->size = 1240
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 309 avpacket->size = 309
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 618 avpacket->size = 618
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 1236 avpacket->size = 1236
realbufreadcount = 4096  parseret = 73 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 3233 avpacket->size = 7402
realbufreadcount = 4096  parseret = 863 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 967 avpacket->size = 10022
realbufreadcount = 4096  parseret = 3129 avpacket->size = 0
realbufreadcount = 4096  parseret = 1010 avpacket->size = 4139
realbufreadcount = 4096  parseret = 2306 avpacket->size = 2306
realbufreadcount = 4096  parseret = 780 avpacket->size = 0
realbufreadcount = 4096  parseret = 3158 avpacket->size = 3938
realbufreadcount = 4096  parseret = 938 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 3040 avpacket->size = 12170
realbufreadcount = 4096  parseret = 1056 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 2174 avpacket->size = 11422
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 623 avpacket->size = 623
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 1246 avpacket->size = 1246
realbufreadcount = 4096  parseret = 53 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 2431 avpacket->size = 6580
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 880 avpacket->size = 880
realbufreadcount = 4096  parseret = 785 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 1181 avpacket->size = 10158
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 2362 avpacket->size = 2362
realbufreadcount = 4096  parseret = 553 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 324 avpacket->size = 13165
realbufreadcount = 4096  parseret = 3772 avpacket->size = 0
realbufreadcount = 4096  parseret = 1810 avpacket->size = 5582
realbufreadcount = 4096  parseret = 2286 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 3615 avpacket->size = 9997
realbufreadcount = 4096  parseret = 481 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 1004 avpacket->size = 9677
realbufreadcount = 4096  parseret = 2388 avpacket->size = 2388
realbufreadcount = 4096  parseret = 704 avpacket->size = 0
realbufreadcount = 4096  parseret = 3793 avpacket->size = 4497
realbufreadcount = 4096  parseret = 303 avpacket->size = 0
[h264 @ 017D6740] non-existing PPS 127 referenced
realbufreadcount = 4096  parseret = 245 avpacket->size = 548
realbufreadcount = 4096  parseret = 737 avpacket->size = 737
realbufreadcount = 4096  parseret = 1474 avpacket->size = 1474
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 905 avpacket->size = 905
realbufreadcount = 4096  parseret = 735 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 1293 avpacket->size = 10220
realbufreadcount = 4096  parseret = 2803 avpacket->size = 0
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 644 avpacket->size = 3447
realbufreadcount = 4096  parseret = 1696 avpacket->size = 1696
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 789 avpacket->size = 789
realbufreadcount = 4096  parseret = 967 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 489 avpacket->size = 9648
realbufreadcount = 4096  parseret = 1332 avpacket->size = 1332
realbufreadcount = 4096  parseret = 2275 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 2952 avpacket->size = 9323
realbufreadcount = 4096  parseret = 1144 avpacket->size = 0
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 2549 avpacket->size = 3693
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 998 avpacket->size = 998
realbufreadcount = 4096  parseret = 549 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 2765 avpacket->size = 7410
[h264 @ 017D6740] non-existing PPS 6 referenced
realbufreadcount = 4096  parseret = 1214 avpacket->size = 1214
realbufreadcount = 4096  parseret = 117 avpacket->size = 0
realbufreadcount = 4096  parseret = 4096 avpacket->size = 0
realbufreadcount = 4096  parseret = 131 avpacket->size = 4344
realbufreadcount = 4096  parseret = 515 avpacket->size = 515
realbufreadcount = 4096  parseret = 1030 avpacket->size = 1030
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 2060 avpacket->size = 2060
realbufreadcount = 4096  parseret = 360 avpacket->size = 0
realbufreadcount = 4096  parseret = 1041 avpacket->size = 1401
[h264 @ 017D6740] FMO is not implemented. Update your FFmpeg version to the newest one from Git. If the problem still occurs, it means that your file has a feature which has not been implemented.
realbufreadcount = 4096  parseret = 2082 avpacket->size = 2082
realbufreadcount = 4096  parseret = 973 avpacket->size = 0
realbufreadcount = 1335  parseret = 1335 avpacket->size = 0

注意的点:

在看 ffmpeg的例子的时候,发现 视频从 h264分帧成为avpacket的代码

和 将 aac 分帧成为 avframe的代码会有不同。

这里要注意。这个区别,在于 在aac分帧的时候,当读取aac文件小于某一个数值的时候,会给内存中不停的加数据,实际上测试对于aac数据 按照视频的写法也是可以的。之所以这么写,是对于其他格式的会有问题,aac实际上没有问题。

相关推荐
理论最高的吻19 分钟前
222. 完全二叉树的节点个数【 力扣(LeetCode) 】
c++·算法·leetcode·职场和发展·二叉树
ducking__40 分钟前
设计模式练习(二) 简单工厂模式
c++·设计模式·简单工厂模式
捕鲸叉40 分钟前
C++创建型设计模式综合示例
开发语言·c++·设计模式
捕鲸叉44 分钟前
C++创建型设计模式体现出的面向对象设计原则
开发语言·c++·设计模式
yangmc041 小时前
区间和 离散化 模板题
c语言·数据结构·c++·算法·矩阵·objective-c
No0d1es1 小时前
2024年9月青少年软件编程(C语言/C++)等级考试试卷(七级)
c语言·开发语言·c++·算法·青少年编程·电子学会·七级
暮色_年华1 小时前
More effective C++:效率(2)
c++
c_simplystudy1 小时前
c++ 类和对象(中)
开发语言·c++·学习
王燕龙(大卫)1 小时前
std::cout打印空的char指针会出现未定义行为
开发语言·c++