Recherche avancée

Médias (3)

Mot : - Tags -/spip

Autres articles (2)

  • Selection of projects using MediaSPIP

    2 mai 2011, par

    The examples below are representative elements of MediaSPIP specific uses for specific projects.
    MediaSPIP farm @ Infini
    The non profit organizationInfini develops hospitality activities, internet access point, training, realizing innovative projects in the field of information and communication technologies and Communication, and hosting of websites. It plays a unique and prominent role in the Brest (France) area, at the national level, among the half-dozen such association. Its members (...)

  • Sélection de projets utilisant MediaSPIP

    29 avril 2011, par

    Les exemples cités ci-dessous sont des éléments représentatifs d’usages spécifiques de MediaSPIP pour certains projets.
    Vous pensez avoir un site "remarquable" réalisé avec MediaSPIP ? Faites le nous savoir ici.
    Ferme MediaSPIP @ Infini
    L’Association Infini développe des activités d’accueil, de point d’accès internet, de formation, de conduite de projets innovants dans le domaine des Technologies de l’Information et de la Communication, et l’hébergement de sites. Elle joue en la matière un rôle unique (...)

Sur d’autres sites (2305)

  • Python cv2 script that scans a giant image to a video. Raises error : Unknown C++ exception from OpenCV code

    26 avril 2022, par Nolrenea

    I wrote a script that scans a giant image to make a video. Normally I just post my scripts straight to my Code Review account, but this script is ugly, needs to be refactored, implements only horizontal scrolling and contains a bug that I can't get rid of.

    


    It is working but not perfect, I can't get the last line at the bottom of the image, with height of image_height % 1080. If I ignore it, the code is working fine, if I try to fix it, it throws exceptions.

    


    Example :

    


    Original image (Google Drive)

    


    Video Output (Google Drive)

    


    As you can see from the video, everything is working properly except the fact that I can't get the bottom line.

    


    Full working code

    



    

    import cv2
import numpy as np
import random
import rpack
from fractions import Fraction
from math import prod

def resize_guide(image_size, target_area):
    aspect_ratio = Fraction(*image_size).limit_denominator()
    horizontal = aspect_ratio.numerator
    vertical = aspect_ratio.denominator
    unit_length = (target_area/(horizontal*vertical))**.5
    return (int(horizontal*unit_length), int(vertical*unit_length))

fourcc = cv2.VideoWriter_fourcc(*'h264')
FRAME = np.zeros((1080, 1920, 3), dtype=np.uint8)

def new_frame():
    return np.ndarray.copy(FRAME)

def center(image):
    frame = new_frame()
    h, w = image.shape[:2]
    yoff = round((1080-h)/2)
    xoff = round((1920-w)/2)
    frame[yoff:yoff+h, xoff:xoff+w] = image
    return frame

