Recherche avancée

Médias (0)

Mot : - Tags -/organisation

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

Autres articles (37)

  • La file d’attente de SPIPmotion

    28 novembre 2010, par

    Une file d’attente stockée dans la base de donnée
    Lors de son installation, SPIPmotion crée une nouvelle table dans la base de donnée intitulée spip_spipmotion_attentes.
    Cette nouvelle table est constituée des champs suivants : id_spipmotion_attente, l’identifiant numérique unique de la tâche à traiter ; id_document, l’identifiant numérique du document original à encoder ; id_objet l’identifiant unique de l’objet auquel le document encodé devra être attaché automatiquement ; objet, le type d’objet auquel (...)

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

Sur d’autres sites (7596)

  • ffmpeg avformat_open_input() function causes memory leak when receiving live stream

    12 septembre 2023, par george_d

    I have live streams (can be UDP or HLS, video codec is H264), from which I grab frames for further processing.

    


    For this purpose, I use ffmpeg + nvjpeg + cuda libraries.

    


    However I noticed memory leak - memory usage periodically (every 10-20 seconds) is increased by 100-400 KB, the amount and period may vary.

    


    After disabling pieces of code one by one, I realized that it is avformat_open_input() which causes memory leak.

    


    No matter which buffer settings (https://ffmpeg.org/ffmpeg-protocols.html#udp) I choose for UDP, the leak still persists. Same goes for HLS streams.

    


    I tried to find anything related to this problem, but all the sources I found claimed that this problem took place in the past and has been fixed.

    


    Is there some mysterious setting I am missing, so that memory could be freed properly ?

    


    Or is this memory supposed to be freed when processing frames (i.e. using av_read_frame() and av_packet_unref(), etc) ?

    


    Minimal example of code to reproduce the problem :

    


    avformat_example.cpp

    


    #include &#xA;extern "C" {&#xA;    #include <libavformat></libavformat>avformat.h>&#xA;    #include <libavcodec></libavcodec>avcodec.h>&#xA;}&#xA;&#xA;int main(int argc, char *argv[]){&#xA;    if (argc &lt; 2) {&#xA;      return 1;&#xA;    }&#xA;&#xA;    char* inputSource = argv[1];&#xA;    AVFormatContext *ctx = NULL;&#xA;&#xA;    if (avformat_open_input(&amp;ctx, inputSource, NULL, NULL) != 0) {&#xA;        av_log(NULL,&#xA;               AV_LOG_ERROR,&#xA;               "Cannot open &#x27;%s&#x27;",&#xA;               inputSource);&#xA;        return 1;&#xA;    }&#xA;&#xA;    /*&#xA;    This loop is placed here to demonstrate&#xA;    avformat_open_input() causing leak.&#xA;    Actually, instead of noop loop there is logic of getting and processing frames,&#xA;    but it doesn&#x27;t matter now.&#xA;    As loop goes on, the amount of leaked memory increases.&#xA;    */&#xA;    while(true) {&#xA;      sleep(1);&#xA;    }&#xA;&#xA;    return 0;&#xA;}&#xA;

    &#xA;

    Compile with :

    &#xA;

    g&#x2B;&#x2B; avformat_example.cpp -lavcodec -lavutil -lavformat -I/usr/include/ffmpeg-cuda -o avformat_open_input_example&#xA;

    &#xA;

    Run :

    &#xA;

    ./avformat_open_input_example "udp://127.0.0.1:5000?reuse=1&amp;pkt_size=1316&amp;buffer_size=1310720&amp;fifo_size=40000"&#xA;

    &#xA;

    Version of ffmpeg underlying libraries :

    &#xA;

    libavutil      58.  7.100 / 58.  7.100&#xA;libavcodec     60. 11.100 / 60. 11.100&#xA;libavformat    60.  5.100 / 60.  5.100&#xA;libavdevice    60.  2.100 / 60.  2.100&#xA;libavfilter     9.  8.100 /  9.  8.100&#xA;libswscale      7.  2.100 /  7.  2.100&#xA;libswresample   4. 11.100 /  4. 11.100&#xA;

    &#xA;

  • How to minimize latency in ffmpeg stream Java ?

    13 juillet 2022, par Taavi Sõerd

    I need to stream ffmpeg video feed in android studio and need minimal latency. Code below has achieved that when playing on galaxy s21 ultra but when I play it on galaxy tab then it's like in slow motion. When i set buffer size to 0 I get minimal latency but can't actually even see the video as it's all corrupted (all gray and colored noise).

    &#xA;

    public class Decode implements Runnable {&#xA;public Activity activity;&#xA;AVFrame pFrameRGB;&#xA;SwsContext sws_ctx;&#xA;ByteBuffer bitmapBuffer;&#xA;Bitmap bmp;&#xA;byte[] array;&#xA;int imageViewWidth = 0;&#xA;int imageViewHeight = 0;&#xA;boolean imageChanged = true;&#xA;int v_stream_idx = -1;&#xA;int klv_stream_idx = -1;&#xA;&#xA;boolean imageDrawMutex = false;&#xA;&#xA;boolean imageIsSet = false;&#xA;ImageView imageView =  MainActivity.getmInstanceActivity().findViewById(R.id.imageView);&#xA;&#xA;String mFilename = "udp://@" &#x2B; MainActivity.connectionIP;;&#xA;UasDatalinkLocalSet mLatestDls;&#xA;&#xA;public Decode(Activity _activity) {&#xA;    this.activity = _activity;&#xA;}&#xA;&#xA;public void create_decoder(AVCodecContext codec_ctx) {&#xA;    imageChanged = true;&#xA;&#xA;    // Determine required buffer size and allocate buffer&#xA;    int numBytes =av_image_get_buffer_size(AV_PIX_FMT_RGBA, codec_ctx.width(),&#xA;            codec_ctx.height(), 1);&#xA;    BytePointer buffer = new BytePointer(av_malloc(numBytes));&#xA;&#xA;    bmp = Bitmap.createBitmap(codec_ctx.width(), codec_ctx.height(), Bitmap.Config.ARGB_8888);&#xA;&#xA;    array = new byte[codec_ctx.width() * codec_ctx.height() * 4];&#xA;    bitmapBuffer = ByteBuffer.wrap(array);&#xA;&#xA;    sws_ctx = sws_getContext(&#xA;            codec_ctx.width(),&#xA;            codec_ctx.height(),&#xA;            codec_ctx.pix_fmt(),&#xA;            codec_ctx.width(),&#xA;            codec_ctx.height(),&#xA;            AV_PIX_FMT_RGBA,&#xA;            SWS_POINT,&#xA;            null,&#xA;            null,&#xA;            (DoublePointer) null&#xA;    );&#xA;&#xA;    if (sws_ctx == null) {&#xA;        Log.d("app", "Can not use sws");&#xA;        throw new IllegalStateException();&#xA;    }&#xA;&#xA;    av_image_fill_arrays(pFrameRGB.data(), pFrameRGB.linesize(),&#xA;            buffer, AV_PIX_FMT_RGBA, codec_ctx.width(), codec_ctx.height(), 1);&#xA;}&#xA;&#xA;@Override&#xA;public void run() {&#xA;    Log.d("app", "Start decoder");&#xA;&#xA;    int ret = -1, i = 0;&#xA;    String vf_path = mFilename;&#xA;&#xA;    AVFormatContext fmt_ctx = new AVFormatContext(null);&#xA;    AVPacket pkt = new AVPacket();&#xA;&#xA;&#xA;    AVDictionary multicastDict = new AVDictionary();&#xA;&#xA;    av_dict_set(multicastDict, "rtsp_transport", "udp_multicast", 0);&#xA;&#xA;    av_dict_set(multicastDict, "localaddr", getIPAddress(true), 0);&#xA;    av_dict_set(multicastDict, "reuse", "1", 0);&#xA;&#xA;    av_dict_set(multicastDict, "buffer_size", "0.115M", 0);&#xA;&#xA;    ret = avformat_open_input(fmt_ctx, vf_path, null, multicastDict);&#xA;    if (ret &lt; 0) {&#xA;        Log.d("app", String.format("Open video file %s failed \n", vf_path));&#xA;        byte[] error_message = new byte[1024];&#xA;        int elen = av_strerror(ret, error_message, 1024);&#xA;        String s = new String(error_message, 0, 20);&#xA;        Log.d("app", String.format("Return: %d", ret));&#xA;        Log.d("app", String.format("Message: %s", s));&#xA;        throw new IllegalStateException();&#xA;    }&#xA;    &#xA;    if (avformat_find_stream_info(fmt_ctx, (PointerPointer) null) &lt; 0) {&#xA;        //System.exit(-1);&#xA;        Log.d("app", "Stream info not found");&#xA;    }&#xA;&#xA;&#xA;    avformat.av_dump_format(fmt_ctx, 0, mFilename, 0);&#xA;&#xA;    int nstreams = fmt_ctx.nb_streams();&#xA;&#xA;    for (i = 0; i &lt; fmt_ctx.nb_streams(); i&#x2B;&#x2B;) {&#xA;        if (fmt_ctx.streams(i).codecpar().codec_type() == AVMEDIA_TYPE_VIDEO) {&#xA;            v_stream_idx = i;&#xA;        }&#xA;        if (fmt_ctx.streams(i).codecpar().codec_type() == AVMEDIA_TYPE_DATA) {&#xA;            klv_stream_idx = i;&#xA;        }&#xA;    }&#xA;    if (v_stream_idx == -1) {&#xA;        Log.d("app", "Cannot find video stream");&#xA;        throw new IllegalStateException();&#xA;    } else {&#xA;        Log.d("app", String.format("Video stream %d with resolution %dx%d\n", v_stream_idx,&#xA;                fmt_ctx.streams(v_stream_idx).codecpar().width(),&#xA;                fmt_ctx.streams(v_stream_idx).codecpar().height()));&#xA;    }&#xA;&#xA;    AVCodecContext codec_ctx = avcodec_alloc_context3(null);&#xA;    avcodec_parameters_to_context(codec_ctx, fmt_ctx.streams(v_stream_idx).codecpar());&#xA;&#xA;&#xA;    AVCodec codec = avcodec_find_decoder(codec_ctx.codec_id());&#xA;&#xA;&#xA;    AVDictionary avDictionary = new AVDictionary();&#xA;&#xA;    av_dict_set(avDictionary, "fflags", "nobuffer", 0);&#xA;&#xA;&#xA;    if (codec == null) {&#xA;        Log.d("app", "Unsupported codec for video file");&#xA;        throw new IllegalStateException();&#xA;    }&#xA;    ret = avcodec_open2(codec_ctx, codec, avDictionary);&#xA;    if (ret &lt; 0) {&#xA;        Log.d("app", "Can not open codec");&#xA;        throw new IllegalStateException();&#xA;    }&#xA;&#xA;    AVFrame frm = av_frame_alloc();&#xA;&#xA;    // Allocate an AVFrame structure&#xA;    pFrameRGB = av_frame_alloc();&#xA;    if (pFrameRGB == null) {&#xA;        //System.exit(-1);&#xA;        Log.d("app", "unable to init pframergb");&#xA;    }&#xA;&#xA;    create_decoder(codec_ctx);&#xA;&#xA;    int width = codec_ctx.width();&#xA;    int height = codec_ctx.height();&#xA;&#xA;    double fps = 15;&#xA;    &#xA;&#xA;    while (true) {&#xA;        try {&#xA;            Thread.sleep(1);&#xA;        } catch (Exception e) {&#xA;&#xA;        }&#xA;&#xA;        try {&#xA;            if (av_read_frame(fmt_ctx, pkt) >= 0) {&#xA;                if (pkt.stream_index() == v_stream_idx) {&#xA;                    avcodec_send_packet(codec_ctx, pkt);&#xA;&#xA;                    if (codec_ctx.width() != width || codec_ctx.height() != height) {&#xA;                        create_decoder(codec_ctx);&#xA;                        width = codec_ctx.width();&#xA;                        height = codec_ctx.height();&#xA;                    }&#xA;                }&#xA;&#xA;                if (pkt.stream_index() == klv_stream_idx) {&#xA;&#xA;                    byte[] klvDataBuffer = new byte[pkt.size()];&#xA;&#xA;                    for (int j = 0; j &lt; pkt.size(); j&#x2B;&#x2B;) {&#xA;                        klvDataBuffer[j] = pkt.data().get(j);&#xA;                    }&#xA;&#xA;                    try {&#xA;                        KLV k = new KLV(klvDataBuffer, KLV.KeyLength.SixteenBytes, KLV.LengthEncoding.BER);&#xA;                        byte[] main_payload = k.getValue();&#xA;&#xA;                        // decode the Uas Datalink Local Set from main_payload binary blob.&#xA;                        mLatestDls = new UasDatalinkLocalSet(main_payload);&#xA;&#xA;                        if (mLatestDls != null) {&#xA;&#xA;                            MainActivity.getmInstanceActivity().runOnUiThread(new Runnable() {&#xA;                                @RequiresApi(api = Build.VERSION_CODES.Q)&#xA;                                @Override&#xA;                                public void run() {&#xA;                                    MainActivity.getmInstanceActivity().updateKlv(mLatestDls);&#xA;                                }&#xA;                            });&#xA;                        }&#xA;                    } catch (Exception e) {&#xA;                        e.printStackTrace();&#xA;                    }&#xA;                    &#xA;                }&#xA;&#xA;                int wasFrameDecoded = 0;&#xA;                while (wasFrameDecoded >= 0) {&#xA;                    wasFrameDecoded = avcodec_receive_frame(codec_ctx, frm);&#xA;&#xA;                    if (wasFrameDecoded >= 0) {&#xA;                        // get clip fps&#xA;                        fps = 15; //av_q2d(fmt_ctx.streams(v_stream_idx).r_frame_rate());&#xA;&#xA;                        sws_scale(&#xA;                                sws_ctx,&#xA;                                frm.data(),&#xA;                                frm.linesize(),&#xA;                                0,&#xA;                                codec_ctx.height(),&#xA;                                pFrameRGB.data(),&#xA;                                pFrameRGB.linesize()&#xA;                        );&#xA;&#xA;                        if(!imageDrawMutex) {&#xA;                            MainActivity.getmInstanceActivity().runOnUiThread(new Runnable() {&#xA;                                @Override&#xA;                                public void run() {&#xA;                                    if (imageIsSet) {&#xA;                                        imageDrawMutex = true;&#xA;                                        pFrameRGB.data(0).position(0).get(array);&#xA;                                        bitmapBuffer.rewind();&#xA;                                        bmp.copyPixelsFromBuffer(bitmapBuffer);&#xA;&#xA;                                        if (imageChanged) {&#xA;                                            (imageView).setImageBitmap(bmp);&#xA;                                            imageChanged = false;&#xA;                                        }&#xA;&#xA;                                        (imageView).invalidate();&#xA;                                        imageDrawMutex = false;&#xA;                                    } else {&#xA;                                        (imageView).setImageBitmap(bmp);&#xA;                                        imageIsSet = true;&#xA;                                    }&#xA;                                }&#xA;                            });&#xA;                        }&#xA;                    }&#xA;                }&#xA;                av_packet_unref(pkt);&#xA;&#xA;            }&#xA;        } catch (Exception e) {&#xA;            e.printStackTrace();&#xA;        }&#xA;&#xA;        if (false) {&#xA;            Log.d("threads", "false");&#xA;&#xA;            av_frame_free(frm);&#xA;&#xA;            avcodec_close(codec_ctx);&#xA;            avcodec_free_context(codec_ctx);&#xA;&#xA;            avformat_close_input(fmt_ctx);&#xA;        }&#xA;    }&#xA;}&#xA;

    &#xA;

    This code is running in Android Studio with Java. I'm quite new on this topic so not really sure even where to start.&#xA;What could be the cause of that ?

    &#xA;

  • Inconsistent behaviour of ffmpeg -i flag

    19 mai 2021, par zeebrah

    I'm trying to write a Bash script that would download an audio track from youtube and convert it to Apple ringtone format, which is .m4r. The tools I employ are youtube-dl and ffmpeg. The former seems to work fine but I have a strange issue with the latter. When I try to pass the name of the file parametrically, shell prints that file or directory can't be found.enter image description here

    &#xA;

    I use the same method for unwraping user input (or my defaults) for both commands but it only seems to work with youtube-dl.

    &#xA;

    Example of what doesn't work and print the text above. Obviously, all the files are in fact there and accessible

    &#xA;

    youtube-dl -i --extract-audio --audio-format m4a -o $filepath_interim  --audio-quality 0 $video_link&#xA;ffmpeg -i $filepath_interim -acodec copy -f ipod -ss $offset  -t $length $filepath_out&#xA;

    &#xA;

    So, I tried to do it with &#x27;&#x27; strings, $(command) syntax, it all failed. I only found one way to make it work, which is to hard code the values of the paths but this defeats the whole purpose of my script.

    &#xA;

    youtube-dl -i --extract-audio --audio-format m4a -o $filepath_interim  --audio-quality 0 $video_link&#xA;ffmpeg -i ~/Downloads/ringtone.m4a -acodec copy -f ipod -ss $offset  -t $length ~/Downloads/ringtone.m4r&#xA;

    &#xA;

    I want to figure out why this keeps happening, whether it is in any way specific to ffmpeg or am I just missing some piece of knowledge about $ name unwrapping.

    &#xA;

    Minimal Working Example. Run with bash or pack in script and run. If your path to bash is different, please change the shebang :

    &#xA;

    #!/usr/local/bin/bash&#xA;# initialise&#xA;filepath_interim="~/Downloads/ringtone.m4a"&#xA;filepath_out="~/Downloads/ringtone.m4r"&#xA;video_link="https://www.youtube.com/watch?v=dQw4w9WgXcQ"&#xA;offset=0&#xA;length=30&#xA;&#xA;# main part&#xA;youtube-dl -i --extract-audio --audio-format m4a -o $filepath_interim  --audio-quality 0 $video_link&#xA;ffmpeg -i $filepath_interim -acodec copy -f ipod -ss $offset  -t $length $filepath_out&#xA;

    &#xA;