java多媒体文件编码、处理工具类

网友投稿 258 2022-11-01


java多媒体文件编码、处理工具类

org.apache.storm storm-core 1.1.0 org.apache.storm storm-kafka 1.0.4 org.jcodec jcodec 0.2.5 test io.humble humble-video-all 0.3.0 org.mp4parser isoparser 1.9.39

合并ffmpeg切割的hls音视频碎片文件

/*** * * @param aggregate 合并待输出文件 * @param segments MPEG transport stream(FFMpeg mpegts)、 MPEG-2 TS视频;波形声音 * @throws InterruptedException * @throws IOException */ private void merge(File aggregate, Collection segments) throws InterruptedException, IOException { Muxer muxer = Muxer.make(aggregate.toString(), MuxerFormat.getFormat(96), "wav"); final MediaPacket packet = MediaPacket.make(); long dts_offset = 0; long pts_offset = 0; for (File segment : segments) { Demuxer demuxer = Demuxer.make(); //option demuxer.open(segment.toString(), null, false, true, null, null); if (muxer.getState() == Muxer.State.STATE_INITED) { int numStreams = demuxer.getNumStreams(); for (int s = 0; s < numStreams; s++) { DemuxerStream demuxerStream = demuxer.getStream(s); Decoder decoder = demuxerStream.getDecoder(); muxer.addNewStream(decoder); } muxer.open(null, null); } long dts_max = 0; long pts_max = 0; while (demuxer.read(packet) >= 0) { if (packet.isComplete()) { packet.setDts(packet.getDts() + dts_offset); packet.setPts(packet.getPts() + pts_offset); dts_max = packet.getDts() + 1; pts_max = packet.getPts() + 1; muxer.write(packet, false); } } dts_offset = dts_max; pts_offset = pts_max; demuxer.close(); } muxer.close(); }

@Test public void testFormat() { MuxerFormat format = MuxerFormat.getFormat(128); System.out.println(format); Collection formats = MuxerFormat.getFormats(); formats.stream().forEach(this::out); } void out(MuxerFormat format) { System.out.printf("%s %s\n",format.getName(),format.getMimeType()); } @Test public void test() throws IOException, InterruptedException { String directory = "C:\\Users\\Administrator\\AppData\\Local\\Temp\\8ad088a2-0bb3-41dc-89d9-2c57ef8414b0"; List files = Files.list(Paths.get(directory)).map(path -> path.toFile()).filter(file -> file.getName().endsWith(".ts")) .collect(Collectors.toList()); File dest = new File(directory+"\\dest.wav"); merge(dest,files); }


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:Mr_matcher的细节2
下一篇:Java(JDK/Tomcat/Maven)运行环境配置及工具(idea/eclipse)安装详细教程
相关文章

 发表评论

暂时没有评论,来抢沙发吧~