Recherche avancée

Médias (1)

Mot : - Tags -/theme

Sur d’autres sites (333)

  • Frames from Video Using OpenCV in Ubuntu with Java 17

    2 août 2023, par bstrdn

    I've been trying to extract frames from a video using OpenCV in an Ubuntu environment with Java 17, but all my attempts have been unsuccessful so far. The main issue is that ffmpeg is not detected by the OpenCV library on ubuntu.

    


    Here's my test code :

    


    Main class

    


    import org.opencv.core.Core;
import org.opencv.videoio.VideoCapture;

public class Main {
  public static String videoPath = "";
  static {
    String osName = System.getProperty("os.name").toLowerCase();
    if (osName.contains("win")) {
      System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
      videoPath = ClassLoader.getSystemResource("video.mp4").getPath();
    } else {
      videoPath = "/video.mp4";
//      System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
      System.load("/usr/lib/opencv_java470.so");
    }
  }

  public static void main(String[] args) throws InterruptedException {
    VideoCapture videoCapture = new VideoCapture(videoPath);
    if (!videoCapture.isOpened()) {
      System.out.println("Error opening video file.");
    } else {
      System.out.println("Everything is fine.");
    }
    System.out.println(Core.getBuildInformation());
    Thread.sleep(1000000000000000000L);
  }
}


    


    Maven :

    


    &lt;?xml version="1.0" encoding="UTF-8"?>&#xA;<project xmlns="http://maven.apache.org/POM/4.0.0">&#xA;  <modelversion>4.0.0</modelversion>&#xA;  <parent>&#xA;    <groupid>org.springframework.boot</groupid>&#xA;    <artifactid>spring-boot-starter-parent</artifactid>&#xA;    <version>3.0.2</version>&#xA;    <relativepath></relativepath> &#xA;  </parent>&#xA;  <groupid>org.example</groupid>&#xA;  <artifactid>untitled</artifactid>&#xA;  <version>1.0-SNAPSHOT</version>&#xA;  <properties>&#xA;    17&#xA;    17&#xA;    UTF-8&#xA;  </properties>&#xA;&#xA;<dependencies>&#xA;<dependency>&#xA;  <groupid>org.bytedeco</groupid>&#xA;  <artifactid>opencv-platform</artifactid>&#xA;  <version>4.7.0-1.5.9</version>&#xA;</dependency>&#xA;&#xA;<dependency>&#xA;  <groupid>org.springframework.boot</groupid>&#xA;  <artifactid>spring-boot-starter-web</artifactid>&#xA;</dependency>&#xA;</dependencies>&#xA;<build>&#xA;<plugins>&#xA;  <plugin>&#xA;    <groupid>org.springframework.boot</groupid>&#xA;    <artifactid>spring-boot-maven-plugin</artifactid>&#xA;  </plugin>&#xA;</plugins>&#xA;</build>&#xA;</project>&#xA;

    &#xA;

    Dockerfile :

    &#xA;

    FROM ubuntu:20.04&#xA;RUN apt-get update &amp;&amp; apt-get install -y openjdk-17-jdk&#xA;RUN apt-get update &amp;&amp; apt-get install -y pkg-config&#xA;RUN apt-get update &amp;&amp; apt-get install -y ffmpeg libavformat-dev libavcodec-dev libswscale-dev libavresample-dev&#xA;ENV JAVA_HOME /usr/lib/jvm/java-17-openjdk-amd64&#xA;COPY target/*.jar /app.jar&#xA;COPY src/main/resources/video.mp4 /&#xA;COPY opencv_java470.so /usr/lib&#xA;ENV JAVA_TOOL_OPTIONS="-Djava.library.path=/usr/lib:/lib:/usr/local/lib:/usr/local:/usr/lib/x86_64-linux-gnu"&#xA;ENV LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/local:/usr/lib/x86_64-linux-gnu&#xA;ENTRYPOINT [ "sh", "-c", "java $JAVA_TOOL_OPTIONS -jar /app.jar" ]&#xA;

    &#xA;

    The application displays the following text (video is not opened) :

    &#xA;

    Error opening video file.&#xA;&#xA;2023-08-02T13:30:58.448538297Z &#xA;2023-08-02T13:30:58.448572597Z General configuration for OpenCV 4.7.0 =====================================&#xA;2023-08-02T13:30:58.448587327Z   Version control:               v4.7.0&#xA;2023-08-02T13:30:58.448590607Z &#xA;2023-08-02T13:30:58.448593217Z   Platform:&#xA;2023-08-02T13:30:58.448596057Z     Timestamp:                   2023-03-27T23:13:34Z&#xA;2023-08-02T13:30:58.448598747Z     Host:                        Linux 5.4.0-1103-azure x86_64&#xA;2023-08-02T13:30:58.448601377Z     CMake:                       3.25.2&#xA;2023-08-02T13:30:58.448604277Z     CMake generator:             Unix Makefiles&#xA;2023-08-02T13:30:58.448606837Z     CMake build tool:            /usr/bin/make&#xA;2023-08-02T13:30:58.448609327Z     Configuration:               RELEASE&#xA;2023-08-02T13:30:58.448611867Z &#xA;.......there is a lot of text......&#xA;2023-08-02T13:30:58.448772865Z &#xA;2023-08-02T13:30:58.448775355Z   Video I/O:&#xA;2023-08-02T13:30:58.448777845Z     DC1394:                      NO&#xA;2023-08-02T13:30:58.448780535Z     FFMPEG:                      NO&#xA;2023-08-02T13:30:58.448783105Z       avcodec:                   NO&#xA;2023-08-02T13:30:58.448785725Z       avformat:                  NO&#xA;2023-08-02T13:30:58.448788295Z       avutil:                    NO&#xA;2023-08-02T13:30:58.448790755Z       swscale:                   NO&#xA;2023-08-02T13:30:58.448793295Z       avresample:                NO&#xA;2023-08-02T13:30:58.448795845Z     GStreamer:                   NO&#xA;2023-08-02T13:30:58.448798255Z     v4l/v4l2:                    YES (linux/videodev2.h)&#xA;2023-08-02T13:30:58.448800885Z &#xA;2023-08-02T13:30:58.448803525Z   Parallel framework:            pthreads&#xA;2023-08-02T13:30:58.448806345Z &#xA;............&#xA;2023-08-02T13:30:58.448859654Z   Java:                          export all functions&#xA;2023-08-02T13:30:58.448862024Z     ant:                         /usr/bin/ant (ver 1.10.5)&#xA;2023-08-02T13:30:58.448864504Z     JNI:                         /opt/hostedtoolcache/jdk/8.0.362/x64/include /opt/hostedtoolcache/jdk/8.0.362/x64/include/linux /opt/hostedtoolcache/jdk/8.0.362/x64/include&#xA;2023-08-02T13:30:58.448867224Z     Java wrappers:               YES&#xA;2023-08-02T13:30:58.448869804Z     Java tests:                  NO&#xA;2023-08-02T13:30:58.448872314Z &#xA;2023-08-02T13:30:58.448874734Z   Install to:                    /usr/local&#xA;

    &#xA;

    Moreover, ffmpeg is installed on Ubuntu.

    &#xA;

    How can i fix this ? I'm deathly tired(

    &#xA;

    Thank you in advance for your assistance !

    &#xA;

    First I tried installation following the official instructions.https://github.com/bytedeco/javacv#required-software

    &#xA;

    Then the solution provided in https://stackoverflow.com/a/76750478/8087508,

    &#xA;

    but the result is the same.

    &#xA;

  • ffmpeg command to use font on subtitle still uses the default one

    3 août 2023, par mika

    my command in python :

    &#xA;

    ffmpegCommandAddSub = [&#xA;    &#x27;ffmpeg&#x27;, &#x27;-i&#x27;, input_video, &#x27;-vf&#x27;, f"subtitles={input_srt}:force_style=&#x27;Fontfile=Borel-Regular.ttf:fontsdir=./&#x27;",&#xA;    &#x27;-c:v&#x27;, &#x27;libx264&#x27;, &#x27;-c:a&#x27;, &#x27;copy&#x27;, output_video&#xA;]&#xA;

    &#xA;

    Borel-Regular.ttf is in the same folder as the python code

    &#xA;

    the font is not applied to the subtitle. what am I doing wrong or didn't pay attention ?

    &#xA;

    FFMPEG -version :

    &#xA;

    ffmpeg version N-111432-g374184a4dc-20230714 Copyright (c) 2000-2023 the FFmpeg &#xA;&#xA;developers&#xA;built with gcc 13.1.0 (crosstool-NG 1.25.0.196_227d99d)&#xA;configuration: --prefix=/ffbuild/prefix --pkg-config-flags=--static --pkg-config=pkg-config --cross-prefix=x86_64-w64-mingw32- --arch=x86_64 --target-os=mingw32 --enable-gpl --enable-version3 --disable-debug --disable-w32threads --enable-pthreads --enable-iconv --enable-libxml2 --enable-zlib --enable-libfreetype &#xA;--enable-libfribidi --enable-gmp --enable-lzma --enable-fontconfig --enable-libvorbis --enable-opencl --disable-libpulse --enable-libvmaf --disable-libxcb --disable-xlib --enable-amf --enable-libaom --enable-libaribb24 --enable-avisynth --enable-chromaprint --enable-libdav1d --enable-libdavs2 --disable-libfdk-aac --enable-ffnvcodec --enable-cuda-llvm --enable-frei0r --enable-libgme --enable-libkvazaar --enable-libass --enable-libbluray --enable-libjxl --enable-libmp3lame --enable-libopus --enable-librist --enable-libssh --enable-libtheora --enable-libvpx --enable-libwebp --enable-lv2 --enable-libvpl --enable-openal --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopenmpt --enable-librav1e --enable-librubberband --enable-schannel --enable-sdl2 --enable-libsoxr --enable-libsrt --enable-libsvtav1 --enable-libtwolame --enable-libuavs3d --disable-libdrm --disable-vaapi --enable-libvidstab --enable-vulkan --enable-libshaderc --enable-libplacebo --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libzimg --enable-libzvbi --extra-cflags=-DLIBTWOLAME_STATIC --extra-cxxflags= --extra-ldflags=-pthread --extra-ldexeflags= --extra-libs=-lgomp --extra-version=20230714&#xA;libavutil      58. 14.100 / 58. 14.100&#xA;libavcodec     60. 22.100 / 60. 22.100&#xA;libavformat    60. 10.100 / 60. 10.100&#xA;libavdevice    60.  2.101 / 60.  2.101&#xA;libavfilter     9.  8.102 /  9.  8.102&#xA;libswscale      7.  3.100 /  7.  3.100&#xA;libswresample   4. 11.100 /  4. 11.100&#xA;libpostproc    57.  2.100 / 57.  2.100&#xA;

    &#xA;

  • The error "Failed to query nvenc max version" typically occurs when using FFmpeg on Linux

    28 juillet 2023, par Well Chen

    The error "Failed to query nvenc max version" typically occurs when using FFmpeg with NVIDIA GPU acceleration (hevc_nvenc) on Linux.

    &#xA;

    Does anyone know how to solve this bug ? Thank you very much.

    &#xA;

    The following code is the FFmpeg code I entered, along with the output content.

    &#xA;

    ffmpeg -ss 10:00 -i /www/wwwroot/pyffmpeg/videos/0/011.mp4 -t 20 -r 30 -b:v 4M -an -vcodec hevc_nvenc -y /www/wwwroot/pyffmpeg/videos/post/999.mp4&#xA;ffmpeg version 6.0 Copyright (c) 2000-2023 the FFmpeg developers&#xA;  built with gcc 8 (GCC)&#xA;  configuration: --extra-cflags=&#x27;-I/usr/local/cuda/include -fPIC &#x27; --extra-ldflags=&#x27;-L/usr/local/cuda/lib64 -ldl &#x27; --pkg-config-flags=--static --enable-shared --enable-gpl --enable-cuvid --enable-nvenc --enable-nonfree --nvcc=&#x27;nvcc=/usr/local/cuda-12.2/bin/nvcc&#x27;&#xA;  WARNING: library configuration mismatch&#xA;  avutil      configuration: --extra-cflags=&#x27;-I/usr/local/cuda-12.2/include -fPIC &#x27; --extra-ldflags=&#x27;-L/usr/local/cuda-12.2/lib64 -ldl &#x27; --pkg-config-flags=--static --enable-shared --enable-gpl --enable-libfreetype --enable-cuvid --enable-nvenc --enable-nonfree --nvcc=/usr/local/cuda-12.2/bin/nvcc --prefix=/usr/local/ffmpeg&#xA;  avcodec     configuration: --extra-cflags=&#x27;-I/usr/local/cuda-12.2/include -fPIC &#x27; --extra-ldflags=&#x27;-L/usr/local/cuda-12.2/lib64 -ldl &#x27; --pkg-config-flags=--static --enable-shared --enable-gpl --enable-libfreetype --enable-cuvid --enable-nvenc --enable-nonfree --nvcc=/usr/local/cuda-12.2/bin/nvcc --prefix=/usr/local/ffmpeg&#xA;  avformat    configuration: --extra-cflags=&#x27;-I/usr/local/cuda-12.2/include -fPIC &#x27; --extra-ldflags=&#x27;-L/usr/local/cuda-12.2/lib64 -ldl &#x27; --pkg-config-flags=--static --enable-shared --enable-gpl --enable-libfreetype --enable-cuvid --enable-nvenc --enable-nonfree --nvcc=/usr/local/cuda-12.2/bin/nvcc --prefix=/usr/local/ffmpeg&#xA;  avdevice    configuration: --extra-cflags=&#x27;-I/usr/local/cuda-12.2/include -fPIC &#x27; --extra-ldflags=&#x27;-L/usr/local/cuda-12.2/lib64 -ldl &#x27; --pkg-config-flags=--static --enable-shared --enable-gpl --enable-libfreetype --enable-cuvid --enable-nvenc --enable-nonfree --nvcc=/usr/local/cuda-12.2/bin/nvcc --prefix=/usr/local/ffmpeg&#xA;  avfilter    configuration: --extra-cflags=&#x27;-I/usr/local/cuda-12.2/include -fPIC &#x27; --extra-ldflags=&#x27;-L/usr/local/cuda-12.2/lib64 -ldl &#x27; --pkg-config-flags=--static --enable-shared --enable-gpl --enable-libfreetype --enable-cuvid --enable-nvenc --enable-nonfree --nvcc=/usr/local/cuda-12.2/bin/nvcc --prefix=/usr/local/ffmpeg&#xA;  swscale     configuration: --extra-cflags=&#x27;-I/usr/local/cuda-12.2/include -fPIC &#x27; --extra-ldflags=&#x27;-L/usr/local/cuda-12.2/lib64 -ldl &#x27; --pkg-config-flags=--static --enable-shared --enable-gpl --enable-libfreetype --enable-cuvid --enable-nvenc --enable-nonfree --nvcc=/usr/local/cuda-12.2/bin/nvcc --prefix=/usr/local/ffmpeg&#xA;  swresample  configuration: --extra-cflags=&#x27;-I/usr/local/cuda-12.2/include -fPIC &#x27; --extra-ldflags=&#x27;-L/usr/local/cuda-12.2/lib64 -ldl &#x27; --pkg-config-flags=--static --enable-shared --enable-gpl --enable-libfreetype --enable-cuvid --enable-nvenc --enable-nonfree --nvcc=/usr/local/cuda-12.2/bin/nvcc --prefix=/usr/local/ffmpeg&#xA;  postproc    configuration: --extra-cflags=&#x27;-I/usr/local/cuda-12.2/include -fPIC &#x27; --extra-ldflags=&#x27;-L/usr/local/cuda-12.2/lib64 -ldl &#x27; --pkg-config-flags=--static --enable-shared --enable-gpl --enable-libfreetype --enable-cuvid --enable-nvenc --enable-nonfree --nvcc=/usr/local/cuda-12.2/bin/nvcc --prefix=/usr/local/ffmpeg&#xA;  libavutil      58.  2.100 / 58.  2.100&#xA;  libavcodec     60.  3.100 / 60.  3.100&#xA;  libavformat    60.  3.100 / 60.  3.100&#xA;  libavdevice    60.  1.100 / 60.  1.100&#xA;  libavfilter     9.  3.100 /  9.  3.100&#xA;  libswscale      7.  1.100 /  7.  1.100&#xA;  libswresample   4. 10.100 /  4. 10.100&#xA;  libpostproc    57.  1.100 / 57.  1.100&#xA;Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;/www/wwwroot/pyffmpeg/videos/0/011.mp4&#x27;:&#xA;  Metadata:&#xA;    major_brand     : isom&#xA;    minor_version   : 512&#xA;    compatible_brands: isomiso2avc1mp41&#xA;    encoder         : Lavf59.6.100&#xA;  Duration: 00:17:48.83, start: 0.000000, bitrate: 4617 kb/s&#xA;  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/bt709, progressive), 1920x1080 [SAR 1:1 DAR 16:9], 4481 kb/s, 30 fps, 30 tbr, 15360 tbn (default)&#xA;    Metadata:&#xA;      handler_name    : ISO Media file produced by Google Inc.&#xA;      vendor_id       : [0][0][0][0]&#xA;  Stream #0:1[0x2](und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 127 kb/s (default)&#xA;    Metadata:&#xA;      handler_name    : ISO Media file produced by Google Inc.&#xA;      vendor_id       : [0][0][0][0]&#xA;Stream mapping:&#xA;  Stream #0:0 -> #0:0 (h264 (native) -> hevc (hevc_nvenc))&#xA;Press [q] to stop, [?] for help&#xA;[hevc_nvenc @ 0x2a577790] Failed to query nvenc max version: unknown error (-756041696): (no details)&#xA;Segmentation faul&#xA;

    &#xA;

    I have installed FFmpeg, NVIDIA GPU drivers, and SDK. It works fine without using GPU acceleration, but it throws an error when using GPU acceleration.

    &#xA;