一共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