Get video Duration using (NReco.VideoInfo.LT)

MelodyS

Member
Joined
Nov 22, 2021
Messages
13
Programming Experience
1-3
I installed NReco.VideoInfo.LT version 1.1.0 to get the duration of a video
ffprobe error:
using System;

using NReco.VideoInfo;

namespace VideoDuration
{
    class Program
    {
        static void Main(string[] args)
        {
          
            var filePath = args.Length > 0 ? args[0] : "Fayrouz.mp4";
            

            var ffProbe = new FFProbe();
            var videoInfo = ffProbe.GetMediaInfo(filePath);

            Console.WriteLine("Duration: {0}", videoInfo.Duration);

            Console.WriteLine("\nPress any key to exit...");
            Console.ReadKey();

        }
    }
}

When trying to run it ,it throws an error :
System.Exception: 'Cannot locate FFProbe: C:\Users\NAGHAM\source\repos\VideoDuration\VideoDuration\bin\Debug\net5.0\ffprobe.exe'

Any help please !!
 
The NReco website says this in the what's new section:
  • in ASP.NET apps ffprobe is extracted to 'App_Data' instead of 'bin' folder to prevent app restart
That suggests that the ffprobe executable is supposed to be being extracted to your application output folder on build. I wonder whether it's being extracted to the bin folder instead of the bin\Debug\net5.0 folder. I'd check that first. Not sure how or if you could fix it if it's being extracted to the wrong place. Might be worth reporting that as a bug to NReco and, in the meantime, adding a post-build task to move that file to the correct folder. You would do that in the project property pages.
 
@jmcilhinney I'm working on a C#(.NET Application)
I installed a zip file with all exe related to ffprobe and moved them to my project folder ,But I got a new error :
System.Exception: 'ffprobe version N-103134-gaccfd015e3 Copyright (c) 2007-2021 the FFmpeg developers
built with gcc 10.3.0 (Rev5, Built by MSYS2 project)
configuration: --disable-static --enable-shared --pkg-config=pkgconf --cc='ccache gcc' --cxx='ccache g++' --disable-autodetect --enable-amf --enable-bzlib --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-iconv --enable-lzma --enable-nvenc --enable-zlib --enable-sdl2 --enable-ffnvcodec --enable-nvdec --enable-cuda-llvm --enable-libmp3lame --enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libdav1d --enable-libaom --disable-debug --enable-fontconfig --enable-libass --enable-libbluray --enable-libfreetype --enable-libmfx --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libwebp --enable-libxml2 --enable-libzimg --enable-libshine --enable-gpl --enable-avisynth --enable-libxvid --enable-libopenmpt --enable-version3 --enable-libsrt --enable-libgsm --enable-libvmaf --enable-libsvtav1 --enable-librtmp --enable-mbedtls --extra-cflags=-DLIBTWOLAME_STATIC --extra-libs=-lstdc++ --extra-cflags=-DLIBXML_STATIC --extra-libs=-liconv --disable-w32threads
libavutil 57. 3.100 / 57. 3.100
libavcodec 59. 4.100 / 59. 4.100
libavformat 59. 4.101 / 59. 4.101
libavdevice 59. 0.100 / 59. 0.100
libavfilter 8. 1.103 / 8. 1.103
libswscale 6. 0.100 / 6. 0.100
libswresample 4. 0.100 / 4. 0.100
libpostproc 56. 0.100 / 56. 0.100
Fayrouz.mp4: No such file or directory

Any help how can I solve it ?
 
Given that NReco.VideoInfo is supposed to use its own embedded version of ffprobe, it doesn't seem like installing it separately is the best solution. It may well work though.

The error message indicates that it is unable to find your video file. Is it located in the same folder as the ffprobe.exe file? If not then that is probably the issue. If it is then I'm not sure where it is looking for it. Regardless, it is almost never a good idea to use a file name alone rather than a full file path. If your video file is in the same folder as your own executable then that's what you should specify. It's not as easy to do that in a console app as in a WinForms app but it's still possible, e.g.
C#:
var applicationStartupPath = new Uri(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)).LocalPath;
var filePath = System.IO.Path.Combine(applicationStartupPath, "Fayrouz.mp4");
 
@jmcilhinney Yes when I move the mp4 folder into the ffprobe.exe path ,it worked with just this line of code var filePath = args.Length > 0 ? args[0] : "Fayrouz.mp4";
Thank you for your help !
But another question if I'm working on a big website where it requires a lot of videos ,is it logic to move their path into ffprobe extension ?.
Or how should I work with such issue ?
 
It would make sense to have all your videos in the same folder somewhere, then specify that folder path when referring to a file. That folder should almost certainly not be the same folder as your EXE, but the application's current directory will be assumed if you don't provide a path. The current directory will often be the folder the EXE was run from but but certainly not always, and it can be changed while the app is running too.
 
I would also recommend exercising extreme caution if you are letting user upload files. The App_Data directory normally allows writes into the directory. That means that anyone with upload capabilities into your app can potentially overwite the executable that is also sitting in your App_Data directory. A malicious user can replace your the NReco version with their own version that has its own malicious payload. Most IIS users (out of frustration figuring out minimum permissions needed) will replace the default app pool identity with a more powerful identity that has admin rights to the entire machine (and/or network). Or even with sticking with the default app pool identity, the app still has pretty powerful rights since it is running effectively as the NetworkService identity which has a lot of machine rights. When NReco is called by your ASP.NET app, it will be running with the app pool identity. Beware.
 
Back
Top Bottom