Giter VIP home page Giter VIP logo

Comments (15)

DJSures avatar DJSures commented on June 4, 2024 1

Use practical programming techniques. Try this.

  1. use Usings
  2. use the FourCC.H264
  3. use a mat for the resize
  4. sure you want a frame rate of 1?
using (VideoWriter writer = new VideoWriter(
  "20240201.mp4", 
   FourCC.H264,
  1, 
  new OpenCvSharp.Size(1920, 1080), 
  true)) {

var path = Path.Combine(AppContext.BaseDirectory, "Images");

using (Mat resized = new Mat()) 
foreach (var item in Directory.GetFiles(path)) {

   using (Mat  mat = Cv2.ImRead(item, ImreadModes.Color)) {

    Cv2.Resize(mat, resized, new OpenCvSharp.Size(1920, 1080));

    writer.Write(resized);
  }
}
}

from opencvsharp.

DJSures avatar DJSures commented on June 4, 2024

Do not use the Sdcb.OpenCvSharp4.mini.runtime.ubuntu.22.04-x64. Notice the word "mini" in the title. That means it is missing features.

Use the opencvsharp4 correct nuget. Open CV has their own native binding nuget packages. You can tell that because they're not named "SDCB". And, they have the open cv logo next to them.

image

from opencvsharp.

1764564459 avatar 1764564459 commented on June 4, 2024

Do not use the Sdcb.OpenCvSharp4.mini.runtime.ubuntu.22.04-x64. Notice the word "mini" in the title. That means it is missing features.

Use the opencvsharp4 correct nuget. Open CV has their own native binding nuget packages. You can tell that because they're not named "SDCB". And, they have the open cv logo next to them.

image

