当前位置: 首页 > news >正文

杭州网站建设是什么域名查询网站

杭州网站建设是什么,域名查询网站,做彩页素材的网站,ai制作海报背景 最近整理视频编解码的代码,早前在jetson上封装了jetson multimedia作为视频编解码的类,供其他同事和其他组使用,但该解码接口有一个问题,无法首先获取视频宽高信息,更无法直接获取视频的帧率、比特率等信息。 解…

背景

最近整理视频编解码的代码,早前在jetson上封装了jetson multimedia作为视频编解码的类,供其他同事和其他组使用,但该解码接口有一个问题,无法首先获取视频宽高信息,更无法直接获取视频的帧率、比特率等信息。

解决方法

  1. 使用ffmpeg库,命令行参数不适合代码集成
  2. 使用ffmpeg的API接口进行封装

源码实现

// ffmpeg_videoinfo.h#ifndef FFMPEG_VIDEOINFO_H
#define FFMPEG_VIDEOINFO_H#include <iostream>
#include <memory>struct VideoAsset {float width; float height;float fps;float bitrate; /** bit per second */float duration; /** seconds */
};#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */int GetVideoInfo(const char *in_file,  std::shared_ptr<VideoAsset> &info);#ifdef __cplusplus
};
#endif#endif  // FFMPEG_VIDEOINFO_H
// ffmpeg_videoinfo.cpp#include "ffmpeg_videoinfo.h"#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */#include <libavformat/avformat.h>
#include <libavcodec/avcodec.h>
#include <libavutil/avutil.h>int GetVideoInfo(const char *in_file,  std::shared_ptr<VideoAsset> &info){// 注册所有格式和编解码器av_register_all();// 创建一个格式上下文(Format Context)AVFormatContext* formatContext = nullptr;if (avformat_open_input(&formatContext, in_file, nullptr, nullptr) != 0) {fprintf(stderr, "Could not open input file '%s'", in_file);return -1;}// 获取流信息if (avformat_find_stream_info(formatContext, nullptr) < 0) {fprintf(stderr, "Could not find stream information '%s'", in_file);return -1;}// 查找视频流int videoStreamIndex = -1;for (unsigned i = 0; i < formatContext->nb_streams; i++) {if (formatContext->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {videoStreamIndex = i;break;}}if (videoStreamIndex == -1) {fprintf(stderr, "Could not find video stream '%s'", in_file);return -1;}// 获取视频流的编码参数AVCodecParameters* codecParameters = formatContext->streams[videoStreamIndex]->codecpar;AVStream* videoStream = formatContext->streams[videoStreamIndex];info->fps = av_q2d(videoStream->avg_frame_rate);info->width = codecParameters->width;info->height = codecParameters->height;int64_t totalSize = 0;int64_t totalDuration = 0;AVPacket packet;while (av_read_frame(formatContext, &packet) >= 0) {if (packet.stream_index == 0) {totalSize += packet.size;totalDuration += packet.duration;}av_packet_unref(&packet);}AVRational timeBase = videoStream->time_base; /** 时间基 */info->duration = (float)totalDuration * av_q2d(timeBase);info->bitrate = (totalDuration > 0) ? (totalSize * 8.0 / info->duration) : 0.0;// 清理avformat_close_input(&formatContext);return 0;
}
#ifdef __cplusplus
};
#endif
// 测试脚本 test_single_videoinfo.cpp#include "ffmpeg_videoinfo.h"int main(int argc, char **argv) {if(argc<2){return 1;}const std::string &input_h264=argv[1];std::shared_ptr<VideoAsset> video_info_ptr = std::make_shared<VideoAsset>();// VideoAsset video_info;int status_code = GetVideoInfo(input_h264.c_str(), video_info_ptr);if (status_code < 0) {printf("GetVideoInfo failed\n");return -1;}printf("bitrate:%f, duration:%f, fps:%f, height:%f, width:%f\n",video_info_ptr->bitrate, video_info_ptr->duration, video_info_ptr->fps, video_info_ptr->height, video_info_ptr->width);return 1;
}
# CMakelist.txt核心add_executable(test_video_info test_single_videoinfo.cpp ffmpeg_videoinfo.h ffmpeg_videoinfo.cpp)
target_compile_features(test_video_info PRIVATE cxx_std_14)
target_link_libraries(test_video_info avcodec avutil avformat)
# 测试./test_video_info /data/videos/l4t.h264# 输出信息示例
[h264 @ 0xaaaac14b16a0] Stream #0: not enough frames to estimate rate; consider increasing probesize
bitrate:30681866.000000, duration:164.490005, fps:20.000000, height:2160.000000, width:3840.000000

后记

本人对ffmpeg接口并不熟悉,以上根据文档及搜索结果进行的实现,不敢保证没有bug,如果各位遇到问题,可以留言交流

http://www.mmbaike.com/news/58862.html

相关文章:

  • 为什么要用模板建站北京seo招聘信息
  • 泰州高端网站建设网络营销策划目的
  • 左右左布局网站建设百度网盘网址是多少
  • 郴州市政府门户网站最新长尾关键词挖掘
  • 光明网站建设网站流量统计系统
  • 网站功能设计讲解优化关键词的方法有哪些
  • 涡阳网站建设fifa最新排名出炉
  • 地方门户网站app百度网站优化公司
  • springmvc做网站长沙关键词快速排名
  • 外贸工厂网站做seo多吗竞价托管
  • 哈尔滨网站制作推广百度搜索量查询
  • 怎么做一家网站企业培训课程名称
  • 上海网站报价竞价托管选择微竞价
  • 怀安网站建设郑州抖音推广
  • 个人做商机网站如何盈利网络推广外包流程
  • 嘉兴做网站建设的公司哪家好搜索引擎推广步骤
  • 枣强网址建站seo站长助手
  • 网站片头动画用什么软件做的谷歌应用商店下载
  • 集团网站策划方案seo快速排名软件网站
  • 政府网站建设如何做外包公司
  • 西安seo服务推广资源seo
  • 如何制作网站导航栏关键词挖掘长尾词
  • 如何将自己做的网站放到网上小说关键词搜索器
  • 网站手机版管理链接域名交易中心
  • wordpress图片设置水印广州seo外包
  • 2023中央农村工作会议关键词优化方法有什么步骤
  • 做网站的公司 杭州大一html网页制作作业
  • 内部劵网站怎么做seo搜索引擎优化是
  • 免费做手机网站建设百度新闻官网首页
  • 做旅游网站平台合作入驻网站开发用什么语言