Recherche avancée

Médias (16)

Mot : - Tags -/mp3

Autres articles (40)

  • Les vidéos

    21 avril 2011, par

    Comme les documents de type "audio", Mediaspip affiche dans la mesure du possible les vidéos grâce à la balise html5 .
    Un des inconvénients de cette balise est qu’elle n’est pas reconnue correctement par certains navigateurs (Internet Explorer pour ne pas le nommer) et que chaque navigateur ne gère en natif que certains formats de vidéos.
    Son avantage principal quant à lui est de bénéficier de la prise en charge native de vidéos dans les navigateur et donc de se passer de l’utilisation de Flash et (...)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • Possibilité de déploiement en ferme

    12 avril 2011, par

    MediaSPIP peut être installé comme une ferme, avec un seul "noyau" hébergé sur un serveur dédié et utilisé par une multitude de sites différents.
    Cela permet, par exemple : de pouvoir partager les frais de mise en œuvre entre plusieurs projets / individus ; de pouvoir déployer rapidement une multitude de sites uniques ; d’éviter d’avoir à mettre l’ensemble des créations dans un fourre-tout numérique comme c’est le cas pour les grandes plate-formes tout public disséminées sur le (...)

Sur d’autres sites (4655)

  • Slow, robotic audio encoding with Humble-Video api (ffmpeg)

    30 novembre 2017, par Walker Knapp

    I have a program that is trying to parse pcm_s16le audio samples from a .wav file and encode it into mp3 using the Humble-Video api.
    This isn’t what the final program is trying to do, but it outlines the problem I’m encountering.
    The issue is that the output audio files sound robotic and slow.

    input.wav (Just some random audio from a video game, ignore the wonky size headers) : https://drive.google.com/file/d/1nQOJGIxoSBDzprXExyTVNyyipSKQjyU0/view?usp=sharing

    output.mp3 :
    https://drive.google.com/file/d/1MfEFw2V7TiKS16SqSTv3wrbh6KoankIj/view?usp=sharing

    output.wav : https://drive.google.com/file/d/1XtDdCtYao0kS0Qe2l6JGu1tC5xvqt62f/view?usp=sharing

    import io.humble.video.*;

    import java.io.*;

    public class AudioEncodingTest {

       private static AudioChannel.Layout inLayout = AudioChannel.Layout.CH_LAYOUT_STEREO;
       private static int inSampleRate = 44100;
       private static AudioFormat.Type inFormat = AudioFormat.Type.SAMPLE_FMT_S16;
       private static int bytesPerSample = 2;

       private static File inFile = new File("input.wav");

       public static void main(String[] args) throws IOException, InterruptedException {
           render("output.mp3");
           render("output.wav");
       }

       public static void render(String filename) throws IOException, InterruptedException {

           //Starting everything up.

           Muxer muxer = Muxer.make(new File(filename).getAbsolutePath(), null, null);
           Codec codec = Codec.guessEncodingCodec(muxer.getFormat(), null, null, null, MediaDescriptor.Type.MEDIA_AUDIO);

           AudioFormat.Type findType = null;
           for(AudioFormat.Type type : codec.getSupportedAudioFormats()) {
               if(findType == null) {
                   findType = type;
               }
               if(type == inFormat) {
                   findType = type;
                   break;
               }
           }

           if(findType == null){
               throw new IllegalArgumentException("Couldn't find valid audio format for codec: " + codec.getName());
           }

           Encoder encoder = Encoder.make(codec);
           encoder.setSampleRate(44100);
           encoder.setTimeBase(Rational.make(1, 44100));
           encoder.setChannels(2);
           encoder.setChannelLayout(AudioChannel.Layout.CH_LAYOUT_STEREO);
           encoder.setSampleFormat(findType);
           encoder.setFlag(Coder.Flag.FLAG_GLOBAL_HEADER, true);

           encoder.open(null, null);
           muxer.addNewStream(encoder);
           muxer.open(null, null);

           MediaPacket audioPacket = MediaPacket.make();
           MediaAudioResampler audioResampler = MediaAudioResampler.make(encoder.getChannelLayout(), encoder.getSampleRate(), encoder.getSampleFormat(), inLayout, inSampleRate, inFormat);
           audioResampler.open();

           MediaAudio rawAudio = MediaAudio.make(1024/bytesPerSample, inSampleRate, 2, inLayout, inFormat);
           rawAudio.setTimeBase(Rational.make(1, inSampleRate));

           //Reading

           try(BufferedInputStream reader = new BufferedInputStream(new FileInputStream(inFile))){
               reader.skip(44);

               int totalSamples = 0;

               byte[] buffer = new byte[1024];
               int readLength;
               while((readLength = reader.read(buffer, 0, 1024)) != -1){
                   int sampleCount = readLength/bytesPerSample;

                   rawAudio.getData(0).put(buffer, 0, 0, readLength);
                   rawAudio.setNumSamples(sampleCount);
                   rawAudio.setTimeStamp(totalSamples);

                   totalSamples += sampleCount;

                   rawAudio.setComplete(true);

                   MediaAudio usedAudio = rawAudio;

                   if(encoder.getChannelLayout() != inLayout ||
                           encoder.getSampleRate() != inSampleRate ||
                           encoder.getSampleFormat() != inFormat){
                           usedAudio = MediaAudio.make(
                                   sampleCount,
                                   encoder.getSampleRate(),
                                   encoder.getChannels(),
                                   encoder.getChannelLayout(),
                                   encoder.getSampleFormat());
                           audioResampler.resample(usedAudio, rawAudio);
                   }

                   do{
                       encoder.encodeAudio(audioPacket, usedAudio);
                       if(audioPacket.isComplete()) {
                           muxer.write(audioPacket, false);
                       }
                   } while (audioPacket.isComplete());
               }
           }
           catch (IOException e){
               e.printStackTrace();
               muxer.close();
               System.exit(-1);
           }

           muxer.close();

       }
    }

    Edit

    I’ve gotten wave file exporting to work, however mp3s remain the same, which is very confusing. I changed the section counting how many samples each buffer of bytes is.

    MediaAudio rawAudio = MediaAudio.make(1024, inSampleRate, channels, inLayout, inFormat);
       rawAudio.setTimeBase(Rational.make(1, inSampleRate));

       //Reading

       try(BufferedInputStream reader = new BufferedInputStream(new FileInputStream(inFile))){
           reader.skip(44);

           int totalSamples = 0;

           byte[] buffer = new byte[1024 * bytesPerSample * channels];
           int readLength;
           while((readLength = reader.read(buffer, 0, 1024 * bytesPerSample * channels)) != -1){
               int sampleCount = readLength/(bytesPerSample * channels);

               rawAudio.getData(0).put(buffer, 0, 0, readLength);
               rawAudio.setNumSamples(sampleCount);
               rawAudio.setTimeStamp(totalSamples);
  • How to check if client is still connected with ffmpeg

    11 décembre 2017, par Adalcar

    I am working on a live-streaming server in C++ using FFMPEG.
    I have a I have an acquisition thread which grabs the images from the cameras and I spawn a new thread on each client connexion to send them the packets.

    Here’s my "send" function :

    void Encoder::_encode()
    {
       int ret = 0;
       if (avcodec_send_frame(ctx, frame) < 0)
           throw new std::runtime_error("error sending a frame for encoding");
       while (ret >= 0)
       {
           ret = avcodec_receive_packet(ctx, pkt);
           if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
               return;
           avio_write(client, pkt->data, pkt->size);
           avio_flush(client);
           av_packet_unref(pkt);
       }
    }

    This encodes the frame and sends it to the client.

    The problem is : whenever the client exits, the thread keeps sending it data, and throws no exception, even when the same client connects again, it will spawn a new thread while the old one keeps running...
    Is there a way to "ping" the client to check whether it is still connected ?

  • Extract audio from video using autogen ffmpeg C# in Unity

    5 décembre 2024, par Johan Sophie

    Hi I'm using ffmpeg autogen to extract audio from video in Unity, but when I following this code, the file write cannot write, it's 0Kb, so what's issue of this or someone have any examples for extract audio using this library, apologize for my English. This is github of library : 
https://github.com/Ruslan-B/FFmpeg.AutoGen

    



    unsafe void TestExtractAudio()
{

    string inFile = Application.streamingAssetsPath + "/" + strFileName;
    string outFile = Application.streamingAssetsPath + "/" + strFileNameAudio;

    AVOutputFormat* outFormat = null;
    AVFormatContext* inFormatContext = null;
    AVFormatContext* outFormatContext = null;
    AVPacket packet;

    ffmpeg.av_register_all();

    inFormatContext = ffmpeg.avformat_alloc_context();
    outFormatContext = ffmpeg.avformat_alloc_context();

    if (ffmpeg.avformat_open_input(&inFormatContext, inFile, null, null) < 0)
    {
        throw new ApplicationException("Could not open input file.");
    }

    if (ffmpeg.avformat_find_stream_info(inFormatContext, null) < 0)
    {
        throw new ApplicationException("Failed to retrieve input stream info.");
    }

    ffmpeg.avformat_alloc_output_context2(&outFormatContext, null, null, outFile);
    if (outFormatContext == null)
    {
        throw new ApplicationException("Could not create output context");
    }

    outFormat = outFormatContext->oformat;

    AVStream* inStream = inFormatContext->streams[1];
    AVStream* outStream = ffmpeg.avformat_new_stream(outFormatContext, inStream->codec->codec);
    if (outStream == null)
    {
        throw new ApplicationException("Failed to allocate output stream.");
    }

    if (ffmpeg.avcodec_copy_context(outStream->codec, inStream->codec) < 0)
    {
        throw new ApplicationException("Couldn't copy input stream codec context to output stream codec context");
    }

    outFormatContext->audio_codec_id = AVCodecID.AV_CODEC_ID_MP3;

    int retcode = ffmpeg.avio_open(&outFormatContext->pb, outFile, ffmpeg.AVIO_FLAG_WRITE);
    if (retcode < 0)
    {
        throw new ApplicationException("Couldn't open output file");
    }

    int returnCode = ffmpeg.avformat_write_header(outFormatContext, null);

    if (returnCode < 0)
    {
        throw new ApplicationException("Error occurred opening output file.");
    }

    while (true)
    {
        if (ffmpeg.av_read_frame(inFormatContext, &packet) < 0)
        {
            break;
        }

        if (packet.stream_index == 1)
        {

            inStream = inFormatContext->streams[1];
            outStream = outFormatContext->streams[0];

            // TODO: Replicate log packet functionality to print out what's inside the packet.

            packet.pts = ffmpeg.av_rescale_q_rnd(packet.pts, inStream->time_base, outStream->time_base,
                AVRounding.AV_ROUND_NEAR_INF | AVRounding.AV_ROUND_PASS_MINMAX);
            packet.dts = ffmpeg.av_rescale_q_rnd(packet.dts, inStream->time_base, outStream->time_base,
                AVRounding.AV_ROUND_NEAR_INF | AVRounding.AV_ROUND_PASS_MINMAX);

            packet.duration = ffmpeg.av_rescale_q(packet.duration, inStream->time_base, outStream->time_base);

            int returncode = ffmpeg.av_interleaved_write_frame(outFormatContext, &packet);

        }

        ffmpeg.av_packet_unref(&packet);
    }

    ffmpeg.av_write_trailer(outFormatContext);


    ffmpeg.avformat_close_input(&inFormatContext);

    ffmpeg.avformat_free_context(outFormatContext);

    Console.WriteLine("Press any key to continue...");

    Console.ReadKey();
}


    



    the value returnCode return less than 0, so someone can fix this, thanks so much for that