JavaCV推流寫音頻幀報錯:org.bytedeco.javacv.FrameRecorder$Exception: avcodec_encode_audio2() error -12: Co...

  咱們在設置推流的音頻配置時(詳細代碼參見JavaCV本地視頻流經過幀圖片添加文本進行字幕合成),指定原拉流時的音頻編碼器:html

// 音頻相關配置,取原音頻配置
 recorder.setSampleRate(grabber.getSampleRate()); System.out.println(grabber.getAudioCodec()); recorder.setAudioCodec(grabber.getAudioCodec());

 

  咱們看輸出:java

86021 準備開始推流... Exception in thread "main" org.bytedeco.javacv.FrameRecorder$Exception: avcodec_encode_audio2() error -12: Could not encode audio packet. at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:1203) at org.bytedeco.javacv.FFmpegFrameRecorder.writeSamples(FFmpegFrameRecorder.java:1193) at org.bytedeco.javacv.FFmpegFrameRecorder.recordSamples(FFmpegFrameRecorder.java:1167) at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:922) at org.bytedeco.javacv.FFmpegFrameRecorder.record(FFmpegFrameRecorder.java:911) at com.lxy.service.SubtitleMix.main(SubtitleMix.java:78) Input #0, matroska,webm, from 'E:\BaiduNetdiskDownload\testout.mkv': Metadata: title : 天下足球網 http://www.txzqw.cc
    ENCODER         : Lavf58.39.101 Duration: 00:01:11.11, start: 0.000000, bitrate: 2485 kb/s Stream #0:0: Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 1k tbn, 50 tbc (default) Metadata: ENCODER : Lavc58.73.102 libx264 DURATION : 00:01:09.243000000 Stream #0:1: Audio: vorbis, 48000 Hz, 5.1, fltp (default) Metadata: ENCODER : Lavc58.73.102 libvorbis DURATION : 00:01:09.331000000 Stream #0:2: Subtitle: ass Metadata: ENCODER : Lavc58.73.102 ssa DURATION : 00:01:11.113000000 [libx264 @ 000000001cfa9a80] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2 [libx264 @ 000000001cfa9a80] profile High, level 3.1, 4:2:0, 8-bit [libx264 @ 000000001cfa9a80] 264 - core 157 - H.264/MPEG-4 AVC codec - Copyleft 2003-2018 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to 'E:\BaiduNetdiskDownload\outtest.mp4': Metadata: encoder : Lavf58.29.100 Stream #0:0: Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720, q=2-31, 25 fps, 12800 tbn, 25 tbc Stream #0:1: Audio: vorbis (mp4a / 0x6134706D), 48000 Hz, stereo, fltp

 

  根據日誌找到源碼:web

if ((ret = avcodec.avcodec_encode_audio2(this.audio_c, this.audio_pkt, frame, this.got_audio_packet)) < 0) { throw new Exception("avcodec_encode_audio2() error " + ret + ": Could not encode audio packet."); } 

 

  再跟:ide

public static native int avcodec_encode_audio2(AVCodecContext var0, AVPacket var1, @Const AVFrame var2, int[] var3);

 

  又是一條死衚衕。至少咱們知道原來的音視頻採用的音頻編碼器是86021,一搜發現this

 

 

  說明這個編碼器不行,把設置音頻編碼器的那一行註釋掉或者設置爲0,使用默認的編碼器就ok了。我指定使用MP3編碼器(就是上面的86017)也能成功。編碼

相關文章
相關標籤/搜索