Closed jhwsx closed 4 years ago
图片挂了,看不了啊; 你把音频循环拼接成和视频时长一样,然后再和视频混合试试
图片中的命令: 音频文件多添加几次,设成循环模式
ffmpeg -i "concat:cut.aac|cut.aac|cut.aac" -acodec copy loop_audio.aac
去除原视频音频
ffmepg -i source.video -vcodec copy -an video.mp4
合并音视频文件
ffmpeg -i video.mp4 -i loop_audio.aac -vcodec copy -acodec copy newvideo.mp4
检查下拼接好的音频有没问题;
添加背景音乐(支持调节原音和配乐的音量)
ffmpeg -y -i /storage/emulated/0/1/input.mp4 -i /storage/emulated/0/1/input.mp3 -filter_complex [0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.2[a0];[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1[a1];[a0][a1]amix=inputs=2:duration=first[aout] -map [aout] -ac 2 -c:v copy -map 0:v:0 -preset superfast /storage/emulated/0/1/result.mp4
谢谢大神。
大神你好,还想再问一下,我使用上面的命令在Meizu M2 Note Android 5.1, API 22上会崩溃,但是在HUAWEI HRY-AL00a Android 10, API 29上是好的,在电脑的命令行中测试:
(base) xxx@xxx:~/下载$ ffmpeg -y -i nuanyangxia.mp4 -i seconds30.mp3 -filter_complex "[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0[a0];[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1[a1];[a0][a1]amix=inputs=2:duration=first[aout]" -map "[aout]" -ac 2 -c:v copy -map 0:v:0 -preset superfast result1909.mp4
ffmpeg version 4.2.2-1ubuntu1 Copyright (c) 2000-2019 the FFmpeg developers
built with gcc 9 (Ubuntu 9.3.0-3ubuntu1)
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'nuanyangxia.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf58.29.100
comment : [p:dk][20330][HUAWEI][BTV-DL09][Android 24][i][h][f][2019-12-18_23:11:12]
copyright : 42115e51f7b367c8b8438b37ea04c12c
Duration: 00:00:27.20, start: 0.000000, bitrate: 7760 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1088x1920, 7664 kb/s, 30 fps, 30 tbr, 1000k tbn, 2000k tbc (default)
Metadata:
handler_name : VideoHandler
Stream #0:1(und): Audio: vorbis (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 86 kb/s (default)
Metadata:
handler_name : SoundHandler
Input #1, mp3, from 'seconds30.mp3':
Metadata:
encoder : Lavf58.29.100
Duration: 00:00:30.07, start: 0.011995, bitrate: 64 kb/s
Stream #1:0: Audio: mp3, 44100 Hz, stereo, fltp, 64 kb/s
Metadata:
encoder : Lavf
Stream mapping:
Stream #0:1 (vorbis) -> aformat
Stream #1:0 (mp3float) -> aformat
amix -> Stream #0:0 (aac)
Stream #0:0 -> #0:1 (copy)
Press [q] to stop, [?] for help
Output #0, mp4, to 'result1909.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
copyright : 42115e51f7b367c8b8438b37ea04c12c
comment : [p:dk][20330][HUAWEI][BTV-DL09][Android 24][i][h][f][2019-12-18_23:11:12]
encoder : Lavf58.29.100
Stream #0:0: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
Metadata:
encoder : Lavc58.54.100 aac
Stream #0:1(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1088x1920, q=2-31, 7664 kb/s, 30 fps, 30 tbr, 1000k tbn, 1000k tbc (default)
Metadata:
handler_name : VideoHandler
[mp3float @ 0x55b2c693fc40] Header missing
Error while decoding stream #1:0: Invalid data found when processing input
[mp3float @ 0x55b2c693fc40] Header missing
Error while decoding stream #1:0: Invalid data found when processing input
frame= 816 fps=0.0 q=-1.0 Lsize= 25901kB time=00:00:27.21 bitrate=7796.7kbits/s speed= 71x
video:25449kB audio:427kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.092899%
虽然输出了结果,但是有 Error 信息。 在客户端时,命令不包含里面的双引号,因为包含时不正确。 可以帮我看一下吗?
使用 demo,在魅族手机上也出错了:
05-08 20:27:19.107 28362-28387/io.microshow.rxffmpeg.app I/art: Explicit concurrent mark sweep GC freed 31132(1739KB) AllocSpace objects, 2(40KB) LOS objects, 17% free, 19MB/23MB, paused 1.150ms total 71.894ms
05-08 20:27:19.109 28362-28401/io.microshow.rxffmpeg.app D/OpenGLRenderer: Flushing caches (mode 0)
05-08 20:27:23.462 28362-28362/io.microshow.rxffmpeg.app D/ViewRootImpl: hardware acceleration is enabled, this = ViewRoot{20368b9b io.microshow.rxffmpeg.app/io.microshow.rxffmpeg.app.activity.MainActivity,ident = 2}
05-08 20:27:23.516 28362-28362/io.microshow.rxffmpeg.app D/Dialog: show
05-08 20:27:23.567 I/TAG_FFMPEG: ffmpeg version 4.0
05-08 20:27:23.567 I/TAG_FFMPEG: Copyright (c) 2000-2018 the FFmpeg developers
05-08 20:27:23.567 I/TAG_FFMPEG: built with gcc 4.9.x (GCC) 20150123 (prerelease)
05-08 20:27:23.568 I/TAG_FFMPEG: configuration: --prefix=/mnt/d/DevConfig/ffmpeg/4.0/build/build_script/lib/ffmpeg/armv8-a --enable-neon --enable-hwaccels --enable-nonfree --enable-gpl --enable-x86asm --disable-shared --enable-static --cross-prefix=/mnt/d/DevConfig/ffmpeg/ndk/android-ndk-r14b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android- --target-os=android --arch=arm64 --cpu=armv8-a --cc=/mnt/d/DevConfig/ffmpeg/ndk/android-ndk-r14b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-gcc --nm=/mnt/d/DevConfig/ffmpeg/ndk/android-ndk-r14b/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/aarch64-linux-android-nm --enable-cross-compile --sysroot=/mnt/d/DevConfig/ffmpeg/ndk/android-ndk-r14b/platforms/android-21/arch-arm64/ --enable-libx264 --enable-encoder=libx264 --enable-libmp3lame --enable-encoder=libmp3lame --enable-libfdk-aac --enable-encoder=libfdk_aac --enable-encoder=aac --enable-encoder=mjpeg --enable-encoder=png --enable-encoder=gif --enable-decode
05-08 20:27:23.584 I/TAG_FFMPEG: libavutil 56. 14.100 / 56. 14.100
05-08 20:27:23.584 I/TAG_FFMPEG: libavcodec 58. 18.100 / 58. 18.100
05-08 20:27:23.584 I/TAG_FFMPEG: libavformat 58. 12.100 / 58. 12.100
05-08 20:27:23.584 I/TAG_FFMPEG: libavdevice 58. 3.100 / 58. 3.100
05-08 20:27:23.584 I/TAG_FFMPEG: libavfilter 7. 16.100 / 7. 16.100
05-08 20:27:23.584 I/TAG_FFMPEG: libswscale 5. 1.100 / 5. 1.100
05-08 20:27:23.584 I/TAG_FFMPEG: libswresample 3. 1.100 / 3. 1.100
05-08 20:27:23.584 I/TAG_FFMPEG: libpostproc 55. 1.100 / 55. 1.100
05-08 20:27:23.585 D/TAG_FFMPEG: Splitting the commandline.
05-08 20:27:23.585 D/TAG_FFMPEG: Reading option '-y' ...
05-08 20:27:23.585 D/TAG_FFMPEG: matched as option 'y' (overwrite output files) with argument '1'.
05-08 20:27:23.585 D/TAG_FFMPEG: Reading option '-i' ...
05-08 20:27:23.585 D/TAG_FFMPEG: matched as input url with argument '/storage/emulated/0/Android/data/com.koki.callshow/files/TrimVideo/20200508_202050.mp4'.
05-08 20:27:23.585 D/TAG_FFMPEG: Reading option '-i' ...
05-08 20:27:23.586 D/TAG_FFMPEG: matched as input url with argument '/storage/emulated/0/Music/逃跑计划'.
05-08 20:27:23.586 D/TAG_FFMPEG: Reading option '-' ...
05-08 20:27:23.586 D/TAG_FFMPEG: matched as output url.
05-08 20:27:23.586 D/TAG_FFMPEG: Reading option '夜空中最亮的星.mp3' ...
05-08 20:27:23.586 D/TAG_FFMPEG: matched as output url.
05-08 20:27:23.586 D/TAG_FFMPEG: Reading option '-filter_complex' ...
05-08 20:27:23.586 D/TAG_FFMPEG: matched as option 'filter_complex' (create a complex filtergraph) with argument '[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1[a0];[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1[a1];[a0][a1]amix=inputs=2:duration=first[aout]'.
05-08 20:27:23.586 D/TAG_FFMPEG: Reading option '-map' ...
05-08 20:27:23.586 D/TAG_FFMPEG: matched as option 'map' (set input stream mapping) with argument '[aout]'.
05-08 20:27:23.586 D/TAG_FFMPEG: Reading option '-ac' ...
05-08 20:27:23.586 D/TAG_FFMPEG: matched as option 'ac' (set number of audio channels) with argument '2'.
05-08 20:27:23.586 D/TAG_FFMPEG: Reading option '-c:v' ...
05-08 20:27:23.586 D/TAG_FFMPEG: matched as option 'c' (codec name) with argument 'copy'.
05-08 20:27:23.586 D/TAG_FFMPEG: Reading option '-map' ...
05-08 20:27:23.586 D/TAG_FFMPEG: matched as option 'map' (set input stream mapping) with argument '0:v:0'.
05-08 20:27:23.586 D/TAG_FFMPEG: Reading option '-preset' ...
05-08 20:27:23.618 D/TAG_FFMPEG: matched as AVOption 'preset' with argument 'superfast'.
05-08 20:27:23.618 D/TAG_FFMPEG: Reading option '/storage/emulated/0/Android/data/com.koki.callshow/files/Video/20200508_202050.mp4' ...
05-08 20:27:23.618 D/TAG_FFMPEG: matched as output url.
05-08 20:27:23.618 D/TAG_FFMPEG: Finished splitting the commandline.
05-08 20:27:23.618 D/TAG_FFMPEG: Parsing a group of options: global .
05-08 20:27:23.618 D/TAG_FFMPEG: Applying option y (overwrite output files) with argument 1.
05-08 20:27:23.618 D/TAG_FFMPEG: Applying option filter_complex (create a complex filtergraph) with argument [0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1[a0];[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1[a1];[a0][a1]amix=inputs=2:duration=first[aout].
05-08 20:27:23.618 D/TAG_FFMPEG: Successfully parsed a group of options.
05-08 20:27:23.618 D/TAG_FFMPEG: Parsing a group of options: input url /storage/emulated/0/Android/data/com.koki.callshow/files/TrimVideo/20200508_202050.mp4.
05-08 20:27:23.618 D/TAG_FFMPEG: Successfully parsed a group of options.
05-08 20:27:23.618 D/TAG_FFMPEG: Opening an input file: /storage/emulated/0/Android/data/com.koki.callshow/files/TrimVideo/20200508_202050.mp4.
05-08 20:27:23.661 D/TAG_FFMPEG: Opening '/storage/emulated/0/Android/data/com.koki.callshow/files/TrimVideo/20200508_202050.mp4' for reading
05-08 20:27:23.661 D/TAG_FFMPEG: Setting default whitelist 'file,crypto'
05-08 20:27:23.696 D/TAG_FFMPEG: Format mov,mp4,m4a,3gp,3g2,mj2 probed with size=2048 and score=100
05-08 20:27:23.696 D/TAG_FFMPEG: ISO: File Type Major Brand: isom
05-08 20:27:23.698 D/TAG_FFMPEG: Unknown dref type 0x206c7275 size 12
05-08 20:27:23.702 D/TAG_FFMPEG: Processing st: 0, edit list 0 - media time: 0, duration: 722970
05-08 20:27:23.703 D/TAG_FFMPEG: Unknown dref type 0x206c7275 size 12
05-08 20:27:23.705 D/TAG_FFMPEG: Processing st: 1, edit list 0 - media time: 0, duration: 384240
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 29.916667 0.006787
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 29.916667 0.006787
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 30.000000 0.000021
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 30.000000 0.019368
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 60.000000 0.000085
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 60.000000 0.018787
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 120.000000 0.000338
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 120.000000 0.017750
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 240.000000 0.001353
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 240.000000 0.016186
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 29.970030 0.001033
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 29.970030 0.001033
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 59.940060 0.004132
05-08 20:27:23.706 D/TAG_FFMPEG: rfps: 59.940060 0.004132
05-08 20:27:23.706 D/TAG_FFMPEG: Before avformat_find_stream_info() pos: 9260017 bytes read:41378 seeks:1 nb_streams:2
05-08 20:27:23.717 D/TAG_FFMPEG: nal_unit_type: 7, nal_ref_idc: 3
05-08 20:27:23.717 D/TAG_FFMPEG: nal_unit_type: 8, nal_ref_idc: 3
05-08 20:27:23.740 D/TAG_FFMPEG: nal_unit_type: 5, nal_ref_idc: 3
05-08 20:27:23.740 D/TAG_FFMPEG: Format yuv420p chosen by get_format().
05-08 20:27:23.740 V/TAG_FFMPEG: Reinit context to 1280x720, pix_fmt: yuv420p
05-08 20:27:23.744 28362-28401/io.microshow.rxffmpeg.app D/Surface: Surface::connect(this=0x7f99a19a00,api=1)
05-08 20:27:23.746 28362-28401/io.microshow.rxffmpeg.app D/mali_winsys: new_window_surface returns 0x3000
05-08 20:27:23.747 28362-28401/io.microshow.rxffmpeg.app D/Surface: Surface::allocateBuffers(this=0x7f99a19a00)
05-08 20:27:23.824 D/TAG_FFMPEG: no picture
05-08 20:27:23.870 D/TAG_FFMPEG: All info found
05-08 20:27:23.871 D/TAG_FFMPEG: After avformat_find_stream_info() pos: 42527 bytes read:116284 seeks:2 frames:2
05-08 20:27:23.871 I/TAG_FFMPEG: Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/storage/emulated/0/Android/data/com.koki.callshow/files/TrimVideo/20200508_202050.mp4':
05-08 20:27:23.871 I/TAG_FFMPEG: Metadata:
05-08 20:27:23.871 I/TAG_FFMPEG: major_brand :
05-08 20:27:23.871 I/TAG_FFMPEG: isom
05-08 20:27:23.871 I/TAG_FFMPEG: minor_version :
05-08 20:27:23.871 I/TAG_FFMPEG: 512
05-08 20:27:23.871 I/TAG_FFMPEG: compatible_brands:
05-08 20:27:23.871 I/TAG_FFMPEG: isomiso2avc1mp41
05-08 20:27:23.871 I/TAG_FFMPEG: encoder :
05-08 20:27:23.871 I/TAG_FFMPEG: Lavf58.12.100
05-08 20:27:23.871 I/TAG_FFMPEG: Duration:
05-08 20:27:23.871 I/TAG_FFMPEG: 00:00:08.03
05-08 20:27:23.871 I/TAG_FFMPEG: , start:
05-08 20:27:23.871 I/TAG_FFMPEG: 0.000000
05-08 20:27:23.871 I/TAG_FFMPEG: , bitrate:
05-08 20:27:23.871 I/TAG_FFMPEG: 9221 kb/s
05-08 20:27:23.871 I/TAG_FFMPEG: Stream #0:0
05-08 20:27:23.871 I/TAG_FFMPEG: (eng)
05-08 20:27:23.871 D/TAG_FFMPEG: , 1, 1/90000
05-08 20:27:23.872 I/TAG_FFMPEG: : Video: h264 (avc1 / 0x31637661), yuv420p, 1280x720, 9086 kb/s
05-08 20:27:23.872 I/TAG_FFMPEG: , SAR 1:1 DAR 16:9
05-08 20:27:23.872 I/TAG_FFMPEG: ,
05-08 20:27:23.872 I/TAG_FFMPEG: 30 fps,
05-08 20:27:23.872 I/TAG_FFMPEG: 30 tbr,
05-08 20:27:23.872 I/TAG_FFMPEG: 90k tbn,
05-08 20:27:23.872 I/TAG_FFMPEG: 180k tbc
05-08 20:27:23.872 I/TAG_FFMPEG: (default)
05-08 20:27:23.872 I/TAG_FFMPEG: Metadata:
05-08 20:27:23.872 I/TAG_FFMPEG: rotate :
05-08 20:27:23.872 I/TAG_FFMPEG: 90
05-08 20:27:23.872 I/TAG_FFMPEG: handler_name :
05-08 20:27:23.872 I/TAG_FFMPEG: VideoHandler
05-08 20:27:23.872 I/TAG_FFMPEG: Side data:
05-08 20:27:23.872 I/TAG_FFMPEG:
05-08 20:27:23.872 I/TAG_FFMPEG: displaymatrix: rotation of -90.00 degrees
05-08 20:27:23.872 I/TAG_FFMPEG: Stream #0:1
05-08 20:27:23.872 I/TAG_FFMPEG: (eng)
05-08 20:27:23.872 D/TAG_FFMPEG: , 1, 1/48000
05-08 20:27:23.872 I/TAG_FFMPEG: : Audio: aac (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 127 kb/s
05-08 20:27:23.872 I/TAG_FFMPEG: (default)
05-08 20:27:23.872 I/TAG_FFMPEG: Metadata:
05-08 20:27:23.872 I/TAG_FFMPEG: handler_name :
05-08 20:27:23.872 I/TAG_FFMPEG: SoundHandler
05-08 20:27:23.872 D/TAG_FFMPEG: Successfully opened the file.
05-08 20:27:23.872 D/TAG_FFMPEG: Parsing a group of options: input url /storage/emulated/0/Music/逃跑计划.
05-08 20:27:23.872 D/TAG_FFMPEG: Successfully parsed a group of options.
05-08 20:27:23.872 D/TAG_FFMPEG: Opening an input file: /storage/emulated/0/Music/逃跑计划.
05-08 20:27:23.872 D/TAG_FFMPEG: Opening '/storage/emulated/0/Music/逃跑计划' for reading
05-08 20:27:23.872 D/TAG_FFMPEG: Setting default whitelist 'file,crypto'
05-08 20:27:23.873 E/TAG_FFMPEG: /storage/emulated/0/Music/逃跑计划: No such file or directory
05-08 20:27:23.874 D/TAG_FFMPEG: Statistics: 116284 bytes read, 2 seeks
05-08 20:27:23.874 A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x2c in tid 28446 (RxCachedThreadS)
是因为路径中有空格导致的,使用构建命令,使用RxFFmpegCommandList构建,可以有效避免路径带有空格等问题。 注意:逢命令中的一个空格,进行一次append,不可以任意分段进行 append 谢谢大神指导。
[0:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=0.2[a0];[1:a]aformat=sample_fmts=fltp:sample_rates=44100:channel_layouts=stereo,volume=1,aloop=loop=-1:size=2e+09[a1];[a0][a1]amix=inputs=2:duration=first[aout]
背景音乐循环
这边的需求是音频较短,视频较长,所以拼接了音频,使音频可以填满视频。 使用的命令如下: 我在电脑上测试,发现有同样的问题: