Recherche avancée

Médias (2)

Mot : - Tags -/kml

Autres articles (21)

  • Librairies et logiciels spécifiques aux médias

    10 décembre 2010, par

    Pour un fonctionnement correct et optimal, plusieurs choses sont à prendre en considération.
    Il est important, après avoir installé apache2, mysql et php5, d’installer d’autres logiciels nécessaires dont les installations sont décrites dans les liens afférants. Un ensemble de librairies multimedias (x264, libtheora, libvpx) utilisées pour l’encodage et le décodage des vidéos et sons afin de supporter le plus grand nombre de fichiers possibles. Cf. : ce tutoriel ; FFMpeg avec le maximum de décodeurs et (...)

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

  • Pas question de marché, de cloud etc...

    10 avril 2011

    Le vocabulaire utilisé sur ce site essaie d’éviter toute référence à la mode qui fleurit allègrement
    sur le web 2.0 et dans les entreprises qui en vivent.
    Vous êtes donc invité à bannir l’utilisation des termes "Brand", "Cloud", "Marché" etc...
    Notre motivation est avant tout de créer un outil simple, accessible à pour tout le monde, favorisant
    le partage de créations sur Internet et permettant aux auteurs de garder une autonomie optimale.
    Aucun "contrat Gold ou Premium" n’est donc prévu, aucun (...)

