Recherche avancée

Médias (0)

Mot : - Tags -/metadatas

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (67)

  • Configurer la prise en compte des langues

    15 novembre 2010, par

    Accéder à la configuration et ajouter des langues prises en compte
    Afin de configurer la prise en compte de nouvelles langues, il est nécessaire de se rendre dans la partie "Administrer" du site.
    De là, dans le menu de navigation, vous pouvez accéder à une partie "Gestion des langues" permettant d’activer la prise en compte de nouvelles langues.
    Chaque nouvelle langue ajoutée reste désactivable tant qu’aucun objet n’est créé dans cette langue. Dans ce cas, elle devient grisée dans la configuration et (...)

  • La sauvegarde automatique de canaux SPIP

    1er avril 2010, par

    Dans le cadre de la mise en place d’une plateforme ouverte, il est important pour les hébergeurs de pouvoir disposer de sauvegardes assez régulières pour parer à tout problème éventuel.
    Pour réaliser cette tâche on se base sur deux plugins SPIP : Saveauto qui permet une sauvegarde régulière de la base de donnée sous la forme d’un dump mysql (utilisable dans phpmyadmin) mes_fichiers_2 qui permet de réaliser une archive au format zip des données importantes du site (les documents, les éléments (...)

  • Des sites réalisés avec MediaSPIP

    2 mai 2011, par

    Cette page présente quelques-uns des sites fonctionnant sous MediaSPIP.
    Vous pouvez bien entendu ajouter le votre grâce au formulaire en bas de page.

Sur d’autres sites (4153)

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

  • Concatenating audio files and superimposing over video

    25 avril 2022, par kah

    I'm trying to write a program that takes a bunch of videos from a folder, compiles them, and then takes another bunch of audio files from a folder and concatenates them to then overlay the combined audio on top of the final video (hope that makes sense). I'm able to process the videos into one final output video, but I keep running into trouble combining the audio. Below I've provided two small sections of code pertaining to audio comp, I'm using moviepy to process the videos and attempting to use it for audio as well.

    &#xA;

    songDirectory = &#x27;./songs/&#x27;&#xA;songList = []&#xA;songs = []&#xA;audioclip=&#x27;&#x27;&#xA;&#xA;def makeCompilation():&#xA;    for filename in os.listdir(songDirectory):&#xA;        f = os.path.join(songDirectory, filename)&#xA;        if os.path.isfile(f) and filename.endswith(".mp3"):&#xA;            audioclip = moviepy.editor.AudioFileClip(f)&#xA;            songList.append(filename)&#xA;&#xA;&#xA;    for song in os.listdir(songDirectory):&#xA;        c = os.path.join(songDirectory, song)&#xA;    audio_clips = moviepy.editor.AudioFileClip(c)&#xA;    audio_output = moviepy.editor.concatenate_audioclips(audio_clips)&#xA;    finalClip = concatenate_videoclips(videos, method="compose")&#xA;    final_duration = finalClip.duration    &#xA;    final_audio_output = audio_output.set_duration(final_duration)&#xA;    final_output= finalClip.set_audio(final_audio_output).fx(afx.audio_fadein, 3.0)&#xA;&#xA;&#xA;    audio_path = "./songs/tempaudiofile.m4a"&#xA;&#xA;    #print(description)&#xA;    # Create compilation&#xA;    final_output.write_videofile(outputFile, threads=8, temp_audiofile=audio_path, remove_temp=True, codec="libx264", audio_codec="aac")&#xA;&#xA;    return description&#xA;

    &#xA;

    The program appeared to be able to find the audio directory, but I needed to be able to use os.path.join(songDirectory, filename) to point directly to each mp3 file so I messed around with it until I got the above code. And when I attempted to iterate through songList, I, as expected, got an error saying that 'str' wasn't iterable, and other errors saying that 'str' has no attribute 'duration'. Essentially, all I need it to do is iterate though the input folder and combine the files by whatever means. Code currently returns the output :

    &#xA;

    &#127794;Free Fredobagz x Aflacko x Flint type beat - &#x27;Default_Dance&#x27; [prod. kah]-jro0v6ogZ0Y.mp4&#xA;225.05&#xA;Total Length: 225.05&#xA;225.05&#xA;Traceback (most recent call last):&#xA;  File "/Users/daddyK/Desktop/comp_ bot/make_compilation3.py", line 127, in <module>&#xA;makeCompilation(path = "./videos/",&#xA;  File "/Users/daddyK/Desktop/comp_ bot/make_compilation3.py", line 110, in makeCompilation&#xA;audio_output = moviepy.editor.concatenate_audioclips(audio_clips)&#xA;  File "/Users/daddyK/Library/Python/3.10/lib/python/site-packages/moviepy/audio/AudioClip.py", line 315, in concatenate_audioclips&#xA;durations = [c.duration for c in clips]&#xA;TypeError: &#x27;AudioFileClip&#x27; object is not iterable&#xA;</module>

    &#xA;


    &#xA;

    At this point I'm a bit stumped, so if anybody could offer some insight as to what I should do to resolve the error and/or if I'm headed in the right direction code-wise I'd greatly appreciate it ! Sorry if the code doesn't make any sense I'll post the whole .py file if needed

    &#xA;

  • Upload video in php without compress [closed]

    23 avril 2022, par i0x4r

    My brother @MARKUS_AO&#xA;He solved a problem, related to displaying messages after the upload is completed, but there is a problem, I was relying on dropzone as it does not compress the video that I want to upload to the server, and the ffmpeg code also does

    &#xA;

    In question

    &#xA;

    I attached the code, I want in a simple way to upload a video completely without compression, as it used to do dropzone, I want any software or anything else for a problem, the goal is that the video is not under compress (it is preferable to upload only one video, not multiple)

    &#xA;

    <form action="so-upload-71955097" method="post" enctype="multipart/form-data">&#xA;  Select file to upload:&#xA;  <input type="file" />&#xA;  <input type="submit" value="Upload File" />&#xA;</form>&#xA;&#xA;&lt;?php&#xA;/* &#xA;    MCVE for:   https://stackoverflow.com/questions/71955097/how-to-show-result-after-uploaded-file-in-php&#xA;*/&#xA;&#xA;//upload.php&#xA;&#xA;$folder_name = &#x27;tmp/&#x27;;&#xA;// $tumb_name = &#x27;thumb/&#x27;;&#xA;// $imageext = &#x27;.png&#x27;;&#xA;&#xA;if(!empty($_FILES)) {&#xA;&#xA;    $temp_file = $_FILES[&#x27;file&#x27;][&#x27;tmp_name&#x27;];&#xA;    $location = $folder_name . $_FILES[&#x27;file&#x27;][&#x27;name&#x27;];&#xA;    move_uploaded_file($temp_file, $location);&#xA;    $upload = $_FILES[&#x27;file&#x27;][&#x27;name&#x27;];&#xA;    $uploadStr = str_replace(" ", "\ ",$upload);&#xA;    $locationStr = str_replace(" ","\ ",$location);&#xA;    // $cmd  = "ffmpeg -y -i {$locationStr} -ss 00:00:15 -vframes 1 thumb/{$uploadStr}.png 2>&amp;1";&#xA;    // echo shell_exec($cmd);&#xA;    &#xA;    // These lines need to be *INSIDE* the "uploading" condition&#xA;    &#xA;    echo "The file " . $location . " has been uploaded";&#xA;    // not working&#xA;    echo "<br />";&#xA;    echo "The file " . $upload . " has been uploaded";&#xA;    // not working&#xA;    echo "<br />";&#xA;    echo "The file " . $uploadStr . " has been uploaded";&#xA;    // not working&#xA;    echo "<br />";&#xA;    echo "The file " . $locationStr . " has been uploaded";&#xA;}&#xA;?>&#xA;

    &#xA;

    Edit :

    &#xA;

    In this project&#xA;https://github.com/AjayACST/PHP-Video-Uploader

    &#xA;

    It uploads high quality videos without reducing the quality or size of the video&#xA;and it appears in its original form without changes.

    &#xA;

    But the problem of the project :&#xA;The message "The file has been uploaded successfully and path" does not appear

    &#xA;

    So MARKUS AO its changes and the project became similar but Without the dropzone.js

    &#xA;

    which is characterized as fully uploading the video, unlike the traditional upload

    &#xA;

    I just need to integrate the dropzone library, and after the upload is complete, the message "The video file123.mov has been uploaded successfully" appears.

    &#xA;

    Maybe that needs ffmpeg&#xA;but that's attached to the code in the post that my brother MARKUS AO edited.

    &#xA;