Recherche avancée

Médias (91)

Autres articles (61)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

  • List of compatible distributions

    26 avril 2011, par

    The table below is the list of Linux distributions compatible with the automated installation script of MediaSPIP. Distribution nameVersion nameVersion number Debian Squeeze 6.x.x Debian Weezy 7.x.x Debian Jessie 8.x.x Ubuntu The Precise Pangolin 12.04 LTS Ubuntu The Trusty Tahr 14.04
    If you want to help us improve this list, you can provide us access to a machine whose distribution is not mentioned above or send the necessary fixes to add (...)

  • Liste des distributions compatibles

    26 avril 2011, par

    Le tableau ci-dessous correspond à la liste des distributions Linux compatible avec le script d’installation automatique de MediaSPIP. Nom de la distributionNom de la versionNuméro de version Debian Squeeze 6.x.x Debian Weezy 7.x.x Debian Jessie 8.x.x Ubuntu The Precise Pangolin 12.04 LTS Ubuntu The Trusty Tahr 14.04
    Si vous souhaitez nous aider à améliorer cette liste, vous pouvez nous fournir un accès à une machine dont la distribution n’est pas citée ci-dessus ou nous envoyer le (...)

Sur d’autres sites (5692)

  • C++ h264 ffmpeg/libav encode/decode(lossless) issues

    1er février 2017, par MrSmith

    Insights to encode/decode video with ffmpeg h264 (lossless)

    So I got something working on the encoding part, encode an avi in 264 however VLC wont play it, however Totem will.
    Decoding the same file proves troublesome. (I want the exact same data/frame going in as going out), I get these ;

    saving frame   5
    Video decoding
    [h264 @ 0x1d19880] decode_slice_header error
    frame :6
    saving frame   6
    Video decoding
    [h264 @ 0x1d19880] error while decoding MB 15 7, bytestream -27
    [h264 @ 0x1d19880] concealing 194 DC, 194 AC, 194 MV errors in I frame
    frame :7
    saving frame   7
    Video decoding
    [h264 @ 0x1d19880] decode_slice_header error

    and ultimatly this

    [H264 Decoder @ 0x7f1320766040] frame :11
    Broken frame packetizing
    [h264 @ 0x1d19880] SPS changed in the middle of the frame
    [h264 @ 0x1d19880] decode_slice_header error
    [h264 @ 0x1d19880] no frame!
    Error while decoding frame 11

    GAME OVER.

    Now I suspect that I have to go back to 1. the encoding part, there is problary a good reason VLC wont play it !

    I encode like this.

    void encode(char *Y,char *U,char *V){
    av_init_packet(&pkt);
    pkt.data = NULL;    // packet data will be allocated by the encoder
    pkt.size = 0;
    fflush(stdout);

    frame->data[0] = (uint8_t*)Y;
    frame->data[1] = (uint8_t*)U;
    frame->data[2] = (uint8_t*)V;
    frame->pts = ++i;

    ret = avcodec_encode_video2(c, &pkt, frame, &got_output);
    if (ret < 0) {
       fprintf(stderr, "Error encoding frame\n");
       exit (EXIT_FAILURE);
    }
    if (got_output) {
       printf("Write frame %3d (size=%5d)\n", i, pkt.size);
       fwrite(pkt.data, 1, pkt.size, f);
       av_free_packet(&pkt);
    }
    }

    And the codec is setup like this :

    AVCodecID dasd = AV_CODEC_ID_H264;
    codec = avcodec_find_encoder(dasd);
    c = avcodec_alloc_context3(codec);
    c->bit_rate = 400000;
    c->width = 320;
    c->height = 240;
    c->time_base= (AVRational){1,25};
    c->gop_size = 10;
    c->max_b_frames=1;
    c->pix_fmt = AV_PIX_FMT_YUV420P;
    av_opt_set(c->priv_data, "preset", "slow", 0);
    avcodec_open2(c, codec, NULL);

    Since I am going for lossless i am not dealing with delayed frames(is this a correct assumption ?)
    I may not actually be encoding lossless, it seems like I may have to go with something like

    AVDictionary *param;
    av_dict_set(&param, "qp", "0", 0);

    And then open...

    So I guess me questions is these :

    • What are the correct codec params for lossless encoding (and advice if h264 is a terrible idea in this regard).
    • Do I need to handle delayed frames when going for lossless ?
    • Why is VLC mad at me ?

    Thanks.

  • How can i save the preview video in pictureBox1 to a avi/mp4 video file on hard disk using directshow ?

    10 avril 2016, par benny dayag

    The first problem maybe it’s not a problem but for some reason the video preview in the pictureBox1 is working but the frame rate seems not right. I can’t figure how to set/change it. The preview video seems a bit dart to the eyes not flickering but not moving smooth.

    The main problem is how to save the preview in the pictureBox1 or directly the streaming to a video file ? The MediaSubtype i’m getting is h.264

    The video is from the device legato game capture.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using DirectShowLib;
    using DirectShowLib.BDA;
    using DirectShowLib.DES;
    using DirectShowLib.DMO;
    using DirectShowLib.Dvd;
    using DirectShowLib.MultimediaStreaming;
    using DirectShowLib.SBE;
    using System.Runtime.InteropServices;
    using System.Management;
    using System.IO;
    using System.Drawing.Imaging;


    namespace Youtube_Manager
    {

       public partial class Elgato_Video_Capture : Form
       {


           IFileSinkFilter sink;

           IFilterGraph2 graph;
           ICaptureGraphBuilder2 captureGraph;
           System.Drawing.Size videoSize;

           string error = "";
           List devices = new List();
           IMediaControl mediaControl;

           public Elgato_Video_Capture()
           {
               InitializeComponent();



               if (comboBox1.Items.Count == 0)
               {
                   for (int xx = 1; xx <= 8; xx++)
                   {
                       comboBox1.Items.Add(xx);
                   }
               }

               InitDevice();
               timer1.Start();
           }

           IBaseFilter smartTeeFilter;
           IPin outPin;
           IPin inPin;
           private void InitDevice()
           {
               try
               {
                   //Set the video size to use for capture and recording
                   videoSize = new Size(827, 505);//1280, 720);

                   //Initialize filter graph and capture graph
                   graph = (IFilterGraph2)new FilterGraph();
                   captureGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
                   captureGraph.SetFiltergraph(graph);
                   //Create filter for Elgato
                   Guid elgatoGuid = new Guid("39F50F4C-99E1-464A-B6F9-D605B4FB5918");
                   Type comType = Type.GetTypeFromCLSID(elgatoGuid);
                   IBaseFilter  elgatoFilter = (IBaseFilter)Activator.CreateInstance(comType);
                   graph.AddFilter(elgatoFilter, "Elgato Video Capture Filter");

                   //Create smart tee filter, add to graph, connect Elgato's video out to smart tee in
                   smartTeeFilter = (IBaseFilter)new SmartTee();

                   graph.AddFilter(smartTeeFilter, "Smart Tee");
                   outPin = GetPin(elgatoFilter, "Video");
                   inPin = GetPin(smartTeeFilter, "Input");
                   SetAndGetAllAvailableResolution(outPin);
                   graph.Connect(outPin, inPin);


                   //Create video renderer filter, add it to graph, connect smartTee Preview pin to video renderer's input pin
                   IBaseFilter videoRendererFilter = (IBaseFilter)new VideoRenderer();

                   graph.AddFilter(videoRendererFilter, "Video Renderer");
                   outPin = GetPin(smartTeeFilter, "Preview");

                   inPin = GetPin(videoRendererFilter, "Input");
                   graph.Connect(outPin, inPin);

                  // int hr = graph.Connect(outPin, inPin); ;
                  // DsError.ThrowExceptionForHR(hr);

                   captureGraph.SetOutputFileName(MediaSubType.Avi, @"e:\screenshots\test1.mp4", out smartTeeFilter, out sink);

                   //Render stream from video renderer
                   captureGraph.RenderStream(PinCategory.VideoPort, MediaType.Video, videoRendererFilter, null, null);
                   //Set the video preview to be the videoFeed panel
                   IVideoWindow vw = (IVideoWindow)graph;
                   vw.put_Owner(pictureBox1.Handle);
                   vw.put_MessageDrain(this.Handle);
                   vw.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
                   vw.SetWindowPosition(0, 0, 827, 505);

                   //Start the preview
                   mediaControl = graph as IMediaControl;
                   mediaControl.Run();
               }
               catch (Exception err)
               {
                   error = err.ToString();
               }
           }

            IPin GetPin(IBaseFilter filter, string pinname)
           {
               IEnumPins epins;
               int hr = filter.EnumPins(out epins);
               checkHR(hr, "Can't enumerate pins");
               IntPtr fetched = Marshal.AllocCoTaskMem(4);
               IPin[] pins = new IPin[1];
               while (epins.Next(1, pins, fetched) == 0)
               {
                   PinInfo pinfo;
                   pins[0].QueryPinInfo(out pinfo);
                   bool found = (pinfo.name == pinname);
                   DsUtils.FreePinInfo(pinfo);
                   if (found)
                       return pins[0];
               }
               checkHR(-1, "Pin not found");
               return null;
           }

           public  void checkHR(int hr, string msg)
           {
               if (hr < 0)
               {
                   MessageBox.Show(msg);
                   DsError.ThrowExceptionForHR(hr);
               }



           }

           public void SetAndGetAllAvailableResolution(IPin VideoOutPin)
           {
               int hr = 0;
               IAMStreamConfig streamConfig = (IAMStreamConfig)VideoOutPin;
               AMMediaType searchmedia;
               AMMediaType CorectvidFormat = new AMMediaType();
               IntPtr ptr;
               int piCount, piSize;
               hr = streamConfig.GetNumberOfCapabilities(out piCount, out piSize);
               ptr = Marshal.AllocCoTaskMem(piSize);
               for (int i = 0; i < piCount; i++)
               {
                   hr = streamConfig.GetStreamCaps(i, out searchmedia, ptr);
                   VideoInfoHeader v = new VideoInfoHeader();

                   Marshal.PtrToStructure(searchmedia.formatPtr, v);
                   if (i == 2)// 4
                   {
                       CorectvidFormat = searchmedia;
                   }
               }
               hr = streamConfig.SetFormat(CorectvidFormat);

               IntPtr pmt = IntPtr.Zero;
               AMMediaType mediaType = new AMMediaType();
               IAMStreamConfig streamConfig1 = (IAMStreamConfig)VideoOutPin;
               hr = streamConfig1.GetFormat(out mediaType);
               BitmapInfoHeader bmpih = new BitmapInfoHeader();
               Marshal.PtrToStructure(mediaType.formatPtr, bmpih);
           }
     }
    }

    I tried to use this line to save the video to a video file but the video file on hard disk is 0 KB so I guess it’s a wrong way to do it.
    I also thought somehow to save each frame(bitmap image) from the pictureBox1 to the hard disk or maybe the memory and use ffmpeg to create/build a video file in real time from each saved frame but I can’t get/save the images(frames) from the pictureBox1 for some reason.

    I tried using DrawToBitmap but all the frames(bitmaps on hard disk saved) are empty size 2.24 KB

    captureGraph.SetOutputFileName(MediaSubType.Avi, @"e:\screenshots\test1.mp4", out smartTeeFilter, out sink);

    This is how I tried to get the frames from the pictureBox1

    public static int counter = 0;
           private void timer1_Tick(object sender, EventArgs e)
           {
               counter++;
               Bitmap bmp = new Bitmap(pictureBox1.ClientSize.Width, pictureBox1.ClientSize.Height);
               pictureBox1.DrawToBitmap(bmp, pictureBox1.ClientRectangle);
               bmp.Save(@"e:\screenshots\" + "screenshot" + counter.ToString("D6") + ".bmp");
               bmp.Dispose();
           }
  • How can i capture a screenshots from pictureBox1 every X milliseconds ?

    9 avril 2016, par Brubaker Haim

    The way it is now it’s capturing screenshots depending on on what screen I am in.
    For example if i’m in my desktop it will take screenshots of my desktop if I move to the form1 and see the pictureBox1 it will take screenshots of the pictureBox1.

    But how can I get directly screenshots from the pictureBox1 no matter on what screen I am ?

    Bitmap bmp1;
           public static int counter = 0;
           private void timer1_Tick(object sender, EventArgs e)
           {
               counter++;

               Rectangle rect = new Rectangle(0, 0, pictureBox1.ClientSize.Width, pictureBox1.ClientSize.Height);
               bmp1 = new Bitmap(rect.Width, rect.Height, PixelFormat.Format32bppArgb);
               Graphics g = Graphics.FromImage(bmp1);
               g.CopyFromScreen(rect.Left, rect.Top, 0, 0, bmp1.Size, CopyPixelOperation.SourceCopy);
               bmp1.Save(@"e:\screenshots\" + "screenshot" + counter.ToString("D6") + ".bmp", ImageFormat.Bmp);
               bmp1.Dispose();
               g.Dispose();
               if (counter == 500)//1200)
               {
                   timer1.Stop();
                   this.Close();
               }
           }

    The timer1 is set now to 100ms interval in the designer.
    But what is a reasonable speed to take screenshots from animation in the pictureBox1 ? In this case I have a game I show in the pictureBox1 and I want to take a screenshots of each frame from the pictureBox1 and in real time to create mp4 video file on the hard disk from each frame I took.

    So instead saving the bmp1 to the hard disk I need somehow to save each frame I capture in memory and build mp4 video file in real time.

    I created a ffmpeg class for that :

    using System;
    using System.Windows.Forms;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Drawing;
    using System.IO.Pipes;
    using System.Runtime.InteropServices;
    using System.Diagnostics;
    using System.IO;
    using DannyGeneral;

    namespace ffmpeg
    {
       public class Ffmpeg
       {
           NamedPipeServerStream p;
           String pipename = "mytestpipe";
           System.Diagnostics.Process process;
           string ffmpegFileName = "ffmpeg.exe";
           string workingDirectory;

           public Ffmpeg()
           {
               workingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
               Logger.Write("workingDirectory: " + workingDirectory);
               if (!Directory.Exists(workingDirectory))
               {
                   Directory.CreateDirectory(workingDirectory);
               }
               ffmpegFileName = Path.Combine(workingDirectory, ffmpegFileName);
               Logger.Write("FfmpegFilename: " + ffmpegFileName);
           }

           public void Start(string pathFileName, int BitmapRate)
           {
               try
               {

                   string outPath = pathFileName;
                   p = new NamedPipeServerStream(pipename, PipeDirection.Out, 1, PipeTransmissionMode.Byte);
                   ProcessStartInfo psi = new ProcessStartInfo();
                   psi.WindowStyle = ProcessWindowStyle.Hidden;
                   psi.UseShellExecute = false;
                   psi.CreateNoWindow = false;
                   psi.FileName = ffmpegFileName;
                   psi.WorkingDirectory = workingDirectory;
                   psi.Arguments = @"-f rawvideo -pix_fmt bgra -video_size 1920x1080 -i \\.\pipe\mytestpipe -c:v mpeg2video -crf 20 -r " + BitmapRate + " " + outPath;
                   process = Process.Start(psi);
                   process.EnableRaisingEvents = false;
                   psi.RedirectStandardError = true;
                   p.WaitForConnection();
               }
               catch (Exception err)
               {
                   Logger.Write("Exception Error: " + err.ToString());
               }
           }

           public void PushFrame(Bitmap bmp)
           {
               try
               {
                   int length;
                   // Lock the bitmap's bits.
                   //bmp = new Bitmap(1920, 1080);
                   Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
                   //Rectangle rect = new Rectangle(0, 0, 1280, 720);
                   System.Drawing.Imaging.BitmapData bmpData =
                       bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly,
                       bmp.PixelFormat);

                   int absStride = Math.Abs(bmpData.Stride);
                   // Get the address of the first line.
                   IntPtr ptr = bmpData.Scan0;

                   // Declare an array to hold the bytes of the bitmap.
                   //length = 3 * bmp.Width * bmp.Height;
                   length = absStride * bmpData.Height;
                   byte[] rgbValues = new byte[length];

                   //Marshal.Copy(ptr, rgbValues, 0, length);
                   int j = bmp.Height - 1;
                   for (int i = 0; i < bmp.Height; i++)
                   {
                       IntPtr pointer = new IntPtr(bmpData.Scan0.ToInt32() + (bmpData.Stride * j));
                       System.Runtime.InteropServices.Marshal.Copy(pointer, rgbValues, absStride * (bmp.Height - i - 1), absStride);
                       j--;
                   }
                   p.Write(rgbValues, 0, length);
                   bmp.UnlockBits(bmpData);
               }
               catch(Exception err)
               {
                   Logger.Write("Error: " + err.ToString());
               }

           }

           public void Close()
           {
               p.Close();
           }
       }
    }

    And using the ffmpeg class like this :

    public static Ffmpeg fmpeg;

    Then

    fmpeg = new Ffmpeg();
    fmpeg.Start(@"e:\screenshots\test.mp4", 25);

    And

    fmpeg.PushFrame(_screenShot);

    My main question is first how to get the screenshots(frames) from the pictureBox1 directly no matter what screen i’m in now ?

    And how to use on each frame with the fmpeg to get a fine mp4 speed video file I mean that I will not miss a frame to capture all frames and also that the mp4 video file will when I play it later will not display a fast video or too slow ?