Recherche avancée

Médias (2)

Mot : - Tags -/doc2img

Autres articles (55)

  • Le profil des utilisateurs

    12 avril 2011, par

    Chaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
    L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...)

  • 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 (...)

  • XMP PHP

    13 mai 2011, par

    Dixit Wikipedia, XMP signifie :
    Extensible Metadata Platform ou XMP est un format de métadonnées basé sur XML utilisé dans les applications PDF, de photographie et de graphisme. Il a été lancé par Adobe Systems en avril 2001 en étant intégré à la version 5.0 d’Adobe Acrobat.
    Étant basé sur XML, il gère un ensemble de tags dynamiques pour l’utilisation dans le cadre du Web sémantique.
    XMP permet d’enregistrer sous forme d’un document XML des informations relatives à un fichier : titre, auteur, historique (...)

Sur d’autres sites (5382)

  • How to optimize ffmpeg w/ x264 for multiple bitrate output files

    10 octobre 2013, par Jonesy

    The goal is to create multiple output files that differ only in bitrate from a single source file. The solutions for this that were documented worked, but had inefficiencies. The solution that I discovered to be most efficient was not documented anywhere that I could see. I am posting it here for review and asking if others know of additional optimizations that can be made.

    Source file       MPEG-2 Video (Letterboxed) 1920x1080 @>10Mbps
                     MPEG-1 Audio @ 384Kbps
    Destiation files  H264 Video 720x400 @ multiple bitrates
                     AAC Audio @ 128Kbps
    Machine           Multi-core Processor

    The video quality at each bitrate is important so we are running in 2-Pass mode with the 'medium' preset

    VIDEO_OPTIONS_P2 = -vcodec libx264 -preset medium -profile:v main -g 72 -keyint_min 24 -vf scale=720:-1,crop=720:400

    The first approach was to encode them all in parallel processes

    ffmpeg -y -i $INPUT_FILE $AUDIO_OPTIONS_P2 $VIDEO_OPTIONS_P2 -b:v 250k -threads auto -f mp4 out-250.mp4 &
    ffmpeg -y -i $INPUT_FILE $AUDIO_OPTIONS_P2 $VIDEO_OPTIONS_P2 -b:v 500k -threads auto -f mp4 out-500.mp4 &
    ffmpeg -y -i $INPUT_FILE $AUDIO_OPTIONS_P2 $VIDEO_OPTIONS_P2 -b:v 700k -threads auto -f mp4 out-700.mp4 &
    

    The obvious inefficiencies are that the source file is read, decoded, scaled, and cropped identically for each process. How can we do this once and then feed the encoders with the result ?

    The hope was that generating all the encodes in a single ffmpeg command would optimize-out the duplicate steps.

    ffmpeg -y -i $INPUT_FILE \
    $AUDIO_OPTIONS_P2 $VIDEO_OPTIONS_P2 -b:v 250k -threads auto -f mp4 out-250.mp4 \
    $AUDIO_OPTIONS_P2 $VIDEO_OPTIONS_P2 -b:v 500k -threads auto -f mp4 out-500.mp4 \
    $AUDIO_OPTIONS_P2 $VIDEO_OPTIONS_P2 -b:v 700k -threads auto -f mp4 out-700.mp4

    However, the encoding time was nearly identical to the previous multi-process approach. This leads me to believe that all the steps are again being performed in duplicate.

    To force ffmpeg to read, decode, and scale only once, I put those steps in one ffmpeg process and piped the result into another ffmpeg process that performed the encoding. This improved the overall processing time by 15%-20%.

    INPUT_STREAM="ffmpeg -i $INPUT_FILE -vf scale=720:-1,crop=720:400 -threads auto -f yuv4mpegpipe -"

    $INPUT_STREAM | ffmpeg -y -f yuv4mpegpipe -i - \
    $AUDIO_OPTIONS_P2 $VIDEO_OPTIONS_P2 -b:v 250k -threads auto out-250.mp4 \
    $AUDIO_OPTIONS_P2 $VIDEO_OPTIONS_P2 -b:v 500k -threads auto out-500.mp4 \
    $AUDIO_OPTIONS_P2 $VIDEO_OPTIONS_P2 -b:v 700k -threads auto out-700.mp4

    Does anyone see potential problems with doing it this way, or know of a better method ?

  • Using WebHDFS to play video over HTTP

    3 février 2015, par Qin.Yang

    I used ffmpeg + libx264 to convert file format as H264, then uploaded the file to Hadoop. I used WebHDFS to access the file by HTTP, but can not online play. If I download this file over HTTP, it can play by HTML5 video. My English is poor, hope you know what I mean.

  • How to render a blend of two videos with alpha channel in python in real time ? [closed]

    21 décembre 2024, par Francesco Calderone

    I need to play two videos in real time in Python.
