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

无锡朝阳网站建设做网站常州

无锡朝阳网站建设,做网站常州,制作图网老版,外贸俄罗斯俄语网站开发源文件#xff1a; #include iostream #include thread using namespace std; extern C { //指定函数是c语言函数#xff0c;函数名不包含重载标注 //引用ffmpeg头文件 #include libavformat/avformat.h } //预处理指令导入库 #pragma …源文件 #include iostream #include thread using namespace std; extern C { //指定函数是c语言函数函数名不包含重载标注 //引用ffmpeg头文件 #include libavformat/avformat.h } //预处理指令导入库 #pragma comment(lib,avformat.lib) #pragma comment(lib,avutil.lib) #pragma comment(lib,avcodec.lib) void PrintErr(int err) {char buf[1024] { 0 };av_strerror(err, buf, sizeof(buf) - 1);cerr endl; } #define CERR(err) if(err!0){ PrintErr(err);getchar();return -1;}int main(int argc, char* argv[]) {//打开媒体文件const char* url v1080.mp4;/// 解封装//解封装输入上下文AVFormatContext* ic nullptr;//初始化格式上下文IC//*Open an input streamand read the header.The codecs are not opened. //* The stream must be closed with avformat_close_input().auto re avformat_open_input(ic, url,NULL, //封装器格式 null 自动探测 根据后缀名或者文件头NULL //参数设置rtsp需要设置);CERR(re);//获取媒体信息 无头部格式re avformat_find_stream_info(ic, NULL);CERR(re);//打印封装信息av_dump_format(ic, 0, url,0 //0表示上下文是输入 1 输出);AVStream* as nullptr; //音频流AVStream* vs nullptr; //视频流for (int i 0; i ic-nb_streams; i){//音频if (ic-streams[i]-codecpar-codec_type AVMEDIA_TYPE_AUDIO){as ic-streams[i];cout 音频 endl;cout sample_rate: as-codecpar-sample_rate endl;}else if (ic-streams[i]-codecpar-codec_type AVMEDIA_TYPE_VIDEO){vs ic-streams[i];cout 视频 endl;cout width: vs-codecpar-width endl;cout height: vs-codecpar-height endl;}}/// 解封装/开始编码到文件中//编码器上下文const char* out_url test_mux.mp4;AVFormatContext* ec nullptr;re avformat_alloc_output_context2(ec, NULL, NULL,out_url //根据文件名推测封装格式);CERR(re);//再output文件的上下文ec中添加视频流、音频流auto mvs avformat_new_stream(ec, NULL); //视频流auto mas avformat_new_stream(ec, NULL); //音频流//打开输出IOre avio_open(ec-pb, out_url, AVIO_FLAG_WRITE);CERR(re);//设置编码音视频流参数//ec-streams[0];//mvs-codecpar;//视频参数if (vs){mvs-time_base vs-time_base;// 时间基数与原视频一致//从解封装复制参数avcodec_parameters_copy(mvs-codecpar, vs-codecpar);}if (as){mas-time_base as-time_base;//从解封装复制参数avcodec_parameters_copy(mas-codecpar, as-codecpar);}//写入文件头re avformat_write_header(ec, NULL);CERR(re);//打印输出上下文av_dump_format(ec, 0, out_url, 1);/// 截取10 ~ 20 秒之间的音频视频 取多不取少// 假定 9 11秒有关键帧 我们取第9秒double begin_sec 10.0; //截取开始时间double end_sec 20.0; //截取结束时间long long begin_pts 0;long long begin_audio_pts 0; //音频的开始时间long long end_pts 0;//换算成pts 换算成输入ic的pts以视频流为准if (vs vs-time_base.num 0){//sec /timebase pts// pts sec/(num/den) sec* (den/num) double t (double)vs-time_base.den / (double)vs-time_base.num;//den分母/num分子begin_pts begin_sec * t;end_pts end_sec * t;}if (as as-time_base.num 0)begin_audio_pts begin_sec * ((double)as-time_base.den / (double)as-time_base.num);//seek输入媒体 移动到第十秒的关键帧位置if (vs)re av_seek_frame(ic, vs-index, begin_pts,AVSEEK_FLAG_FRAME | AVSEEK_FLAG_BACKWARD); //向后关键帧CERR(re);AVPacket pkt;for (;;){re av_read_frame(ic, pkt);if (re ! 0){PrintErr(re);break;}AVStream* in_stream ic-streams[pkt.stream_index];AVStream* out_stream nullptr;long long offset_pts 0; //偏移pts用于截断的开头pts运算if (vs pkt.stream_index vs-index){cout 视频:;//超过第20秒退出只存10~20秒if (pkt.pts end_pts){av_packet_unref(pkt);break;}out_stream ec-streams[0];offset_pts begin_pts;}else if (as pkt.stream_index as-index){cout 音频:;out_stream ec-streams[1];offset_pts begin_audio_pts;}cout pkt.pts : pkt.dts : pkt.size endl;//重新计算pts dts duration//a * bq输入basetime / cq输出basetimeif (out_stream){pkt.pts av_rescale_q_rnd(pkt.pts - offset_pts, in_stream-time_base,out_stream-time_base, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));pkt.dts av_rescale_q_rnd(pkt.dts - offset_pts, in_stream-time_base,out_stream-time_base, (AVRounding)(AV_ROUND_NEAR_INF | AV_ROUND_PASS_MINMAX));pkt.duration av_rescale_q(pkt.duration, in_stream-time_base, out_stream-time_base);}pkt.pos -1;//写入音视频帧 会清理pktre av_interleaved_write_frame(ec,pkt);if (re ! 0){PrintErr(re);}//av_packet_unref(pkt);//this_thread::sleep_for(100ms);}//写入结尾 包含文件偏移索引re av_write_trailer(ec);if (re ! 0)PrintErr(re);avformat_close_input(ic);avio_closep(ec-pb);avformat_free_context(ec);ec nullptr;return 0; }运行结果 成功生产力另一个mp4文件内容为我们重新封装的音视频流和解封装之前的视频一样
http://www.zqtcl.cn/news/563941/

