2014-04-09 09:16 阅读 57


I would like to merge a flv with mp3 without touching / removing flv audio stream using ffmpeg in php. I tried many commands and none helps. Here is the command I am using now.

/usr/bin/ffmpeg -i "4bpCRRV82x.flv"-i "Someday.mp3" -vcodec libx264  -shortest "output.mp4"

But it replaces flv audio with the mp3 inputting. Any help and suggestions will be highly appreciable. Thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    doushi8187 doushi8187 2014-04-10 22:53

    Assuming both inputs contain stereo audio you can use the amerge audio filter to merge both stereo streams into a single four channel stream, then use the pan audio filter to combine the appropriate channels into a single stereo stream:

    ffmpeg -i video.flv -i audio.mp3 -filter_complex \
    "[0:a][1:a]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[a]" \
    -map 0:v -map "[a]" -c:v copy -c:a aac -strict experimental -shortest out.mp4
    • The video can be stream copied (depending on the input video format) as shown in the example if you do not need to re-encode it, but if you must re-encode then see the FFmpeg and x264 Encoding Guide.

    • The example uses the native FFmpeg AAC encoder which requires -strict experimental (or the alias -strict -2). See the FFmpeg and AAC Encoding Guide for information on other encoders.

    • The option -shortest will finish encoding when the shortest input stream ends.

    • See Manipulating audio channels with ffmpeg for more examples.

    • Make sure you're using a recent version of ffmpeg. See the FFmpeg Download page for builds for Windows, OS X, and Linux.

    点赞 评论 复制链接分享
  • douyan8413 douyan8413 2014-04-09 11:06

    As of the ffmpeg documentation you may use the amerge filter

    ffmpeg -i input.mkv -filter_complex "[0:1][0:2][0:3][0:4][0:5][0:6] amerge=inputs=6" -c:a pcm_s16le output.mkv
    点赞 评论 复制链接分享
  • dongmi8980 dongmi8980 2014-04-10 15:06

    FLV does not support multiple audio streams. Technically is is possible in the binary format by incrementing the stream id. However the FLV documentation says the stream id should always be 0. so even if you did create this file, most players would not play it.

    点赞 评论 复制链接分享