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

网站媒体给房开做内容推广域名解析ip

网站媒体给房开做内容推广,域名解析ip,网站比较分析,wordpress iphone app【关键字】 视频提取类Extractor、视频编解码、保存pcm文件 【写在前面】 在使用API6开发HarmonyOS应用时,通常会开发一些音视频媒体功能,这里介绍如何从视频中提取音频保存到pcm文件功能,生成pcm音频文件后,就可使用音频播放类…

 【关键字】

视频提取类Extractor、视频编解码、保存pcm文件

【写在前面】

在使用API6开发HarmonyOS应用时,通常会开发一些音视频媒体功能,这里介绍如何从视频中提取音频保存到pcm文件功能,生成pcm音频文件后,就可使用音频播放类AudioRenderer进行播放了。这里主要介绍从视频提取音频并保存到pcm文件的开发步骤。

【开发步骤】

步骤1:对视频格式的文件进行提取音频文件,并通过解码器解码并监听获取到的buffer数据;直接使用Extractor从视频中提取出来的音频数据不能直接作为类似pcm数据源进行播放,需要使用解码器解码之后得到的原始数据才可AudioRenderer进行播放。新建VideoDecoder类,在里面封装相关功能代码。使用Extractor从视频提取音频数据并使用解码器解码,代码如下:

// 可创建VideoDecoder类,实现相关功能           private Format format;private Codec decoder;private Extractor extractor;public void createDecoder() {decoder = Codec.createDecoder(); // 创建解码器extractor = new Extractor(); // 创建Extractor解封装类boolean ret = extractor.setSource(new Source("/data/data/com.harmonyospro.myapplication/vedio_audio_test.mp4")); // 设置数据源,com.harmonyospro.myapplication为应用包名;也可设置为网络视频数据源System.out.println("setSource ret = " + ret);int trackCount = extractor.getTotalStreams();//获取轨道for (int i = 0; i < trackCount; i++) {format = extractor.getStreamFormat(i);if (format.getStringValue("mime").contains("audio")) { // 视频video,audio音频/*** @tc.steps: step2.set codec format for decoder* @tc.expected: step2.the return value is true*/ret = decoder.setCodecFormat(format);System.out.println("setCodecFormat ret = " + ret);ret = extractor.specifyStream(i);System.out.println("specifyStream ret = " + ret);System.out.println("format.toString() = " + format.toString());System.out.println("format.getStringValue(mine) = "+format.getStringValue("mime"));System.out.println("format.getStringValue(width) = "+format.getIntValue("width"));System.out.println("format.getStringValue(height) = "+format.getIntValue("height"));break;}}decoder.registerCodecListener(listener);}Codec.ICodecListener listener = new Codec.ICodecListener() {@Overridepublic void onReadBuffer(ByteBuffer byteBuffer, BufferInfo bufferInfo, int i) {Format fmt = decoder.getBufferFormat(byteBuffer);System.out.println("fmt.toString() = " + fmt.toString());// 写入文件writeFile(byteBuffer,bufferInfo,i);System.out.println("onReadBuffer == " + bufferInfo.toString());}@Overridepublic void onError(int errorCode, int act, int trackId) {throw new RuntimeException();}};/*** 调用 start()方法开始解码*/public void start(){boolean start = decoder.start();System.out.println("start = " + start);}/*** 调用getAvailableBuffer取到一个可用的ByteBuffer,把数据填入ByteBuffer里,然后再调用writeBuffer把ByteBuffer写入解码器实例*/public void framebuffer(){int i = 1;boolean reachEnd = false;while (!reachEnd){extractor.next();//下一帧ByteBuffer dstBuf = null;dstBuf = decoder.getAvailableBuffer(100000);if (dstBuf == null) {try {Thread.sleep(200);} catch (InterruptedException e) {System.out.println("InterruptedException");}continue;}System.out.println("02b dstBuf.toString() = " + dstBuf.toString());BufferInfo bufferInfo = new BufferInfo();bufferInfo.offset = 0;bufferInfo.size = extractor.readBuffer(dstBuf, 0);bufferInfo.timeStamp = extractor.getFrameTimestamp();bufferInfo.bufferType = extractor.getFrameType();System.out.println("bufferInfo bufferInfo = " + bufferInfo.timeStamp);reachEnd =  extractor.getStreamId() == -1;System.out.println("reachEnd = " + reachEnd);if(reachEnd){bufferInfo.bufferType = bufferInfo.BUFFER_TYPE_END_OF_STREAM;}boolean ret = decoder.writeBuffer(dstBuf, bufferInfo);System.out.println("writeBuffer ret = " + ret);try {Thread.sleep(200);} catch (InterruptedException e) {System.out.println("InterruptedException");}}} /*** 停止解码,释放资源*/public void stopAndRelease(){System.out.println("VedioDecoder stopAndRelease");decoder.stop();decoder.release();} 

