简体   繁体   中英

FFmpeg in Docker container not capturing frames

I need to capture some frames over ethernet so decided to use FFmpeg.

I managed to get it working and capturing on my host before I moved into working inside my Docker containers.

If I run the command on my host, this is the output that I see:

╰─$ ffmpeg -y -i udp://@:15004 -r 10 -frames:v 1 frame.png
ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers
  built with gcc 9 (Ubuntu 9.3.0-10ubuntu2)
  configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
  libavutil      56. 31.100 / 56. 31.100
  libavcodec     58. 54.100 / 58. 54.100
  libavformat    58. 29.100 / 58. 29.100
  libavdevice    58.  8.100 / 58.  8.100
  libavfilter     7. 57.100 /  7. 57.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  5.100 /  5.  5.100
  libswresample   3.  5.100 /  3.  5.100
  libpostproc    55.  5.100 / 55.  5.100
[h264 @ 0x55ba0869d440] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x55ba0869d440] decode_slice_header error
[h264 @ 0x55ba0869d440] no frame!
[h264 @ 0x55ba0869d440] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x55ba0869d440] decode_slice_header error
[h264 @ 0x55ba0869d440] no frame!
[h264 @ 0x55ba0869d440] non-existing PPS 0 referenced
    Last message repeated 1 times
[h264 @ 0x55ba0869d440] decode_slice_header error
[h264 @ 0x55ba0869d440] no frame!
Input #0, mpegts, from 'udp://@:15004':
  Duration: N/A, start: 905.464878, bitrate: N/A
  Program 1 
    Stream #0:0[0x11]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 640x512, 60 fps, 60 tbr, 90k tbn, 120 tbc
    Stream #0:1[0x21]: Data: klv (KLVA / 0x41564C4B)
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> png (native))
Press [q] to stop, [?] for help
Output #0, image2, to 'frame.png':
  Metadata:
    encoder         : Lavf58.29.100
    Stream #0:0: Video: png, rgb24, 640x512, q=2-31, 200 kb/s, 10 fps, 10 tbn, 10 tbc
    Metadata:
      encoder         : Lavc58.54.100 png
frame=    1 fps=0.0 q=-0.0 Lsize=N/A time=00:00:00.10 bitrate=N/A speed=1.23x    
video:399kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown

However, when I try to run the exact same command inside my docker container, it looks like it tries to do something but never progress beyond this point to capture the frame.

vinden75lr           | ffmpeg version 4.3.4-0+deb11u1 Copyright (c) 2000-2021 the FFmpeg developers
vinden75lr           |   built with gcc 10 (Debian 10.2.1-6)
vinden75lr           |   configuration: --prefix=/usr --extra-version=0+deb11u1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libdav1d --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libmfx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
vinden75lr           |   libavutil      56. 51.100 / 56. 51.100
vinden75lr           |   libavcodec     58. 91.100 / 58. 91.100
vinden75lr           |   libavformat    58. 45.100 / 58. 45.100
vinden75lr           |   libavdevice    58. 10.100 / 58. 10.100
vinden75lr           |   libavfilter     7. 85.100 /  7. 85.100
vinden75lr           |   libavresample   4.  0.  0 /  4.  0.  0
vinden75lr           |   libswscale      5.  7.100 /  5.  7.100
vinden75lr           |   libswresample   3.  7.100 /  3.  7.100
vinden75lr           |   libpostproc    55.  7.100 / 55.  7.100

This is the code that actually executes the command, possible I'm doing something wrong here? This was a very quick and dirty implementation, just wanted to confirm I could capture a frame before doing anything else.

    void VindenCamera::save_image_to_file(){
        std::string filename;

        SPDLOG_INFO("Creating image filename {}", filename);
        create_filename(filename);

        std::string ffmpeg_still_frame_command("ffmpeg -y -i udp://@:15004 -r 10 -frames:v 1 " + filename);

        system(ffmpeg_still_frame_command.c_str());
    }

您可能需要使用--net=host运行 Docker,否则容器将拥有自己的 IP 地址,并且不一定能够看到与主机相同的 UDP 数据包。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM