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

网站跟网页的区别是什么意思福建建设执业资格网站报名系统

网站跟网页的区别是什么意思,福建建设执业资格网站报名系统,网站建设开发哪家质量好,筑人才官网本来不是什么难搞的问题,代码写完了,音频流信息中的详细信息,具体代码表现为 format_ctx->streams[audio_stream_index]->codecpar是空指针。 这个查了一圈也没人给出正确答案,实际上是由于我自己编译的ffmpeg时候&#x…

本来不是什么难搞的问题,代码写完了,音频流信息中的详细信息,具体代码表现为

format_ctx->streams[audio_stream_index]->codecpar是空指针。

这个查了一圈也没人给出正确答案,实际上是由于我自己编译的ffmpeg时候,开启的选项的导致的。把音频解码器相关的给禁掉了。重新开启相关编译选项,编译ffmpeg后,一切正常。

具体的选项为:

ffmpeg 交叉编译./configure --prefix=../arm-ffmpegbuild \
--enable-shared \
--enable-libmp3lame \--enable-libx264 \--enable-gpl \--disable-asm \--enable-version3 \--enable-libmp3lame \--enable-libx264 \--enable-libvpx \--enable-nonfree \--cross-prefix=aarch64-linux- \--target-os=linux \--extra-cflags="-I /opt/ffmpeg_test_make/lame-3.100/lamebuild/include" \--extra-ldflags="-L /opt/ffmpeg_test_make/lame-3.100/lamebuild/lib" \--enable-cross-compile \--enable-small \--arch=arm64 \--enable-decoder=h264 \--enable-parser=h264 \--enable-demuxer=rtsp \--extra-ldflags="-L ../x264build/lib" \--extra-cflags="-I ../x264build/include"lame交叉编译./configure \--host=aarch64-linux \--prefix=/opt/ffmpeg_test_make/lame-3.100/lamebuild \cc=aarch64-linux-gcc 

话不多说上代码:


bool FfpDecoderWav::dump_wav(std::string rtsp_url, std::string file_path) {AVDictionary *format_options = NULL;av_dict_set(&format_options, "rtsp_transport", "tcp", 0); // 以tcp的方式打开,av_register_all();avformat_network_init();// 打开 RTSP 流int reconnect_times = 3;AVFormatContext *format_ctx = NULL;bool online = false;while (reconnect_times-- > 0) {if (format_ctx != NULL) {avformat_close_input(&format_ctx);format_ctx = NULL;}format_ctx = avformat_alloc_context();if (avformat_open_input(&format_ctx, rtsp_url.c_str(), NULL, &format_options) != 0) {Logger::error("open rtsp url:{} faile", rtsp_url);// std::this_thread::sleep_for(std::chrono::milliseconds(500));usleep(100000);} else {online = true;break;}}av_dict_free(&format_options); // 释放 format_optionsif (!online) {return false;}Logger::info("open rtsp url:{} for wav success", rtsp_url);// 查找音频流int audio_stream_index = -1;if (avformat_find_stream_info(format_ctx, NULL) < 0) {Logger::info("can not avformat_find_stream_info url:{}", rtsp_url);return false;}AVCodec *codec = NULL;audio_stream_index = av_find_best_stream(format_ctx, AVMEDIA_TYPE_AUDIO, -1, -1, &codec, 0);std::cout << "codec name :" << codec->name << std::endl;std::cout << "codec long_name :" << codec->long_name << std::endl;std::cout << "codec AVMediaType :" << (int)codec->type << std::endl;std::cout << "codec AVCodecID :" << (int)codec->id << std::endl;if (audio_stream_index < 0 || codec == NULL) {Logger::info("can not find sound stream rtsp url:{}", rtsp_url);return false;}Logger::info("find sound stream success index:{}", audio_stream_index);av_dump_format(format_ctx, 0, rtsp_url.c_str(), 0);bool had_audio_code = true;SwrContext *swr_ctx = NULL;AVCodecContext *codec_ctx = avcodec_alloc_context3(codec);if (format_ctx->streams[audio_stream_index]->codecpar) {Logger::info("avcodec_alloc_context3 success channels={}", codec_ctx->channels);Logger::info("avcodec_alloc_context3 success sample_rate={}", codec_ctx->sample_rate);// std::cout << "had codecpar inf" << std::endl;// printf("had codecpar inf\n");avcodec_parameters_to_context(codec_ctx, format_ctx->streams[audio_stream_index]->codecpar);if (avcodec_open2(codec_ctx, codec, NULL) < 0) {Logger::info("avcodec_open2 error rtsp url:{}", rtsp_url);return false;}Logger::info("avcodec_open2 success channels={}", codec_ctx->channels);Logger::info("avcodec_open2 success sample_rate={}", codec_ctx->sample_rate);// 创建重采样上下文swr_ctx = swr_alloc_set_opts(NULL, NUM_CHANNELS, AV_SAMPLE_FMT_S16, SAMPLE_RATE, codec_ctx->channels,codec_ctx->sample_fmt, codec_ctx->sample_rate, 0, NULL);Logger::info("swr_alloc_set_opts success");if (!swr_ctx || swr_init(swr_ctx) < 0) {// Logger::info("swr_init error rtsp url:{}", rtsp_url);return false;}} else {printf("cdecpar is nullodecpar is nullodecpar is nullodecpar is null\n");std::cout << "codecpar is null" << std::endl;had_audio_code = false;}// 创建输出 WAV 文件std::ofstream wav_file(file_path.c_str(), std::ios::binary);if (!wav_file) {// Logger::info("fopen local_path save wav failed path:{}", file_path);return false;}// Logger::info("open wav_file success");//  写入 WAV 文件头WAVHeader wav_header;unsigned int file_size = sizeof(wav_header);// Logger::info("wav_header size:{}", file_size);wav_file.write((const char *)&wav_header, file_size);time_t start_time = time(NULL);AVPacket packet;int ret = 0;int count = 1000;while (true) {if (ret = av_read_frame(format_ctx, &packet) < 0) {// Logger::info("av_read_frame failed: {}", ret);break;}time_t current_time = time(NULL);time_t duration = current_time - start_time;if (duration > 60) {// Logger::info("save sound end by 20 s time");break;}if (packet.stream_index == audio_stream_index) {if (!had_audio_code) {wav_file.write((char *)packet.data, packet.size);std::cout << "write sws data codecpar inf insfsjfjaslkjfas" << std::endl;printf(" wav_file.write((char *)packet.data, packet.size);\n");continue;}AVFrame *frame = av_frame_alloc();if (avcodec_send_packet(codec_ctx, &packet) >= 0 && avcodec_receive_frame(codec_ctx, frame) >= 0) {uint8_t *out_buffer[NUM_CHANNELS];int out_samples = 0;int out_size = 0;for (int i = 0; i < NUM_CHANNELS; i++) {out_buffer[i] = (uint8_t *)malloc(frame->nb_samples * 2 * sizeof(uint8_t));}out_samples = swr_convert(swr_ctx, out_buffer, frame->nb_samples, (const uint8_t **)frame->data,frame->nb_samples);out_size = out_samples * NUM_CHANNELS * 2;wav_file.write(reinterpret_cast<char *>(out_buffer[0]), out_size);// std::cout << "write sws data codecpar inf" << std::endl;// printf(" wav_file.write(reinterpret_cast<char *>(out_buffer[0]), out_siz22;\n");for (int i = 0; i < NUM_CHANNELS; i++) {free(out_buffer[i]);}}av_frame_free(&frame);}av_packet_unref(&packet);}// 更新 WAV 文件头中的数据大小uint32_t subchunk2Size = static_cast<unsigned int>(wav_file.tellp()) - 44;uint32_t chunkSize = subchunk2Size + 36;wav_file.seekp(4, std::ios::beg);wav_file.write(reinterpret_cast<char *>(&chunkSize), 4);wav_file.seekp(40, std::ios::beg);wav_file.write(reinterpret_cast<char *>(&subchunk2Size), 4);// 关闭文件wav_file.close();// 释放资源avcodec_close(codec_ctx);avcodec_free_context(&codec_ctx);avformat_close_input(&format_ctx);swr_free(&swr_ctx);// Logger::info("save local_path  wav success path:{}", file_path);return true;
}

