Recherche avancée

Médias (1)

Mot : - Tags -/Rennes

Autres articles (78)

  • 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

  • Organiser par catégorie

    17 mai 2013, par

    Dans MédiaSPIP, une rubrique a 2 noms : catégorie et rubrique.
    Les différents documents stockés dans MédiaSPIP peuvent être rangés dans différentes catégories. On peut créer une catégorie en cliquant sur "publier une catégorie" dans le menu publier en haut à droite ( après authentification ). Une catégorie peut être rangée dans une autre catégorie aussi ce qui fait qu’on peut construire une arborescence de catégories.
    Lors de la publication prochaine d’un document, la nouvelle catégorie créée sera proposée (...)

  • Récupération d’informations sur le site maître à l’installation d’une instance

    26 novembre 2010, par

    Utilité
    Sur le site principal, une instance de mutualisation est définie par plusieurs choses : Les données dans la table spip_mutus ; Son logo ; Son auteur principal (id_admin dans la table spip_mutus correspondant à un id_auteur de la table spip_auteurs)qui sera le seul à pouvoir créer définitivement l’instance de mutualisation ;
    Il peut donc être tout à fait judicieux de vouloir récupérer certaines de ces informations afin de compléter l’installation d’une instance pour, par exemple : récupérer le (...)

Sur d’autres sites (4690)

  • 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;

  • Batch execute (ffmpeg) command on multiple sets of images at once [Novice]

    23 septembre 2021, par Ethan Kendrick

    I'm relatively new to navigating Python libraries, Windows batch processing, and coding as a whole. Here is my situation :

    &#xA;

    I have multiple folders each with n images in them, where n is a number divisible by 7.&#xA;In each folder, the images are in sets of 7, grouped by their name. If one set of these images was named "apple", I would have the following seven images with the following naming structure :

    &#xA;

    Apple.0_aspect-gigapixel-art-scale-4_00x.png,&#xA;Apple.1_aspect-gigapixel-art-scale-4_00x.png,&#xA;Apple.2_aspect-gigapixel-art-scale-4_00x.png,&#xA;Apple.3_aspect-gigapixel-art-scale-4_00x.png,&#xA;Apple.4_aspect-gigapixel-art-scale-4_00x.png,&#xA;Apple.5_aspect-gigapixel-art-scale-4_00x.png&#xA;Apple_aspect-gigapixel-art-scale-4_00x.png&#xA;(Please note that that order matters, the numberless file should be the last, but if the files are sorted by alphabetical/date, that should already be the case.)

    &#xA;

    For each one of these sets of images inside of one of the folders, I am using ffmpeg to make a video file with the guidelines outlined in this post. On that post I received great help from the user Gyan, who gave me this command : ffmpeg -framerate 10 -i %d.png -vf "split=2[head][loop];[head]trim=end_frame=4[head];[loop]trim=start_frame=3,setpts=PTS-STARTPTS,loop=6:4:0,shuffleframes=1 2 3 2[tail];[head][tail]concat=n=2:v=1:a=0" out.mp4. I am wanting to batch execute this command in each of my folders of images, having it create a video file for each one of the groups of 7.

    &#xA;

    TLDR ; How can I batch execute a ffmpeg command (above) on multiple sets of images at once ?

    &#xA;

    Thank you all so much. I very much appreciate the help I've received so far.

    &#xA;

  • Append two videos without duplicating FFMPEG

    10 septembre 2021, par Hasindu Lanka

    Let's say we have 2 video files (X,Y) in the same format, codec and dimensions.

    &#xA;

    X is a longer video with several gigabytes in size. Y is a short 10 second video. I want to append Y to the end of X without creating another copy of X (Because it's big in size)

    &#xA;

    I have to repeat this process for hours with many 10 second videos arriving one after another.

    &#xA;

    Currently, I'm concatenating files using ffmpeg.

    &#xA;

    ffmpeg -f concat -safe 0 -i chunk.list -c copy final-video.mkv

    &#xA;

    chunk.list contains file names of X and several 10 second videos. After this, X will be deleted and replaced by final-video.mkv. Then, repeat.

    &#xA;

    But this needs twice the storage capacity and I/O operations. How to do this without creating duplicates ?

    &#xA;

    It's okay to duplicate these 10 second videos. But duplicating that bigger file X really hurts performance.

    &#xA;

    Additional info :

    &#xA;

    All these videos will be encoded with H264, H265, VP8 or VP9 and contained in MKV or MP4 as they are codec copy friendly. Only one of these formats will be used.

    &#xA;

    This is for a special case screen recorder that's supposed to run on cloud and preemptive remote desktops (Linux).&#xA;HTML/JS browser front-end captures the screen and sends to the back-end (Golang) as chunks through HTTP. Network route is undefined and unreliable as there can be firewalls/proxies between the front-end and the back-end. Therefore, we can't use connections like UDP. So the only option is to send video chunks using HTTP.

    &#xA;

    It's FOSS on https://github.com/HasinduLanka/screencorder

    &#xA;