使用FFMPEG Android库将PCM转换为m4a

时间:2016-04-11 18:24:07

标签: java android ffmpeg

我正在使用https://github.com/WritingMinds/ffmpeg-android-java

我有一个使用AudioRecord创建的PCM文件。

我现在正在尝试将PCM文件转换为m4a文件。

运行以下命令可以转换它,但它会加速音频,使录音中的声音听起来像花栗鼠。

完成命令:ffmpeg -f s16be -i /storage/emulated/0/GMT/recordTestNew.pcm -strict -2 -y -c:aac -b:176k / storage / emulated / 0 / GMT / recordTestFFMPEG .M4A

哪个给出了

SUCCESS with output : WARNING: linker: /data/user/0/com.globalmedicaltranscriptionapp/files/ffmpeg has text relocations. This is wasting memory and prevents security hardening. Please fix.
                                                                            ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers
                                                                              built on Oct  7 2014 15:08:46 with gcc 4.8 (GCC)
                                                                              configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/armeabi-v7a-neon --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -mfpu=neon' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
                                                                              libavutil      54.  7.100 / 54.  7.100
                                                                              libavcodec     56.  1.100 / 56.  1.100
                                                                              libavformat    56.  4.101 / 56.  4.101
                                                                              libavdevice    56.  0.100 / 56.  0.100
                                                                              libavfilter     5.  1.100 /  5.  1.100
                                                                              libswscale      3.  0.100 /  3.  0.100
                                                                              libswresample   1.  1.100 /  1.  1.100
                                                                              libpostproc    53.  0.100 / 53.  0.100
                                                                            [s16be @ 0xf72ba000] Estimating duration from bitrate, this may be inaccurate
                                                                            Guessed Channel Layout for  Input Stream #0.0 : mono
                                                                            Input #0, s16be, from '/storage/emulated/0/GMT/recordTestNew.pcm':
                                                                              Duration: 00:00:02.70, bitrate: 705 kb/s
                                                                                Stream #0:0: Audio: pcm_s16be, 44100 Hz, 1 channels, s16, 705 kb/s
                                                                            Output #0, ipod, to '/storage/emulated/0/GMT/recordTestFFMPEG.m4a':
                                                                              Metadata:
                                                                                encoder         : Lavf56.4.101
                                                                                Stream #0:0: Audio: aac (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 128 kb/s
                                                                                Metadata:
                                                                                  encoder         : Lavc56.1.100 aac
                                                                            Stream mapping:
                                                                              Stream #0:0 -> #0:0 (pcm_s16be (native) -> aac (native))
                                                                            Press [q] to stop, [?] for help
                                                                            size=      30kB time=00:00:01.90 bitrate= 130.0kbits/s    
                                                                            size=      44kB time=00:00:02.71 bitrate= 131.8kbits/s    
                                                                            video:0kB audio:43kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 2.801121%

音频剪辑实际上应该长约11秒。频率应为11025,编码使用的是Android的AudioFormat.ENCODING_PCM_16BIT,频道正在使用AndioFormat.CHANNEL_IN_DEFAULT。

这是我第一次使用音频,所以这是一场斗争。我使用AudioRecord的原因是因为我需要将音频文件放在允许我拆分它们的形式中,并可能在中间添加新的音频剪辑。

由于频率未传递到输出,这似乎是一个问题。我尝试将上述命令更新为

完成命令:ffmpeg -f s16be -ar 11025 -i /storage/emulated/0/GMT/recordTestNew.pcm -strict -2 -y -c:aac /storage/emulated/0/GMT/recordTestFFMPEG.m4a

哪个给出了

FAILED with output : WARNING: linker: /data/user/0/com.globalmedicaltranscriptionapp/files/ffmpeg has text relocations. This is wasting memory and prevents security hardening. Please fix.
                                                                            ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers
                                                                              built on Oct  7 2014 15:08:46 with gcc 4.8 (GCC)
                                                                              configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/armeabi-v7a-neon --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -mfpu=neon' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
                                                                              libavutil      54.  7.100 / 54.  7.100
                                                                              libavcodec     56.  1.100 / 56.  1.100
                                                                              libavformat    56.  4.101 / 56.  4.101
                                                                              libavdevice    56.  0.100 / 56.  0.100
                                                                              libavfilter     5.  1.100 /  5.  1.100
                                                                              libswscale      3.  0.100 /  3.  0.100
                                                                              libswresample   1.  1.100 /  1.  1.100
                                                                              libpostproc    53.  0.100 / 53.  0.100
                                                                            [s16be @ 0xf707a000] Estimating duration from bitrate, this may be inaccurate
                                                                            Guessed Channel Layout for  Input Stream #0.0 : mono
                                                                            Input #0, s16be, from '/storage/emulated/0/GMT/recordTestNew.pcm':
                                                                              Duration: 00:00:10.81, bitrate: 176 kb/s
                                                                                Stream #0:0: Audio: pcm_s16be, 11025 Hz, 1 channels, s16, 176 kb/s
                                                                            [aac @ 0xf7043c00] Too many bits per frame requested
                                                                            Output #0, ipod, to '/storage/emulated/0/GMT/recordTestFFMPEG.m4a':
                                                                                Stream #0:0: Audio: aac, 0 channels, 128 kb/s
                                                                                Metadata:
                                                                                  encoder         : Lavc56.1.100 aac
                                                                            Stream mapping:
                                                                              Stream #0:0 -> #0:0 (pcm_s16be (native) -> aac (native))
                                                                            Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

04-11 14:22:23.029 11026-11026 / com.globalmedicaltranscriptionapp D / AudioPlayer:完成命令:ffmpeg -f s16be -ar 11025 -i /storage/emulated/0/GMT/recordTestNew.pcm -strict -2 -y -c:aac /storage/emulated/0/GMT/recordTestFFMPEG.m4a

这样做会使输入看起来具有正确的持续时间和比特率,但后来我得到以下错误。

Stream #0:0 -> #0:0 (pcm_s16be (native) -> aac (native))
Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height

我已经尝试了其他一百万个配置,但仍然无法使其正常工作。

我做错了什么?

0 个答案:

没有答案