Recherche avancée

Médias (1)

Mot : - Tags -/biographie

Autres articles (80)

  • MediaSPIP version 0.1 Beta

    16 avril 2011, par

    MediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
    Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...)

  • MediaSPIP 0.1 Beta version

    25 avril 2011, par

    MediaSPIP 0.1 beta is the first version of MediaSPIP proclaimed as "usable".
    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 (...)

  • Amélioration de la version de base

    13 septembre 2013

    Jolie sélection multiple
    Le plugin Chosen permet d’améliorer l’ergonomie des champs de sélection multiple. Voir les deux images suivantes pour comparer.
    Il suffit pour cela d’activer le plugin Chosen (Configuration générale du site > Gestion des plugins), puis de configurer le plugin (Les squelettes > Chosen) en activant l’utilisation de Chosen dans le site public et en spécifiant les éléments de formulaires à améliorer, par exemple select[multiple] pour les listes à sélection multiple (...)

Sur d’autres sites (9032)

  • Problems encoding audio stream for RTMP server using ffmpeg libraries

    18 mars, par Filipe José

    I am working on an C++ application that captures audio using miniaudio, and sends the data to a RTMP server running on nginx which will generate an HLS stream to be consumed by a web browser.
I was successful in encoding the data and writing to an .flv file (which I believe to be the container for RTMP), and everything works out fine.

    


    I've also tested the server by running the ffmpeg cli tool directly, and the RTMP server is generating the .m3u8 playlist file as well as the .ts files correctly.

    


    The problem I'm having is that when I change the output on avio_open2() to use the RTMP server url instead of a file name, the HLS files are not being generated, even though I get logging information about a successful connection, and also see "Audio Data" packets being sent to the server and the respective ACK response when using Wireshark.

    


    Is there anything that is conceptually different between encoding to a file or to a server when using the ffmpeg libav ?

    


    I have a class for the audio encoding :

    


    AudioEncoder(int sampleRate){
  av_log_set_level(AV_LOG_DEBUG);
  m_formatContext = avformat_alloc_context();
  const AVOutputFormat* outputFormat = av_guess_format("flv", NULL, NULL);
  if (!outputFormat) {
    std::cerr << "Could not find aac output format" << std::endl;
    exit(-1);
  }
  m_formatContext->oformat = outputFormat;

  result = avio_open2(&m_ioContext, "rtmp://localhost/live/test",AVIO_FLAG_WRITE, NULL, NULL);
  if( result < 0){
    std::cerr << "Could not open output stream: " << error_string(result) << std::endl;
    exit(-1); 
  }
  m_formatContext->pb = m_ioContext;
  
  const AVCodec* codec = avcodec_find_encoder(AV_CODEC_ID_AAC);
  if(!codec){
    std::cerr << "Codec not found." << std::endl;
    exit(-1);
  }
  
  m_codecContext = avcodec_alloc_context3(codec);
  if (!m_codecContext) {
    std::cerr << "Could not alloc codec context" << std::endl;
    exit(-1);
  }
  AVChannelLayout layout;
  av_channel_layout_default(&layout, 1);
  m_codecContext->sample_fmt = AV_SAMPLE_FMT_FLTP;
  m_codecContext->bit_rate = 128000;
  m_codecContext->sample_rate = sampleRate;
  m_codecContext->ch_layout = layout;

  m_avStream = avformat_new_stream(m_formatContext, codec);
  if (!m_avStream) {
    std::cerr << "Could not create stream." << std::endl;
    exit(-1);
  } 
  result = avcodec_parameters_from_context(m_avStream->codecpar, m_codecContext);
  if ( result < 0) {
    std::cerr << "Failed to copy codec parameters to stream: " << error_string(result) << std::endl;
    exit(-1);
  }
  m_avStream->time_base = AVRational{1, m_codecContext->sample_rate};

  result = avcodec_open2(m_codecContext, codec, NULL);
  if ( result < 0) {
    std::cerr << "Failed to open codec: "<< error_string(result) << std::endl;
    exit(-1);
  }

  result = avformat_write_header(m_formatContext, NULL);
  if ( result < 0) {
    std::cerr << "Failed to write format header: "<< error_string(result) << std::endl;
    exit(-1);
  }
}


    


    And an Encode function that is called by miniaudio :

    


    void Encode(const void* data, unsigned int frames){
  AVPacket* packet = av_packet_alloc();
  if (!packet) {
    std::cerr << "Error allocating packet" << std::endl;
    return;
  }

  AVFrame* frame = av_frame_alloc();
  if (!frame) {
    std::cerr << "Error allocating frame" << std::endl;
    av_packet_free(&packet);
    return;
  }
  frame->format = m_codecContext->sample_fmt;
  frame->ch_layout = m_codecContext->ch_layout;
  frame->sample_rate = m_codecContext -> sample_rate;
  frame->nb_samples = frames;
  if (frames) {
    int result = av_frame_get_buffer(frame, 0);
    if ( result < 0) {
      std::cerr << "Error allocating frame buffer: " << error_string(result) << std::endl;
      av_frame_free(&frame);
      av_packet_free(&packet);
      return;
    }
  }
  frame->data[0] = (uint8_t*)data;

  int result = avcodec_send_frame(m_codecContext, frame); 
  if (result < 0) {
    std::cerr << "Error sending frame to encoder: " << error_string(result) << std::endl; 
  }

  result = avcodec_receive_packet(m_codecContext, packet); 
  if (result == AVERROR(EAGAIN) || result == AVERROR_EOF) {
    std::cout << "EAGAIN" << std::endl;
    // If we get AVERROR_EAGAIN, the encoder needs more data, so we'll return and try again later
    av_frame_free(&frame);
    av_packet_free(&packet);
    return;
  } else if (result < 0) {
    std::cerr << "Error receiving packet from encoder: " << error_string(result) << std::endl;
    av_frame_free(&frame);
    av_packet_free(&packet);
    return;
  }
  else {
    packet->stream_index = m_avStream->index;
    packet->pts = av_rescale_q(frames, AVRational{1, m_codecContext->sample_rate}, m_avStream->time_base);
    packet->dts = packet->pts;
    packet->duration = av_rescale_q(1024, AVRational{1, m_codecContext->sample_rate}, m_avStream->time_base);

    result = av_write_frame(m_formatContext, packet);
    if ( result < 0) {
      std::cerr << "Error writing frame: " << error_string(result) << std::endl;
    }
  }
  //Clean up resources
  av_frame_free(&frame);
  av_packet_unref(packet);
  av_packet_free(&packet);
}


    


    On a final note, I have been able to stream to a TCP server developed in Golang using ADTS as the container and the same method, but I've decided to delegate the task to Nginx.

    


  • FFmpeg av_interleaved_write_frame invalid parameter -22

    21 octobre 2017, par Frank Natoli

    Windows 7 64 bit environment. C# Windows Forms application calling FFmpeg libraries through C++ bridge DLL including avcodec-57.dll, avformat-57.dll, avutil-55.dll, swresample-2.dll and swscale-4.dll to write MPEG-4 file using H.264/MPEG-4 AVC codec. When writing a single MP4 file, never a problem. When writing multiple MP4 files concurrently, via multiple C# threads, occasionally get av_interleaved_write_frame failure -22 which is invalid parameter on one or two but never all files. Needless to say, the parameters never change. Does FFmpeg use temporary files ? Is it possible that there is a fratricidal effect when using the same DLLs to write multiple files concurrently ?
    Edit : placed mutex at entry/exit to my write frame function, see source below, and can no longer reproduce the problem. It would appear something about FFmpeg is not thread-safe.

    extern "C" __declspec(dllexport) int ffmpeg_write_video_frame(FFMPEG_CONTEXT *ffmpegContext, uint8_t *frameBuffer)
    {
    #ifdef SINGLE_THREAD
       WaitForSingleObject(hMutex, INFINITE);
    #endif
       AVFrame *frame = ffmpeg_get_video_frame(&ffmpegContext->video, frameBuffer);
       if (frame == NULL)
       {
           MessageBox(GetActiveWindow(), "ffmpeg_get_video_frame returned NULL", "ffmpeg_write_video_frame", MB_OK);
    #ifdef SINGLE_THREAD
           ReleaseMutex(hMutex);
    #endif
           return(-1);
       }

       AVPacket pkt = { 0 };
       av_init_packet(&pkt);

       // encode the image
       int got_packet = 0;
       int result = avcodec_encode_video2(ffmpegContext->video.avCodecContext, &pkt, frame, &got_packet);
       if (result < 0)
       {
           char text[256];
           sprintf_s(text, sizeof(text), "avcodec_encode_videos failure=%d", result);
           MessageBox(GetActiveWindow(), text, "ffmpeg_write_video_frame", MB_OK);
    #ifdef SINGLE_THREAD
           ReleaseMutex(hMutex);
    #endif
           return(result);
       }

       // if the encoder has produced an output packet
       if (got_packet)
       {
           result = ffmpeg_write_frame(ffmpegContext->avFormatContext, &ffmpegContext->video.avCodecContext->time_base, ffmpegContext->video.avStream, &pkt);
           if (result < 0)
           {
               char text[256];
               sprintf_s(text, sizeof(text), "ffmpeg_write_frame failure=%d", result);
               MessageBox(GetActiveWindow(), text, "ffmpeg_write_video_frame", MB_OK);
    #ifdef SINGLE_THREAD
               ReleaseMutex(hMutex);
    #endif
               return(result);
           }
       }
    #ifdef SINGLE_THREAD
       ReleaseMutex(hMutex);
    #endif
       return (0);
    }

    extern "C" int ffmpeg_write_frame(AVFormatContext *fmt_ctx, const AVRational *time_base, AVStream *st, AVPacket *pkt)
    {
       /* rescale output packet timestamp values from codec to stream timebase */
       av_packet_rescale_ts(pkt, *time_base, st->time_base);
       pkt->stream_index = st->index;

       /* Write the compressed frame to the media file. */
    #if 0
       log_packet(fmt_ctx, pkt);
    #endif
       int result = av_interleaved_write_frame(fmt_ctx, pkt);
       if (result < 0)
       {
           char text[256];
           sprintf_s(text, sizeof(text), "av_interleaved_write_frame failure=%d", result);
           MessageBox(GetActiveWindow(), text, "ffmpeg_write_frame", MB_OK);
       }
       return(result);
    }
  • Unable to find ffmpeg when compressing [duplicate]

    20 octobre 2020, par Programmer

    I made this script for compressing videos :

    


    import os
import sys
import subprocess
result = subprocess.run('ffmpeg -i output.mp4 -b 800k output.mp4')
print(result)


    


    When I run this a error will come like this :

    


      result = subprocess.run('ffmpeg -i output.mp4 -b 800k output.mp4')
  File "C:\Program Files\Python37\lib\subprocess.py", line 488, in run
    with Popen(*popenargs, **kwargs) as process:
  File "C:\Program Files\Python37\lib\subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files\Python37\lib\subprocess.py", line 1207, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified