Recherche avancée

Médias (3)

Mot : - Tags -/pdf

Autres articles (75)

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

  • Organiser par catégorie

    17 mai 2013, par

    Dans MédiaSPIP, une rubrique a 2 noms : catégorie et rubrique.
    Les différents documents stockés dans MédiaSPIP peuvent être rangés dans différentes catégories. On peut créer une catégorie en cliquant sur "publier une catégorie" dans le menu publier en haut à droite ( après authentification ). Une catégorie peut être rangée dans une autre catégorie aussi ce qui fait qu’on peut construire une arborescence de catégories.
    Lors de la publication prochaine d’un document, la nouvelle catégorie créée sera proposée (...)

  • Récupération d’informations sur le site maître à l’installation d’une instance

    26 novembre 2010, par

    Utilité
    Sur le site principal, une instance de mutualisation est définie par plusieurs choses : Les données dans la table spip_mutus ; Son logo ; Son auteur principal (id_admin dans la table spip_mutus correspondant à un id_auteur de la table spip_auteurs)qui sera le seul à pouvoir créer définitivement l’instance de mutualisation ;
    Il peut donc être tout à fait judicieux de vouloir récupérer certaines de ces informations afin de compléter l’installation d’une instance pour, par exemple : récupérer le (...)

Sur d’autres sites (4759)

  • 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);
  • Is there a way to use youtube-dl in async

    8 octobre 2024, par Stam Kaly

    I have an application where I use zmq with asyncio to communicate with the clients who have the ability to download a video with youtube-dl to the server. I tried adding await to youtube_dl's download function but it gave me an error since it was not a coroutine. My code right now is simply looking like this :

    



    import asyncio
import youtube_dl


async def networking_stuff():
    download = True
    while True:
        if download:
            print("Received a request for download")
            await youtube_to_mp3("https://www.youtube.com/watch?v=u9WgtlgGAgs")
            download = False
        print("Working..")
        await asyncio.sleep(2)


async def youtube_to_mp3(url):
    ydl_opts = {
        'format': 'bestaudio/best',
        'postprocessors': [{
            'key': 'FFmpegExtractAudio',
            'preferredcodec': 'mp3',
            'preferredquality': '192',
        }]
    }

    with youtube_dl.YoutubeDL(ydl_opts) as ydl:
        ydl.download([url])


loop = asyncio.get_event_loop()
loop.create_task(networking_stuff())
loop.run_forever()


    



    which gives the following output :

    



    Received a request for download
[youtube] u9WgtlgGAgs: Downloading webpage
[youtube] u9WgtlgGAgs: Downloading video info webpage
[youtube] u9WgtlgGAgs: Extracting video information
[youtube] u9WgtlgGAgs: Downloading MPD manifest
[download] Destination: The Cardigans - My Favourite Game “Stone Version”-u9WgtlgGAgs.webm
[download] 100% of 4.20MiB in 00:03
[ffmpeg] Destination: The Cardigans - My Favourite Game “Stone Version”-u9WgtlgGAgs.mp3
Deleting original file The Cardigans - My Favourite Game “Stone Version”-u9WgtlgGAgs.webm (pass -k to keep)
Working..
Working..
....
Working..
Working..


    



    whereas I would expect the Working.. message to be printed in between youtube-dl's messages as well. Am I missing something here or is this impossible with async/await ? Is ffmpeg blocking ? If so, can I run the download in async without converting to mp3 or is using threads the only way ?

    


  • FFmpeg generic error in an external library

    13 octobre 2017, par Mher Didaryan

    I’m trying to encode the game play from Unreal Engine with h264_nvenc encoder on a windows with FFmpeg 3.3.3. FFmpeg was configured with —enable-cuda —enable-cuvid —enable-nvenc
    However avcodec_open2 can’t open the codec.

    Below is the function where call to avcodec_alloc_context3 is.

    void Encoder::AddStream(AVCodecID CodecID)
    {

    VideoCodec = avcodec_find_encoder(CodecID);
    if (!VideoCodec) {
       UE_LOG(LogTemp, Error, TEXT("Could not find encoder for '%s'"), ANSI_TO_TCHAR(avcodec_get_name(CodecID)));
    }

    VideoSt.Stream = avformat_new_stream(FmtCtx, nullptr);
    if (!VideoSt.Stream) {
       UE_LOG(LogTemp, Error, TEXT("Could not allocate stream"));
    }

    VideoSt.Stream->id = FmtCtx->nb_streams - 1;
    VideoSt.Ctx = avcodec_alloc_context3(VideoCodec);
    if (!VideoSt.Ctx) {
       UE_LOG(LogTemp, Error, TEXT("Could not alloc an encoding context"));
    }

    VideoSt.Ctx->codec_id = CodecID;
    VideoSt.Ctx->flags = 0;
    VideoSt.Ctx->me_range = 16;
    VideoSt.Ctx->max_qdiff = 4;
    VideoSt.Ctx->refs = 0;
    VideoSt.Ctx->qmin = 2;
    VideoSt.Ctx->qmax = 31;
    VideoSt.Ctx->qcompress = 0.6;
    VideoSt.Ctx->width = ViewportSize.X;
    VideoSt.Ctx->height = ViewportSize.Y;
    VideoSt.Ctx->bit_rate = 4000000;
    VideoSt.Stream->time_base = VideoSt.Ctx->time_base = { 1, 30 };
    VideoSt.Ctx->gop_size = 25;
    VideoSt.Ctx->max_b_frames = 0;
    VideoSt.Ctx->thread_count = 1;
    VideoSt.Ctx->pix_fmt = AV_PIX_FMT_YUV420P;
    VideoSt.Ctx->codec_type = AVMEDIA_TYPE_VIDEO;

    if (FmtCtx->oformat->flags & AVFMT_GLOBALHEADER)
       VideoSt.Ctx->flags |= AV_CODEC_FLAG_GLOBAL_HEADER;

    }

    As answer to this question suggests same issue I use avcodec_alloc_context3. Am I doing something wrong or error caused buy another reason ?

    Below is the part where call to avcodec_open2 is. It’s called after Encoder::AddStream so everything is set up I guess.

    auto c = VideoSt.Ctx;
    AVDictionary* opt = nullptr;
    av_dict_copy(&opt, Opt, 0);
    auto ret = avcodec_open2(c, VideoCodec, &opt);

    What can cause Generic error in an external library ?