Recherche avancée

Médias (1)

Mot : - Tags -/biomaping

Autres articles (43)

  • Les tâches Cron régulières de la ferme

    1er décembre 2010, par

    La gestion de la ferme passe par l’exécution à intervalle régulier de plusieurs tâches répétitives dites Cron.
    Le super Cron (gestion_mutu_super_cron)
    Cette tâche, planifiée chaque minute, a pour simple effet d’appeler le Cron de l’ensemble des instances de la mutualisation régulièrement. Couplée avec un Cron système sur le site central de la mutualisation, cela permet de simplement générer des visites régulières sur les différents sites et éviter que les tâches des sites peu visités soient trop (...)

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 is the first MediaSPIP stable release.
    Its official release date is June 21, 2013 and is announced here.
    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 (...)

  • Use, discuss, criticize

    13 avril 2011, par

    Talk to people directly involved in MediaSPIP’s development, or to people around you who could use MediaSPIP to share, enhance or develop their creative projects.
    The bigger the community, the more MediaSPIP’s potential will be explored and the faster the software will evolve.
    A discussion list is available for all exchanges between users.

Sur d’autres sites (6735)

  • Is there a way to extract frames from a video file using ffmpeg to memory and make some manipulation on each frame ?

    28 octobre 2022, par Rojer Brief

    The goal is to extract each time a frame from the video file then make histogram from the image and then to move to the next frame. this way all the frames.

    


    The frames extraction and the histogram manipulation is working fine when the frames have saved as images on the hard disk. but now i want to do it all in memory.

    


    to extract the frames i'm using ffmpeg because i think it's fast enough :

    


    ffmpeg -r 1 -i MyVid.mp4 -r 1 "$filename%03d.png


    


    for now i'm using the ffmpeg in command prompt window.

    


    with this command it will save on the hard disk over 65000 images(frames).