One video is a background video with no alpha channel. I am using H264 but it can be any codec.
The second video is an overlay video. This video with an alpha channel needs to be played in real-time on top of the first video. I am using Quicktime 444 with an alpha channel but again, it can be any codec.

    


    In terms of libraries, I tried a combination of cv and numpy, I tried pymovie, pyAV, ffmpeg... so far, all the results have been unsuccessful. When the videos render, the frame rate drops way below 30FPS, and the resulting stream is glitchy.

    


    I also tried rendering the video without an alpha channel and performing green screen chroma keying in real-time. Needless to say, even worse.

    


    What solution can I use ?

    


    Here's my attempted code with ffmpeg

    


    import ffmpeg
import cv2
import numpy as np

def decode_video_stream(video_path, pix_fmt, width, height, fps):
    process = (
        ffmpeg
        .input(video_path)
        .output('pipe:', format='rawvideo', pix_fmt=pix_fmt, s=f'{width}x{height}', r=fps)
        .run_async(pipe_stdout=True, pipe_stderr=True)
    )
    return process

def read_frame(process, width, height, channels):
    frame_size = width * height * channels
    raw_frame = process.stdout.read(frame_size)
    if not raw_frame:
        return None
    frame = np.frombuffer(raw_frame, np.uint8).reshape((height, width, channels))
    return frame

def play_videos_with_alpha(base_video_path, alpha_video_path, resolution=(1280, 720), fps=30):
    width, height = resolution
    frame_time = int(1000 / fps)  # Frame time in milliseconds

    # Initialize FFmpeg decoding processes
    base_process = decode_video_stream(base_video_path, 'rgb24', width, height, fps)
    alpha_process = decode_video_stream(alpha_video_path, 'rgba', width, height, fps)

    cv2.namedWindow("Blended Video", cv2.WINDOW_NORMAL)

    try:
        while True:
            # Read frames
            base_frame = read_frame(base_process, width, height, channels=3)
            alpha_frame = read_frame(alpha_process, width, height, channels=4)

            # Restart processes if end of video is reached
            if base_frame is None:
                base_process.stdout.close()
                base_process = decode_video_stream(base_video_path, 'rgb24', width, height, fps)
                base_frame = read_frame(base_process, width, height, channels=3)

            if alpha_frame is None:
                alpha_process.stdout.close()
                alpha_process = decode_video_stream(alpha_video_path, 'rgba', width, height, fps)
                alpha_frame = read_frame(alpha_process, width, height, channels=4)

            # Separate RGB and alpha channels from alpha video
            rgb_image = cv2.cvtColor(alpha_frame[:, :, :3], cv2.COLOR_RGB2BGR)
            alpha_channel = alpha_frame[:, :, 3] / 255.0  # Normalize alpha

            # Convert base frame to BGR format for blending
            base_image = cv2.cvtColor(base_frame, cv2.COLOR_RGB2BGR)

            # Blend the images
            blended_image = (base_image * (1 - alpha_channel[:, :, None]) + rgb_image * alpha_channel[:, :, None]).astype(np.uint8)

            # Display the result
            cv2.imshow("Blended Video", blended_image)

            if cv2.waitKey(frame_time) & 0xFF == ord('q'):
                break

    except Exception as e:
        print("Error during playback:", e)

    finally:
        # Clean up
        base_process.stdout.close()
        alpha_process.stdout.close()
        cv2.destroyAllWindows()

base_video_path = "test.mp4"  # Background video
alpha_video_path = "test.mov"  # Overlay video
play_videos_with_alpha(base_video_path, alpha_video_path, resolution=(1280, 720), fps=30)


    


    Which is so far the version that drops less frames. I've been thinking about threading, or using CUDA, but ideally I want something that runs pretty much on any machine. What would be the least computationally heavy operation without reducing the frame size (1920 x 1080) and without pre-rendering the blend and exporting pre-blended file ? Is there a way ? Maybe I'm getting at it all wrong. I feel lost. Please help. Thanks.