Sur d’autres sites (5585)

  • How to decode mp3 to raw sample data for FFMpeg using FFMediaToolkit

    28 décembre 2022, par Lee

    My objective is to create a video slideshow with audio using a database as the source. The final implementation video and audio inputs need to be memory streams or byte arrays, not a file system path. The sample code is file based for portability. It's just trying to read a file based mp3 then write it to the output.

    


    I've tried a few FFMpeg wrappers and I'm open to alternatives. This code is using FFMediaToolkit. The video portion of the code works. It's the audio that I can't get to work.

    


    The input is described as "A 2D jagged array of multi-channel sample data with NumChannels rows and NumSamples columns." The datatype is float[][].

    


    My mp3 source is mono. I'm using NAudio.Wave to decode the mp3. It is then split into chunks equal to the frame size for the sample rate. It is then converted into the jagged float with the data on channel 0.

    


    The FFMpeg decoder displays a long list of "buffer underflow" and "packet too large, ignoring buffer limits to mux it". C# returns "Specified argument was out of the range of valid values." The offending line of code being "file.Audio.AddFrame(frameAudio)".

    


    The source is 16 bit samples. The PCM_S16BE codec is the only one that I could get to accept 16 bit sample format. I could only get the MP3 encoder to work with "Signed 32-bit integer (planar)" as the sample format. I'm not certain if the source data needs to be converted from 16 to 32 bit to use the codec.

    


    `

    


    using FFMediaToolkit;
using FFMediaToolkit.Decoding;
using FFMediaToolkit.Encoding;
using FFMediaToolkit.Graphics;
using System;
using System.Collections.Generic;
using System.Drawing.Imaging;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FFMediaToolkit.Audio;
using NAudio.Wave;
using FFmpeg.AutoGen;

    internal class FFMediaToolkitTest
    {
        const int frameRate = 30;
        const int vWidth = 1920;
        const int vHeight = 1080;
        const int aSampleRate = 24_000; // source sample rate
        //const int aSampleRate = 44_100;
        const int aSamplesPerFrame = aSampleRate / frameRate;
        const int aBitRate = 32_000;
        const string dirInput = @"D:\Websites\Vocabulary\Videos\source\";
        const string pathOutput = @"D:\Websites\Vocabulary\Videos\example.mpg";

        public FFMediaToolkitTest()
        {
            try
            {
                FFmpegLoader.FFmpegPath = ".";  //  FFMpeg  DLLs in root project directory
                var settings = new VideoEncoderSettings(width: vWidth, height: vHeight, framerate: frameRate, codec: VideoCodec.H264);
                settings.EncoderPreset = EncoderPreset.Fast;
                settings.CRF = 17;

                //var settingsAudio = new AudioEncoderSettings(aSampleRate, 1, (AudioCodec)AVCodecID.AV_CODEC_ID_PCM_S16BE);  // Won't run with low bitrate.
                var settingsAudio = new AudioEncoderSettings(aSampleRate, 1, AudioCodec.MP3); // mpg runs with SampleFormat.SignedDWordP
                settingsAudio.Bitrate = aBitRate;
                //settingsAudio.SamplesPerFrame = aSamplesPerFrame;
                settingsAudio.SampleFormat = SampleFormat.SignedDWordP;

                using (var file = MediaBuilder.CreateContainer(pathOutput).WithVideo(settings).WithAudio(settingsAudio).Create())
                {
                    var files = Directory.GetFiles(dirInput, "*.jpg");
                    foreach (var inputFile in files)
                    {
                        Console.WriteLine(inputFile);
                        var binInputFile = File.ReadAllBytes(inputFile);
                        var memInput = new MemoryStream(binInputFile);
                        var bitmap = Bitmap.FromStream(memInput) as Bitmap;
                        var rect = new System.Drawing.Rectangle(System.Drawing.Point.Empty, bitmap.Size);
                        var bitLock = bitmap.LockBits(rect, ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb);
                        var bitmapData = ImageData.FromPointer(bitLock.Scan0, ImagePixelFormat.Bgr24, bitmap.Size);

                        for (int i = 0; i < 60; i++)
                            file.Video.AddFrame(bitmapData); 
                        bitmap.UnlockBits(bitLock);
                    }

                    var mp3files = Directory.GetFiles(dirInput, "*.mp3");
                    foreach (var inputFile in mp3files)
                    {
                        Console.WriteLine(inputFile);
                        var binInputFile = File.ReadAllBytes(inputFile);
                        var memInput = new MemoryStream(binInputFile);

                        foreach (float[][] frameAudio in GetFrames(memInput))
                        {
                            file.Audio.AddFrame(frameAudio); // encode the frame
                        }
                    }
                    //Console.WriteLine(file.Audio.CurrentDuration);
                    Console.WriteLine(file.Video.CurrentDuration);
                    Console.WriteLine(file.Video.Configuration);
                }
            }
            catch (Exception e)
            {
                Vocab.LogError("FFMediaToolkitTest", e.StackTrace + " " + e.Message);
                Console.WriteLine(e.StackTrace + " " + e.Message);
            }

            Console.WriteLine();
            Console.WriteLine("Done");
            Console.ReadLine();
        }


        public static List GetFrames(MemoryStream mp3stream)
        {
            List output = new List();
            
            int frameCount = 0;

            NAudio.Wave.StreamMediaFoundationReader smfReader = new StreamMediaFoundationReader(mp3stream);
            Console.WriteLine(smfReader.WaveFormat);
            Console.WriteLine(smfReader.WaveFormat.AverageBytesPerSecond); //48000
            Console.WriteLine(smfReader.WaveFormat.BitsPerSample);  // 16
            Console.WriteLine(smfReader.WaveFormat.Channels);  // 1 
            Console.WriteLine(smfReader.WaveFormat.SampleRate);     //24000

            Console.WriteLine("PCM bytes: " + smfReader.Length);
            Console.WriteLine("Total Time: " + smfReader.TotalTime);

            int samplesPerFrame = smfReader.WaveFormat.SampleRate / frameRate;
            int bytesPerFrame = samplesPerFrame * smfReader.WaveFormat.BitsPerSample / 8;
            byte[] byteBuffer = new byte[bytesPerFrame];

            while (smfReader.Read(byteBuffer, 0, bytesPerFrame) != 0)
            {
                float[][] buffer = Convert16BitToFloat(byteBuffer);
                output.Add(buffer);
                frameCount++;
            }
            return output;
        }

        public static float[][] Convert16BitToFloat(byte[] input)
        {
            // Only works with single channel data
            int inputSamples = input.Length / 2;
            float[][] output = new float[1][]; 
            output[0] = new float[inputSamples];
            int outputIndex = 0;
            for (int n = 0; n < inputSamples; n++)
            {
                short sample = BitConverter.ToInt16(input, n * 2);
                output[0][outputIndex++] = sample / 32768f;
            }
            return output;
        }

    }




    


    `

    


    I've tried multiple codecs with various settings. I couldn't get any of the codecs to accept a mp4 output file extension. FFMpeg will run but error out with mpg as the output file.

    


  • Render image without creating Bitmap/WritableBitmap C#

    8 février 2018, par Mohamed Al-Hosary

    I’m using ffmpeg to decode H.264 streams. I have a pointer to image data in memory and i can create a WritableBitmap using this code :

        var _rmlive = new WriteableBitmap(e.Width, e.Hieght, 1, 1, PixelFormats.Bgr24, null);
    _rmlive.WritePixels(_rectLive, e.PointerToBuffer, _arraySize, e.Stride);

    and i can get a Bitmap object out of the pointer using this code :

    byte[] inBytes = new byte[size];
           Marshal.Copy(ptr, inBytes, 0, (int)size);
               var b = new Bitmap(width, height, PixelFormat.Format24bppRgb);
               var BoundsRect = new System.Drawing.Rectangle(0, 0, width, height);
               BitmapData bmpData = b.LockBits(BoundsRect,
                                               ImageLockMode.WriteOnly,
                                               b.PixelFormat);
               IntPtr ptr = bmpData.Scan0;
               int bytes = bmpData.Stride * b.Height;
               try
               {
                   Marshal.Copy(inBytes, 0, ptr, bytes);
               }
               catch (Exception e)
               {
               }
               finally
               {
                   b.UnlockBits(bmpData);
               }

    then i can render and display it in WPF but it consumes a lot of CPU resources (specially for full HD frames).
    the question is it is possible to render/display the image directly from the pointer without creating Bitmap/WritableBitmap in c# / WPF ?

  • FFMpeg on docker

    31 mai 2022, par user1765862

    I'm trying to run FFMpegCore library in the docker
Here is my Dockerfile

    


    FROM public.ecr.aws/lambda/dotnet:6 AS base

FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim as build
WORKDIR /src
COPY ["AWSServerless.csproj", "AWSServerless/"]
RUN dotnet restore "AWSServerless/AWSServerless.csproj"

WORKDIR "/src/AWSServerless"
COPY . .
RUN dotnet build "AWSServerless.csproj" --configuration Release --output /app/build

FROM build AS publish

#fix for using System.Drawing.Common on docker
RUN apt-get update && apt-get install -y apt-utils libgdiplus libc6-dev

RUN apt-get install -y ffmpeg

RUN dotnet publish "AWSServerless.csproj" \
            --configuration Release \ 
            --runtime linux-x64 \
            --self-contained false \ 
            --output /app/publish \
            -p:PublishReadyToRun=true  

FROM base AS final
WORKDIR /var/task

CMD ["AWSServerless::AWSServerless.LambdaEntryPoint::FunctionHandlerAsync"]
COPY --from=publish /app/publish .


    


    When I try to use any of FFMpegCore commands I'm getting following error in the log

    


    


    System.ComponentModel.Win32Exception (2) : An error occurred trying to
start process 'ffmpeg' with working directory '/var/task'. No such
file or directory