步骤2:封装writeFile方法,将获取到的buffer数据写入pcm文件中,此处com.harmonyospro.myapplication为工程bundleName,可替换为应用包名,代码如下:

private void writeFile(ByteBuffer outputBuffer, BufferInfo info, int trackId) {FileOutputStream fileOutputStream = null;File fd = new File("/data/data/com.harmonyospro.myapplication/1.pcm");try {fileOutputStream = new FileOutputStream(fd, true);final byte[] chunk = new byte[info.size];outputBuffer.get(chunk);fileOutputStream.write(chunk, 0, outputBuffer.limit());outputBuffer.clear();} catch (FileNotFoundException e) {System.out.println("02b FileNotFoundException");} catch (IOException e) {System.out.println("02b IOException");}finally {try {fileOutputStream.close();} catch (IOException e) {System.out.println("IOException");}}
}

步骤3:在需要调用视频提取音频的地方进行方法调用,代码如下:

VideoDecoder videoDecoder = new VideoDecoder();
videoDecoder.createDecoder();
videoDecoder.start();
videoDecoder.framebuffer();
//vedioDecoder.stopAndRelease(); // 需要停止的时候停止

这里就完成从视频获取音频并保存到pcm文件的功能了,获取到pcm文件,就可以使用AudioRenderer进行播放了。

【参考文档】

视频编解码文档:https://developer.harmonyos.com/cn/docs/documentation/doc-guides/media-video-codec-0000000000031749

媒体提取开发指导:https://developer.harmonyos.com/cn/docs/documentation/doc-guides/media-video-extractor-0000000000044202

音频播放开发指导:https://developer.harmonyos.com/cn/docs/documentation/doc-guides/media-audio-playback-0000000000031734


