Reputation: 6571
I am using .net ffmpeg wrapper to post watermark on videos. Posting watermark works fine if i execute ffmpeg command directly but failed to find suitable watermark png file location if command executed via asp.net application.
here is sample ffmpeg command
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();
i tried direct code too
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 error output as
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
Error on point ( Could find no file with path 'watermark.png' ) shows watermark.png file not found. I place watermark.png file in the following locations but still can't found
i: application root
ii: root where actual aspx page located
iii: ffmpeg root
iv: ffmpeg/bin/
I also used complete path but still can't detected.
Note: if i use same ffmpeg command in php and place watermark.png on location where actual php page exist watermark properly detected and command executed properly, but same approach not working in asp.net
Can any one help me where should i place watermark.png file so that script can access it.
Upvotes: 1
Views: 1712
Reputation: 33192
For your question I have no clue how you execute ffmpeg exactly, as you didn't post the corresponding code, so I will answer more generally speaking.
When you refer to some file by a relative path (watermark.png
) it must be located in the current working directory, of course.
Normal subprocesses inherit the current working directory from the process creating the subprocess (aka. your asp.net app and/or webserver) or the implementation may choose some default path unless set explicitly. However most APIs let you specify an initial working directory for the process to be created, e.g. ProcessStartInfo.
E.g. Here is a complete example that works for me:
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);
}
}
}
}
And the output:
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
Oh, and out.avi of course contains the watermark. ;)
Upvotes: 2