def image_scanning(file, fps=60, pan_increment=64, horizontal_increment=8, fast_decrement=256):
    image = cv2.imread(file)
    height, width = image.shape[:2]
    assert width*height >= 1920*1080
    video_writer = cv2.VideoWriter(file+'.mp4', fourcc, fps, (1920, 1080))
    fit_height = True
    if height < 1080:
        width = width*1080/height
        image = cv2.resize(image, (width, 1080), interpolation = cv2.INTER_AREA)
    aspect_ratio = width / height
    zooming_needed = False
    if 4/9 <= aspect_ratio <= 16/9:
        new_width = round(width*1080/height)
        fit = cv2.resize(image, (new_width, 1080), interpolation = cv2.INTER_AREA)
        zooming_needed = True
    
    elif 16/9 < aspect_ratio <= 32/9:
        new_height = round(height*1920/width)
        fit = cv2.resize(image, (1920, new_height), interpolation = cv2.INTER_AREA)
        fit_height = False
        zooming_needed = True
    
    centered = center(fit)
    for i in range(fps):
        video_writer.write(centered)
    if fit_height:
        xoff = round((1920 - new_width)/2)
        while xoff:
            if xoff - pan_increment >= 0:
                xoff -= pan_increment
            else:
                xoff = 0
            frame = new_frame()
            frame[0:1080, xoff:xoff+new_width] = fit
            video_writer.write(frame)
    else:
        yoff = round((1080 - new_height)/2)
        while yoff:
            if yoff - pan_increment >= 0:
                yoff -= pan_increment
            else:
                yoff = 0
            frame = new_frame()
            frame[yoff:yoff+new_height, 0:1920] = fit
            video_writer.write(frame)
    
    if zooming_needed:
        if fit_height:
            width_1, height_1 = new_width, 1080
        else:
            width_1, height_1 = 1920, new_height
        new_area = width_1 * height_1
        original_area = width * height
        area_diff = original_area - new_area
        unit_diff = area_diff / fps
        for i in range(1, fps+1):
            zoomed = cv2.resize(image, resize_guide((width_1, height_1), new_area+unit_diff*i), interpolation=cv2.INTER_AREA)
            zheight, zwidth = zoomed.shape[:2]
            zheight = min(zheight, 1080)
            zwidth = min(zwidth, 1920)
            frame = new_frame()
            frame[0:zheight, 0:zwidth] = zoomed[0:zheight, 0:zwidth]
            video_writer.write(frame)
    y, x = 0, 0
    completed = False
    while y != height - 1080:
        x = 0
        while x != width - 1920:
            if x + horizontal_increment + 1920 <= width:
                x += horizontal_increment
                frame = image[y:y+1080, x:x+1920]
                video_writer.write(frame)
            else:
                x = width - 1920
                frame = image[y:y+1080, x:x+1920]
                for i in range(round(fps/3)):
                    video_writer.write(frame)
                if y == height - 1080:
                    completed = True
        while x != 0:
            if x - fast_decrement - 1920 >= 0:
                x -= fast_decrement
            else:
                x = 0
            frame = image[y:y+1080, x:x+1920]
            video_writer.write(frame)
        if y + 2160 <= height:
            y += 1080
        else:
            y = height - 1080
    cv2.destroyAllWindows()
    video_writer.release()
    del video_writer


    


    The above the the code needed to produce the example video. It is working but the bottom line is missing.

    


    Now if I change the last few lines to this :

    


            if y + 2160 <= height:
            y += 1080
        else:
            y = height - 1080
            x = 0
            while x != width - 1920:
                if x + horizontal_increment + 1920 <= width:
                    x += horizontal_increment
                    frame = image[y:y+1080, x:x+1920]
                    video_writer.write(frame)
    cv2.destroyAllWindows()
    video_writer.release()
    del video_writer


    


    I expect it to include the bottom line, but it just throws exceptions instead :

    


    OpenCV: FFMPEG: tag 0x34363268/&#x27;h264&#x27; is not supported with codec id 27 and format &#x27;mp4 / MP4 (MPEG-4 Part 14)&#x27;&#xA;OpenCV: FFMPEG: fallback to use tag 0x31637661/&#x27;avc1&#x27;&#xA;---------------------------------------------------------------------------&#xA;error                                     Traceback (most recent call last)&#xA; in <module>&#xA;----> 1 image_scanning("D:/collages/91f53ebcea2a.png")&#xA;&#xA; in image_scanning(file, fps, pan_increment, horizontal_increment, fast_decrement)&#xA;    122                     x &#x2B;= horizontal_increment&#xA;    123                     frame = image[y:y&#x2B;1080, x:x&#x2B;1920]&#xA;--> 124                     video_writer.write(frame)&#xA;    125     cv2.destroyAllWindows()&#xA;    126     video_writer.release()&#xA;&#xA;error: Unknown C&#x2B;&#x2B; exception from OpenCV code&#xA;</module>

    &#xA;

    (If you can't get the example code working I can't help you, but I am using Python 3.9.10 x64 on Windows 10, and I have this file : "C :\Windows\System32\openh264-1.8.0-win64.dll", the '.avi' format generates video files with Gibibytes (binary unit, not SI Gigabyte) of size)

    &#xA;

    How to get rid of the exception ?

    &#xA;

  • docker service create : How to deal with custom or unknown parameter needed by linuxserver/ffmpeg image ?

    24 mai 2022, par Mike

    I am new to docker and docker swarm and started dockerizing several services and am trying to get them running as docker swarm services. I ran into a road block with the linuxserver/ffmpeg image :

    &#xA;

      &#xA;
    1. it uses a —device parameter which is not implemented in create service
    2. &#xA;

    3. it expects several custom parameters to pass them to the ffmpeg encoder
    4. &#xA;

    &#xA;

    From my research up to now I assume that passing parameters is not implemented in docker create service, but maybe you can think of a workaround ? (unfortunately the image does not process environment variables, or at least they are not documented)

    &#xA;

    This is how I start dockerized ffmpeg (working fine in standalone mode) :

    &#xA;

    docker run -d /
    &#xA;—network="host" /
    &#xA;—device=/dev/video0 :/dev/video0 / ### error : unknow flag
    &#xA;—name ffmpeg_streamer /
    &#xA;—restart always -it /
    &#xA;-v $(pwd)/video :/video /
    &#xA;linuxserver/ffmpeg / ### custom parameters below here
    &#xA;-stream_loop /
    &#xA;-1 -re -nostdin /
    &#xA;-i "/video/test.avi" /
    &#xA;-f pulse /
    &#xA;-vcodec libx264 /
    &#xA;-preset:v veryfast /
    &#xA;-b:v 400k /
    &#xA;-f flv rtmp ://localhost:1935/live/streamkey

    &#xA;

    Many thanks for looking into this !

    &#xA;

  • ffmpeg -vcodec is not working , unknown encoder [closed]

    24 mai 2022, par Younghwan Kim

    i want to use ffmpeg to encode ,&#xA;but i guess it's not working '-vcodec' option,

    &#xA;

    command :

    &#xA;

     ffmpeg -i test.mp4 -vcodec videocodec -acodec audiocodec test.flv 2>&amp;1&#xA;

    &#xA;

    output :

    &#xA;

      libswresample   4.  3.100 /  4.  3.100&#xA;  libpostproc    56.  3.100 / 56.  3.100&#xA;  Input #0, mov,mp4,m4a,3gp,3g2,mj2, from &#x27;test.mp4&#x27;:&#xA;  Metadata:&#xA;  major_brand     : isom&#xA;  minor_version   : 512&#xA;  compatible_brands: isomiso2avc1mp41&#xA;  encoder         : Lavf58.45.100&#xA;  Duration: 00:02:34.40, start: 0.000000, bitrate: 934 kb/s&#xA;  Stream #0:0[0x1](und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(progressive), &#xA;  1916x1032 [SAR 1:1 DAR 479:258], 921 kb/s, 30 fps, 30 tbr, 15360 tbn (default)&#xA;  Metadata:&#xA;  handler_name    : VideoHandler&#xA;  vendor_id       : [0][0][0][0]&#xA;  Stream #0:1[0x2](eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 4 kb/s &#xA;  (default)&#xA;  Metadata:&#xA;  handler_name    : AAC Audio Track&#xA;  vendor_id       : [0][0][0][0]&#xA;  **Unknown encoder &#x27;videocodec&#x27;**&#xA;

    &#xA;

    how can i figure it out ?

    &#xA;