Recherche avancée

Médias (1)

Mot : - Tags -/biographie

Autres articles (76)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

  • De l’upload à la vidéo finale [version standalone]

    31 janvier 2010, par

    Le chemin d’un document audio ou vidéo dans SPIPMotion est divisé en trois étapes distinctes.
    Upload et récupération d’informations de la vidéo source
    Dans un premier temps, il est nécessaire de créer un article SPIP et de lui joindre le document vidéo "source".
    Au moment où ce document est joint à l’article, deux actions supplémentaires au comportement normal sont exécutées : La récupération des informations techniques des flux audio et video du fichier ; La génération d’une vignette : extraction d’une (...)

Sur d’autres sites (9146)

  • avformat/mpegts : parse sections with multiple tables

    9 mai 2018, par Aman Gupta
    avformat/mpegts : parse sections with multiple tables
    

    Fixes PMT parsing in some mpegts streams which contain
    multiple tables within the PMT pid. Previously, the parser
    assumed only one table was present in each packet, and discarded
    the rest of the section data after attempting to parse the first
    table.

    A similar issue was documented in the BeyondTV software[1], which
    helped me diagnose the same bug in the ffmpeg mpegts demuxer. I also
    tried DVBInspector, libdvbpsi's dvbinfo, and tstools' tsinfo to
    help debug. The former two properly read PMTs with multiple tables,
    whereas the last has the same bug as ffmpeg.

    I've created a minimal sample[2] which contains the combined PMT.
    Here's what ffmpeg probe shows before and after this patch :

    Before :

    Input #0, mpegts, from 'combined-pmt-tids.ts' :
    Duration : 00:00:01.08, start : 4932.966167, bitrate : 741 kb/s
    Program 1
    No Program
    Stream #0:0[0xf9d] : Audio : ac3, 48000 Hz, mono, fltp, 96 kb/s
    Stream #0:1[0xf9b] : Audio : mp3, 0 channels, fltp
    Stream #0:2[0xf9c] : Unknown : none

    After :

    Input #0, mpegts, from 'combined-pmt-tids.ts' :
    Duration : 00:00:01.11, start : 4932.966167, bitrate : 718 kb/s
    Program 1
    Stream #0:0[0xf9b] : Video : mpeg2video ([2][0][0][0] / 0x0002), none(tv, top first), 29.97 fps, 29.97 tbr, 90k tbn, 90k tbc
    Stream #0:1[0xf9c](eng) : Audio : ac3 (AC-3 / 0x332D4341), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:2[0xf9d](spa) : Audio : ac3 (AC-3 / 0x332D4341), 48000 Hz, mono, fltp, 96 kb/s

    With the patch, the PMT is parsed correctly so the streams are
    created in the correct order, are associated with "Program 1",
    and their codecs are set correctly.

    [1] http://forums.snapstream.com/vb/showpost.php?p=343816&postcount=201
    [2] https://s3.amazonaws.com/tmm1/combined-pmt-tids.ts

    Signed-off-by : Aman Gupta <aman@tmm1.net>
    Signed-off-by : Michael Niedermayer <michael@niedermayer.cc>

    • [DH] libavformat/mpegts.c
  • 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.

    &#xA;

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

    &#xA;

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

    &#xA;

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

    &#xA;

    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.

    &#xA;

    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.

    &#xA;

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

    &#xA;

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

    &#xA;

    Minimal example of code to reproduce the problem :

    &#xA;

    avformat_example.cpp

    &#xA;

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