but instead saving them on the hard disk i wonder if i can make the histogram manipulation on each frame in memory instead saving all the 65000 frames to the hard disk.

    


    then i want to find specific images using the histogram and save to the hard disk this frames.

    


    the histogram part for now is also using files from the hard disk and not from the memory :

    


    private void btnLoadHistogram_Click(object sender, System.EventArgs e)
        {
            string[] files = Directory.GetFiles(@"d:\screenshots\", "*.jpg");

            for (int i = 0; i < files.Length; i++)
            {
                sbInfo.Text = "Loading image";
                if (pbImage.Image != null)
                    pbImage.Image.Dispose();

                pbImage.Image = Image.FromFile(files[i]);//txtFileName.Text);

                Application.DoEvents();

                sbInfo.Text = "Computing histogram";
                long[] myValues = GetHistogram(new Bitmap(pbImage.Image));

                Histogram.DrawHistogram(myValues);

                sbInfo.Text = "";   
            }   
        }

        public long[] GetHistogram(System.Drawing.Bitmap picture)
        {
            long[] myHistogram = new long[256];

            for (int i=0;i3;
                    myHistogram[Temp]++;
                }

            return myHistogram;
        }


    


    and the code of the class of the constrol HistogramaDesenat :

    


    using System;&#xA;using System.Collections;&#xA;using System.ComponentModel;&#xA;using System.Drawing;&#xA;using System.Data;&#xA;using System.Windows.Forms;&#xA;&#xA;namespace Histograma&#xA;{&#xA;    /// <summary>&#xA;    /// Summary description for HistogramaDesenat.&#xA;    /// </summary>&#xA;    public class HistogramaDesenat : System.Windows.Forms.UserControl&#xA;    {&#xA;        /// <summary> &#xA;        /// Required designer variable.&#xA;        /// </summary>&#xA;        private System.ComponentModel.Container components = null;&#xA;&#xA;        public HistogramaDesenat()&#xA;        {&#xA;            // This call is required by the Windows.Forms Form Designer.&#xA;            InitializeComponent();&#xA;&#xA;            // TODO: Add any initialization after the InitializeComponent call&#xA;&#xA;            this.Paint &#x2B;= new PaintEventHandler(HistogramaDesenat_Paint);&#xA;            this.Resize&#x2B;=new EventHandler(HistogramaDesenat_Resize);&#xA;        }&#xA;&#xA;        /// <summary> &#xA;        /// Clean up any resources being used.&#xA;        /// </summary>&#xA;        protected override void Dispose( bool disposing )&#xA;        {&#xA;            if( disposing )&#xA;            {&#xA;                if(components != null)&#xA;                {&#xA;                    components.Dispose();&#xA;                }&#xA;            }&#xA;            base.Dispose( disposing );&#xA;        }&#xA;&#xA;        #region Component Designer generated code&#xA;        /// <summary> &#xA;        /// Required method for Designer support - do not modify &#xA;        /// the contents of this method with the code editor.&#xA;        /// </summary>&#xA;        private void InitializeComponent()&#xA;        {&#xA;            // &#xA;            // HistogramaDesenat&#xA;            // &#xA;            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));&#xA;            this.Name = "HistogramaDesenat";&#xA;            this.Size = new System.Drawing.Size(208, 176);&#xA;        }&#xA;        #endregion&#xA;&#xA;        private void HistogramaDesenat_Paint(object sender, PaintEventArgs e)&#xA;        {&#xA;            if (myIsDrawing)&#xA;            {&#xA;&#xA;                Graphics g = e.Graphics;&#xA;                Pen myPen = new Pen(new SolidBrush(myColor),myXUnit);&#xA;                //The width of the pen is given by the XUnit for the control.&#xA;                for (int i=0;i/We draw each line &#xA;                    g.DrawLine(myPen,&#xA;                        new PointF(myOffset &#x2B; (i*myXUnit), this.Height - myOffset), &#xA;                        new PointF(myOffset &#x2B; (i*myXUnit), this.Height - myOffset - myValues[i] * myYUnit));&#xA;&#xA;                    //We plot the coresponding index for the maximum value.&#xA;                    if (myValues[i]==myMaxValue)&#xA;                    {&#xA;                        SizeF mySize = g.MeasureString(i.ToString(),myFont);&#xA;&#xA;                        g.DrawString(i.ToString(),myFont,new SolidBrush(myColor),&#xA;                            new PointF(myOffset &#x2B; (i*myXUnit) - (mySize.Width/2), this.Height - myFont.Height ),&#xA;                            System.Drawing.StringFormat.GenericDefault);&#xA;                    }&#xA;                }&#xA;&#xA;                //We draw the indexes for 0 and for the length of the array beeing plotted&#xA;                g.DrawString("0",myFont, new SolidBrush(myColor),new PointF(myOffset,this.Height - myFont.Height),System.Drawing.StringFormat.GenericDefault);&#xA;                g.DrawString((myValues.Length-1).ToString(),myFont, &#xA;                    new SolidBrush(myColor),&#xA;                    new PointF(myOffset &#x2B; (myValues.Length * myXUnit) - g.MeasureString((myValues.Length-1).ToString(),myFont).Width,&#xA;                    this.Height - myFont.Height),&#xA;                    System.Drawing.StringFormat.GenericDefault);&#xA;&#xA;                //We draw a rectangle surrounding the control.&#xA;                g.DrawRectangle(new System.Drawing.Pen(new SolidBrush(Color.Black),1),0,0,this.Width-1,this.Height-1);&#xA;            }&#xA;&#xA;        }&#xA;&#xA;        long myMaxValue;&#xA;        private long[] myValues;&#xA;        private bool myIsDrawing;&#xA;&#xA;        private float myYUnit; //this gives the vertical unit used to scale our values&#xA;        private float myXUnit; //this gives the horizontal unit used to scale our values&#xA;        private int myOffset = 20; //the offset, in pixels, from the control margins.&#xA;&#xA;        private Color myColor = Color.Black;&#xA;        private Font myFont = new Font("Tahoma",10);&#xA;&#xA;        [Category("Histogram Options")]&#xA;        [Description ("The distance from the margins for the histogram")]&#xA;        public int Offset&#xA;        {&#xA;            set&#xA;            {&#xA;                if (value>0)&#xA;                    myOffset= value;&#xA;            }&#xA;            get&#xA;            {&#xA;                return myOffset;&#xA;            }&#xA;        }&#xA;&#xA;        [Category("Histogram Options")]&#xA;        [Description ("The color used within the control")]&#xA;        public Color DisplayColor&#xA;        {&#xA;            set&#xA;            {&#xA;                myColor = value;&#xA;            }&#xA;            get&#xA;            {&#xA;                return myColor;&#xA;            }&#xA;        }&#xA;&#xA;        /// <summary>&#xA;        /// We draw the histogram on the control&#xA;        /// </summary>&#xA;        /// The values beeing draw&#xA;        public void DrawHistogram(long[] Values)&#xA;        {&#xA;            myValues = new long[Values.Length];&#xA;            Values.CopyTo(myValues,0);&#xA;&#xA;            myIsDrawing = true;&#xA;            myMaxValue = getMaxim(myValues);&#xA;&#xA;            ComputeXYUnitValues();&#xA;&#xA;            this.Refresh();&#xA;        }&#xA;&#xA;        /// <summary>&#xA;        /// We get the highest value from the array&#xA;        /// </summary>&#xA;        /// The array of values in which we look&#xA;        /// <returns>The maximum value</returns>&#xA;        private long getMaxim(long[] Vals)&#xA;        {&#xA;            if (myIsDrawing)&#xA;            {&#xA;                long max = 0;&#xA;                for (int i=0;i max)&#xA;                        max = Vals[i];&#xA;                }&#xA;                return max;&#xA;            }&#xA;            return 1;&#xA;        }&#xA;&#xA;        private void HistogramaDesenat_Resize(object sender, EventArgs e)&#xA;        {&#xA;            if (myIsDrawing)&#xA;            {&#xA;                ComputeXYUnitValues();&#xA;            }&#xA;            this.Refresh();&#xA;        }&#xA;&#xA;        private void ComputeXYUnitValues()&#xA;        {&#xA;            myYUnit = (float) (this.Height - (2 * myOffset)) / myMaxValue;&#xA;            myXUnit = (float) (this.Width - (2 * myOffset)) / (myValues.Length-1);&#xA;        }&#xA;    }&#xA;}&#xA;

    &#xA;

    so in the end this is what i want to do :

    &#xA;

      &#xA;
    • extract the frames from the video file in memory using the ffmpeg.

      &#xA;

    • &#xA;

    • instead using Directory.GetFiles i want to make the histogram manipulation on each frame from the memory that is extracted by the ffmpeg.

      &#xA;

    • &#xA;

    • each extracted frame image to use the histogram to find if there is a lightning(weather lightning) in the image.

      &#xA;

    • &#xA;

    • if there is a lightning save the frame image to the hard disk.

      &#xA;

    • &#xA;

    &#xA;

  • Huge memory leak when filtering video with libavfilter

    29 mai 2017, par Captain Jack

    I have a relatively simple FFMPEG C program, to which a video frame is fed, processed via filter graph and sent to frame renderer.

    Here are some code snippets :

    /* Filter graph here */
    char args[512];
    enum AVPixelFormat pix_fmts[] = {AV_PIX_FMT_RGB32 };    
    AVFilterGraph   *filter_graph;
    avfilter_register_all();
    AVFilter *buffersrc  = avfilter_get_by_name("buffer");
    AVFilter *buffersink = avfilter_get_by_name("ffbuffersink");
    AVBufferSinkParams *buffersink_params;
    AVFilterInOut *outputs = avfilter_inout_alloc();
    AVFilterInOut *inputs  = avfilter_inout_alloc();
    filter_graph = avfilter_graph_alloc();

    snprintf(args, sizeof(args),
           "video_size=%dx%d:pix_fmt=%d:time_base=%d/%d:pixel_aspect=%d/%d",
           av->codec_ctx->width, av->codec_ctx->height, av->codec_ctx->pix_fmt,
           av->codec_ctx->time_base.num, av->codec_ctx->time_base.den,
           av->codec_ctx->sample_aspect_ratio.num, av->codec_ctx->sample_aspect_ratio.den);

    if(avfilter_graph_create_filter(&amp;av->buffersrc_ctx, buffersrc, "in",args, NULL, filter_graph) &lt; 0)
    {
       fprintf(stderr, "Cannot create buffer source\n");
       return(0);
    }

    /* buffer video sink: to terminate the filter chain. */
    buffersink_params = av_buffersink_params_alloc();
    buffersink_params->pixel_fmts = pix_fmts;

    if(avfilter_graph_create_filter(&amp;av->buffersink_ctx, buffersink, "out",NULL, buffersink_params, filter_graph) &lt; 0)
    {
       printf("Cannot create buffer sink\n");
       return(HACKTV_ERROR);
    }

     /* Endpoints for the filter graph. */
       outputs->name       = av_strdup("in");
       outputs->filter_ctx = av->buffersrc_ctx;
       outputs->pad_idx    = 0;
       outputs->next       = NULL;

       inputs->name       = av_strdup("out");
       inputs->filter_ctx = av->buffersink_ctx;
       inputs->pad_idx    = 0;
       inputs->next       = NULL;

    const char *filter_descr = "vflip";

       if (avfilter_graph_parse_ptr(filter_graph, filter_descr, &amp;inputs, &amp;outputs, NULL) &lt; 0)
    {
       printf("Cannot parse filter graph\n");
       return(0);
    }

    if (avfilter_graph_config(filter_graph, NULL) &lt; 0)
    {
       printf("Cannot configure filter graph\n");
       return(0);
    }

    av_free(buffersink_params);
    avfilter_inout_free(&amp;inputs);
    avfilter_inout_free(&amp;outputs);

    The above code is called by these elsewhere :

    av->frame_in->pts = av_frame_get_best_effort_timestamp(av->frame_in);

    /* push the decoded frame into the filtergraph*/
    if (av_buffersrc_add_frame(av->buffersrc_ctx, av->frame_in) &lt; 0)
    {
       printf( "Error while feeding the filtdergraph\n");
       break;
    }

    /* pull filtered pictures from the filtergraph */
    if(av_buffersink_get_frame(av->buffersink_ctx, av->frame_out) &lt; 0)
    {
         printf( "Error while sourcing the filtergraph\n");
          break;
     }  

    /* do stuff with frame */

    Now, the code works absolutely fine and the video comes out the way I expect it to (vertically flipped for testing purposes).

    The biggest issue I have is that there is a massive memory leak. An high res video will consume 2Gb in a matter of seconds and crash the program. I traced the leak to this piece of code :

    /* push the decoded frame into the filtergraph*/
    if (av_buffersrc_add_frame(av->buffersrc_ctx, av->frame_in) &lt; 0)

    If I bypass the filter by doing av->frame_out=av->frame_in; without pushing the frame into it (and obviously not pulling from it), there is no leak and memory usage is stable.

    Now, I am very new to C, so be gentle, but it seems like I should be clearing out the buffersrc_ctx somehow but no idea how. I’ve looked in official documentations but couldn’t find anything.

    Can someone advise ?

  • Increased File Size When Converting MP4 to WebM using FFmpeg

    23 décembre 2024, par kimgijeong

    I am using FFmpeg to convert MP4 to WebM with the following command :

    &#xA;

    ffmpeg -y -hide_banner -nostats \&#xA;-f mov,mp4,m4a,3gp,3g2,mj2 -i "http://127.0.0.1:80/lotteon-low-bitrate.mp4" \&#xA;-threads auto -f webm -acodec libopus -b:a 96.059k -vcodec libsvtav1 -preset 11 -pix_fmt yuv420p \&#xA;-vf "scale=&#x27;min(-1, iw)&#x27;:&#x27;min(-1,ih)&#x27;:force_original_aspect_ratio=decrease,crop=trunc(iw/2)*2:trunc(ih/2)*2" \&#xA;"/usr/local/m2/m2temp/xcdrtmp/2052_1.webm"&#xA;

    &#xA;

    However, the output webm file size is larger than the source MP4 file. For example :

    &#xA;

      &#xA;
    • Source MP4 : 4.6 MB (bit rate : 994,053 bps)

      &#xA;

    • &#xA;

    • Output WebM : 16 MB (bit rate : 3,902,037 bps)

      &#xA;

    • &#xA;

    &#xA;

    I know SVT-AV1 encoder defaults to CRF mode. Due to not specifying the bitrate explicitly, the SVT-AV1 encoder automatically sets the bit_rate. It appears that the encoder is setting it to a much higher value (3,323,104 bps), causing the increase in file size compared to the source MP4 (994,053 bps). Here are the methods i tried to reduce the WebM file size compared to the source MP4 :

    &#xA;

      &#xA;
    1. -b:v 994k
    2. &#xA;

    &#xA;

    I tried to match the target bitrate with the source MP4's bitrate to reduce the output size, but encountered the following error :

    &#xA;

    Svt[error]: Instance 1: Force key frames is not supported for VBR mode Last message r&#xA;epeated 2 times [libsvtav1 @ 0x239dd100] Error setting encoder parameters: bad parameter (0x80001005)&#xA;

    &#xA;

    Looking at the official documentation, this mode change (from CRF to VBR when setting a target bitrate) appears to be expected behavior. However, the error is puzzling since I haven't set any force keyframe parameters in the FFmpeg command.

    &#xA;

      &#xA;
    1. svtav1-params "mbr=994k"
    2. &#xA;

    &#xA;

    The second method i tried was using the svtav1-params "mbr=994k" option to set the maxrate while maintaining CRF mode This method showed some improvement, but the output file size was still larger than the source MP4.

    &#xA;

      &#xA;
    • Output WebM : 5MB (bit rate : 1,209,877 bps)
    • &#xA;

    &#xA;

    The more critical reason why we can't adopt the second method (using svtav1-params "mbr=994k") is that even for the same MP4 source file, the output file size varies slightly with each encoding.

    &#xA;

      &#xA;
    1. -b:v 994k -svtav1-params “rc=2:pred-struct=1”(CBR, low delay)
    2. &#xA;

    &#xA;

    The final method I tried was setting the target bitrate while using CBR (Constant Bit Rate) and low-delay mode The default value for pred-structure is 2(random access), but I had to use low-delay mode due to the following error :

    &#xA;

    Svt[error]: CBR Rate control is currently not supported for SVT_AV1_PRED_RANDOM_ACCESS, use VBR mode&#xA;

    &#xA;

    This way was the only approach among those i tried that successfully reduced the output size.

    &#xA;

      &#xA;
    • Output WebM : 4.3MB (bit rate : 1,032,373 bps)
    • &#xA;

    &#xA;

    In summary, I have three questions about this MP4 to WebM conversion issue :

    &#xA;

      &#xA;
    1. When setting the target bitrate with -b:v 994k, the switch to VBR mode is expected behavior. However, why does the force keyframe error occur when we haven't explicitly set any force keyframe parameters ?

      &#xA;

    2. &#xA;

    3. Why does the output WebM file size fluctuate when setting maxrate either through -maxrate or svtav1-params "mbr=994k", even when using the same MP4 source file ?

      &#xA;

    4. &#xA;

    5. Besides using -b:v 994k -svtav1-params "rc=2:pred-struct=1" (CBR with low delay), are there any other methods that can guarantee a WebM output size smaller than the source MP4 when converting from MP4 to WebM ?

      &#xA;

    6. &#xA;

    &#xA;

    I am using a recent version of the SVT-AV1 codec :

    &#xA;

    Svt[info]: SVT [version]:       SVT-AV1 Encoder Lib 58146ca&#xA;Svt[info]: SVT [build]  :       GCC 11.5.0 20240719 (Red Hat 11.5.0-2)   64 bit&#xA;Svt[info]: LIB Build date: Oct 28 2024 07:40:59&#xA;ffmpeg video svt-av1&#xA;

    &#xA;