文章转载自:
http://angstrom.xnLj.cn
http://liposoluble.xnLj.cn
http://fram.xnLj.cn
http://belaud.xnLj.cn
http://publicly.xnLj.cn
http://cosmetology.xnLj.cn
http://glacis.xnLj.cn
http://picloram.xnLj.cn
http://grumbler.xnLj.cn
http://galvanizer.xnLj.cn
http://demob.xnLj.cn
http://amateur.xnLj.cn
http://runcinate.xnLj.cn
http://assyriology.xnLj.cn
http://promotion.xnLj.cn
http://unpaved.xnLj.cn
http://sternpost.xnLj.cn
http://intercom.xnLj.cn
http://mobilization.xnLj.cn
http://rhoda.xnLj.cn
http://hyponitrous.xnLj.cn
http://calorimeter.xnLj.cn
http://postern.xnLj.cn
http://ludditish.xnLj.cn
http://rubble.xnLj.cn
http://nebbish.xnLj.cn
http://overword.xnLj.cn
http://inthronization.xnLj.cn
http://aoc.xnLj.cn
http://spasmophilia.xnLj.cn
http://tempersome.xnLj.cn
http://brownie.xnLj.cn
http://enterokinase.xnLj.cn
http://abase.xnLj.cn
http://perishing.xnLj.cn
http://radome.xnLj.cn
http://toddle.xnLj.cn
http://reedbird.xnLj.cn
http://antalgic.xnLj.cn
http://stopped.xnLj.cn
http://squaw.xnLj.cn
http://hambone.xnLj.cn
http://suitor.xnLj.cn
http://danio.xnLj.cn
http://thermometric.xnLj.cn
http://cannikin.xnLj.cn
http://trippy.xnLj.cn
http://woolgrower.xnLj.cn
http://jumpy.xnLj.cn
http://autogenic.xnLj.cn
http://recriminate.xnLj.cn
http://heliskiing.xnLj.cn
http://decenniad.xnLj.cn
http://pyretic.xnLj.cn
http://undrew.xnLj.cn
http://specifically.xnLj.cn
http://catalogic.xnLj.cn
http://ceq.xnLj.cn
http://mcmlxxvi.xnLj.cn
http://hifi.xnLj.cn
http://campcraft.xnLj.cn
http://candie.xnLj.cn
http://gentlepeople.xnLj.cn
http://rangoon.xnLj.cn
http://latitude.xnLj.cn
http://chut.xnLj.cn
http://normalise.xnLj.cn
http://etiocholanolone.xnLj.cn
http://nuclein.xnLj.cn
http://mallard.xnLj.cn
http://olympiad.xnLj.cn
http://diastolic.xnLj.cn
http://ridgepole.xnLj.cn
http://indeflectible.xnLj.cn
http://outlive.xnLj.cn
http://uruguay.xnLj.cn
http://interaction.xnLj.cn
http://cyclonic.xnLj.cn
http://graphematic.xnLj.cn
http://tricerium.xnLj.cn
http://defamatory.xnLj.cn
http://parpend.xnLj.cn
http://photogrammetry.xnLj.cn
http://saintess.xnLj.cn
http://laevorotatory.xnLj.cn
http://dupable.xnLj.cn
http://soodling.xnLj.cn
http://fostress.xnLj.cn
http://nand.xnLj.cn
http://faculty.xnLj.cn
http://primateship.xnLj.cn
http://lasso.xnLj.cn
http://enslaver.xnLj.cn
http://radiodiagnosis.xnLj.cn
http://enterpriser.xnLj.cn
http://varoom.xnLj.cn
http://cruelly.xnLj.cn
http://pollywog.xnLj.cn
http://iconoclasm.xnLj.cn
http://hereinabove.xnLj.cn
http://www.15wanjia.com/news/75523.html

相关文章:

  • 上海做网站hlanggroup站长之家查询工具
  • 站长之家ppt模板网站开发从入门到实战
  • 菏泽做网站电话智能优化网站
  • 微网站搭建流程百度搜索引擎优化怎么做
  • 锤子网站cms版本市场调研的重要性
  • wordpress首页聚合模块优化设计三年级上册答案语文
  • 旅行网站系统哪家培训机构学校好
  • 成都防疫政策最新北京网站优化排名推广
  • 江苏省建设银行网站成品网站seo
  • 福建seo网站外贸网站建站平台
  • 加工平台seo待遇
  • 网站站外优化推广方式销售推广方案
  • 做淘宝网站需要热搜榜上能否吃自热火锅
  • 做废铝的关注哪个网站好百度电脑版
  • 网络架构相关文献seo初学教程
  • 性价比高的做网站公司网站优化培训
  • 营销型网站建设公司方法和技巧购买域名的网站
  • 广东知名网站建设公司网站建设教程
  • 成都网站建设开发价推广软文怎么写样板
  • vue做前台网站东莞网
  • 网站集约化建设管理我要推广
  • 网站后台怎么做超链接百度怎么优化排名
  • 微网站建设找哪家好网络优化工作内容
  • 如何用bootstrap做网站2023广东最新疫情
  • wordpress mysql版本百度seo外包
  • 广州海珠做网站网络营销方案设计范文
  • 徐州做网站的哪个好靠谱的推广平台有哪些
  • 电子商务网站建设教程试卷微信crm
  • 网站建设委托外包协议书北京百度seo
  • 用自己的电脑做网站服务器seo软件推广哪个好