.net利用ffmpeg视频加水印方法-新闻详情

.net利用ffmpeg视频加水印方法


发布时间:2016-11-08责任编辑:朱明 浏览:1806


1.1       ffmpeg格式

ffmpeg [[options][`-i' input_file]]... {[options] output_file}...

如果没有输入文件,那么视音频捕捉(只在Linux下有效,因为Linux下把音视频设备当作文件句柄来处理)就会起作用。作为通用的规则,选项一般用于下一个特定的文件。如果你给 –b 64选项,改选会设置下一个视频速率。对于原始输入文件,格式选项可能是需要的。缺省情况下,ffmpeg试图尽可能的无损转换,采用与输入同样的音频视频参数来输出。

1.2      流复制:复制文件的流,只更改容器(文件)格式。

./ffmpeg –v debug –i inputfile.mpg –c copy  -f asf outfile.asf

-f:设置混合器

-c:设置编码器。当为 copy:指复制编码流

-i:输入文件

-v:调试信息级别(quietpanicfatalerrorwarninginfoverbosedebug

ASP.NET下使用:


[csharp]
//
添加水印,fileName视频地址,imgFile水印图片地址,outputFile输出地址  
public int WaterMark(string fileName, string imgFile, string outputFile) 

    //
取得ffmpeg.exe的路径,路径配置在Web.Config,:<add   key="ffmpeg"   value="E:aspx1ffmpeg.exe"   />     
    string ffmpeg = Server.MapPath(PublicMethod.ffmpegbin); 
    if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(fileName))) 
    { 
        return 0; 
    } 
    //
建立ffmpeg进程  
    System.Diagnostics.ProcessStartInfo WaterMarkstartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg); 
    //
后台运行  
    WaterMarkstartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; 
    //
运行参数  
    string config="   -i   " + fileName + " -vf "movie=" + imgFile + " [watermark]; [in][watermark] overlay=0:0 [out]" " + outputFile; 
    WaterMarkstartInfo.Arguments = config; 
    try 
    { 
        //
开始加水印  
        System.Diagnostics.Process.Start(WaterMarkstartInfo); 
    } 
    catch 
    { 
        return 0; 
    } 
     
    return 1; 

    //添加水印,fileName视频地址,imgFile水印图片地址,outputFile输出地址
    public int WaterMark(string fileName, string imgFile, string outputFile)
    {
        //
取得ffmpeg.exe的路径,路径配置在Web.Config,:<add   key="ffmpeg"   value="E:aspx1ffmpeg.exe"   />  
        string ffmpeg = Server.MapPath(PublicMethod.ffmpegbin);
        if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(fileName)))
        {
            return 0;
        }
        //
建立ffmpeg进程
        System.Diagnostics.ProcessStartInfo WaterMarkstartInfo = new System.Diagnostics.ProcessStartInfo(ffmpeg);
        //
后台运行
        WaterMarkstartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
        //
运行参数
        string config="   -i   " + fileName + " -vf "movie=" + imgFile + " [watermark]; [in][watermark] overlay=0:0 [out]" " + outputFile;
        WaterMarkstartInfo.Arguments = config;
        try
        {
            //
开始加水印
            System.Diagnostics.Process.Start(WaterMarkstartInfo);
        }
        catch
        {
            return 0;
        }
       
        return 1;
    }

 

 

敬业工作室  供稿