gpt4 book ai didi

c# - 在 asp.net 应用程序中使用 ffmpeg 查找水印路径时出错

转载 作者:行者123 更新时间:2023-12-04 22:56:23 24 4
gpt4 key购买 nike

我正在使用 .net ffmpeg wrapper在视频上发布水印。如果我直接执行 ffmpeg 命令,但如果通过 asp.net 应用程序执行命令,则无法找到合适的水印 png 文件位置,则发布水印工作正常。

这是示例 ffmpeg 命令

string RootPath = HttpContext.Current.Server.MapPath(HttpContext.Current.Request.ApplicationPath);
_mhandler.FFMPEGPath = RootPath + "/ffmpeg_aug_2013/bin/ffmpeg.exe";
_mhandler.InputPath = RootPath + "/contents/original";
_mhandler.OutputPath = RootPath + "/contents/mp4";
_mhandler.BackgroundProcessing = false;
_mhandler.FileName = "wildlife.wmv";
_mhandler.OutputFileName = "wildlife_ddd";
string presetpath = RootPath + "/ffmpeg_aug_2013/presets/libx264-ipod640.ffpreset";
_mhandler.OutputExtension = ".mp4";
_mhandler.Parameters = "-s 640x380 -b:v 500k -bufsize 500k -b:a 128k -ar 44100 -c:v libx264 -vf \"movie = watermark.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:main_h-overlay_h-10 [out]\"";
_mhandler.Parameters = _mhandler.Parameters + " -fpre \"" + presetpath + "\"";
VideoInfo info = _mhandler.Process();

我也试过直接代码
string _out = "";
Process _process = new Process();
_process.StartInfo.UseShellExecute = false;
_process.StartInfo.RedirectStandardInput = true;
//_process.StartInfo.RedirectStandardOutput = true;
_process.StartInfo.RedirectStandardError = true;
_process.StartInfo.CreateNoWindow = true;
_process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
_process.StartInfo.FileName = _ffmpegpath;
_process.StartInfo.Arguments = cmd;
if (_process.Start())
{
_process.WaitForExit(ExitProcess);
_out = _process.StandardError.ReadToEnd();
if (!_process.HasExited)
_process.Kill();

return _out;
}

ffmpeg 错误输出为

FFMPEG Output:ffmpeg version N-55753-g88909be Copyright (c) 2000-2013 the FFmpeg developers built on Aug 24 2013 21:40:51 with gcc 4.7.3 (GCC) configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetype --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib libavutil 52. 42.100 / 52. 42.100 libavcodec 55. 29.100 / 55. 29.100 libavformat 55. 14.102 / 55. 14.102 libavdevice 55. 3.100 / 55. 3.100 libavfilter 3. 82.102 / 3. 82.102 libswscale 2. 5.100 / 2. 5.100 libswresample 0. 17.103 / 0. 17.103 libpostproc 52. 3.100 / 52. 3.100 [asf @ 024c9960] Stream #0: not enough frames to estimate rate; consider increasing probesize Guessed Channel Layout for Input Stream

0.0 : stereo Input #0, asf, from 'F:\own\mhp_new/contents/original\wildlife.wmv': Metadata:

SfOriginalFPS : 299700 WMFSDKVersion : 11.0.6001.7000 WMFSDKNeeded : 0.0.0.0000 comment : Footage: Small World Productions, Inc; Tourism New Zealand | Producer: Gary F. Spradling | Music: Steve Ball title : Wildlife in HD copyright : © 2008 Microsoft Corporation IsVBR : 0 DeviceConformanceTemplate: AP@L3 Duration: 00:00:30.09, start: 0.000000, bitrate: 6977 kb/s Stream #0:0(eng): Audio: wmav2 (a1[0][0] / 0x0161), 44100 Hz, stereo, fltp, 192 kb/s Stream

0:1(eng): Video: vc1 (Advanced) (WVC1 / 0x31435657), yuv420p, 1280x720, 5942 kb/s, 29.97 tbr, 1k tbn, 1k tbc [image2 @ 024c76e0]

Could find no file with path 'watermark.png' and index in the range 0-4 [Parsed_movie_0 @ 024c0540] Failed to avformat_open_input 'watermark.png' [AVFilterGraph @ 024ca100] Error initializing filter 'movie' with args 'watermark.png' Error opening filters! Error Code= 0



点错误(找不到路径为 'watermark.png' 的文件)显示 watermark.png 文件未找到。
我将 watermark.png 文件放在以下位置但仍然找不到

i: 应用程序根

ii: 实际 aspx 页面所在的根目录

三:ffmpeg根

四:ffmpeg/bin/

我也使用了完整路径,但仍然无法检测到。

注意:如果我在 php 中使用相同的 ffmpeg 命令并将 watermark.png 放置在实际 php 页面存在的位置,水印被正确检测到并且命令正确执行,但同样的方法在 asp.net 中不起作用

谁能帮我把 watermark.png 文件放在哪里,以便脚本可以访问它。

最佳答案

