FFMPEG 实现混音,加水印,加文字,模糊水印任意滤镜组合

2019-01-12 22:53:30

一共15种组合一下搞定;先伪代码没逻辑错误,然后就撸正式代码,后面测试就有点小顺利了

伪代码:

根据参数构造ffmpeg参数命令
构造元素视频方面有水印,文字,去水印;音频方面有混音一个
构造顺序: 先音频后视频 1:音频 2:水印 3:文字 4:去水印
伪代码
audioExist = false
videoExist = false
var filterPara string
var tailPara string
cmd += ffmpeg -loglevel verbose -i a.mp4
if(音频||水印||文字||去水印)
    filterPara += -filter_complex 
if(音频)
    cmd += -i b.mp3
    filterPara += "[0:a][1:a]amix=inputs=2:duration=shortest:dropout_transition=2[a]"
    tailPara += '-map 0:v:0 -map "[a]"'
    audioExist = true
if(水印)
    cmd += -i c.jpg
    if(audioExist)
        filterPara += ;[2:v]scale=94:167[vv];[0:v][vv]overlay=102:102
    else
        filterPara += [1:v]scale=94:167[vv];[0:v][vv]overlay=102:102
    videoExist = true
if(文字)
    if(!audioExist&&!videoExist)
        filterPara += ""
    else if(videoExist)
        filterPara += ","
    else 
        filterPara += ";"
    filterPara += ...
    videoExist = true
if(去水印)
    if(!audioExist&&!videoExist)
        filterPara += ""
    else if(videoExist)
        filterPara += ","
    else 
        filterPara += ";"
    filterPara += ...
tailPara += -f mp4 -movflags faststart fileName.mp4 -y
 
cmd += filterPara + tailPara



测试

4个滤镜全组合: 4+6+4+1 = 15种情况

四个全选

//音频+水印+文本+去水印  

curl -i -d '{"audiourl":"http://zxw-ybktest.chinacloudapp.cn/otvcloud_y1cc0ca0-f176-44d3-9d6c-d0634e71c5f6.mp3","cpid":"yz","mp4url":"http://183.131.106/lzy2214test.mp4","returl":"http://180.11.29.170:8880/backend-web/content/recReEditUrl.do","taskid":"1","imagelayers":{"height":"167","offsetX":"102","offsetY":"102","src":"http://13.131.159.21:1006/lzy/1522458959462-1522458959386_24_u=657178443,1345964771&fm=27&gp=0.jpg","width":"94"},"delogo":{"height":"20","offsetX":"10","offsetY":"10","width":"100"},"txtlayers":[{"fontColor":"#000000","fontSize":"14","offsetX":"305","offsetY":"277","text":"world"},{"fontColor":"#000000","fontSize":"14","offsetX":"100","offsetY":"100","text":"hello"}]}' http://183.11.19.27:8080/editvod



  • 2019-12-18 23:26:00

    FFMPEG命令记录

    ffmpeg,拼接两个音频,剪切音频片段,多个音频混音,剪切一段MP4并转换成gif,改变音量大小,音频淡入淡出,音频格式处理

  • 2019-12-19 00:04:44

    ffmpeg concat video and mix audio

    在ffmpeg中,官网给出两种连接媒体文件(音频、视频、etc..)的解决方案。 the concat "demuxer" the concat "protocol" 对比而言, demuxer更加灵活一些,需要媒体文件是属于相同的编解码器,但是可以属于不同的容器格式(mp3,wav, mp4, mov, etc..). 而protocol只适用于少数集中容器格式。

  • 2019-12-19 00:16:30

    android采用FFmpeg实现音频混合与拼接剪切

    接触FFmpeg有一段时间了,它是音视频开发的开源库,几乎其他所有播放器、直播平台都基于FFmpeg进行二次开发。本篇文章来总结下采用FFmpeg进行音频处理:音频混合、音频剪切、音频拼接与音频转码。

  • 2019-12-19 15:01:58

    spring boot 在Linux下服务启动报错Unable to find Java

    将 Spring boot 安装为 Linux 服务启动,后输入 service myapp start 报错 Unable to find Java ,但是使用 java -jar myapp.jar 启动成功。不知道为啥引起的,经过百度找到下面这个解决方法和我的情况一样,终于把问题解决

  • 2019-12-19 16:44:01

    根据条件配置多个npm仓库

    scope 是一种很好的包管理方式。统一的“命名空间”,清晰、好辨识;在 registry 中使用统一的 organization 管理,不必担心命名冲突和冒用等。 在实际使用中,一个常见的场景是公司的私有仓库。使用统一的 scope 定义在私有仓库中定义私有包,绝对是一个非常好的方式。 指定 scope 从指定仓库安装