Thank you for your reply. After using the package you provided, I encountered an error:

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HN0U21A3VC7G", Request id "0HN0U21A3VC7G:00000002": An unhandled exception was thrown by the application.
      System.TypeInitializationException: The type initializer for 'OpenCvSharp.Internal.NativeMethods' threw an exception.
       ---> System.DllNotFoundException: Unable to load shared library 'OpenCvSharpExtern' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: libOpenCvSharpExtern: cannot open shared object file: No such file or directory
         at OpenCvSharp.Internal.NativeMethods.redirectError(CvErrorCallback errCallback, IntPtr userdata, IntPtr& prevUserdata)
         at OpenCvSharp.Internal.ExceptionHandler.RegisterExceptionCallback()
         at OpenCvSharp.Internal.NativeMethods.LoadLibraries(IEnumerable`1 additionalPaths)
         at OpenCvSharp.Internal.NativeMethods..cctor()
         --- End of inner exception stack trace ---
         at OpenCvSharp.Internal.NativeMethods.videoio_VideoWriter_fourcc(SByte c1, SByte c2, SByte c3, SByte c4, Int32& returnValue)
         at Program.<>c.<<Main>$>b__0_0() in /mediator/Program.cs:line 261
         at lambda_method1(Closure , Object , HttpContext )
         at Microsoft.AspNetCore.Http.RequestDelegateFactory.<>c__DisplayClass36_0.<Create>b__0(HttpContext httpContext)
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
  • The installed project provides examples of installation related dependencies#L9
  • /app# ldd runtimes/ubuntu.20.04-x64/native/libOpenCvSharpExtern.so Display Results:
linux-vdso.so.1 (0x00007ffdd9f4b000)
        libtesseract.so.4 => /lib/x86_64-linux-gnu/libtesseract.so.4 (0x00007f14ad059000)
        libgtk-x11-2.0.so.0 => /lib/x86_64-linux-gnu/libgtk-x11-2.0.so.0 (0x00007f14acbe2000)
        libgdk-x11-2.0.so.0 => /lib/x86_64-linux-gnu/libgdk-x11-2.0.so.0 (0x00007f14acb21000)
        libcairo.so.2 => /lib/x86_64-linux-gnu/libcairo.so.2 (0x00007f14ac9f9000)
        libgdk_pixbuf-2.0.so.0 => /lib/x86_64-linux-gnu/libgdk_pixbuf-2.0.so.0 (0x00007f14ac9c9000)
        libgobject-2.0.so.0 => /lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f14ac967000)
        libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f14ac82d000)
        libdc1394.so.22 => not found
        libavcodec.so.58 => /lib/x86_64-linux-gnu/libavcodec.so.58 (0x00007f14ab425000)
        libavformat.so.58 => /lib/x86_64-linux-gnu/libavformat.so.58 (0x00007f14ab18c000)
        libavutil.so.56 => /lib/x86_64-linux-gnu/libavutil.so.56 (0x00007f14aaed3000)
        libswscale.so.5 => /lib/x86_64-linux-gnu/libswscale.so.5 (0x00007f14aae33000)
        libjpeg.so.8 => /lib/x86_64-linux-gnu/libjpeg.so.8 (0x00007f14aadb2000)
        libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f14aad77000)
        libtiff.so.5 => /lib/x86_64-linux-gnu/libtiff.so.5 (0x00007f14aacf0000)
        libIlmImf-2_3.so.24 => not found
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f14aacd4000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f14aaccd000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f14aacc8000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f14aaa9c000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f14aa9b5000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f14aa995000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f14aa76c000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f14b124c000)
        libarchive.so.13 => /lib/x86_64-linux-gnu/libarchive.so.13 (0x00007f14aa6a0000)
        liblept.so.5 => /lib/x86_64-linux-gnu/liblept.so.5 (0x00007f14aa3f5000)
        libgomp.so.1 => /lib/x86_64-linux-gnu/libgomp.so.1 (0x00007f14aa3ab000)
        libgmodule-2.0.so.0 => /lib/x86_64-linux-gnu/libgmodule-2.0.so.0 (0x00007f14aa3a4000)
        libpangocairo-1.0.so.0 => /lib/x86_64-linux-gnu/libpangocairo-1.0.so.0 (0x00007f14aa392000)
        libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f14aa252000)
        libXfixes.so.3 => /lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f14aa248000)
        libatk-1.0.so.0 => /lib/x86_64-linux-gnu/libatk-1.0.so.0 (0x00007f14aa21e000)
        libgio-2.0.so.0 => /lib/x86_64-linux-gnu/libgio-2.0.so.0 (0x00007f14aa045000)
        libpangoft2-1.0.so.0 => /lib/x86_64-linux-gnu/libpangoft2-1.0.so.0 (0x00007f14aa02a000)
        libpango-1.0.so.0 => /lib/x86_64-linux-gnu/libpango-1.0.so.0 (0x00007f14a9fc3000)
        libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f14a9f79000)
        libXrender.so.1 => /lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f14a9f6a000)
        libXinerama.so.1 => /lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f14a9f65000)
        libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x00007f14a9f51000)
        libXrandr.so.2 => /lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f14a9f44000)
        libXcursor.so.1 => /lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f14a9f38000)
        libXcomposite.so.1 => /lib/x86_64-linux-gnu/libXcomposite.so.1 (0x00007f14a9f33000)
        libXdamage.so.1 => /lib/x86_64-linux-gnu/libXdamage.so.1 (0x00007f14a9f2c000)
        libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x00007f14a9f17000)
        libpixman-1.so.0 => /lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007f14a9e6c000)
        libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f14a9da4000)
        libxcb-shm.so.0 => /lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007f14a9d9f000)
        libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f14a9d75000)
        libxcb-render.so.0 => /lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007f14a9d64000)
        libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x00007f14a9d57000)
        libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f14a9ce1000)
        libswresample.so.3 => /lib/x86_64-linux-gnu/libswresample.so.3 (0x00007f14a9cbf000)
        libvpx.so.7 => /lib/x86_64-linux-gnu/libvpx.so.7 (0x00007f14a99af000)
        libwebpmux.so.3 => /lib/x86_64-linux-gnu/libwebpmux.so.3 (0x00007f14a99a0000)
        libwebp.so.7 => /lib/x86_64-linux-gnu/libwebp.so.7 (0x00007f14a9933000)
        liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f14a9908000)
        libdav1d.so.5 => /lib/x86_64-linux-gnu/libdav1d.so.5 (0x00007f14a9782000)
        librsvg-2.so.2 => /lib/x86_64-linux-gnu/librsvg-2.so.2 (0x00007f14a8d1a000)
        libzvbi.so.0 => /lib/x86_64-linux-gnu/libzvbi.so.0 (0x00007f14a8c8b000)
        libsnappy.so.1 => /lib/x86_64-linux-gnu/libsnappy.so.1 (0x00007f14a8c7f000)
        libaom.so.3 => /lib/x86_64-linux-gnu/libaom.so.3 (0x00007f14a870f000)
        libcodec2.so.1.0 => /lib/x86_64-linux-gnu/libcodec2.so.1.0 (0x00007f14a7868000)
        libgsm.so.1 => /lib/x86_64-linux-gnu/libgsm.so.1 (0x00007f14a7859000)
        libmp3lame.so.0 => /lib/x86_64-linux-gnu/libmp3lame.so.0 (0x00007f14a77e4000)
        libopenjp2.so.7 => /lib/x86_64-linux-gnu/libopenjp2.so.7 (0x00007f14a778c000)
        libopus.so.0 => /lib/x86_64-linux-gnu/libopus.so.0 (0x00007f14a772c000)
        libshine.so.3 => /lib/x86_64-linux-gnu/libshine.so.3 (0x00007f14a7400000)
        libspeex.so.1 => /lib/x86_64-linux-gnu/libspeex.so.1 (0x00007f14a770e000)
        libtheoraenc.so.1 => /lib/x86_64-linux-gnu/libtheoraenc.so.1 (0x00007f14a76d6000)
        libtheoradec.so.1 => /lib/x86_64-linux-gnu/libtheoradec.so.1 (0x00007f14a76b8000)
        libtwolame.so.0 => /lib/x86_64-linux-gnu/libtwolame.so.0 (0x00007f14a7693000)
        libvorbis.so.0 => /lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007f14a7664000)
        libvorbisenc.so.2 => /lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007f14a7355000)
        libx264.so.163 => /lib/x86_64-linux-gnu/libx264.so.163 (0x00007f14a7094000)
        libx265.so.199 => /lib/x86_64-linux-gnu/libx265.so.199 (0x00007f14a612f000)
        libxvidcore.so.4 => /lib/x86_64-linux-gnu/libxvidcore.so.4 (0x00007f14a601c000)
        libva.so.2 => /lib/x86_64-linux-gnu/libva.so.2 (0x00007f14a7633000)
        libmfx.so.1 => /lib/x86_64-linux-gnu/libmfx.so.1 (0x00007f14a7623000)
        libxml2.so.2 => /lib/x86_64-linux-gnu/libxml2.so.2 (0x00007f14a5e3a000)
        libbz2.so.1.0 => /lib/x86_64-linux-gnu/libbz2.so.1.0 (0x00007f14a7610000)
        libgme.so.0 => /lib/x86_64-linux-gnu/libgme.so.0 (0x00007f14a5dea000)
        libopenmpt.so.0 => /lib/x86_64-linux-gnu/libopenmpt.so.0 (0x00007f14a5c29000)
        libchromaprint.so.1 => /lib/x86_64-linux-gnu/libchromaprint.so.1 (0x00007f14a5c1a000)
        libbluray.so.2 => /lib/x86_64-linux-gnu/libbluray.so.2 (0x00007f14a5bc3000)
        libgnutls.so.30 => /lib/x86_64-linux-gnu/libgnutls.so.30 (0x00007f14a59d8000)
        librabbitmq.so.4 => /lib/x86_64-linux-gnu/librabbitmq.so.4 (0x00007f14a59c0000)
        libsrt-gnutls.so.1.4 => /lib/x86_64-linux-gnu/libsrt-gnutls.so.1.4 (0x00007f14a5901000)
        libssh-gcrypt.so.4 => /lib/x86_64-linux-gnu/libssh-gcrypt.so.4 (0x00007f14a5876000)
        libzmq.so.5 => /lib/x86_64-linux-gnu/libzmq.so.5 (0x00007f14a57da000)
        libva-drm.so.2 => /lib/x86_64-linux-gnu/libva-drm.so.2 (0x00007f14a57d5000)
        libva-x11.so.2 => /lib/x86_64-linux-gnu/libva-x11.so.2 (0x00007f14a57cd000)
        libvdpau.so.1 => /lib/x86_64-linux-gnu/libvdpau.so.1 (0x00007f14a57c7000)
        libdrm.so.2 => /lib/x86_64-linux-gnu/libdrm.so.2 (0x00007f14a57b1000)
        libOpenCL.so.1 => /lib/x86_64-linux-gnu/libOpenCL.so.1 (0x00007f14a579f000)
        libzstd.so.1 => /lib/x86_64-linux-gnu/libzstd.so.1 (0x00007f14a56ce000)
        libjbig.so.0 => /lib/x86_64-linux-gnu/libjbig.so.0 (0x00007f14a56bd000)
        libdeflate.so.0 => /lib/x86_64-linux-gnu/libdeflate.so.0 (0x00007f14a5699000)
        libnettle.so.8 => /lib/x86_64-linux-gnu/libnettle.so.8 (0x00007f14a5653000)
        libacl.so.1 => /lib/x86_64-linux-gnu/libacl.so.1 (0x00007f14a5649000)
        liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007f14a5627000)
        libgif.so.7 => /lib/x86_64-linux-gnu/libgif.so.7 (0x00007f14a561c000)
        libharfbuzz.so.0 => /lib/x86_64-linux-gnu/libharfbuzz.so.0 (0x00007f14a554d000)
        libmount.so.1 => /lib/x86_64-linux-gnu/libmount.so.1 (0x00007f14a5509000)
        libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f14a54dd000)
        libfribidi.so.0 => /lib/x86_64-linux-gnu/libfribidi.so.0 (0x00007f14a54bf000)
        libthai.so.0 => /lib/x86_64-linux-gnu/libthai.so.0 (0x00007f14a54b4000)
        libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f14a5483000)
        libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f14a547a000)
        libbrotlidec.so.1 => /lib/x86_64-linux-gnu/libbrotlidec.so.1 (0x00007f14a546c000)
        libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f14a5464000)
        libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f14a545c000)
        libsoxr.so.0 => /lib/x86_64-linux-gnu/libsoxr.so.0 (0x00007f14a53f5000)
        libcairo-gobject.so.2 => /lib/x86_64-linux-gnu/libcairo-gobject.so.2 (0x00007f14a53e9000)
        libogg.so.0 => /lib/x86_64-linux-gnu/libogg.so.0 (0x00007f14a53de000)
        libnuma.so.1 => /lib/x86_64-linux-gnu/libnuma.so.1 (0x00007f14a53cf000)
        libicuuc.so.70 => /lib/x86_64-linux-gnu/libicuuc.so.70 (0x00007f14a51d4000)
        libmpg123.so.0 => /lib/x86_64-linux-gnu/libmpg123.so.0 (0x00007f14a5178000)
        libvorbisfile.so.3 => /lib/x86_64-linux-gnu/libvorbisfile.so.3 (0x00007f14a516d000)
        libudfread.so.0 => /lib/x86_64-linux-gnu/libudfread.so.0 (0x00007f14a5162000)
        libp11-kit.so.0 => /lib/x86_64-linux-gnu/libp11-kit.so.0 (0x00007f14a5025000)
        libidn2.so.0 => /lib/x86_64-linux-gnu/libidn2.so.0 (0x00007f14a5004000)
        libunistring.so.2 => /lib/x86_64-linux-gnu/libunistring.so.2 (0x00007f14a4e5a000)
        libtasn1.so.6 => /lib/x86_64-linux-gnu/libtasn1.so.6 (0x00007f14a4e42000)
        libhogweed.so.6 => /lib/x86_64-linux-gnu/libhogweed.so.6 (0x00007f14a4dfa000)
        libgmp.so.10 => /lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f14a4d78000)
        libssl.so.3 => /lib/x86_64-linux-gnu/libssl.so.3 (0x00007f14a4cd2000)
        libcrypto.so.3 => /lib/x86_64-linux-gnu/libcrypto.so.3 (0x00007f14a488f000)
        libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f14a4751000)
        libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f14a472b000)
        libgssapi_krb5.so.2 => /lib/x86_64-linux-gnu/libgssapi_krb5.so.2 (0x00007f14a46d7000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f14a46bf000)
        libsodium.so.23 => /lib/x86_64-linux-gnu/libsodium.so.23 (0x00007f14a4665000)
        libpgm-5.3.so.0 => /lib/x86_64-linux-gnu/libpgm-5.3.so.0 (0x00007f14a4614000)
        libnorm.so.1 => /lib/x86_64-linux-gnu/libnorm.so.1 (0x00007f14a44e9000)
        libgraphite2.so.3 => /lib/x86_64-linux-gnu/libgraphite2.so.3 (0x00007f14a44c2000)
        libblkid.so.1 => /lib/x86_64-linux-gnu/libblkid.so.1 (0x00007f14a448b000)
        libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f14a43f2000)
        libdatrie.so.1 => /lib/x86_64-linux-gnu/libdatrie.so.1 (0x00007f14a43e9000)
        libbrotlicommon.so.1 => /lib/x86_64-linux-gnu/libbrotlicommon.so.1 (0x00007f14a43c6000)
        libicudata.so.70 => /lib/x86_64-linux-gnu/libicudata.so.70 (0x00007f14a27a8000)
        libkrb5.so.3 => /lib/x86_64-linux-gnu/libkrb5.so.3 (0x00007f14a26dd000)
        libk5crypto.so.3 => /lib/x86_64-linux-gnu/libk5crypto.so.3 (0x00007f14a26ac000)
        libcom_err.so.2 => /lib/x86_64-linux-gnu/libcom_err.so.2 (0x00007f14a26a6000)
        libkrb5support.so.0 => /lib/x86_64-linux-gnu/libkrb5support.so.0 (0x00007f14a2698000)
        libmd.so.0 => /lib/x86_64-linux-gnu/libmd.so.0 (0x00007f14a268b000)
        libkeyutils.so.1 => /lib/x86_64-linux-gnu/libkeyutils.so.1 (0x00007f14a2684000)
        libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f14a266e000)

from opencvsharp.

DJSures avatar DJSures commented on June 4, 2024

I'm not certain - but this might be worth a try. It seems the nuget package creates a runtime directory for "ubuntu.20.04-x64"

When you build the linux64 project, it isn't copying the libOpenCVSharpExtern.so from the ubuntu.20.04-x64 directory. If you look in the Linux64 directory, you won't see the .so file.

So here's what I suggest.

  1. Build the project
  2. Manually copy the libOpenCVSharpExtern.so from the runtimes\ubuntu.20.04-x64 folder into your bin\Debug

That will put the file in the folder with the executable and it should be found. Try that

from opencvsharp.

DJSures avatar DJSures commented on June 4, 2024

Oh, lastly - i haven't used VideoWriter, so i'm not sure about how the native opencvsharp linux library was compiled. Meaning, I don't know if it includes the ffmpeg bindings or how it works. According to the open cv documentation for VideoWriter, it requires ffmpeg: https://docs.opencv.org/3.4/dd/d9e/classcv_1_1VideoWriter.html

Check with my previous response recommendation and that'll be a first step toward a solution.

from opencvsharp.

1764564459 avatar 1764564459 commented on June 4, 2024

Oh, lastly - i haven't used VideoWriter, so i'm not sure about how the native opencvsharp linux library was compiled. Meaning, I don't know if it includes the ffmpeg bindings or how it works. According to the open cv documentation for VideoWriter, it requires ffmpeg: https://docs.opencv.org/3.4/dd/d9e/classcv_1_1VideoWriter.html

Check with my previous response recommendation and that'll be a first step toward a solution.

Thank you for your reply, so does the runtime environment need to install ffmpeg?

from opencvsharp.

DJSures avatar DJSures commented on June 4, 2024

Thank you for your reply, so does the runtime environment need to install ffmpeg?

You have to install ffmpeg native, i believe. I haven't used it, so I can't be certain. I can only get you as far as using the correct Linux64 bindings for OpenCVSharpExtern.so

If you have success, please share your steps so others can learn from it (including myself!)

from opencvsharp.

1764564459 avatar 1764564459 commented on June 4, 2024

Thank you for your reply, so does the runtime environment need to install ffmpeg?

You have to install ffmpeg native, i believe. I haven't used it, so I can't be certain. I can only get you as far as using the correct Linux64 bindings for OpenCVSharpExtern.so

If you have success, please share your steps so others can learn from it (including myself!)

Hello,I have used the image package provided by the author to address this issue. It can be played using a Windows player, but the browser does not support playback. Is there a solution?

from opencvsharp.

1764564459 avatar 1764564459 commented on June 4, 2024

After setting up FourCC on my end, it already supports browser playback, but black blocks will appear in the first 4 frames of video playback on Windows.

  • code:
VideoWriter writer = new VideoWriter("202401311120.mp4", VideoWriter.FourCC('h', '2', '6', '4') , 1
    , new OpenCvSharp.Size(1920, 1080), true);

from opencvsharp.

DJSures avatar DJSures commented on June 4, 2024

I gave it a shot and it works. You're right about ffmpeg library, it just needs to be installed in the OS.

Here's what i used for the constructor which worked great...

          _vw = new VideoWriter(
            "/tmp/video.mkv",
            FourCC.H264,
            30,
            new Size(320, 240));

from opencvsharp.

1764564459 avatar 1764564459 commented on June 4, 2024

I gave it a shot and it works. You're right about ffmpeg library, it just needs to be installed in the OS.

Here's what i used for the constructor which worked great...

          _vw = new VideoWriter(
            "/tmp/video.mkv",
            FourCC.H264,
            30,
            new Size(320, 240));

A black block will appear in the first 4 frames of a video generated from one image per frame.

from opencvsharp.

DJSures avatar DJSures commented on June 4, 2024

I'd look into your code that's creating the mat, which is being written as a frame. Ensure you're not disposing of it or modifying it in another thread. Also, if you're re-using the same mat, I have yet to try that, but maybe the video writer is threaded. Could you try cloning the mat first and see if that helps? (don't forget to wrap the clone in a using to dispose it) I don't know the inner workings of FFmpeg, such as whether the write() method is threaded.

But I also need to see your code to guess the issue.

from opencvsharp.

1764564459 avatar 1764564459 commented on June 4, 2024

I'd look into your code that's creating the mat, which is being written as a frame. Ensure you're not disposing of it or modifying it in another thread. Also, if you're re-using the same mat, I have yet to try that, but maybe the video writer is threaded. Could you try cloning the mat first and see if that helps? (don't forget to wrap the clone in a using to dispose it) I don't know the inner workings of FFmpeg, such as whether the write() method is threaded.

But I also need to see your code to guess the issue.

The following is the generated video code:

VideoWriter writer = new VideoWriter("20240201.mp4", VideoWriter.FourCC('m', 'p', '4', 'v') , 1
    , new OpenCvSharp.Size(1920, 1080), true);

var path = Path.Combine(AppContext.BaseDirectory, "Images");

foreach (var item in Directory.GetFiles(path))
{
   Mat  mat = Cv2.ImRead(item, ImreadModes.Color);
    Cv2.Resize(mat, mat, new OpenCvSharp.Size(1920, 1080));

    writer.Write(mat);

    mat.Dispose();
}

writer.Dispose();

from opencvsharp.

1764564459 avatar 1764564459 commented on June 4, 2024

I have also encountered a situation where the video is continuously generated in a loop, and the program memory becomes larger and larger without releasing memory.

from opencvsharp.

1764564459 avatar 1764564459 commented on June 4, 2024

Use practical programming techniques. Try this.

  1. use Usings
  2. use the FourCC.H264
  3. use a mat for the resize
  4. sure you want a frame rate of 1?
using (VideoWriter writer = new VideoWriter(
  "20240201.mp4", 
   FourCC.H264,
  1, 
  new OpenCvSharp.Size(1920, 1080), 
  true)) {

var path = Path.Combine(AppContext.BaseDirectory, "Images");

using (Mat resized = new Mat()) 
foreach (var item in Directory.GetFiles(path)) {

   using (Mat  mat = Cv2.ImRead(item, ImreadModes.Color)) {

    Cv2.Resize(mat, resized, new OpenCvSharp.Size(1920, 1080));

    writer.Write(resized);
  }
}
}

thank you, I will use your code to see the effect.

from opencvsharp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.