对于您的问题,我不知道您是如何准确执行 ffmpeg 的,因为您没有发布相应的代码,所以我会更笼统地回答。

当您通过相对路径( watermark.png )引用某个文件时,它必须位于 current working directory 中。 , 当然。

普通子进程从创建子进程的进程(又名你的 asp.net 应用程序和/或 web 服务器)继承当前工作目录,或者除非明确设置,否则实现可能会选择一些默认路径。然而,大多数 API 允许您为要创建的进程指定一个初始工作目录,例如ProcessStartInfo .

  • 要么让您的代码为子进程设置正确的工作目录。
  • 或者通过绝对路径引用文件。但是请注意,您可能需要转义路径和命令行的其余部分,甚至可能多次转义(诸如“\”或空格之类的东西)。

  • 例如。这是一个对我有用的完整示例:
    using System;
    using System.Diagnostics;
    using System.IO;

    namespace ffmpeg_test
    {
    class Program
    {
    static readonly string exe = @"E:\ffmpeg-zeranoe\bin\ffmpeg.exe";
    static readonly string invid = @"E:\in.avi";
    static readonly string outvid = @"E:\out.avi";

    static void Main(string[] args)
    {
    using (var proc = new Process()) {
    Console.WriteLine("Current Directory: {0}", Directory.GetCurrentDirectory());
    proc.StartInfo.UseShellExecute = false;
    proc.StartInfo.FileName = exe;
    proc.StartInfo.WorkingDirectory = new FileInfo(invid).Directory.FullName;
    Console.WriteLine("Working Directory: {0}", proc.StartInfo.WorkingDirectory);
    proc.StartInfo.Arguments = string.Format(
    "-y -i \"{0}\" -vf \"movie=watermark.png [watermark]; [in][watermark] overlay=10:10 [out]\" {1}",
    invid, outvid);
    Console.WriteLine("Arguments: {0}", proc.StartInfo.Arguments);
    proc.StartInfo.LoadUserProfile = false;
    proc.Start();
    proc.WaitForExit();
    Console.WriteLine("Result: {0}", proc.ExitCode);
    }
    }
    }
    }

    和输出:
    E:\MSVC\ffmpeg_test\bin\Debug>dir e:\watermark.png e:\in.avi /B
    watermark.png
    in.avi

    E:\MSVC\ffmpeg_test\bin\Debug>ffmpeg_test.exe
    Current Directory: E:\MSVC\ffmpeg_test\bin\Debug
    Working Directory: E:\
    Arguments: -y -i "E:\in.avi" -vf "movie=watermark.png [watermark]; [in][watermark] overlay=10:10 [out]" E:\out.avi
    ffmpeg version N-55796-gb74213d Copyright (c) 2000-2013 the FFmpeg developers
    built on Aug 26 2013 19:43:51 with gcc 4.7.3 (GCC)
    configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-avisynth --enable-bzlib --enable-fontconfi
    g --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libcaca --enable-libfreetyp
    e --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopenco
    re-amrwb --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsoxr --enable-libsp
    eex --enable-libtheora --enable-libtwolame --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvorbis --enable-lib
    vpx --enable-libx264 --enable-libxavs --enable-libxvid --enable-zlib
    libavutil 52. 42.100 / 52. 42.100
    libavcodec 55. 29.100 / 55. 29.100
    libavformat 55. 14.102 / 55. 14.102
    libavdevice 55. 3.100 / 55. 3.100
    libavfilter 3. 82.102 / 3. 82.102
    libswscale 2. 5.100 / 2. 5.100
    libswresample 0. 17.103 / 0. 17.103
    libpostproc 52. 3.100 / 52. 3.100
    Input #0, avi, from 'E:\in.avi':
    Metadata:
    encoder : Lavf55.13.103
    Duration: 00:00:25.46, start: 0.000000, bitrate: 2944 kb/s
    Stream #0:0: Video: h264 (High) (H264 / 0x34363248), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 47.95 fps, 23.98 tbr, 47.
    95 tbn, 47.95 tbc
    Stream #0:1: Audio: mp3 (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p, 192 kb/s
    Output #0, avi, to 'E:\out.avi':
    Metadata:
    ISFT : Lavf55.14.102
    Stream #0:0: Video: mpeg4 (FMP4 / 0x34504D46), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 23.98 tbn, 23
    .98 tbc
    Stream #0:1: Audio: mp3 (libmp3lame) (U[0][0][0] / 0x0055), 48000 Hz, stereo, s16p
    Stream mapping:
    Stream #0:0 -> #0:0 (h264 -> mpeg4)
    Stream #0:1 -> #0:1 (mp3 -> libmp3lame)
    Press [q] to stop, [?] for help
    frame= 609 fps=146 q=31.0 Lsize= 3614kB time=00:00:25.56 bitrate=1158.0kbits/s
    video:3169kB audio:396kB subtitle:0 global headers:0kB muxing overhead 1.379961%
    Result: 0

    哦,out.avi 当然包含水印。 ;)

    关于c# - 在 asp.net 应用程序中使用 ffmpeg 查找水印路径时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18469719/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com