相关文章:

  • 花木公司网站源码双语外贸网站源码
  • 什么公司做网站会提供源代码创业做招商加盟类网站赚钱
  • 东莞网站建设排名基因数据库网站开发价格
  • 天河区营销型网站建设科技自立自强
  • 网站域名账号江苏百度推广代理商
  • 专题网站建站对网站分析
  • 外贸出口网站建设如何搭建自己的网站服务器
  • 云南省建设厅网站职称评审房地产推广方案和推广思路
  • 湘潭建设路街道网站app的设计与开发
  • 《网站开发实践》 实训报告广告策划书案例完整版
  • 一级 爰做片免费网站做中学学中做网站
  • 网站排名如何提升网络营销的有哪些特点
  • 巨腾外贸网站建设个人主页网站模板免费
  • 有哪些网站免费做推广淄博网站电子商城平台建设
  • 网站建设的技术支持论文做网站买什么品牌笔记本好
  • 凡科网站后台在哪里.工程与建设
  • 静态网站源文件下载建设手机网站价格
  • 苏州做网站优化的网站开发邮件
  • 做网站怎么搭建环境阿里云大学 网站建设
  • 网站改版业务嵌入式培训推荐
  • 腾讯云 怎样建设网站网站开发 报价
  • 网络科技公司门户网站免费人脉推广官方软件
  • 建和做网站网络营销推广可以理解为
  • 太原市网站建设网站人防工程做资料的网站
  • 怎么做免费推广网站做网站第一部
  • 橙色网站后台模板WordPress的SEO插件安装失败
  • 做网站好还是做微信小程序好外包加工网外放加工活
  • 中国建设银行网站查征信电子商务网站建设及推广
  • 扫描网站漏洞的软件php网站后台验证码不显示
  • 诸城哪里有做网站的做网站的尺寸