Recherche avancée

Médias (2)

Mot : - Tags -/documentation

Autres articles (105)

  • Les formats acceptés

    28 janvier 2010, par

    Les commandes suivantes permettent d’avoir des informations sur les formats et codecs gérés par l’installation local de ffmpeg :
    ffmpeg -codecs ffmpeg -formats
    Les format videos acceptés en entrée
    Cette liste est non exhaustive, elle met en exergue les principaux formats utilisés : h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 m4v : raw MPEG-4 video format flv : Flash Video (FLV) / Sorenson Spark / Sorenson H.263 Theora wmv :
    Les formats vidéos de sortie possibles
    Dans un premier temps on (...)

  • Gestion de la ferme

    2 mars 2010, par

    La ferme est gérée dans son ensemble par des "super admins".
    Certains réglages peuvent être fais afin de réguler les besoins des différents canaux.
    Dans un premier temps il utilise le plugin "Gestion de mutualisation"

  • ANNEXE : Les plugins utilisés spécifiquement pour la ferme

    5 mars 2010, par

    Le site central/maître de la ferme a besoin d’utiliser plusieurs plugins supplémentaires vis à vis des canaux pour son bon fonctionnement. le plugin Gestion de la mutualisation ; le plugin inscription3 pour gérer les inscriptions et les demandes de création d’instance de mutualisation dès l’inscription des utilisateurs ; le plugin verifier qui fournit une API de vérification des champs (utilisé par inscription3) ; le plugin champs extras v2 nécessité par inscription3 (...)

