Recherche avancée

Médias (1)

Mot : - Tags -/remix

Autres articles (67)

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

  • HTML5 audio and video support

    13 avril 2011, par

    MediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
    The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
    For older browsers the Flowplayer flash fallback is used.
    MediaSPIP allows for media playback on major mobile platforms with the above (...)

Sur d’autres sites (12392)

  • Efficiently Fetching the Latest Frame from a Live Stream using OpenCV in Python

    10 juillet 2023, par Nicolantonio De Bari

    Problem :

    


    I have a FastAPI server that connects to a live video feed using cv2.VideoCapture. The server then uses OpenCV to process the frames for object detection and sends the results to a WebSocket. Here's the relevant part of my code :

    


    class VideoProcessor:
    # ...

    def update_frame(self, url):
        logger.info("update_frame STARTED")
        cap = cv2.VideoCapture(url)
        while self.capture_flag:
            ret, frame = cap.read()
            if ret:
                frame = cv2.resize(frame, (1280, 720))
                self.current_frame = frame
            else:
                logger.warning("Failed to read frame, retrying connection...")
                cap.release()
                time.sleep(1)
                cap = cv2.VideoCapture(url)

    async def start_model(self, url, websocket: WebSocket):
        # ...
        threading.Thread(target=self.update_frame, args=(url,), daemon=True).start()
        while self.capture_flag:
            if self.current_frame is not None:
                frame = cv2.resize(self.current_frame, (1280, 720))
                bbx = await self.process_image(frame)
                await websocket.send_text(json.dumps(bbx))
                await asyncio.sleep(0.1)


    


    Currently, I'm using a separate thread (update_frame) to continuously fetch frames from the live feed and keep the most recent one in self.current_frame.

    


    The issue with this method is that it uses multi-threading and continuously reads frames in the background, which is quite CPU-intensive. The cv2.VideoCapture.read() function fetches the oldest frame in the buffer, and OpenCV does not provide a direct way to fetch the latest frame.

    


    Goal

    


    I want to optimize this process by eliminating the need for a separate thread and fetching the latest frame directly when I need it. I want to ensure that each time I process a frame in start_model, I'm processing the most recent frame from the live feed.

    


    I have considered a method of continuously calling cap.read() in a tight loop to "clear" the buffer, but I understand that this is inefficient and can lead to high CPU usage.

    


    Attempt :

    


    What I then tried to do is use ffmpeg & subprocess to get the latest frame, but I dont seem to understand how to get the latest frame then.

    


    async def start_model(self, url, websocket: WebSocket):
    try:
        logger.info("Model Started")
        self.capture_flag = True

        command = ["ffmpeg", "-i", url, "-f", "image2pipe", "-pix_fmt", "bgr24", "-vcodec", "rawvideo", "-"]
        pipe = subprocess.Popen(command, stdout=subprocess.PIPE, bufsize=10**8)

        while self.capture_flag:
            raw_image = pipe.stdout.read(1280*720*3)  # read 720p frame (BGR)
            if raw_image == b'':
                logger.warning("Failed to read frame, retrying connection...")
                await asyncio.sleep(1) # delay for 1 second before retrying
                continue
            
            frame = np.fromstring(raw_image, dtype='uint8')
            frame = frame.reshape((720, 1280, 3))
            if frame is not None:
                self.current_frame = frame
                frame = cv2.resize(self.current_frame, (1280, 720))
                bbx = await self.process_image(frame)
                await websocket.send_text(json.dumps(bbx))
                await asyncio.sleep(0.1)
                
        pipe.terminate()

    except WebSocketDisconnect:
        logger.info("WebSocket disconnected during model operation")
        self.capture_flag = False  # Ensure to stop the model operation when the WebSocket disconnects


    


    Question

    


    Is there a more efficient way to fetch the latest frame from a live stream using OpenCV in Python ? Can I modify my current setup to get the newest frame without having to read all the frames in a separate thread ?
Or is there another library that I could use ?

    


    I know a similar question has been asked, but not related to video streaming.

    


  • Monitoring for failure and quickly restarting systemd service

    16 février 2024, par mzrt

    I am running a 24/7 youtube stream on Ubuntu. My ffmpeg command is wrapped in a systemd service. On several occasions the ffmpeg command has failed and systemd has not restarted quickly enough to keep the youtube stream alive. When this happens I need to daemon-reload and restart the systemd service.

    


    To counter this I have written a bash script that checks the log for stream ending errors, however, it does not seem to be working. I have had failures since implementing this script, and it did not seem to have been triggered.

    


    two questions :

    


      

    1. is there a more efficient way to do what I am doing ?
    2. 


    3. if not, can anyone identify what I am doing wrong ?
    4. 


    


    #!/bin/bash

RESET=0

while true; do
    # Get the current time minus 1 minute
    LAST_1_MINUTE=$(date -d '1 minute ago' '+%b %e %H:%M:%S')
    
    # Run the command to check for the error within the last minute
    if journalctl --since "$LAST_1_MINUTE" | grep -qi "Error writing trailer"; then
        if [ $RESET -lt 1 ]; then
            # Perform actions if error is detected
            sudo systemctl daemon-reload && \
            echo "Restarting master.service by monitor.sh script at $(date)" >> /var/log/monitor.log && \
            sudo systemctl restart master.service
            RESET=2
        fi
    else
        RESET=$((RESET - 1))
    fi

    # Wait for 20 seconds before the next iteration
    sleep 20
done


    


  • avcodec/ffv1dec : Switch to ProgressFrames

    2 septembre 2022, par Andreas Rheinhardt
    avcodec/ffv1dec : Switch to ProgressFrames
    

    Avoids implicit av_frame_ref() and therefore allocations
    and error checks. It also avoids explicitly allocating
    the AVFrames (done implicitly when getting the buffer).

    It also fixes a data race : The AVFrame's sample_aspect_ratio
    is currently updated after ff_thread_finish_setup()
    and this write is unsynchronized with the read in av_frame_ref().
    Removing the implicit av_frame_ref() fixed this.

    Signed-off-by : Andreas Rheinhardt <andreas.rheinhardt@outlook.com>

    • [DH] libavcodec/ffv1.h
    • [DH] libavcodec/ffv1dec.c