Search code examples
pythonffmpeghttp-live-streaminglive-streaming

Python FFmpeg Video Streaming: hls.output() does not work for live camera capture


I am trying to capture camera live stream and make HLS stream from it. I am using Fantech Luminous C30 webcam. I get this error:

ERROR:root:ffmpeg failed to execute command: b'ffmpeg version 2022-12-11-git-c3e20f78b0-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers\r\n  built with gcc 12.1.0 (Rev2, Built by MSYS2 project)\r\n 
 configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint\r\n  libavutil      57. 43.100 / 57. 43.100\r\n  libavcodec     59. 55.100 / 59. 55.100\r\n  libavformat    59. 34.102 / 59. 34.102\r\n  libavdevice    59.  8.101 / 59.  8.101\r\n  libavfilter     8. 52.100 /  8. 52.100\r\n  libswscale      6.  8.112 /  6.  8.112\r\n  libswresample   4.  9.100 /  4.  9.100\r\n  libpostproc    56.  7.100 / 56.  7.100\r\nFantech Luminous C30: No such file or directory\r\n'
Traceback (most recent call last):
  File "c:\Users\ltadic\Desktop\hls stream\camera_stream.py", line 12, in <module>
    hls.output('C:\\Users\\ltadic\\Desktop\\camera_stream\\hls.m3u8')
  File "C:\Users\ltadic\AppData\Local\Programs\Python\Python311\Lib\site-packages\ffmpeg_streaming\_media.py", line 93, in output
    self.run(ffmpeg_bin, monitor, **options)
  File "C:\Users\ltadic\AppData\Local\Programs\Python\Python311\Lib\site-packages\ffmpeg_streaming\_media.py", line 121, in run  
    asyncio.run(self.async_run(ffmpeg_bin, monitor, **options))
  File "C:\Users\ltadic\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\ltadic\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ltadic\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 650, in run_until_complete     
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\ltadic\AppData\Local\Programs\Python\Python311\Lib\site-packages\ffmpeg_streaming\_media.py", line 112, in async_run
    self._run(ffmpeg_bin, monitor, **options)
  File "C:\Users\ltadic\AppData\Local\Programs\Python\Python311\Lib\site-packages\ffmpeg_streaming\_media.py", line 106, in _run
    self.pipe, err = process.run()
                     ^^^^^^^^^^^^^
  File "C:\Users\ltadic\AppData\Local\Programs\Python\Python311\Lib\site-packages\ffmpeg_streaming\_process.py", line 122, in run
    raise RuntimeError('ffmpeg failed to execute command: ', error)
RuntimeError: ('ffmpeg failed to execute command: ', "b'ffmpeg version 2022-12-11-git-c3e20f78b0-full_build-www.gyan.dev Copyright (c) 2000-2022 the FFmpeg developers\\r\\n  built with gcc 12.1.0 (Rev2, Built by MSYS2 project)\\r\\n  configuration: --enable-gpl --enable-version3 --enable-static --disable-w32threads --disable-autodetect --enable-fontconfig --enable-iconv --enable-gnutls --enable-libxml2 --enable-gmp --enable-bzlib --enable-lzma --enable-libsnappy --enable-zlib --enable-librist --enable-libsrt --enable-libssh --enable-libzmq --enable-avisynth --enable-libbluray --enable-libcaca --enable-sdl2 --enable-libaribb24 --enable-libdav1d --enable-libdavs2 --enable-libuavs3d --enable-libzvbi --enable-librav1e --enable-libsvtav1 --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs2 --enable-libxvid --enable-libaom --enable-libjxl --enable-libopenjpeg --enable-libvpx --enable-mediafoundation --enable-libass --enable-frei0r --enable-libfreetype --enable-libfribidi --enable-liblensfun --enable-libvidstab --enable-libvmaf --enable-libzimg --enable-amf --enable-cuda-llvm --enable-cuvid --enable-ffnvcodec --enable-nvdec --enable-nvenc --enable-d3d11va --enable-dxva2 --enable-libvpl --enable-libshaderc --enable-vulkan --enable-libplacebo --enable-opencl --enable-libcdio --enable-libgme --enable-libmodplug --enable-libopenmpt --enable-libopencore-amrwb --enable-libmp3lame --enable-libshine --enable-libtheora --enable-libtwolame --enable-libvo-amrwbenc --enable-libilbc --enable-libgsm --enable-libopencore-amrnb --enable-libopus --enable-libspeex --enable-libvorbis --enable-ladspa --enable-libbs2b --enable-libflite --enable-libmysofa --enable-librubberband --enable-libsoxr --enable-chromaprint\\r\\n  libavutil      57. 43.100 / 57. 43.100\\r\\n  libavcodec     59. 55.100 / 59. 55.100\\r\\n  libavformat    59. 34.102 / 59. 34.102\\r\\n  libavdevice    59.  8.101 / 59.  8.101\\r\\n  libavfilter     8. 52.100 /  8. 52.100\\r\\n  libswscale 
     6.  8.112 /  6.  8.112\\r\\n  libswresample   4.  9.100 /  4.  9.100\\r\\n  libpostproc    56.  7.100 / 56.  7.100\\r\\nFantech Luminous C30: No such file or directory\\r\\n'")

This is my code:

import ffmpeg_streaming
from ffmpeg_streaming import Formats,Bitrate, Representation, Size 

video = ffmpeg_streaming.input('Fantech Luminous C30', capture = True)

_360p  = Representation(Size(640, 360), Bitrate(276 * 1024, 128 * 1024))
_480p  = Representation(Size(854, 480), Bitrate(750 * 1024, 192 * 1024))
_720p  = Representation(Size(1280, 720), Bitrate(2048 * 1024, 320 * 1024))

hls = video.hls(Formats.h264())
hls.representations(_360p, _480p, _720p)
hls.output('C:\\Users\\ltadic\\Desktop\\camera_stream\\hls.m3u8')

Solution

  • It seems that FFmpeg reported an error while trying to capture the video from your webcam. There may be a problem with the path or name of the webcam given in the error message: "Fantech Luminous C30: No such file or directory". A possible reason for this error could be that FFmpeg is not able to find the webcam. Make sure that the webcam is connected to your computer and that the driver for the webcam is installed. Make sure FFmpeg is using the correct webcam. It could also be that FFmpeg does not have the required codecs or libraries to capture the video from the webcam. Make sure that FFmpeg is configured and compiled correctly and that all the required libraries are present. Did you tried to open your webcam with other applications?