Recherche avancée

Médias (91)

Autres articles (68)

  • Personnaliser les catégories

    21 juin 2013, par

    Formulaire de création d’une catégorie
    Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
    Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
    On peut modifier ce formulaire dans la partie :
    Administration > Configuration des masques de formulaire.
    Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
    Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...)

  • Support de tous types de médias

    10 avril 2011

    Contrairement à beaucoup de logiciels et autres plate-formes modernes de partage de documents, MediaSPIP a l’ambition de gérer un maximum de formats de documents différents qu’ils soient de type : images (png, gif, jpg, bmp et autres...) ; audio (MP3, Ogg, Wav et autres...) ; vidéo (Avi, MP4, Ogv, mpg, mov, wmv et autres...) ; contenu textuel, code ou autres (open office, microsoft office (tableur, présentation), web (html, css), LaTeX, Google Earth) (...)

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

Sur d’autres sites (6968)

  • ffmpeg : crop video into two grayscale sub-videos ; guarantee monotonical frames ; and get timestamps

    13 mars 2021, par lurix66

    The need

    


    Hello, I need to extract two regions of a .h264 video file via the crop filter into two files. The output videos need to be monochrome and extension .mp4. The encoding (or format ?) should guarantee that video frames are organized monotonically. Finally, I need to get the timestamps for both files (which I'd bet are the same timestamps that I would get from the input file, see below).

    


    In the end I will be happy to do everything in one command via an elegant one liner (via a complex filter I guess), but I start doing it in multiple steps to break it down in simpler problems.

    


    In this path I get into many difficulties and despite having searched in many places I don't seem to find solutions that work. Unfortunately I'm no expert of ffmpeg or video conversion, so the more I search, the more details I discover, the less I solve problems.

    


    Below you find some of my attempts to work with the following options :

    


      

    • -filter:v "crop=400:ih:260:0,format=gray" to do the crop and the monochrome conversion
    • 


    • -vf showinfo possibly combined with -vsync 0 or -copyts to get the timestamps via stderr redirection &> filename
    • 


    • -c:v mjpeg to force monotony of frames (are there other ways ?)
    • 


    


    1. cropping each region and obtaining monochrome videos

    


    $ ffmpeg -y -hide_banner -i inVideo.h264 -filter:v "crop=400:ih:260:0,format=gray" outL.mp4
$ ffmpeg -y -hide_banner -i inVideo.h264 -filter:v "crop=400:ih:1280:0,format=gray" outR.mp4


    


    The issue here is that in the output files the frames are not organized monotonically (I don't understand why ; how come would that make sense in any video format ? I can't say if that comes from the input file).

    


    EDIT. Maybe it is not frames, but packets, as returned by av .demux() method that are not monotonic (see below "instructions to reproduce...")

    


    I have got the advice to do a ffmpeg -i outL.mp4 outL.mjpeg after, but this produces two videos that look very pixellated (at least playing them with ffplay) despite being surprisingly 4x bigger than the input. Needless to say, I need both monotonic frames and lossless conversion.

    


    EDIT. I acknowledge the advice to specify -q:v 1 ; this fixes the pixellation effect but produces a file even bigger, 12x in size. Is it necessary ? (see below "instructions to reproduce...")

    


    2. getting the timestamps

    


    I found this piece of advice, but I don't want to generate hundreds of image files, so I tried the following :

    


    $ ffmpeg -y -hide_banner -i outL.mp4 -vf showinfo -vsync 0 &>tsL.txt
$ ffmpeg -y -hide_banner -i outR.mp4 -vf showinfo -vsync 0 &>tsR.txt


    


    The issue here is that I don't get any output because ffmpeg claims it needs an output file.

    


    The need to produce an output file, and the doubt that the timestamps could be lost in the previous conversions, leads me back to making a first attempt of a one liner, where I am testing also the -copyts option, and the forcing the encoding with -c:v mjpeg option as per the advice mentioned above (don't know if in the right position though)

    


    ffmpeg -y -hide_banner -i testTex2.h264 -copyts -filter:v "crop=400:ih:1280:0,format=gray" -vf showinfo -c:v mjpeg eyeL.mp4 &>tsL.txt


    


    This does not work because surprisingly the output .mp4 I get is the same as the input. If instead I put the -vf showinfo option just before the stderr redirection, I get no redirected output

    


    ffmpeg -y -hide_banner -i testTex2.h264 -copyts -filter:v "crop=400:ih:260:0,format=gray" -c:v mjpeg outR.mp4 -vf showinfo dummy.mp4 &>tsR.txt


    


    In this case I get the desired timestamps output (too much : I will need some solution to grab only the pts and pts_time data out of it) but I have to produce a big dummy file. The worst thing is anyway, that the mjpeg encoding produces a low resolution very pixellated video again

    


    I admit that the logic how to place the options and the output files on the command line is obscure to me. Possible combinations are many, and the more options I try the more complicated it gets, and I am not getting much closer to the solution.

    


    3. [EDIT] instructions how to reproduce this

    


      

    • get a .h264 video
    • 


    • turn it into .mp by ffmpeg command $ ffmpeg -i inVideo.h264 out.mp4
    • 


    • run the following python cell in a jupyter-notebook
    • 


    • see that the packets timestamps have diffs greater and less than zero
    • 


    


    %matplotlib inline
import av
import numpy as np
import matplotlib.pyplot as mpl

fname, ext="outL.direct", "mp4"

cont=av.open(f"{fname}.{ext}")
pk_pts=np.array([p.pts for p in cont.demux(video=0) if p.pts is not None])

cont=av.open(f"{fname}.{ext}")
fm_pts=np.array([f.pts for f in cont.decode(video=0) if f.pts is not None])

print(pk_pts.shape,fm_pts.shape)

mpl.subplot(211)
mpl.plot(np.diff(pk_pts))

mpl.subplot(212)
mpl.plot(np.diff(fm_pts))


    


      

    • finally create also the mjpeg encoded files in various ways, and check packets monotony with the same script (see also file size)
    • 


    


    $ ffmpeg -i inVideo.h264 out.mjpeg
$ ffmpeg -i inVideo.h264 -c:v mjpeg out.c_mjpeg.mp4
$ ffmpeg -i inVideo.h264 -c:v mjpeg -q:v 1 out.c_mjpeg_q1.mp4


    


    Finally, the question

    


    What is a working way / the right way to do it ?

    


    Any hints, even about single steps and how to rightly combine them will be appreciated. Also, I am not limited tio the command line, and I would be able to try some more programmatic solution in python (jupyter notebook) instead of the command line if someone points me in that direction.

    


  • Open VideoStream using OpenCV 4.5.1 works on Windows but fails on Docker python:3.9.2-slim-buster for specific IP cam

    18 mai 2021, par Qua285

    I have 2 ip cameras - one of Hikvision and another of Provision ISR. Both use Onvif and work on VLC.
I've written a simple python script to record images every 5 sec from their video stream.
On Windows 10, using VSCode they both work as expected. Once deployed to a Docker container, my script works as expected with the Hikvision but fails with the Provision ISR - it doesn't open the stream.

    


    Running python -c "import cv2; print(cv2.getBuildInformation())" on windows (venv 3.9.2) and on docker machine bring slightly different results but it's beyond my understanding to take something out of it...
Here is the Windows one :

    


    General configuration for OpenCV 4.5.1 =====================================
  Version control:               4.5.1

  Platform:
    Timestamp:                   2021-01-02T14:30:58Z
    Host:                        Windows 6.3.9600 AMD64
    CMake:                       3.18.4
    CMake generator:             Visual Studio 14 2015 Win64
    CMake build tool:            C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe
    MSVC:                        1900

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (15 files):         + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (29 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2

  C/C++:
    Built as dynamic libs?:      NO
    C++ standard:                11
    C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe  (ver 19.0.24241.7)
    C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 
/MP  /MT /O2 /Ob2 /DNDEBUG
    C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 
/MP  /MTd /Zi /Ob0 /Od /RTC1
    C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
    C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP   /MT /O2 /Ob2 /DNDEBUG
    C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi  /fp:precise     /MP /MTd /Zi /Ob0 /Od /RTC1
    Linker flags (Release):      /machine:x64  /NODEFAULTLIB:atlthunk.lib /INCREMENTAL:NO  /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib
    Linker flags (Debug):        /machine:x64  /NODEFAULTLIB:atlthunk.lib /debug /INCREMENTAL  /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib
    ccache:                      NO
    Precompiled headers:         YES
    Extra dependencies:          ade wsock32 comctl32 gdi32 ole32 setupapi ws2_32
    3rdparty dependencies:       ittnotify libprotobuf zlib libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf quirc ippiw ippicv

  OpenCV modules:
    To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 java python2 ts
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO

  Windows RT support:            NO

  GUI:
    Win32 UI:                    YES
    VTK support:                 NO

  Media I/O:
    ZLib:                        build (ver 1.2.11)
    JPEG:                        build-libjpeg-turbo (ver 2.0.6-62)
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         build (ver 1.6.37)
    TIFF:                        build (ver 42 - 4.0.10)
    JPEG 2000:                   build (ver 2.3.1)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES (prebuilt binaries)
      avcodec:                   YES (58.91.100)
      avformat:                  YES (58.45.100)
      avutil:                    YES (56.51.100)
      swscale:                   YES (5.7.100)
      avresample:                YES (4.0.0)
    GStreamer:                   NO
    DirectShow:                  YES
    Media Foundation:            YES
      DXVA:                      NO

  Parallel framework:            Concurrency

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2020.0.0 Gold [2020.0.0]
           at:                   C:/Users/appveyor/AppData/Local/Temp/1/pip-req-build-wvn_it83/_skbuild/win-amd64-3.9/cmake-build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                C:/Users/appveyor/AppData/Local/Temp/1/pip-req-build-wvn_it83/_skbuild/win-amd64-3.9/cmake-build/3rdparty/ippicv/ippicv_win/iw
    Lapack:                      NO
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  OpenCL:                        YES (NVD3D11)
    Include path:                C:/Users/appveyor/AppData/Local/Temp/1/pip-req-build-wvn_it83/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 3:
    Interpreter:                 C:/Python39-x64/python.exe (ver 3.9)
    Libraries:                   C:/Python39-x64/libs/python39.lib (ver 3.9.0)
    numpy:                       C:/Users/appveyor/AppData/Local/Temp/1/pip-build-env-sk7r7w_5/overlay/Lib/site-packages/numpy/core/include (ver 1.19.3)
    install path:                python

  Python (for build):            C:/Python27-x64/python.exe

  Java:
    ant:                         NO
    JNI:                         C:/Program Files/Java/jdk1.8.0/include C:/Program Files/Java/jdk1.8.0/include/win32 C:/Program Files/Java/jdk1.8.0/include
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    C:/Users/appveyor/AppData/Local/Temp/1/pip-req-build-wvn_it83/_skbuild/win-amd64-3.9/cmake-install
-----------------------------------------------------------------


    


    this is the Docker one (python:3.9.2-slim-buster) :

    


    General configuration for OpenCV 4.5.1 =====================================
  Version control:               4.5.1-dirty

  Platform:
    Timestamp:                   2021-01-02T13:04:10Z
    Host:                        Linux 4.15.0-1077-gcp x86_64
    CMake:                       3.18.4
    CMake generator:             Unix Makefiles
    CMake build tool:            /bin/gmake
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (15 files):         + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (29 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (4 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      NO
    C++ standard:                11
    C++ Compiler:                /usr/lib/ccache/compilers/c++  (ver 9.3.1)
    C++ flags (Release):         -Wl,-strip-all   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -Wl,-strip-all   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/lib/ccache/compilers/cc
    C flags (Release):           -Wl,-strip-all   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -Wl,-strip-all   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -L/root/ffmpeg_build/lib  -Wl,--gc-sections -Wl,--as-needed
    Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -L/root/ffmpeg_build/lib  -Wl,--gc-sections -Wl,--as-needed
    ccache:                      YES
    Precompiled headers:         NO
    Extra dependencies:          ade Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test Qt5::Concurrent /lib64/libpng.so /lib64/libz.so dl m pthread rt
    3rdparty dependencies:       ittnotify libprotobuf libjpeg-turbo libwebp libtiff libopenjp2 IlmImf quirc ippiw ippicv

  OpenCV modules:
    To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo python3 stitching video videoio
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 java python2 ts
    Applications:                -
    Documentation:               NO
    Non-free algorithms:         NO

  GUI:
    QT:                          YES (ver 5.15.0)
      QT OpenGL support:         NO
    GTK+:                        NO
    VTK support:                 NO

  Media I/O:
    ZLib:                        /lib64/libz.so (ver 1.2.7)
    JPEG:                        libjpeg-turbo (ver 2.0.6-62)
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         /lib64/libpng.so (ver 1.5.13)
    TIFF:                        build (ver 42 - 4.0.10)
    JPEG 2000:                   build (ver 2.3.1)
    OpenEXR:                     build (ver 2.3.0)
    HDR:                         YES
    SUNRASTER:                   YES
    PXM:                         YES
    PFM:                         YES

  Video I/O:
    DC1394:                      NO
    FFMPEG:                      YES
      avcodec:                   YES (58.109.100)
      avformat:                  YES (58.61.100)
      avutil:                    YES (56.60.100)
      swscale:                   YES (5.8.100)
      avresample:                NO
    GStreamer:                   NO
    v4l/v4l2:                    YES (linux/videodev2.h)

  Parallel framework:            pthreads

  Trace:                         YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP:                   2020.0.0 Gold [2020.0.0]
           at:                   /tmp/pip-req-build-ddpkm6fn/_skbuild/linux-x86_64-3.9/cmake-build/3rdparty/ippicv/ippicv_lnx/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                /tmp/pip-req-build-ddpkm6fn/_skbuild/linux-x86_64-3.9/cmake-build/3rdparty/ippicv/ippicv_lnx/iw
    Lapack:                      NO
    Eigen:                       NO
    Custom HAL:                  NO
    Protobuf:                    build (3.5.1)

  OpenCL:                        YES (no extra features)
    Include path:                /tmp/pip-req-build-ddpkm6fn/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python 3:
    Interpreter:                 /opt/python/cp39-cp39/bin/python (ver 3.9)
    Libraries:                   libpython3.9.a (ver 3.9.0)
    numpy:                       /tmp/pip-build-env-jqrfyj0w/overlay/lib/python3.9/site-packages/numpy/core/include (ver 1.19.3)
    install path:                python

  Python (for build):            /bin/python2.7

  Java:
    ant:                         NO
    JNI:                         NO
    Java wrappers:               NO
    Java tests:                  NO

  Install to:                    /tmp/pip-req-build-ddpkm6fn/_skbuild/linux-x86_64-3.9/cmake-install
-----------------------------------------------------------------


    


    If relevant, the docker is installed on an Intel NUC with Ubuntu Desktop 20.04

    


    If relevant, this is the dockerfile I've used to build the image :

    


    FROM python:3.9.2-slim-buster as builder

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Without this setting, Python never prints anything out.
ENV PYTHONUNBUFFERED=1

RUN pip install --upgrade pip
COPY ./Cam/requirements.txt .
RUN pip install -r requirements.txt
RUN apt-get update
RUN apt-get install ffmpeg libsm6 libxext6 -y

WORKDIR /app

FROM builder
COPY ./Cam .
CMD ["python", "camStreamer.py"]


    


    and last, this is the script code (simplified) :

    


    import os, logging, threading
from os.path import join
import sys, inspect, datetime, time
from pathlib import Path
import cv2
import imutils
from imutils.video import VideoStream

def StartRecording(showVideoWindow, interval, imagePath):
    key = None
    cam = VideoStream(os.getenv("CAM_RTSP")).start()
    counter = 0
    try:
        while True:
            ## 2 min retry to connect if frame is None
            if counter > 60/interval*2: break

            ts = time.time()
            ## Wait for [interval] seconds
            while ts + interval > time.time():
                continue
            print(f"Counter: {counter}, ts: {str(ts)}")

            frame = cam.read()
            if frame is None:
                counter += 1
                continue
            counter = 0

            print("frame is valid")
            if showVideoWindow:
                frame = imutils.resize(frame, width=1200)
                cv2.imshow('VIDEO', frame)

            imageName = f"{datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%dT%H_%M_%S')}.jpg"
            cv2.imwrite(join(imagePath, imageName), frame)
            print("saved image to disk")

            key = cv2.waitKey(1) & 0xFF
            if key == ord('q') or key == ord('r'):
                break

    except Exception as e:
        exc_tb = sys.exc_info()[2]
        extra = ""
        print(f"{inspect.stack()[0][3]}: {e} (lineno: {exc_tb.tb_lineno}) {extra}")
    finally:
        if showVideoWindow: cv2.destroyAllWindows()
        cam.stop()
        return key


while True:
    log.warning(f"Starting {Name}")
    key = StartRecording(
                showVideoWindow=(Env.startswith("development") and os.getenv("SHOW_VIDEO") == "True"),
                interval=int(os.getenv("SAVE_IMAGE_INTERVAL")),
                imagePath=os.getenv('CAPTURE_FOLDER')
                )
    if key == ord('q'):
        break


    


    I apologize for the very long post. Hopefully someone can put me on the right direction...

    


  • Streaming Rtsp stream to website using FFmpeg and FFserver.

    23 août 2016, par Pallav Gupta

    I am working on a website for a client and one of the requirement is to embed the video from HikVision DVR DS7116. I have the RTSP url for the DVR. I want help with FFmpeg and FFserver. I already have written my ffserver config file.

    /etc/ffserver.config

    Port 9500
    # bind to all IPs aliased or not
    BindAddress 0.0.0.0
    # max number of simultaneous clients
    MaxClients 1000
    # max bandwidth per-client (kb/s)
    MaxBandwidth 10000
    # Suppress that if you want to launch ffserver as a daemon.
    NoDaemon

    <feed>
    File /tmp/feed1.ffm
    FileMaxSize 5M
    </feed>

    <stream>
    Feed feed1.ffm
    Format swf
    VideoCodec flv
    VideoFrameRate 15
    VideoBufferSize 80000
    VideoBitRate 100
    VideoQMin 1
    VideoQMax 5
    VideoSize 352x288
    PreRoll 0
    Noaudio
    </stream>

    I next run my ffserver and ffmpeg command which is

    ffserver &amp; ffmpeg -re -i rtsp://admin:12345@192.168.1.3/MPEG-4/ch1/main/av_stream  http://192.168.1.105:9500/feed1.ffm

    The output which i receive is as follows

    ffmpeg version N-80901-gfebc862 Copyright (c) 2000-2016 the FFmpeg developers
     built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
     configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab

     libavutil      55. 28.100 / 55. 28.100
     libavcodec     57. 48.101 / 57. 48.101
     libavformat    57. 41.100 / 57. 41.100
     libavdevice    57.  0.102 / 57.  0.102
     libavfilter     6. 47.100 /  6. 47.100
     libavresample   3.  0.  0 /  3.  0.  0
     libswscale      4.  1.100 /  4.  1.100
     libswresample   2.  1.100 /  2.  1.100
     libpostproc    54.  0.100 / 54.  0.100

    [rtsp @ 0x20c4720] Missing PPS in sprop-parameter-sets, ignoring
    [h264 @ 0x20c7f60] non-existing PPS 0 referenced
       Last message repeated 1 times
    [h264 @ 0x20c7f60] decode_slice_header error
    [h264 @ 0x20c7f60] no frame!
    [rtsp @ 0x20c4720] RTP: missed 1137 packets
    [rtsp @ 0x20c4720] max delay reached. need to consume packet
    [rtsp @ 0x20c4720] RTP: missed 1125 packets
    [rtsp @ 0x20c4720] max delay reached. need to consume packet
    [rtsp @ 0x20c4720] RTP: missed 1126 packets

    Guessed Channel Layout for Input Stream #0.1 : mono
    Input #0, rtsp, from 'rtsp://admin:12345@192.168.1.3/MPEG-4/ch1/main/av_stream':
     Metadata:
       title           : HIK Media Server
       comment         : HIK Media Server Session Description : standard
     Duration: N/A, start: 0.000000, bitrate: N/A
       Stream #0:0: Video: h264 (Baseline), yuv420p, 352x288, 10 fps, 25 tbr, 90k tbn, 20 tbc
       Stream #0:1: Audio: pcm_mulaw, 8000 Hz, 1 channels, s16, 64 kb/s
    [ffm @ 0x21c0e80] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.

    Output #0, ffm, to 'http://192.168.1.105:9500/feed1.ffm':
     Metadata:
       title           : HIK Media Server
       comment         : HIK Media Server Session Description : standard
       creation_time   : now
       encoder         : Lavf57.41.100
       Stream #0:0: Video: flv1 (flv), yuv420p, 352x288, q=1-5, 100 kb/s, 10 fps, 1000k tbn, 15 tbc

       Metadata:
         encoder         : Lavc57.48.101 flv
       Side data:
         cpb: bitrate max/min/avg: 200000/0/100000 buffer size: 655360000 vbv_delay: -1

    Stream mapping:
     Stream #0:0 -> #0:0 (h264 (native) -> flv1 (flv))
    Press [q] to stop, [?] for help
    frame=    0 fps=0.0 q=0.0 size=       4kB time=00:00:00.00 bitrate=N/A speed=   frame=    0 fps=0.0 q=0.0 size=       4kB time=00:00:00.00 bitrate=N/A speed=   frame=    0 fps=0.0 q=0.0 size=       4kB time=00:00:00.00 bitrate=N/A speed=   Past duration 1.003319 too large
       Last message repeated 1 times
    Past duration 1.005333 too large
    frame=   31 fps= 15 q=31.0 size=      56kB time=00:00:02.00 bitrate= 229.4kbits/Past duration 1.005653 too large
    Past duration 1.005989 too large
    frame=   37 fps= 15 q=24.8 size=      76kB time=00:00:02.40 bitrate= 259.4kbits/Past duration 1.006660 too large
    Past duration 1.006996 too large
    frame=   46 fps= 15 q=31.0 size=      80kB time=00:00:03.00 bitrate= 218.5kbits/Past duration 1.007988 too large
    Past duration 1.008659 too large
    frame=   53 fps= 15 q=31.0 size=      96kB time=00:00:03.46 bitrate= 226.9kbits/Past duration 1.009987 too large
    Past duration 1.010323 too large
    frame=   61 fps= 15 q=24.8 size=     116kB time=00:00:04.00 bitrate= 237.6kbits/Past duration 1.010994 too large
    Past duration 1.011330 too large
    Past duration 1.011986 too large
    frame=   68 fps= 15 q=31.0 size=     120kB time=00:00:04.46 bitrate= 220.1kbits/Past duration 1.012657 too large

    [rtsp @ 0x20c4720] max delay reached. need to consume packet
    [rtsp @ 0x20c4720] RTP: missed 1114 packets
    [rtsp @ 0x20c4720] max delay reached. need to consume packet
    [rtsp @ 0x20c4720] RTP: missed 1115 packets
    Past duration 1.012993 too large
    frame=   76 fps= 15 q=31.0 size=     140kB time=00:00:05.00 bitrate= 229.4kbits/Past duration 1.013664 too large
    Past duration 1.014320 too large
    Past duration 1.014656 too large
    frame=   83 fps= 15 q=31.0 size=     144kB time=00:00:05.46 bitrate= 215.8kbits/Past duration 1.015327 too large
    [rtsp @ 0x20c4720] max delay reached. need to consume packet
    [rtsp @ 0x20c4720] RTP: missed 1103 packets
    [rtsp @ 0x20c4720] max delay reached. need to consume packet
    [rtsp @ 0x20c4720] RTP: missed 1104 packets

    Past duration 1.015999 too large
    frame=   91 fps= 15 q=31.0 size=     160kB time=00:00:06.00 bitrate= 218.5kbits/Past duration 1.016655 too large
    Past duration 1.017326 too large
    Past duration 1.017998 too large
    frame=   98 fps= 15 q=31.0 size=     180kB time=00:00:06.46 bitrate= 228.0kbits/Past duration 1.018654 too large
    [rtsp @ 0x20c4720] max delay reached. need to consume packet
    [rtsp @ 0x20c4720] RTP: missed 1092 packets
    [rtsp @ 0x20c4720] max delay reached. need to consume packet
    [rtsp @ 0x20c4720] RTP: missed 1093 packets
    Past duration 1.019325 too large
    frame=  106 fps= 15 q=31.0 size=     184kB time=00:00:07.00 bitrate= 215.3kbits/Past duration 1.019997 too large
    [rtsp @ 0x20c4720] max delay reached. need to consume packet
    [rtsp @ 0x20c4720] RTP: missed 35 packets
    Past duration 1.020653 too large
    frame=  161 fps= 15 q=31.0 size=     264kB time=00:00:10.66 bitrate= 202.8kbits/Past duration 1.032661 too large
    Past duration 1.033333 too large
    frame=  167 fps= 15 q=31.0 Lsize=     276kB time=00:00:11.06 bitrate= 204.3kbits/s dup=94 drop=0 speed=0.964x
    video:265kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 4.280833%

    I can see that with some errors, the stream starts.
    When i put the output url in my html code, there is no stream. I also tried playing the network stream in VLC and did not get anything. Can anyone please help me with that ? Any leads are also appreciated. Thank you.

    My HTML Code is :