如何使用FFMPEG从编码的视频中提取AVPACKET的重要信息
How to extract important information of an AVPacket from an encoded video using FFMPEG
我编写了一个代码,以读取编码域中的视频,并能够检索诸如帧的大小和持续时间之类的信息。Avpacket类由变量作为数据组成。我可以阅读它,但是由于它是一个咬合阵列,所以我不能以可读的格式使用它。我想使用此数据与另一个视频文件进行比较。请帮助。
void CFfmpegmethods::VideoRead(){
av_register_all();
avformat_network_init();
ofstream outdata;
const char *url = "H:\Sanduni_projects\Sample_video.mp4";
AVDictionary *options = NULL;
AVFormatContext *s = avformat_alloc_context(); //NULL;
AVPacket *pkt = new AVPacket();
//open an input stream and read the header
int ret = avformat_open_input(&s, url, NULL, NULL);
//avformat_find_stream_info(s, &options); //finding the missing information
if (ret < 0)
abort();
av_dict_set(&options, "video_size", "640x480", 0);
av_dict_set(&options, "pixel_format", "rgb24", 0);
if (avformat_open_input(&s, url, NULL, &options) < 0){
abort();
}
av_dict_free(&options);
AVDictionaryEntry *e;
if (e = av_dict_get(options, "", NULL, AV_DICT_IGNORE_SUFFIX)) {
fprintf(stderr, "Option %s not recognized by the demuxer.n", e->key);
abort();
}
int i = 1;
int j = 0;
int64_t duration = 0;
int size = 0;
uint8_t *data = 0; //Unsigned integer type with a width of exactly 8 bits.
int sum = 0;
int total_size = 0;
int total_duration = 0;
int packet_size = 0;
int64_t stream_index = 0;
int64_t bit_rate = 0;
//writing data to a file
outdata.open("H:\Sanduni_projects\log.txt");
if (!outdata){
cerr << "Error: file could not be opened" << endl;
exit(1);
}
//Split what is stored in the file into frames and return one for each call
//returns the next frame of the stream
while(1){
int frame = av_read_frame(s, pkt);
if (frame < 0) break;
duration = pkt->duration;
size = pkt->size;
total_size = total_size + size;
total_duration = total_duration + duration;
cout << "frame:" << i << " " << size << " " << duration << endl;
data = pkt->data;
outdata << "Frame: " << i << " ";
outdata << data<< endl;
for (j = 0; j < size; j++){
}
i++;
//pkt_no++;
//outdata << sum << endl;
}
//make the packet free
av_packet_unref(pkt);
delete pkt;
cout << "total size: " << total_size << endl;
cout << "total duration:" << total_duration << endl;
outdata.close();
//Close the file after reading
avformat_close_input(&s);
}
我不能以可读格式使用它
你为什么要那个?您想输出您的Avpacket的详细信息吗?然后,您需要从AvformatContext获取这些详细信息。AVPacket
具有stream_index
,您可以使用它来获取数据包代表的流的详细信息。另一个有用的信息是PTS/DTS和数据包的大小。
AVPacket pkt = ...;
AVFormatContext *s = ... ;
AVStream* stream = s->streams[pkt.stream_index]; // get the stream
基本上每个媒体文件都包含多个流。打开文件时,AVFormatContext
存储有关打开的文件的信息。AVFormatContext::streams
是您媒体文件一部分的流(例如音频,视频(。这样,从每个AVPacket
来看,您可以获得数据包代表的Avstream。在AVStream
中,您可以检查codec
,流的duration
和其他有用的参数。
相关文章:
- 正在查找文档以获得PS4平台的C++中的设备信息
- 为什么在运行时没有向我们提供有关分段错误的更多信息?
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 如何设置一个范围来提取我想要获得的信息
- 系统参数信息A 与 SPI_GETMOUSE 返回 0
- 为什么 gcovr 会生成空覆盖率统计信息?
- 我已经阅读了很多关于 2d 数组的信息,但我在作业中使用它时遇到了麻烦
- 将信息输入到下面显示的结构向量中的正确语法/格式是什么
- 调试符号中缺少 QObject 类信息(编辑但存在其他 Qt 类)
- 为什么数组大小信息可用于"sizeof"运算符和 delete[] 运算符,但在将数组作为参数传递到
- Pisarze - 来自波兰奥林匹克信息学的数据分析任务
- 将数组信息存储到 c++ 向量中有一个"Access violation reading location"
- C++20 个模块在 clang (Windows):在最简单的示例中键入信息错误
- C++ 如何暂停控制台输出,以便用户可以在继续之前阅读信息
- 如何从WebAssembly模块检测浏览器信息?
- Visual Studio 2017 C++,不能使用 typeid() 获取信息对象,缺少指针?;
- 如何实现具有多个平台__FILE__和__LINE__信息的 C/C++ 可变参数日志记录宏?
- 按字母顺序打印存储在字符数组中的信息
- std::extent 实现详细信息说明
- 如何使用FFMPEG从编码的视频中提取AVPACKET的重要信息