解决FFmmpeg合成的MP4文件播放没声音

5 篇文章 2 订阅
2 篇文章 0 订阅

目录

前言

一、问题是什么?

二、进行测试

1.测试ffmpeg.exe

2.测试MP4文件

3.发现问题

三、解决问题

找到一个Tanscoding的代码 



前言

之前使用FFmpeg库合成H264文件和aac文件为MP4文件,最近发现了一个问题


 

一、问题是什么?

把合成的Mp4文件上传到网页客户端,发现后台用ffmpeg.exe程序升高音量后的文件,直接音量没有了,但是原文件使用播放器播放的时候视频音频正常,这就有点奇怪了。

二、进行测试

1.测试ffmpeg.exe

用另外的MP4文件进行音量处理,没有影响声音,那ffmpeg.exe应该是没啥问题的

2.测试MP4文件

把MP4文件下载到一台普通安卓机里面,发现也是没有声音的,所以这里就要怀疑一下MP4文件格式是否有问题了

3.发现问题

既然Mp4文件存在问题,联想到了合成MP4的时候遇到了一个提示

[AVBSFContext @ 0x2baf00] Codec 'h264' (28) is not supported by the bitstream filter 'aac_adtstoasc'. Supported codecs are: aac (86018)

 

这里说和H264不支持比特流过滤器 aac_adtstoasc,支持的编解码器有:aac,所以合成的时候选择的声音格式不对

三、解决问题

没办法,只能再找资料,看看是哪里的问题,

一开始先怀疑是不是版本有问题,因为很多代码是参考的雷神之前的视音频复用器(muxer)的代码,可能是和雷神用的库版本不一样,试了两个不同的版本,还是有这句提示,而且程序还会到最后的时候挂掉

然后修改 bitstream_filter有关的代码
 

AVBitStreamFilterContext* aacbsfc = av_bitstream_filter_init("aac_adtstoasc");

av_bitstream_filter_filter(aacbsfc, out_stream->codec, NULL, &pkt.data, &pkt.size, pkt.data, pkt.size, 0);

av_bitstream_filter_close(aacbsfc);

因为运行的时候有提示这几个函数过时了,要使用新的API接口,我测试了新的接口,编译通过就是最后合成的时候有一大堆错误,哎,难啊

 

然后就去网上找有没有muxing的代码参考,发现很少示例是muxing的,其他demux,decode的倒是不少,

找到一个Tanscoding的代码 

他是读取视频文件Sample.mkv,解复用抽取音视流,分别编码为HEVC/H.265视频流和OGG音频流,并封装为Sample.ts,他这里也会用到把视频流和音频流再合起来,但是没有用到了bitstream_filter相关的函数,

我突发奇想,我也把相关的代码去掉看看,去掉之后,居然能正常合成文件,然后测试音量拉高也是可以的,困扰许久的问题就这样解决了。。。,可能雷神用的FFmepg版本比较老或者有什么其他原因吧,在我用的版本代码中测试到会有和这个现象。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
在Spring Boot中整合FFmpeg需要完成以下几个步骤: 1. 将FFmpeg安装到本地环境中,并将其添加到系统的环境变量中。 2. 创建一个Java工程,并添加FFmpeg的Java接口库(JNA)的依赖。 ```xml <dependency> <groupId>net.java.dev.jna</groupId> <artifactId>jna-platform</artifactId> <version>5.5.0</version> </dependency> ``` 3. 在程序中使用FFmpeg的Java接口库(JNA)调用FFmpeg命令行。例如,使用FFmpeg进行视频码: ```java import com.sun.jna.Library; import com.sun.jna.Native; public interface Ffmpeg extends Library { Ffmpeg INSTANCE = Native.load("avformat", Ffmpeg.class); int avformat_open_input(AVFormatContextByReference ps, String url, AVInputFormat fmt, AVDictionary options); int avformat_find_stream_info(AVFormatContext ic, AVDictionary options); int avcodec_find_decoder(AVCodecParameters par); int avcodec_open2(AVCodecContext codec, AVCodec par, AVDictionary options); int avcodec_receive_frame(AVCodecContext codec, AVFrame frame); int avcodec_send_packet(AVCodecContext codec, AVPacket pkt); int avformat_alloc_output_context2(AVFormatContextByReference ctx, AVOutputFormat oformat, String format_name, String filename); int avio_open(AVIOContextByReference[] pb, String url, int flags); int avformat_write_header(AVFormatContext s, AVDictionary options); int avformat_write_frame(AVFormatContext s, AVPacket pkt); int av_write_trailer(AVFormatContext s); int avcodec_find_encoder(AVCodecParameters par); int avformat_new_stream(AVFormatContext s, AVCodec codec); int avcodec_parameters_from_context(AVCodecParameters par, AVCodecContext codec); int avcodec_encode_video2(AVCodecContext avctx, AVPacket avpkt, AVFrame frame, int[] got_packet_ptr); int av_image_alloc(PointerArray pointers, IntBuffer linesizes, int width, int height, int pix_fmt, int align); int avpicture_fill(AVPicture picture, ByteBuffer ptr, int pix_fmt, int width, int height); } ``` 4. 对于FFmpeg的Java接口库(JNA)的使用,可以参考FFmpeg官方文档(https://www.ffmpeg.org/doxygen/trunk/examples.html)。 以上是整合FFmpeg到Spring Boot的基本步骤,需要注意的是,由于FFmpeg是一个C++编写的程序,使用Java调用FFmpeg需要使用FFmpeg的Java接口库(JNA),并且需要对FFmpeg的Java接口库(JNA)进行一定的学习和了解。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

独尊0136

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值