wav格式的数据头文件:

struct WAVHeader {char chunkID[4] = {'R', 'I', 'F', 'F'};uint32_t chunkSize = 0;char format[4] = {'W', 'A', 'V', 'E'};char subchunk1ID[4] = {'f', 'm', 't', ' '};uint32_t subchunk1Size = 16;uint16_t audioFormat = 1;uint16_t numChannels = NUM_CHANNELS;uint32_t sampleRate = SAMPLE_RATE;uint32_t byteRate = SAMPLE_RATE * NUM_CHANNELS * 16 / 8;uint16_t blockAlign = 4;uint16_t bitsPerSample = 16;char subchunk2ID[4] = {'d', 'a', 't', 'a'};uint32_t subchunk2Size = 4;
};

最后,就是wav注意的地方,一共是两个值:

chunkSize 和subchunk2Size

// 更新 WAV 文件头中的数据大小

也就是说:subchunk2Size是出去wav文件头部数据意外的数据长度。

即文件总长度减去头部长度44个字节。

chunkSize=subchunk2Size+36

具体为什么,可以查看wav格式的说明。

http://www.yayakq.cn/news/234574/

相关文章:

  • 网站空间域名注册计算机软件开发规范1988作废
  • 台州网站制作怎么给网站做后台
  • 门网站建设wordpress扁平化
  • 找图做素材啥网站好网站开发形象设计要求
  • 静态网站 apache网站创建方案
  • 科技网站新版网站上线济宁网站建设第一品牌
  • 无限成都成都市广播电视台官方网站设计软件名称
  • 网站自然排名这么做简阳seo排名优化课程
  • 兰州网站排名优化公司如何把做的网站变成链接
  • 深圳做网站哪家公司比较好而且不贵手机麻将app制作开发
  • 上海大学生兼职做网站百度推广优化是什么意思
  • 如何制作网站教程视频讲解wordpress 优化版本
  • 传媒网站设计公司长春快速建站
  • 昆明网站关键词优化网站外链隐形框架是什么
  • 网站后台信息维护要怎么做百度seo优化技巧
  • seo公司怎么样seo排名优化点击软件有哪些
  • 淄博市网站开发昆山网站建设昆山
  • 做传销网站后果严重吗数字营销专业
  • 网站源码上传教程全面的手机网站建设
  • 网站建设知识点的总结花都区营销型网站建设
  • 雪域什么网站是做电影的wordpress升级机制
  • 做网站的数据从哪里来做淘客的网站有哪些
  • 优秀茶叶网站设计新手开网店从哪里找货源
  • 西安网站建设hyk123互联网关键词优化
  • 潍坊专业人员继续教育关键词优化报价查询
  • 央视优购物官方网站微网站预览
  • 网站建设需要多少wordpress登陆的插件
  • 建设政务门户网站的基本意义重庆市建设工程管理信息网
  • 网站解析出问题 邮件收不到了公司做网站的费用计什么科目
  • 网站建设确认函网页版查询系统制作