Recherche avancée

Médias (91)

Autres articles (64)

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

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

  • Increase/Decrease audio volume using FFmpeg

    9 juin 2016, par williamtroup

    I’m am currently using C# invokes to call the FFmpeg APIs to handle video and audio. I have the following code in place to extract the audio from a video and write it to a file.

    while (ffmpeg.av_read_frame(formatContext, &packet) >= 0)
    {
       if (packet.stream_index == streamIndex)
       {
           while (packet.size > 0)
           {
               int frameDecoded;
               int frameDecodedResult = ffmpeg.avcodec_decode_audio4(codecContext, frame, &frameDecoded, packet);

               if (frameDecoded > 0 && frameDecodedResult >= 0)
               {
                   //writeAudio.WriteFrame(frame);

                   packet.data += totalBytesDecoded;
                   packet.size -= totalBytesDecoded;
               }
           }

           frameIndex++;
       }

       Avcodec.av_free_packet(&packet);
    }

    This is all working correctly. I’m currently using the FFmpeg.AutoGen project for the API access.

    I want to be able to increase/decrease the volume of the audio before its written to the file, but I cannot seem to find a command or any help with this. Does it have to be done manually ?

    Update 1 :

    After receiving some help, this is the class layout I have :

    public unsafe class FilterVolume
    {
       #region Private Member Variables

       private AVFilterGraph* m_filterGraph = null;
       private AVFilterContext* m_aBufferSourceFilterContext = null;
       private AVFilterContext* m_aBufferSinkFilterContext = null;

       #endregion

       #region Private Constant Member Variables

       private const int EAGAIN = 11;

       #endregion

       public FilterVolume(AVCodecContext* codecContext, AVStream* stream, float volume)
       {
           CodecContext = codecContext;
           Stream = stream;
           Volume = volume;

           Initialise();
       }

       public AVFrame* Adjust(AVFrame* frame)
       {
           AVFrame* returnFilteredFrame = ffmpeg.av_frame_alloc();

           if (m_aBufferSourceFilterContext != null && m_aBufferSinkFilterContext != null)
           {
               int bufferSourceAddFrameResult = ffmpeg.av_buffersrc_add_frame(m_aBufferSourceFilterContext, frame);
               if (bufferSourceAddFrameResult < 0)
               {
               }

               int bufferSinkGetFrameResult = ffmpeg.av_buffersink_get_frame(m_aBufferSinkFilterContext, returnFilteredFrame);
               if (bufferSinkGetFrameResult < 0 && bufferSinkGetFrameResult != -EAGAIN)
               {
               }
           }

           return returnFilteredFrame;
       }

       public void Dispose()
       {
           Cleanup(m_filterGraph);
       }

       #region Private Properties

       private AVCodecContext* CodecContext { get; set; }
       private AVStream* Stream { get; set; }
       private float Volume { get; set; }

       #endregion

       #region Private Setup Helper Functions

       private void Initialise()
       {
           m_filterGraph = GetAllocatedFilterGraph();

           string aBufferFilterArguments = string.Format("sample_fmt={0}:channel_layout={1}:sample_rate={2}:time_base={3}/{4}",
               (int)CodecContext->sample_fmt,
               CodecContext->channel_layout,
               CodecContext->sample_rate,
               Stream->time_base.num,
               Stream->time_base.den);

           AVFilterContext* aBufferSourceFilterContext = CreateFilter("abuffer", m_filterGraph, aBufferFilterArguments);
           AVFilterContext* volumeFilterContext = CreateFilter("volume", m_filterGraph, string.Format("volume={0}", Volume));
           AVFilterContext* aBufferSinkFilterContext = CreateFilter("abuffersink", m_filterGraph);

           LinkFilter(aBufferSourceFilterContext, volumeFilterContext);
           LinkFilter(volumeFilterContext, aBufferSinkFilterContext);

           SetFilterGraphConfiguration(m_filterGraph, null);

           m_aBufferSourceFilterContext = aBufferSourceFilterContext;
           m_aBufferSinkFilterContext = aBufferSinkFilterContext;
       }

       #endregion

       #region Private Cleanup Helper Functions

       private static void Cleanup(AVFilterGraph* filterGraph)
       {
           if (filterGraph != null)
           {
               ffmpeg.avfilter_graph_free(&filterGraph);
           }
       }

       #endregion

       #region Provate Helpers

       private AVFilterGraph* GetAllocatedFilterGraph()
       {
           AVFilterGraph* filterGraph = ffmpeg.avfilter_graph_alloc();
           if (filterGraph == null)
           {
           }

           return filterGraph;
       }

       private AVFilter* GetFilterByName(string name)
       {
           AVFilter* filter = ffmpeg.avfilter_get_by_name(name);
           if (filter == null)
           {
           }

           return filter;
       }

       private void SetFilterGraphConfiguration(AVFilterGraph* filterGraph, void* logContext)
       {
           int filterGraphConfigResult = ffmpeg.avfilter_graph_config(filterGraph, logContext);
           if (filterGraphConfigResult < 0)
           {
           }
       }

       private AVFilterContext* CreateFilter(string filterName, AVFilterGraph* filterGraph, string filterArguments = null)
       {
           AVFilter* filter = GetFilterByName(filterName);
           AVFilterContext* filterContext;

           int aBufferFilterCreateResult = ffmpeg.avfilter_graph_create_filter(&filterContext, filter, filterName, filterArguments, null, filterGraph);
           if (aBufferFilterCreateResult < 0)
           {
           }

           return filterContext;
       }

       private void LinkFilter(AVFilterContext* source, AVFilterContext* destination)
       {
           int filterLinkResult = ffmpeg.avfilter_link(source, 0, destination, 0);
           if (filterLinkResult < 0)
           {
           }
       }

       #endregion
    }

    The Adjust() function is called after a frame is decoded. I’m currently getting a -22 error when av_buffersrc_add_frame() is called. This indicates that a parameter is invalid, but after debugging, I cannot see anything that would be causing this.

    This is how the code is called :

    while (ffmpeg.av_read_frame(formatContext, &packet) >= 0)
    {
       if (packet.stream_index == streamIndex)
       {
           while (packet.size > 0)
           {
               int frameDecoded;
               int frameDecodedResult = ffmpeg.avcodec_decode_audio4(codecContext, frame, &frameDecoded, packet);

               if (frameDecoded > 0 && frameDecodedResult >= 0)
               {
                   AVFrame* filteredFrame = m_filterVolume.Adjust(frame);

                   //writeAudio.WriteFrame(filteredFrame);

                   packet.data += totalBytesDecoded;
                   packet.size -= totalBytesDecoded;
               }
           }

           frameIndex++;
       }

       Avcodec.av_free_packet(&packet);
    }

    Update 2 :

    Cracked it. The "channel_layout" option in the filter argument string is supposed to be a hexadecimal. This is what the string formatting should look like :

    string aBufferFilterArguments = string.Format("sample_fmt={0}:channel_layout=0x{1}:sample_rate={2}:time_base={3}/{4}",
       (int)CodecContext->sample_fmt,
       CodecContext->channel_layout,
       CodecContext->sample_rate,
       Stream->time_base.num,
       Stream->time_base.den);
  • Evolution #2269 : Prise en compte des variantes d’une langue

    8 septembre 2015, par Valéry -

    Notons au passage que ceci implique que #LANG donne un tag de langue complet incluant le subtag région

    Celui-ci est au passage exigé par le protocole OpenGraph :

    og:locale - The locale these tags are marked up in. Of the format language_TERRITORY. Default is en_US.

  • Video from images in Python

    26 février 2018, par R. Patterson

    I can draw a series of images using plt.draw() and plt.pause() so it produces something similar to an animation in the python window. I have modified each of the images with various labels, drawings etc.

    import numpy as np
    from PIL import Image
    import matplotlib.pyplot as plt
    import math

    def display(Intensity):
       l = plt.Line2D(Intensity[0],Intensity[1],color='yellow') #draw ROI/IAL
       ax = plt.gca()
       ax.add_line(l)
       plt.axis('off')
       plt.pause(0.05)
       plt.draw()
       plt.clf()

    #rotate region of interest
    def rotate(origin,Intensity,increment):
       ox, oy = origin #coordinates of centre or rotation
       x_points=[]
       y_points=[]
       angle=math.radians(increment)#change in angle between each image
       for i in range(0,len(Intensity[0])):
           px, py = Intensity[0][i], Intensity[1][i]
           qx = ox+math.cos(angle)*(px-ox)-math.sin(angle)*(py-oy)
           x_points.append(qx)
           qy = oy+math.sin(angle)*(px-ox)+math.cos(angle)*(py-oy)
           y_points.append(qy)
       rotatecoordinates=[]
       rotatecoordinates.append(x_points)
       rotatecoordinates.append(y_points)
       return rotatecoordinates

    def animation(list, Intensity):
       inc=0
       for value in list:
           item = np.array(value)
           rotated=rotate([128,128],Intensity,inc)
           im=plt.imshow(item, interpolation='nearest')
           display(rotated)
           inc+=1

    Image_list=[]
    for i in range(0,50):
       array=np.linspace(0,1,256*256)
       mat=np.reshape(array,(256,256))
       img=Image.fromarray(np.uint8(mat*255),'L') #create images
       Image_list.append(img)

    myROI=([100,150,150,100,100],[100,100,150,150,100]) #region of interest on image
    animation(Image_list,myROI)

    I would like to produce a video file using the images produced. I can’t use the module imageio, imagemagick, opencv, cv2 etc. I think ffmpeg would work, I have the following code.

    def save():
       os.system("ffmpeg -r 1 -i img%01d.png -vcodec mpeg4 -y movie.mp4")

    I don’t understand how to use it in relation to the code I already have. It doesn’t take any arguments, how would I relate it to the images I have ? I know how to use imagej/fiji to produce videos from images but I would like to do this in python and also it runs out of memory (I have a lot of images, over 2000). Any help would be appreciated, thank you.