emgucv
emgucv copied to clipboard
[BUG] VideoWriter fails to initialize on Docker
Describe the bug Trying to initialize VideoWriter for .mp4 file is met with error: [ INFO:[email protected]] global videoio_registry.cpp:244 VideoBackendRegistry VIDEOIO: Enabled backends(9, sorted by priority): FFMPEG(1000); GSTREAMER(990); INTEL_MFX(980); V4L2(970); CV_IMAGES(960); CV_MJPEG(950); FIREWIRE(940); UEYE(930); OBSENSOR(920) [ WARN:[email protected]] global cap_gstreamer.cpp:2617 open OpenCV | GStreamer warning: cannot link elements Unhandled exception. System.NullReferenceException: Unable to create VideoWriter. Make sure you have the specific codec installed Here is my build information in regards to Video I/O:
Video I/O:
DC1394: YES (2.2.6)
FFMPEG: YES
avcodec: YES (58.134.100)
avformat: YES (58.76.100)
avutil: YES (56.70.100)
swscale: YES (5.9.100)
avresample: NO
GStreamer: YES (1.20.3)
v4l/v4l2: YES (linux/videodev2.h)
The ffmpeg throws the same error without the warning part.
** OS / Platform ** Docker container built as Ubuntu 22.04
** .Net version ** .NET 8
CPU Architecture AMD64
** Emgu CV package used** Emgu.CV.runtime.windows-4.9 (for testing in non-docker environment), Emgu.CV.runtime.ubuntu-x64
To Reproduce
Emgu.CV.CvInvoke.LogLevel = Emgu.CV.CvEnum.LogLevel.Info;
Backend[] backends = CvInvoke.WriterBackends;
int backend_idx = 0; //any backend;
foreach (Backend be in backends)
{
Console.WriteLine(be.Name);
if (be.Name.Equals("FFMPEG"))
{
backend_idx = be.ID;
break;
}
}
Console.WriteLine(CvInvoke.BuildInformation);
VideoWriter videoWriter = new VideoWriter(Path.Combine("CreatedFiles", fileName), backend_idx,
VideoWriter.Fourcc('a', 'v', 'c', '1'), 30, new Size(1280, 720), true);
Note: the FourCC has no impact whatsoever here.
Expected behavior VideoWriter should initialize with chosen backend
Screenshots Not applicable
Additional context Here is my dockerfile for further reference:
FROM mcr.microsoft.com/dotnet/aspnet:8.0-jammy-amd64 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get -y install curl xz-utils build-essential \
libgtk-3-dev libgstreamer1.0-dev libavcodec-dev libavutil-dev libswscale-dev \
libavformat-dev libdc1394-dev libv4l-dev cmake-curses-gui \
ocl-icd-dev freeglut3-dev libgeotiff-dev libusb-1.0-0-dev \
libvtk9-dev libfreetype-dev libharfbuzz-dev qtbase5-dev libeigen3-dev \
libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgflags-dev \
libgoogle-glog-dev libatlas-base-dev liblapacke-dev libva-dev bzip2
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["testapp.csproj", "."]
RUN dotnet restore "./testapp.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "./testapp.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./testapp.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
RUN curl -LO https://github.com/BtbN/FFmpeg-Builds/releases/download/latest/ffmpeg-n6.1-latest-linux64-gpl-shared-6.1.tar.xz && \
mkdir ffmpeg_binaries && \
tar -xJf ffmpeg-n6.1-latest-linux64-gpl-shared-6.1.tar.xz -C ffmpeg_binaries --strip-components 1 && \
rm ffmpeg-n6.1-latest-linux64-gpl-shared-6.1.tar.xz && \
curl -LO https://github.com/cisco/openh264/releases/download/v1.8.0/libopenh264-1.8.0-linux64.4.so.bz2 && \
bzip2 -d libopenh264-1.8.0-linux64.4.so.bz2
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "testapp.dll"]
The ffmpeg downloaded is used for other part of the application, not for openCV
When I use non-docker Windows environment, everything works flawlessly (Ffmpeg with openh264 included as dll).