Recherche avancée

Médias (91)

Autres articles (85)

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

    Certains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

  • 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

Sur d’autres sites (8979)

  • Problem : FFmpeg and C++ extract and save frame

    26 mai 2021, par Simba_cl25

    I am doing a project where I must do the following : extract frames (along with the associated metadata - KLV) from a video given a period (for the moment every 10 seconds).
I have followed codes found on internet but I get an error that I can find a solution to.

    


    extern "C" {&#xA;#include <libavcodec></libavcodec>avcodec.h>&#xA;#include <libavformat></libavformat>avformat.h>&#xA;#include <libavdevice></libavdevice>avdevice.h>&#xA;#include <libswscale></libswscale>swscale.h>&#xA;#include <libavfilter></libavfilter>avfilter.h>&#xA;#include <libswresample></libswresample>swresample.h>&#xA;#include <libavutil></libavutil>avutil.h>&#xA;#include <libavutil></libavutil>imgutils.h> &#xA;}&#xA;&#xA;static void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame);&#xA;&#xA;&#xA;int main(int argc, const char * argv[])&#xA;{&#xA;    AVFormatContext *pFormatCtx;&#xA;    int             i, videoStream;&#xA;    AVCodecContext  *pCodecCtx = NULL;&#xA;    const AVCodec         *pCodec = NULL;&#xA;    AVFrame         *pFrame;&#xA;    AVFrame         *pFrameRGB;&#xA;    AVPacket        *packet = av_packet_alloc();&#xA;    AVStream        *pStream;&#xA;    int             numBytes;&#xA;    int64_t         Duration;&#xA;    uint8_t         *buffer;&#xA;    bool frameFinished = false;&#xA;&#xA;    // Open video file - check for errors&#xA;    pFormatCtx = 0;&#xA;    if (avformat_open_input(&amp;pFormatCtx, "00Video\\VideoR.ts", 0, 0) != 0)&#xA;        return -1; &#xA;&#xA;    if (avformat_find_stream_info(pFormatCtx, 0) &lt; 0)&#xA;        return -1;&#xA;&#xA;    if (av_find_best_stream(pFormatCtx, AVMEDIA_TYPE_VIDEO, -1, -1, 0, 0) &lt;0)&#xA;        return -1;&#xA;&#xA;    av_dump_format(pFormatCtx, 0, "00Video\\VideoR.ts", false);&#xA;&#xA;&#xA;    // Find the first video stream&#xA;    videoStream = -1;&#xA;    for (i = 0; i &lt; pFormatCtx->nb_streams; i&#x2B;&#x2B;)&#xA;        if (pFormatCtx->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)&#xA;        {&#xA;            videoStream = i;&#xA;            break;&#xA;        }&#xA;    if (videoStream == -1)&#xA;        return -1; &#xA;    &#xA;&#xA;&#xA;    // Find the decoder for the video stream&#xA;    pCodec = avcodec_find_decoder(pFormatCtx->streams[videoStream]->codecpar->codec_id);&#xA;    pCodecCtx = avcodec_alloc_context3(pCodec);&#xA;&#xA;    if (pCodec == NULL)&#xA;    {&#xA;        fprintf(stderr, "Codec not found\n");&#xA;        return -1; &#xA;    }&#xA;&#xA;&#xA;    if (avcodec_open2(pCodecCtx, pCodec, NULL) &lt; 0)&#xA;    {&#xA;        fprintf(stderr, "Could not open codec\n");&#xA;        return -1; &#xA;    }&#xA;&#xA;    // Hack to correct wrong frame rates that seem to be generated by some codecs&#xA;    if (pCodecCtx->time_base.num > 1000 &amp;&amp; pCodecCtx->time_base.den == 1)&#xA;        pCodecCtx->time_base.den = 1000;&#xA;&#xA;&#xA;&#xA;&#xA;    // Allocate video frame - original frame &#xA;    pFrame = av_frame_alloc();&#xA;&#xA;    if (!pFrame) {&#xA;        fprintf(stderr, "Could not allocate video frame\n");&#xA;        return -1;&#xA;    }&#xA;&#xA;&#xA;    // Allocate an AVFrame structure&#xA;    pFrameRGB = av_frame_alloc();&#xA;&#xA;    if (pFrameRGB == NULL)&#xA;    {&#xA;        fprintf(stderr, "Could not allocate video RGB frame\n");&#xA;        return -1;&#xA;    }&#xA;&#xA;    &#xA;    Duration = av_rescale_q(vstrm->duration, vstrm->time_base, { 1,1000 });&#xA;    &#xA;    numBytes = av_image_get_buffer_size(pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, 0);&#xA;    buffer = (uint8_t*)av_malloc(numBytes * sizeof(uint8_t));&#xA;&#xA;&#xA;    av_image_fill_arrays(pFrameRGB->data, pFrameRGB->linesize, buffer, AV_PIX_FMT_RGB24, pCodecCtx->width, pCodecCtx->height, 1);&#xA;    &#xA;    &#xA;        &#xA;    &#xA;    i = 0;&#xA;    while (av_read_frame(pFormatCtx, packet) >= 0)&#xA;    {&#xA;        // Is this a packet from the video stream?&#xA;        if (packet->stream_index == videoStream)&#xA;        {&#xA;            int ret;&#xA;            ret = avcodec_send_packet(pCodecCtx, packet);&#xA;            if (ret &lt; 0 || ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) {&#xA;                fprintf(stderr, "Error sending a packet for decoding\n");&#xA;                //break;&#xA;            }&#xA;            while (ret >= 0) {&#xA;                ret = avcodec_receive_frame(pCodecCtx, pFrame);&#xA;                if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)&#xA;                    return -1;&#xA;                else if (ret &lt; 0) {&#xA;                    fprintf(stderr, "Error during decoding\n");&#xA;                    return -1;&#xA;                 frameFinished = true;&#xA;                }&#xA;&#xA;&#xA;                // Did we get a video frame?&#xA;                if (frameFinished)&#xA;                {&#xA;                    static struct SwsContext *img_convert_ctx;&#xA;&#xA;                    &#xA;                    if (img_convert_ctx == NULL) {&#xA;                        int w = pCodecCtx->width;&#xA;                        int h = pCodecCtx->height;&#xA;                        img_convert_ctx = sws_getContext(w, h,&#xA;                            pCodecCtx->pix_fmt,&#xA;                            w, h, AV_PIX_FMT_RGB24, SWS_FAST_BILINEAR,&#xA;                            NULL, NULL, NULL);&#xA;&#xA;                        if (img_convert_ctx == NULL) {&#xA;                            fprintf(stderr, "Cannot initialize the conversion context!\n");&#xA;                            exit(1);&#xA;                        }&#xA;                    }&#xA;&#xA;                    int ret = sws_scale(img_convert_ctx, pFrame->data, pFrame->linesize, 0,&#xA;                        pCodecCtx->height, pFrameRGB->data, pFrameRGB->linesize);&#xA;&#xA;&#xA;                    // Save the frame to disk&#xA;                    if (i &lt;= Duration)&#xA;                    {&#xA;                        SaveFrame(pFrameRGB, pCodecCtx->width, pCodecCtx->height, i);&#xA;                        i &#x2B;= 10*1000;&#xA;                    }&#xA;                }&#xA;            }&#xA;&#xA;        &#xA;        }&#xA;&#xA;        // Free the packet that was allocated by av_read_frame&#xA;        av_packet_unref(packet);&#xA;    }&#xA;&#xA;    &#xA;&#xA;    // Free the RGB image&#xA;    free(buffer);&#xA;    av_free(pFrameRGB);&#xA;&#xA;    // Free the YUV frame&#xA;    av_free(pFrame);&#xA;&#xA;    // Close the codec&#xA;    avcodec_close(pCodecCtx);&#xA;&#xA;    // Close the video file&#xA;    avformat_close_input(&amp;pFormatCtx);&#xA;    return 0;&#xA;    &#xA;}&#xA;&#xA;&#xA;&#xA;&#xA;static void SaveFrame(AVFrame *pFrame, int width, int height, int iFrame)&#xA;{&#xA;    FILE *pFile;&#xA;    char szFilename[32];&#xA;    int  y;&#xA;&#xA;&#xA;    // Open file&#xA;    sprintf(szFilename, "Im\\frame%d.png", iFrame);&#xA;    pFile = fopen(szFilename, "wb");&#xA;    if (pFile == NULL)&#xA;        return;&#xA;&#xA;    // Write header&#xA;    fprintf(pFile, "P6\n%d %d\n255\n", width, height);&#xA;    // Write pixel data&#xA;    for (y = 0; y &lt; height; y&#x2B;&#x2B;)&#xA;        fwrite(pFrame->data[0] &#x2B; y * pFrame->linesize[0], 1, width*3, pFile);&#xA;&#xA;    // Close file&#xA;    fclose(pFile);&#xA;}&#xA;

    &#xA;

    The error I get is :

    &#xA;

    [swscaler @ 03055A80] bad dst image pointers&#xA;

    &#xA;

    I think is because

    &#xA;

    numBytes = av_image_get_buffer_size(pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, 0);&#xA;

    &#xA;

    Returns a negative value ( -22) but I don't know why.

    &#xA;

    Thanks,

    &#xA;

  • How to convert mp3 data to wav data ?

    12 mai 2023, par Yali

    I have a wav audio file and i extracted data from that wav using python pydub module and i got this data

    &#xA;

    [-139 18 -215 34 -196 6 -295 -31 -301 -35 -211 13 -93 47&#xA;-60 39 -58 7 -17 2]

    &#xA;

    (this is first 10 data i got more than 1 million data)

    &#xA;

    from pydub import AudioSegment&#xA;import numpy as np&#xA;&#xA;song = AudioSegment.from_file("test.wav")&#xA;extract_data = np.array(song.get_array_of_samples())&#xA;print(extract_data[:10])&#xA;

    &#xA;

    then i converted wav to mp3 using that module and again extracted data from mp3 file and i got this data

    &#xA;

    [-108 7 -193 24 -223 11 -239 -31 -248 -43 -203 -10 -101 23&#xA;-14 24 10 15 24 16]

    &#xA;

    (this is first 10 data i got more than 1 million data)

    &#xA;

    song = AudioSegment.from_file("test.wav")&#xA;song.export("test.mp3")&#xA;mp3_song = AudioSegment.from_file("test.mp3")&#xA;extract_data = np.array(mp3_song.get_array_of_samples())&#xA;print(extract_data[:10])&#xA;

    &#xA;

    and again i converted mp3 to wav now i got mp3 data instead of wav data.

    &#xA;

    mp3_song = AudioSegment.from_file("test.mp3")&#xA;mp3_song.export("test1.wav", format="wav")&#xA;&#xA;song = AudioSegment.from_file("test1.wav")&#xA;extract_data = np.array(song.get_array_of_samples())&#xA;print(extract_data[:10])&#xA;

    &#xA;

    My point is how to convert mp3 data to original wav data ?

    &#xA;

    please help me,

    &#xA;

    Thanks.

    &#xA;

  • How to save last 30 seconds of video in py

    5 juin 2024, par Mateus Coelho

    I want the last 30 seconds to be recorded every time I click enter and sent to the cloud. for example, if I click at 00:10:30, I want a video that records from 00:10:00 to 00:10:30 and if I click in sequence at 00:10:32, I need another different video that in its content is recorded from 00:10:02 to 00:10:32.

    &#xA;

    I think I have a problem where I will always end up recovering from the same buffer in the last 30 seconds. Is there any approach so that whenever I click enter I retrieve a unique video ? Is my current approach the best for the problem ? Or should I use something else ?

    &#xA;

    import subprocess&#xA;import os&#xA;import keyboard&#xA;from datetime import datetime&#xA;from google.cloud import storage&#xA;&#xA;# Configuration&#xA;STATE = "mg"&#xA;CITY = "belohorizonte"&#xA;COURT = "duna"&#xA;RTSP_URL = "rtsp://Apertai:130355va@192.168.0.2/stream1"&#xA;BUCKET_NAME = "apertai-cloud"&#xA;CREDENTIALS_PATH = "C:/Users/Abidu/ApertAI/key.json"&#xA;&#xA;def start_buffer_stream():&#xA;    # Command for continuous buffer that overwrites itself every 30 seconds&#xA;    buffer_command = [&#xA;        &#x27;ffmpeg&#x27;,&#xA;        &#x27;-i&#x27;, RTSP_URL,&#xA;        &#x27;-map&#x27;, &#x27;0&#x27;,&#xA;        &#x27;-c&#x27;, &#x27;copy&#x27;,&#xA;        &#x27;-f&#x27;, &#x27;segment&#x27;,&#xA;        &#x27;-segment_time&#x27;, &#x27;30&#x27;,  # Duration of each segment&#xA;        &#x27;-segment_wrap&#x27;, &#x27;2&#x27;,  # Number of segments to wrap around&#xA;        &#x27;-reset_timestamps&#x27;, &#x27;1&#x27;,  # Reset timestamps at the start of each segment&#xA;        &#x27;buffer-%03d.ts&#x27;  # Save segments with a numbering pattern&#xA;    ]&#xA;    return subprocess.Popen(buffer_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)&#xA;&#xA;def save_last_30_seconds_from_buffer(buffer_file):&#xA;    datetime_now = datetime.now()&#xA;    datetime_now_formatted = f"{datetime_now.day:02}{datetime_now.month:02}{datetime_now.year}-{datetime_now.hour:02}{datetime_now.minute:02}"&#xA;    output_file_name = os.path.abspath(f"{STATE}-{CITY}-{COURT}-{datetime_now_formatted}.mp4")&#xA;&#xA;    # Copy the most recent buffer segment to the output file&#xA;    save_command = [&#xA;        &#x27;ffmpeg&#x27;,&#xA;        &#x27;-i&#x27;, buffer_file,&#xA;        &#x27;-c&#x27;, &#x27;copy&#x27;,&#xA;        output_file_name&#xA;    ]&#xA;    subprocess.run(save_command, check=True)&#xA;    print(f"Saved last 30 seconds: {output_file_name}")&#xA;    return output_file_name&#xA;&#xA;def upload_to_google_cloud(file_name):&#xA;    client = storage.Client.from_service_account_json(CREDENTIALS_PATH)&#xA;    bucket = client.bucket(BUCKET_NAME)&#xA;    blob = bucket.blob(os.path.basename(file_name).replace("-", "/"))&#xA;    blob.upload_from_filename(file_name, content_type=&#x27;application/octet-stream&#x27;)&#xA;    print(f"Uploaded {file_name} to {BUCKET_NAME}")&#xA;    os.remove(file_name)  # Clean up the local file&#xA;&#xA;def main():&#xA;    print("Starting continuous buffer for RTSP stream...")&#xA;    start_time = datetime.now()&#xA;    buffer_process = start_buffer_stream()&#xA;    print("Press &#x27;Enter&#x27; to save the last 30 seconds of video...")&#xA;&#xA;    while True:&#xA;        # Verify if 30 seconds has passed since start&#xA;        if keyboard.is_pressed(&#x27;enter&#x27;):&#xA;            print("Saving last 30 seconds of video...")&#xA;            elapsed_time = (datetime.now() - start_time).total_seconds()&#xA;            # Determine which buffer segment to save&#xA;            if elapsed_time % 60 &lt; 30:&#xA;                buffer_file = &#x27;buffer-000.ts&#x27;&#xA;            else:&#xA;                buffer_file = &#x27;buffer-001.ts&#x27;&#xA;            final_video = save_last_30_seconds_from_buffer(buffer_file)&#xA;            upload_to_google_cloud(final_video)&#xA;&#xA;if _name_ == "_main_":&#xA;    main()&#xA;&#xA;&#xA;

    &#xA;