Sur d’autres sites (7090)

  • how to send audio or video by packet though udp and sync the iamge and audio

    24 janvier 2019, par Wei Wen

    how to send part of video and audio from mp4 as packet though udp from server
    Client will play the part of packet resevice.

    import java.awt.Dimension ; import java.awt.image.BufferedImage ; import
    java.io.ByteArrayOutputStream ; import java.io.IOException ; import
    java.io.ObjectOutputStream ; import java.math.BigInteger ; import
    java.net.DatagramPacket ; import java.net.DatagramSocket ; import
    java.net.ServerSocket ; import java.net.Socket ; import
    java.nio.ByteBuffer ; import java.nio.ShortBuffer ; import
    java.util.ArrayList ; import java.util.Arrays ; import
    javax.imageio.ImageIO ; import javax.sound.sampled.AudioFileFormat ;
    import javax.sound.sampled.AudioFormat ; import javax.swing.JTextArea ;

    import org.bytedeco.javacv.FFmpegFrameGrabber ; import
    org.bytedeco.javacv.Frame ; import
    org.bytedeco.javacv.Java2DFrameConverter ;

    import Enum.EType.ClientState ; import View.SingleDisplayWindow ;

    import java.security.InvalidKeyException ; import
    java.security.NoSuchAlgorithmException ; import java.util.Timer ; import
    java.util.TimerTask ; import java.util.concurrent.CountDownLatch ;
    import java.util.concurrent.ExecutionException ;

    import javax.crypto.BadPaddingException ; import
    javax.crypto.IllegalBlockSizeException ; import
    javax.crypto.NoSuchPaddingException ; import
    org.bytedeco.javacv.FrameGrabber ;

    public class SCon private final static int PORT = 8888 ;

    private final JTextArea TEXT_AREA ; private volatile
    SingleDisplayWindow DISPLAY ; /////

    private final String BD_USER_NAME, DB_PASSWORD ; private Database
    database ;

    private boolean isRunning ;

    private RSA serverRSA, clientRSA ;

    private int keyIndex, typeID = 0 ; private String mediatype = "" ;
    private ArrayList sHandlers ;

    private FileStreamingThread fileStreamingThread ; private
    VideoStreamingThread videoStreamingThread ; private BroadcastThread
    broadcastThread ; private ConnectThread connectThread ;

    private volatile static byte[] currentVideoFrame = new byte[0],
    currentAudioFrame = new byte[0] ; // current image music

    public void run() startServer() ;

     isRunning = true;       fileStreamingThread = new

    FileStreamingThread(videoFile) ; videoStreamingThread = new
    VideoStreamingThread(videoFile) ;
    //CountDownLatch latch = new CountDownLatch(1) ; fileStreamingThread.start() ; videoStreamingThread.start() ;
    //latch.countDown() ;

             broadcastThread = new BroadcastThread();        broadcastThread.start();

     connectThread = new ConnectThread();        connectThread.start();  }

    public void stop() isRunning = false ;

     try {           new Socket("localhost", PORT);

     } catch (IOException e) {           e.printStackTrace();        }

     while (fileStreamingThread.isAlive()) {

     }

     while (broadcastThread.isAlive()) {

     }

     while (connectThread.isAlive()) {

     }

     for (SHandler sHandler : sHandlers) {           sHandler.connectionClose();
     }       sHandlers.clear();      DISPLAY.dispose();
     TEXT_AREA.append("\nServer stop\n");    }


     private class VideoStreamingThread extends Thread {         private

    FFmpegFrameGrabber grabber ; // Used to extract frames from video file.
    private Java2DFrameConverter converter ; // Used to convert frames to
    image private int curIndex ; // Current key index

     public VideoStreamingThread(String video_file) {            videoFile =

    videoFile ; grabber = new FFmpegFrameGrabber(videoFile) ;
    converter = new Java2DFrameConverter() ; try
    grabber.restart() ;

         } catch (FrameGrabber.Exception e) {
             e.printStackTrace();            }           curIndex = keyIndex;        }

     public void run() {             try {

             while (isRunning) {
                 curIndex = keyIndex;
                 Frame frame = null;
                 System.out.println("v1");
                 if ((frame = grabber.grab()) != null) { // Grab next frame from video file
                     if (frame.image != null) { // image frame

                         BufferedImage bi = converter.convert(frame); // convert frame to image

                         // Convert BufferedImage to byte[]
                         ByteArrayOutputStream baos = new ByteArrayOutputStream();
                         ImageIO.write(bi, "jpg", baos);
                         // Encrypt data and store as the current image of byte[] type
                         currentVideoFrame = ciphers[curIndex].doFinal(baos.toByteArray());                                                                          
                         //////////////////
                         DISPLAY.setSize(new Dimension(bi.getWidth(), bi.getHeight()));
                         DISPLAY.updateImage(bi); // Display image
                     //  Thread.sleep((long) ( 999 / grabber.getFrameRate()));

                         ///////////////
                         typeID = 1;
                         mediatype = grabber.getFormat();

                     }
                 } else {
                     grabber.restart();
                 } // Restart when reached end of video
             }
             grabber.close();

         } catch (IOException e) {
             e.printStackTrace();

         } catch (IllegalBlockSizeException e) {
             e.printStackTrace();

         } catch (BadPaddingException e) {
             e.printStackTrace();

         }           //catch (InterruptedException e) {e.printStackTrace(); }        }

     public synchronized int getCurKeyIndex() {          return curIndex;        }

     public synchronized void getVideoFile(String video_file) {
         videoFile = video_file;             grabber = new

    FFmpegFrameGrabber(video_file) ; converter = new
    Java2DFrameConverter() ;

         try {
             grabber.release();
             grabber.restart();

         } catch (FrameGrabber.Exception e) {
             e.printStackTrace();            }       }   }       private class FileStreamingThread extends Thread {      private FFmpegFrameGrabber

    grabber ; // Used to extract frames from video file. private int
    curIndex ; // Current key index

     public FileStreamingThread(String video_file) {             videoFile =

    videoFile ; grabber = new FFmpegFrameGrabber(videoFile) ; try
    grabber.restart() ;

         } catch (FrameGrabber.Exception e) {
             e.printStackTrace();            }           curIndex = keyIndex;        }

     public void run() {             try {

             while (isRunning) {
                 curIndex = keyIndex;
                 Frame frame = null;

                 System.out.println("a2");
                 if ((frame = grabber.grabSamples()) != null) { // Grab next frame from video file
                     if (frame.samples != null) { // audio frame
                         // Encrypt audio

                         ShortBuffer channelSamplesShortBuffer = (ShortBuffer) frame.samples[0];
                         channelSamplesShortBuffer.rewind();

                         ByteBuffer outBuffer = ByteBuffer.allocate(channelSamplesShortBuffer.capacity() * 2);

                         for (int i = 0; i < channelSamplesShortBuffer.capacity(); i++) {
                             short val = channelSamplesShortBuffer.get(i);
                             outBuffer.putShort(val);
                         }

                         AudioFileFormat audiofileFormat = new AudioFileFormat(null, null, typeID);
                         AudioFormat audioFormat = new AudioFormat(44100, 16, 2, true, true);
                         //System.out.println(grabber.getSampleFormat());
                         // Encrypt data and store as the current audio of byte[] type
                         currentAudioFrame = ciphers[curIndex].doFinal(outBuffer.array());

                         DISPLAY.updateAudio(outBuffer.array(), grabber.getFormat()); // Display image audio
                     //  Thread.sleep((long) (1000 / grabber.getSampleRate()));

                          //                         AudioFormat audioFormat = new AudioFormat(grabber.getSampleRate(), grabber.getAudioBitrate(),

    grabber.getAudioChannels(), true, true) ;
    // DISPLAY.updateAudio(outBuffer.array(), audioFormat) ; //
    Display image audio
    outBuffer.clear() ;

                         typeID = 2;
                         mediatype = grabber.getFormat();

                     }      
                 } else {
                     grabber.restart();
                 } // Restart when reached end of video
             }
             grabber.close();

         } catch (IOException e) {
             e.printStackTrace();

         } catch (IllegalBlockSizeException e) {
             e.printStackTrace();

         } catch (BadPaddingException e) {
             e.printStackTrace();

         }       }

     public synchronized int getCurKeyIndex() {          return curIndex;        }

     public synchronized void getVideoFile(String video_file) {
         videoFile = video_file;             grabber = new

    FFmpegFrameGrabber(video_file) ;

         try {
             grabber.release();
             grabber.restart();

         } catch (FrameGrabber.Exception e) {
             e.printStackTrace();            }       }   }

    public void setVideoFile(String videoFile) this.videoFile =
    videoFile ;

    public void setThreadFile(String video_file)
    fileStreamingThread.getVideoFile(video_file) ;
    videoStreamingThread.getVideoFile(video_file) ;

    private class BroadcastThread extends Thread public void run()
    while (isRunning)
    Thread.yield() ;

             for (int i = 0; i < sHandlers.size(); i++) {
                 if (sHandlers.get(i).getClientState() == ClientState.R) {
                     sHandlers.get(i).setClientState(ClientState.W);
                     BroadcastWorker workerThread = new BroadcastWorker(sHandlers.get(i));
                     workerThread.start();
                 }
             }           }       }   }

    private class BroadcastWorker extends Thread SHandler sHandler =
    null ;

     public BroadcastWorker(SHandler sHandler) {             this.sHandler =

    sHandler ;

     public void run() {             try {
             DatagramSocket out = new DatagramSocket(); // used to send UDP packets

             while (sHandler.getClientState() == ClientState.W) {
                 Thread.yield();

                 StreamFile s = new StreamFile(typeID, currentVideoFrame, currentAudioFrame, mediatype);
                 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                 ObjectOutputStream os = new ObjectOutputStream(outputStream);
                 os.writeObject(s);
                 byte[] data = outputStream.toByteArray();
                     // Create and send UDP packet
                 DatagramPacket videoPacket = new DatagramPacket(data, data.length,
                         sHandler.getClientSocket().getInetAddress(),
                         Integer.parseInt(sHandler.getClientPort()));
                     out.send(videoPacket);

             }           } catch (IOException e) {
             e.printStackTrace();            }       }   }

    private class ConnectThread extends Thread public void run()
    TEXT_AREA.append("\nWaiting for clients’ connection.....\n") ;

         try {
             ServerSocket serverSocket = new ServerSocket(PORT);
             Socket clientSocket = null;

             while (isRunning) {
                 clientSocket = serverSocket.accept();

                 if (isRunning) {
                     SHandler sHandler = new SHandler(clientSocket, serverRSA, clientRSA, sessionKeys[keyIndex],
                             TEXT_AREA);
                     sHandler.start();
                     sHandlers.add(sHandler);
                 }
             }
             serverSocket.close();
             if (clientSocket != null) {
                 clientSocket.close();
             }

         } catch (IOException e) {
             e.printStackTrace();            }       }   } }

    my audio and image not sync.

  • using Accord.Video.FFMPEG aka(AForge) give exception error paramter is not valid. how to solve it ?

    12 avril 2023, par Sheron Blumental

    I want to extract all the frames from a mp4 video file and display them on a pictureBox.

    


    The exception happens after clicking the start button on the line :

    


    var frame = videoReader.ReadVideoFrame();


    


    the message

    


    System.ArgumentException&#xA;  HResult=0x80070057&#xA;  Message=Parameter is not valid.&#xA;  Source=System.Drawing&#xA;  StackTrace:&#xA;   at System.Drawing.Bitmap..ctor(Int32 width, Int32 height, PixelFormat format)&#xA;   at Accord.Video.FFMPEG.VideoFileReader.DecodeVideoFrame(BitmapData bitmapData)&#xA;   at Accord.Video.FFMPEG.VideoFileReader.readVideoFrame(Int32 frameIndex, BitmapData output)&#xA;   at Accord.Video.FFMPEG.VideoFileReader.ReadVideoFrame()&#xA;   at Extract_Frames.Form1.<getvideoframesasync>d__15.MoveNext() in D:\Csharp Projects\Extract Frames\Form1.cs:line 114&#xA;   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)&#xA;   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)&#xA;   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()&#xA;   at Extract_Frames.Form1.d__17.MoveNext() in D:\Csharp Projects\Extract Frames\Form1.cs:line 151&#xA;</getvideoframesasync>

    &#xA;

    the full code

    &#xA;

    using Accord.IO;&#xA;using Accord.Video;&#xA;using Accord.Video.FFMPEG;&#xA;using System;&#xA;using System.Collections.Generic;&#xA;using System.ComponentModel;&#xA;using System.Data;&#xA;using System.Drawing;&#xA;using System.IO;&#xA;using System.Linq;&#xA;using System.Reflection;&#xA;using System.Reflection.Emit;&#xA;using System.Text;&#xA;using System.Threading;&#xA;using System.Threading.Tasks;&#xA;using System.Windows.Forms;&#xA;&#xA;namespace Extract_Frames&#xA;{&#xA;    public partial class Form1 : Form&#xA;    {&#xA;        Bitmap frame = null;&#xA;        Graphics frameGraphics = null;&#xA;        bool isVideoRunning = false;&#xA;        IProgress<bitmap> videoProgress = null;&#xA;        private CancellationTokenSource cts = null;&#xA;        private readonly object syncRoot = new object();&#xA;        private static long pause = 0;&#xA;        private int frameRate = 0;&#xA;        private List<bitmap> frames = new List<bitmap>();&#xA;        string fileName;&#xA;&#xA;        public Form1()&#xA;        {&#xA;            InitializeComponent();&#xA;            &#xA;        }&#xA;&#xA;        private void Form1_Load(object sender, EventArgs e)&#xA;        {&#xA;&#xA;        }&#xA;&#xA;        private void StopPlayback(bool cancel)&#xA;        {&#xA;            lock (syncRoot)&#xA;            {&#xA;                if (cancel) cts?.Cancel();&#xA;                cts?.Dispose();&#xA;                cts = null;&#xA;            }&#xA;        }&#xA;&#xA;        int counter =1;&#xA;        private void Updater(Bitmap videoFrame)&#xA;        {&#xA;            frames.Add(videoFrame);&#xA;&#xA;            label1.Text = "Current Frame Number : " &#x2B; counter;&#xA;            trackBar1.Value = counter;&#xA;            counter&#x2B;&#x2B;;&#xA;&#xA;            //Size size = new Size(videoFrame.Width, videoFrame.Height);&#xA;            //pictureBox1.ClientSize = size;&#xA;            using (videoFrame) frameGraphics.DrawImage(videoFrame, Point.Empty);&#xA;&#xA;            pictureBox1.Invalidate();&#xA;        }&#xA;&#xA;        private async Task GetVideoFramesAsync(IProgress<bitmap> updater, string fileName, int intervalMs, CancellationToken token = default)&#xA;        {&#xA;            using (var videoReader = new VideoFileReader())&#xA;            {&#xA;                if (token.IsCancellationRequested) return;&#xA;                videoReader.Open(fileName);&#xA;&#xA;                videoReader.ReadVideoFrame(1);&#xA;                trackBar1.Value = 1;&#xA;&#xA;                label1.Text = "Current Frame Number : " &#x2B; counter.ToString();&#xA;&#xA;                while (true)&#xA;                {&#xA;                    if (Interlocked.Read(ref pause) == 0)&#xA;                    {&#xA;                        var frame = videoReader.ReadVideoFrame();&#xA;&#xA;                        if (token.IsCancellationRequested || frame is null) break;&#xA;                        updater.Report(frame);&#xA;                    }&#xA;                    await Task.Delay(frameRate).ConfigureAwait(false);&#xA;                }&#xA;            }&#xA;        }&#xA;&#xA;        private void trackBar2_Scroll(object sender, EventArgs e)&#xA;        {&#xA;            frameRate = trackBar2.Value / 25;&#xA;        }&#xA;&#xA;        private async void buttonStart_Click(object sender, EventArgs e)&#xA;        {&#xA;            string fileName = textBox1.Text;&#xA;&#xA;            if (isVideoRunning) return;&#xA;            isVideoRunning = true;&#xA;&#xA;            using (var videoReader = new VideoFileReader())&#xA;            {&#xA;                videoReader.Open(fileName);&#xA;                frame = new Bitmap(videoReader.Width &#x2B; 2, videoReader.Height &#x2B; 2);&#xA;                trackBar1.Maximum = (int)videoReader.FrameCount;&#xA;            }&#xA;&#xA;            videoProgress = new Progress<bitmap>((bitmap) => Updater(bitmap));&#xA;            cts = new CancellationTokenSource();&#xA;            pictureBox1.Image = frame;&#xA;            try&#xA;            {&#xA;                frameGraphics = Graphics.FromImage(frame);&#xA;                // Set the fame rate to 25 frames per second&#xA;                //int frameRate = 1000 / 25;&#xA;                await GetVideoFramesAsync(videoProgress, fileName, frameRate, cts.Token);&#xA;            }&#xA;            finally&#xA;            {&#xA;                frameGraphics?.Dispose();&#xA;                StopPlayback(false);&#xA;                isVideoRunning = false;&#xA;            }&#xA;        }&#xA;&#xA;        private void buttonPause_Click(object sender, EventArgs e)&#xA;        {&#xA;            if (pause == 0)&#xA;            {&#xA;                buttonPause.Text = "Resume";&#xA;                Interlocked.Increment(ref pause);&#xA;            }&#xA;            else&#xA;            {&#xA;                Interlocked.Decrement(ref pause);&#xA;                buttonPause.Text = "Pause";&#xA;            }&#xA;        }&#xA;&#xA;        private void buttonStop_Click(object sender, EventArgs e)&#xA;        {&#xA;            StopPlayback(true);&#xA;        }&#xA;&#xA;        protected override void OnFormClosing(FormClosingEventArgs e)&#xA;        {&#xA;            if (isVideoRunning) StopPlayback(true);&#xA;            pictureBox1.Image?.Dispose();&#xA;            base.OnFormClosing(e);&#xA;        }&#xA;&#xA;        private void pictureBox1_Paint(object sender, PaintEventArgs e)&#xA;        {&#xA;            ControlPaint.DrawBorder(e.Graphics, pictureBox1.ClientRectangle, Color.Red, ButtonBorderStyle.Solid);&#xA;        }&#xA;&#xA;        private void trackBar1_Scroll(object sender, EventArgs e)&#xA;        {&#xA;            pictureBox1.Image = frames[trackBar1.Value];&#xA;        }&#xA;&#xA;        private void button1_Click(object sender, EventArgs e)&#xA;        {&#xA;            using (OpenFileDialog openFileDialog = new OpenFileDialog())&#xA;            {&#xA;                openFileDialog.InitialDirectory = "c:\\";&#xA;                openFileDialog.Filter = "video files (*.mp4)|*.mp4|All files (*.*)|*.*";&#xA;                openFileDialog.FilterIndex = 2;&#xA;                openFileDialog.RestoreDirectory = true;&#xA;&#xA;                if (openFileDialog.ShowDialog() == DialogResult.OK)&#xA;                {&#xA;                    //Get the path of specified file&#xA;                    textBox1.Text = openFileDialog.FileName;&#xA;                }&#xA;            }&#xA;        }&#xA;    }&#xA;}&#xA;</bitmap></bitmap></bitmap></bitmap></bitmap>

    &#xA;

  • dynamically update image in video stream using ffmpeg

    1er mars 2021, par omega1

    I have the following ffmpeg command which works, but I would like image3.jpg to update every 30 seconds (image3.jpg changes every 30 seconds). I read that I needed to move the file from a .tmp file image3.jpg.tmp to image3.jpg but this is not working either.

    &#xA;

    The script places a few images on screen and takes an audio stream as its input and then outputs to a RMTP server, all works except image3.jpg only updates if I stop the ffmpeg command and restart it (which I cannot do as it is a live stream).

    &#xA;

    I'm also struggling with where to add a drawtext within the filter_complex section if anyone could help with that also ?

    &#xA;

    Thanks.

    &#xA;

    ffmpeg \&#xA;    -stream_loop -1 \&#xA;    -re -y \&#xA;    -i image1.png \&#xA;    -i image2.png \&#xA;    -i image3.jpg \&#xA;    -i http://audio_stream \&#xA;    -filter_complex "[1]scale=1200:280:force_original_aspect_ratio=decrease:-1[wm]; [0][wm]overlay=1:1[bg]; [2]scale=150:635:force_original_aspect_ratio=decrease:-1[wm1]; [bg][wm1]overlay=W-w-1:1" \&#xA;    -crf 10 \&#xA;    -profile:v baseline \&#xA;    -s 1280x720 \&#xA;    -bufsize 6000k \&#xA;    -vb 400k \&#xA;    -maxrate 1500k \&#xA;    -deinterlace \&#xA;    -vcodec libx264 \&#xA;    -preset veryfast \&#xA;    -g 300 \&#xA;    -r 5 \&#xA;    -f flv \&#xA;    rtmp://rmtp_server&#xA;

    &#xA;