Recherche avancée

Médias (1)

Mot : - Tags -/musée

Autres articles (38)

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

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    The zip file provided here only contains the sources of MediaSPIP in its standalone version.
    To get a working installation, you must manually install all-software dependencies on the server.
    If you want to use this archive for an installation in "farm mode", you will also need to proceed to other manual (...)

  • Mise à jour de la version 0.1 vers 0.2

    24 juin 2013, par

    Explications des différents changements notables lors du passage de la version 0.1 de MediaSPIP à la version 0.3. Quelles sont les nouveautés
    Au niveau des dépendances logicielles Utilisation des dernières versions de FFMpeg (>= v1.2.1) ; Installation des dépendances pour Smush ; Installation de MediaInfo et FFprobe pour la récupération des métadonnées ; On n’utilise plus ffmpeg2theora ; On n’installe plus flvtool2 au profit de flvtool++ ; On n’installe plus ffmpeg-php qui n’est plus maintenu au (...)

Sur d’autres sites (2199)

  • C++ ffmpeg API created video does not open in some players

    18 novembre 2017, par ar2015

    After my previous question, I found codes from here to create videos in C++ using avcodec of ffmpeg libraries.

    I have modified this code to comply with C++. Everything is fine and it creates mp4 videos. Except for the output video opens with some video managers and does not open with some others.

    E.g. I can open it on Linux by totem (the slider does not allow back and forth anyway). But VLC (on the same Linux machine) does not open this file. Probably, there will be similar problem in windows.

    Is there any missing process for this code causing this problem ?

    #include
    #include
    #include
    #include <string>
    #include <iostream>

    extern "C" {
       #include <libavcodec></libavcodec>avcodec.h>
       #include <libavutil></libavutil>opt.h>
       #include <libavutil></libavutil>imgutils.h>
    }

    static void encode(AVCodecContext *enc_ctx, AVFrame *frame, AVPacket *pkt,
                      FILE *outfile)
    {
       int ret;

       /* send the frame to the encoder */
       if (frame)
           std::cout&lt;&lt;"Send frame "&lt;&lt;(frame->pts)&lt;= 0) {
           ret = avcodec_receive_packet(enc_ctx, pkt);
           if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
               return;
           else if (ret &lt; 0) {
               fprintf(stderr, "Error during encoding\n");
               exit(1);
           }

           std::cout&lt;&lt;"Write packet "&lt;&lt;(pkt->pts)&lt;&lt;" (size="&lt;&lt;(pkt->size)&lt;&lt;")"&lt;/ printf("Write packet %3" PRId64" (size=%5d)\n", pkt->pts, pkt->size);
           fwrite(pkt->data, 1, pkt->size, outfile);
           av_packet_unref(pkt);
       }
    }

    int main(int argc, char **argv)
    {
       const char *filename;
       const AVCodec *codec;
       AVCodecContext *c= NULL;
       int i, ret, x, y;
       FILE *f;
       AVFrame *frame;
       AVPacket *pkt;
       uint8_t endcode[] = { 0, 0, 1, 0xb7 };

       if (argc &lt; 2) {
           fprintf(stderr, "Usage: %s <output file="file">\n", argv[0]);
           exit(0);
       }
       filename = argv[1];
       std::string codec_name = "mpeg4";

       avcodec_register_all();

       /* find the mpeg1video encoder */
       codec = avcodec_find_encoder_by_name(codec_name.c_str());
       if (!codec) {
           fprintf(stderr, "Codec '%s' not found\n", codec_name.c_str());
           exit(1);
       }

       c = avcodec_alloc_context3(codec);
       if (!c) {
           fprintf(stderr, "Could not allocate video codec context\n");
           exit(1);
       }

       pkt = av_packet_alloc();
       if (!pkt)
           exit(1);

       /* put sample parameters */
       // c->bit_rate = 400000;
       c->bit_rate = 4000000;
       /* resolution must be a multiple of two */
       // c->width = 352;
       // c->height = 288;
       c->width = 640;
       c->height = 480;
       /* frames per second */
       c->time_base = (AVRational){1, 25};
       c->framerate = (AVRational){25, 1};

       /* emit one intra frame every ten frames
        * check frame pict_type before passing frame
        * to encoder, if frame->pict_type is AV_PICTURE_TYPE_I
        * then gop_size is ignored and the output of encoder
        * will always be I frame irrespective to gop_size
        */
       c->gop_size = 10;
       c->max_b_frames = 1;
       c->pix_fmt = AV_PIX_FMT_YUV420P;

       if (codec->id == AV_CODEC_ID_H264)
           av_opt_set(c->priv_data, "preset", "slow", 0);

       /* open it */
       ret = avcodec_open2(c, codec, NULL);
       if (ret &lt; 0) {
           fprintf(stderr, "Could not open codec\n");
           // fprintf(stderr, "Could not open codec: %s\n", av_err2str(ret));
           exit(1);
       }

       f = fopen(filename, "wb");
       if (!f) {
           fprintf(stderr, "Could not open %s\n", filename);
           exit(1);
       }

       frame = av_frame_alloc();
       if (!frame) {
           fprintf(stderr, "Could not allocate video frame\n");
           exit(1);
       }
       frame->format = c->pix_fmt;
       frame->width  = c->width;
       frame->height = c->height;

       ret = av_frame_get_buffer(frame, 32);
       if (ret &lt; 0) {
           fprintf(stderr, "Could not allocate the video frame data\n");
           exit(1);
       }

       /* encode 10 second of video */
       for (i = 0; i &lt; 250; i++) {
           fflush(stdout);

           /* make sure the frame data is writable */
           ret = av_frame_make_writable(frame);
           if (ret &lt; 0)
               exit(1);

           /* prepare a dummy image */
           /* Y */
           for (y = 0; y &lt; c->height; y++) {
               for (x = 0; x &lt; c->width; x++) {
                   frame->data[0][y * frame->linesize[0] + x] = uint8_t(x + y + i * 3);
               }
           }

           /* Cb and Cr */
           for (y = 0; y &lt; c->height/2; y++) {
               for (x = 0; x &lt; c->width/2; x++) {
                   frame->data[1][y * frame->linesize[1] + x] = uint8_t(128 + y + i * 2);
                   frame->data[2][y * frame->linesize[2] + x] = uint8_t(64 + x + i * 5);
               }
           }

           frame->pts = i;

           /* encode the image */
           encode(c, frame, pkt, f);
       }

       /* flush the encoder */
       encode(c, NULL, pkt, f);

       /* add sequence end code to have a real MPEG file */
       fwrite(endcode, 1, sizeof(endcode), f);
       fclose(f);

       avcodec_free_context(&amp;c);
       av_frame_free(&amp;frame);
       av_packet_free(&amp;pkt);

       return 0;
    }
    </output></iostream></string>

    build :

    g++ -I ./FFmpeg/ video.cpp -L ./fflibs -lavdevice -lavfilter -lavformat -lavcodec -lrt -ldl -lXfixes -lXext -lX11 -lasound -lSDL -lz -lrt -lswresample -lswscale -lavutil -lm -llzma -lbz2 -lswresample -lpthread

    run

    ./a.out myvideo.mp4

    This video will be fine if converted in bash via

    ffmpeg -i myvideo.mp4 out1.mp4

    But I look for a method to fix it from the code.

    Generated video played on totem (Ubuntu) :

    c++ ffmpeg avcodec

    Video after conversion :

    converted

  • Joining realtime raw PCM streams with ffmpeg and streaming them back out

    15 avril 2024, par Nathan Ladwig

    I am trying to use ffmpeg to join two PCM streams. I have it sorta kinda working but it's not working great.

    &#xA;

    I am using Python to receive two streams from two computers running Scream Audio Driver ( ttps ://github.com/duncanthrax/scream )

    &#xA;

    I am taking them in over UDP and writing them to pipes. The pipes are being received by ffmpeg and mixed, it's writing the mixed stream to another pipe. I'm reading that back in Python and sending it to the target receiver.

    &#xA;

    My ffmpeg command is

    &#xA;

    [&#x27;ffmpeg&#x27;, &#xA;&#x27;-use_wallclock_as_timestamps&#x27;, &#x27;true&#x27;, &#x27;-f&#x27;, &#x27;s24le&#x27;, &#x27;-ac&#x27;, &#x27;2&#x27;, &#x27;-ar&#x27;, &#x27;48000&#x27;, &#x27;-i&#x27;, &#x27;/tmp/ffmpeg-fifo-1&#x27;,&#xA;&#x27;-use_wallclock_as_timestamps&#x27;, &#x27;true&#x27;, &#x27;-f&#x27;, &#x27;s24le&#x27;, &#x27;-ac&#x27;, &#x27;2&#x27;, &#x27;-ar&#x27;, &#x27;48000&#x27;, &#x27;-i&#x27;, &#x27;/tmp/ffmpeg-fifo-2&#x27;,&#xA;&#x27;-filter_complex&#x27;, &#x27;[0]aresample=async=1[a0],[1]aresample=async=1[a1],[a0][a1]amix&#x27;, &#x27;-y&#x27;,&#xA;&#x27;-f&#x27;, &#x27;s24le&#x27;, &#x27;-ac&#x27;, &#x27;2&#x27;, &#x27;-ar&#x27;, &#x27;48000&#x27;, &#x27;/tmp/ffmpeg-fifo-in&#x27;]&#xA;

    &#xA;

    My main issue is that it should be reading ffmpeg-fifo-1 and ffmpeg-fifo-2 asynchronously, but it appears to be not. When the buffers get more than 50 frames out of sync with each other ffmpeg hangs and doesn't recover. I would like to fix this.

    &#xA;

    In this hacky test code the number of frames sent over each stream are counted and empty frames are sent if the count hits 12. This keeps ffmpeg happy.

    &#xA;

    The code below takes in two 48KHz 24-bit stereo PCM streams with Scream's header, mixes them, applies the same header, and sends them back out.

    &#xA;

    It works most of the time. Sometimes I'm getting blasted with static, I think this is when only one or two bytes of a frame are making it to ffmpeg, and it loses track.

    &#xA;

    The header is always 1152 bytes of pcm data with a 5 byte header. It's described in the Scream repo readme

    &#xA;

    This is my header :

    &#xA;

    01 18 02 03 00

    &#xA;

    01 - 48KHz&#xA;18 - Sampling Rate (18h=24d, 24bit)&#xA;02 - 2 channels&#xA;03 00 - WAVEFORMATEXTENSIBLE

    &#xA;

    import socket&#xA;import struct&#xA;import threading&#xA;import os&#xA;import sys&#xA;import time&#xA;import subprocess&#xA;import tempfile&#xA;import select&#xA;&#xA;class Sender(threading.Thread):&#xA;    def __init__(self):&#xA;        super().__init__()&#xA;        TEMPDIR = tempfile.gettempdir() &#x2B; "/"&#xA;        self.fifoin = TEMPDIR &#x2B; "ffmpeg-fifo-in"&#xA;        self.start()&#xA;&#xA;    def run(self):&#xA;        self.fd = open(self.fifoin, "rb")&#xA;        self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)&#xA;        while True:&#xA;            try:&#xA;                header = bytes([0x01, 0x18, 0x02, 0x03, 0x00])  # 48khz, 24-bit, stereo&#xA;                data = self.fd.read(1152)&#xA;                sendbuf = header &#x2B; data&#xA;                self.sock.sendto(sendbuf, ("192.168.3.199", 4010))  # Audio sink&#xA;            except Exception as e:&#xA;                print("Except")&#xA;                print(e)&#xA;&#xA;class Receiver(threading.Thread):&#xA;    def __init__(self):&#xA;        super().__init__()&#xA;        TEMPDIR = tempfile.gettempdir() &#x2B; "/"&#xA;        self.fifo1 = TEMPDIR &#x2B; "ffmpeg-fifo-1"&#xA;        self.fifo2 = TEMPDIR &#x2B; "ffmpeg-fifo-2"&#xA;        self.fifoin = TEMPDIR &#x2B; "ffmpeg-fifo-in"&#xA;        self.fifos = [self.fifo1, self.fifo2]&#xA;        try:&#xA;            try:&#xA;                os.remove(self.fifoin)&#xA;            except:&#xA;                pass&#xA;            os.mkfifo(self.fifoin)&#xA;        except:&#xA;            pass&#xA;        self.start()&#xA;        sender=Sender()&#xA;&#xA;    def run(self):&#xA;        ffmpeg_command=[&#x27;ffmpeg&#x27;, &#x27;-use_wallclock_as_timestamps&#x27;, &#x27;true&#x27;, &#x27;-f&#x27;, &#x27;s24le&#x27;, &#x27;-ac&#x27;, &#x27;2&#x27;, &#x27;-ar&#x27;, &#x27;48000&#x27;, &#x27;-i&#x27;, self.fifo1,&#xA;                                  &#x27;-use_wallclock_as_timestamps&#x27;, &#x27;true&#x27;, &#x27;-f&#x27;, &#x27;s24le&#x27;, &#x27;-ac&#x27;, &#x27;2&#x27;, &#x27;-ar&#x27;, &#x27;48000&#x27;, &#x27;-i&#x27;, self.fifo2,&#xA;                                  &#x27;-filter_complex&#x27;, &#x27;[0]aresample=async=1[a0],[1]aresample=async=1[a1],[a0][a1]amix&#x27;, "-y", &#x27;-f&#x27;, &#x27;s24le&#x27;, &#x27;-ac&#x27;, &#x27;2&#x27;, &#x27;-ar&#x27;, &#x27;48000&#x27;, self.fifoin]&#xA;        print(ffmpeg_command)&#xA;&#xA;        sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)&#xA;        sock.setsockopt(socket.SOL_SOCKET,socket.SO_RCVBUF,4096)&#xA;        sock.bind(("", 16401))&#xA;&#xA;        recvbuf = bytearray(1157)&#xA;        framecount = [0,0]&#xA;        closed = 1&#xA;        while True:&#xA;            ready = select.select([sock], [], [], .2)&#xA;            if ready[0]:&#xA;                recvbuf, addr = sock.recvfrom(1157)&#xA;                if closed == 1:&#xA;                    for fifo in self.fifos:&#xA;                        try:&#xA;                            try:&#xA;                                os.remove(fifo)&#xA;                            except:&#xA;                                pass&#xA;                            os.mkfifo(fifo)&#xA;                        except:&#xA;                            pass&#xA;                    framecount = [0,0]&#xA;                    print("data, starting ffmpeg")&#xA;                    ffmpeg = subprocess.Popen (ffmpeg_command, shell=False, stdout=subprocess.PIPE, stdin=subprocess.PIPE)&#xA;                    fifo1_fd = os.open(self.fifo1, os.O_RDWR)&#xA;                    fifo1_file = os.fdopen(fifo1_fd, &#x27;wb&#x27;, 0)&#xA;                    fifo2_fd = os.open(self.fifo2, os.O_RDWR)&#xA;                    fifo2_file = os.fdopen(fifo2_fd, &#x27;wb&#x27;, 0)&#xA;                    closed = 0&#xA;                    for i in range(0,6):&#xA;                        fifo1_file.write(bytes([0]*1157))&#xA;                        fifo2_file.write(bytes([0]*1157))&#xA;&#xA;                if addr[0] == "192.168.3.199":&#xA;                    fifo1_file.write(recvbuf[5:])&#xA;                    framecount[0] = framecount[0] &#x2B; 1&#xA;&#xA;                if addr[0] == "192.168.3.119":&#xA;                    fifo2_file.write(recvbuf[5:])&#xA;                    framecount[1] = framecount[1] &#x2B; 1&#xA;&#xA;                # Keep buffers roughly in sync while playing&#xA;                targetframes=max(framecount)&#xA;                if targetframes - framecount[0] > 11:&#xA;                    while (targetframes - framecount[0]) > 0:&#xA;                        fifo1_file.write(bytes([0]*1157))&#xA;                        framecount[0] = framecount[0] &#x2B; 1&#xA;&#xA;                if targetframes - framecount[1] > 11:&#xA;                    while (targetframes - framecount[1]) > 0:&#xA;                        fifo2_file.write(bytes([0]*1157))&#xA;                        framecount[1] = framecount[1] &#x2B; 1&#xA;            else:&#xA;                if closed == 0:&#xA;                    ffmpeg.kill()&#xA;                    print("No data, killing ffmpeg")&#xA;                    fifo1_file.close()&#xA;                    fifo2_file.close()&#xA;                    closed = 1&#xA;receiver=Receiver()&#xA;&#xA;while True:&#xA;    time.sleep(50000)&#xA;

    &#xA;

    Does anybody have any pointers on how I can make this better ?

    &#xA;

  • Piwik 2.1 – Changes for Plugin developers

    24 février 2014, par Piwik Core Team — Development

    This blog post is aimed at developers of Piwik Plugins. If you are simply using Piwik and not developing plugins for Piwik, you do not need to read this post.

    Piwik 2.1 will be released in a few days . This blog post will inform Piwik Plugin developers of the changes in Piwik 2.1 that may require that you update your plugin to work with this latest version.

    Breaking API changes

    Piwik can now handle an unlimited number of users having Super User access (#2589 #4564). In the past Piwik was limited to one Super User who was defined in the config file. From now on all users with Super User access are defined in the database the same way a regular user is. This brought some API changes but we will stay backward compatible until the first of April 2014. This gives you some time to migrate any custom plugins you may use. Although there is a layer for backward compatibility we recommend to make sure your plugin works with Piwik as soon as possible before April 1st.

    List of changes

    Deprecated methods

    The following methods are deprecated and we recommend to use the new methods from now on. There are also some methods which won’t be replaced so make sure to adjust the logic of your plugin.

    \Piwik\Piwik::isUserIsSuperUser =&gt; \Piwik\Piwik::hasUserSuperUserAccess
    \Piwik\Piwik::setUserIsSuperUser =&gt; \Piwik\Piwik::setUserHasSuperUserAccess
    \Piwik\Piwik::checkUserIsSuperUser =&gt; \Piwik\Piwik::checkUserHasSuperUserAccess
    \Piwik\Access::isSuperUser =&gt; \Piwik\Access::hasSuperUserAccess
    \Piwik\Access::checkUserIsSuperUser =&gt; \Piwik\Access::checkUserHasSuperUserAccess
    \Piwik\Access::setSuperUser =&gt; \Piwik\Access::setSuperUserAccess
    \FakeAccess::checkUserIsSuperUser =&gt; FakeAccess::checkUserHasSuperUserAccess
    \FakeAccess::setSuperUser =&gt; FakeAccess::setSuperUserAccess
    \Piwik\Piwik::isUserIsSuperUserOrTheUser =&gt; \Piwik\Piwik::hasUserSuperUserAccessOrIsTheUser
    \Piwik\Piwik::checkUserIsSuperUserOrTheUser =&gt; \Piwik\Piwik::checkUserHasSuperUserAccessOrIsTheUser
    \FakeAccess::getSuperUserLogin =&gt; No replacement
    \Piwik\Piwik::getSuperUserLogin =&gt; No replacement, returns the userLogin of the first Super User we find in the database
    \Piwik\Piwik::getSuperUserEmail =&gt; No replacement, returns an empty string from now on
    \Piwik\Access::getSuperUserLogin =&gt; No replacement, returns the userLogin of the first Super User we find in the database

    Config Super User

    As mentioned, the Super User was defined in the config and you have accessed the Super User’s data either by using a convenient method like Piwik::getSuperUserLogin or directly via the Config object as follows :

    \Piwik\Config::getInstance-&gt;superUser

    As the config user is no longer defined in the config this will no longer work in the future. To stay backward compatible we return the first super user found in the database. This is not necessarily always the same user. So if you have used the super user login in some way in your plugin, make sure you are using the new function such as Piwik::getSuperUserLogin

    Extended Auth Interface

    The last change affects plugins who specify their own Authentication mechanism, for instance when using the custom LoginLDAP plugin. From now on the interface \Piwik\Auth (​https://github.com/piwik/piwik/blob/master/core/Auth.php) requires the methods setTokenAuth and setLogin. There is no backward compatibility layer but we had a look at some plugins defining a custom Authentication adapter to make sure those methods are already defined there as expected.

    For another example of a Login plugin, check out the LoginHttpAuth plugin on the Marketplace.

    After updating the plugin

    After you have made changes in your plugin to keep it compatible with Piwik 2.1, your plugin will no longer work with previous Piwik versions. Therefore you should define the minimum required version in your plugin.json file as follows :

    "require": {
    "piwik": "&gt;=2.1"
    }

    Summary

    Piwik 2.1 introduces some changes in the Piwik Core APIs. This blog post explains how to modify any Plugins compatible with Piwik 2.0 to be compatible with Piwik 2.1. Thank you for taking the time to update your plugins !

    Let us know if you have any feedback. Happy hacking !

    PS : if you use the Web Analytics APIs and the Web Tracking APIs, we guarantee that we will support backwards compatibility of our Web APIs.