Recherche avancée

Médias (0)

Mot : - Tags -/utilisateurs

Aucun média correspondant à vos critères n’est disponible sur le site.

Autres articles (63)

  • MediaSPIP Core : La Configuration

    9 novembre 2010, par

    MediaSPIP Core fournit par défaut trois pages différentes de configuration (ces pages utilisent le plugin de configuration CFG pour fonctionner) : une page spécifique à la configuration générale du squelettes ; une page spécifique à la configuration de la page d’accueil du site ; une page spécifique à la configuration des secteurs ;
    Il fournit également une page supplémentaire qui n’apparait que lorsque certains plugins sont activés permettant de contrôler l’affichage et les fonctionnalités spécifiques (...)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

  • Les autorisations surchargées par les plugins

    27 avril 2010, par

    Mediaspip core
    autoriser_auteur_modifier() afin que les visiteurs soient capables de modifier leurs informations sur la page d’auteurs

Sur d’autres sites (11306)

  • Resampling audio using libswresample, leaves small amount of noise after resampling

    20 juillet 2020, par Milo

    I'm trying to resample audio from 44Khz to 48Khz and I'm getting s small light noise after resampling. As if someone is gently ticking the mic. This happens both ways. From 48Khz to 44Khz and vice versa.

    


    I've read that this can happen because swrContext still has some data left and that I shoudl flush the context before resampling next frame. And although this helps a little (less noticeable noise), it's still present.

    


    I've tried using FFmpeg resample filter instead, but the output is just loud incoherent noise. I'm pretty sure that libswresample should not output any noise on resampling which means that I just don't know how to use it well and I'm missing some options.

    


    This is the code for resampler.

    


    int ResampleFrame(VideoState * videoState, AVFrame *decoded_audio_frame,     enum AVSampleFormat out_sample_fmt, uint8_t * out_buf)
{
 int in_sample_rate = videoState->audio->ptrAudioCodecCtx_->sample_rate;
 int out_sample_rate = SAMPLE_RATE;

// get an instance of the AudioResamplingState struct, create if NULL
AudioResamplingState* arState = getAudioResampling(videoState->audio->ptrAudioCodecCtx_->channel_layout);

if (!arState->swr_ctx)
{
    printf("swr_alloc error.\n");
    return -1;
}

// get input audio channels
arState->in_channel_layout = (videoState->audio->ptrAudioCodecCtx_->channels ==
            av_get_channel_layout_nb_channels(videoState->audio->ptrAudioCodecCtx_->channel_layout)) ?
            videoState->audio->ptrAudioCodecCtx_->channel_layout :
            av_get_default_channel_layout(videoState->audio->ptrAudioCodecCtx_->channels);


// check input audio channels correctly retrieved
if (arState->in_channel_layout <= 0)
{
    printf("in_channel_layout error.\n");
    return -1;
}


arState->out_channel_layout = AV_CH_LAYOUT_STEREO;

// retrieve number of audio samples (per channel)
arState->in_nb_samples = decoded_audio_frame->nb_samples;
if (arState->in_nb_samples <= 0)
{
    printf("in_nb_samples error.\n");
    return -1;
}

// Set SwrContext parameters for resampling
av_opt_set_int(arState->swr_ctx, "in_channel_layout", arState->in_channel_layout, 0);
av_opt_set_int(arState->swr_ctx, "in_sample_rate", in_sample_rate, 0);
av_opt_set_sample_fmt(arState->swr_ctx, "in_sample_fmt", videoState->audio->ptrAudioCodecCtx_->sample_fmt, 0);


// Set SwrContext parameters for resampling
av_opt_set_int(arState->swr_ctx, "out_channel_layout", arState->out_channel_layout, 0);
av_opt_set_int(arState->swr_ctx, "out_sample_rate", out_sample_rate, 0);
av_opt_set_sample_fmt(arState->swr_ctx, "out_sample_fmt", out_sample_fmt, 0);


// initialize SWR context after user parameters have been set
int ret = swr_init(arState->swr_ctx);
if (ret < 0)
   {
    printf("Failed to initialize the resampling context.\n");
    return -1;
   }


 // retrieve output samples number taking into account the progressive delay
int64_t delay = swr_get_delay(arState->swr_ctx, videoState->audio->ptrAudioCodecCtx_->sample_rate) + arState->in_nb_samples;
arState->out_nb_samples = av_rescale_rnd(delay, out_sample_rate, in_sample_rate, AV_ROUND_UP );

// check output samples number was correctly rescaled
if (arState->out_nb_samples <= 0)
{
    printf("av_rescale_rnd error\n");
    return -1;
}

// get number of output audio channels
arState->out_nb_channels = av_get_channel_layout_nb_channels(arState->out_channel_layout);

// allocate data pointers array for arState->resampled_data and fill data
// pointers and linesize accordingly
// check memory allocation for the resampled data was successful
ret = av_samples_alloc_array_and_samples(&arState->resampled_data, &arState->out_linesize, arState->out_nb_channels, arState->out_nb_samples, out_sample_fmt, 0);
if (ret < 0)
   {
    printf("av_samples_alloc_array_and_samples() error: Could not allocate destination samples.\n");
    return -1;
   }


if (arState->swr_ctx)
   {
    // do the actual audio data resampling
    // check audio conversion was successful
    int ret_num_samples = swr_convert(arState->swr_ctx,arState->resampled_data,arState->out_nb_samples,(const uint8_t**)decoded_audio_frame->data, decoded_audio_frame->nb_samples);
    //int ret_num_samples = swr_convert_frame(arState->swr_ctx,arState->resampled_data,arState->out_nb_samples,(const uint8_t**)decoded_audio_frame->data, decoded_audio_frame->nb_samples);

    if (ret_num_samples < 0)
       {
        printf("swr_convert_error.\n");
        return -1;
       }


    // get the required buffer size for the given audio parameters
    // check audio buffer size
    arState->resampled_data_size = av_samples_get_buffer_size(&arState->out_linesize,   arState->out_nb_channels,ret_num_samples,out_sample_fmt,1);

    if (arState->resampled_data_size < 0)
       {
        printf("av_samples_get_buffer_size error.\n");
        return -1;
       }
   } else {
           printf("swr_ctx null error.\n");
           return -1;
          }



// copy the resampled data to the output buffer
memcpy(out_buf, arState->resampled_data[0], arState->resampled_data_size);


// flush the swr context
int delayed = swr_convert(arState->swr_ctx,arState->resampled_data,arState->out_nb_samples,NULL,0);



if (arState->resampled_data)
   {
    av_freep(&arState->resampled_data[0]);
   }

av_freep(&arState->resampled_data);
arState->resampled_data = NULL;

int ret_data_size = arState->resampled_data_size;



return ret_data_size;
}


    


    I also tries using the filter as shown here but my output is just noise.

    


    This is my filter code

    


    int  ResampleFrame(AVFrame *frame, uint8_t *out_buf)
{
   /* Push the decoded frame into the filtergraph */
    qint32 ret;
    ret = av_buffersrc_add_frame_flags(buffersrc_ctx1, frame, AV_BUFFERSRC_FLAG_KEEP_REF);
    if (ret < 0) 
       {
        printf("ResampleFrame: Error adding frame to buffer\n");
        // Delete input frame and return null
        av_frame_unref(frame);
        return 0;
    }


    //printf("resampling\n");
    AVFrame *resampled_frame = av_frame_alloc();


    /* Pull filtered frames from the filtergraph */
    ret = av_buffersink_get_frame(buffersink_ctx1, resampled_frame);

    /* Set the timestamp on the resampled frame */
    resampled_frame->best_effort_timestamp = resampled_frame->pts;

    if (ret < 0) 
       {
        av_frame_unref(frame);
        av_frame_unref(resampled_frame);
        return 0;
       }


    int buffer_size = av_samples_get_buffer_size(NULL,   2,resampled_frame->nb_samples,AV_SAMPLE_FMT_S16,1);

    memcpy(out_buf,resampled_frame->data,buffer_size);

    //av_frame_unref(frame);
    av_frame_unref(resampled_frame);
    return buffer_size;
}





QString filter_description1 = "aresample=48000,aformat=sample_fmts=s16:channel_layouts=stereo,asetnsamples=n=1024:p=0";

int InitAudioFilter(AVStream *inputStream) 
{

    char args[512];
    int ret;
    const AVFilter *buffersrc = avfilter_get_by_name("abuffer");
    const AVFilter *buffersink = avfilter_get_by_name("abuffersink");
    AVFilterInOut *outputs = avfilter_inout_alloc();
    AVFilterInOut *inputs = avfilter_inout_alloc();
    filter_graph = avfilter_graph_alloc();


    const enum AVSampleFormat out_sample_fmts[] = {AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE};
    const int64_t out_channel_layouts[] = {AV_CH_LAYOUT_STEREO, -1};
    const int out_sample_rates[] = {48000, -1};

    snprintf(args, sizeof(args), "time_base=%d/%d:sample_rate=%d:sample_fmt=%s:channel_layout=0x%" PRIx64,
                         inputStream->codec->time_base.num, inputStream->codec->time_base.den,
                         inputStream->codec->sample_rate,
                         av_get_sample_fmt_name(inputStream->codec->sample_fmt),
                         inputStream->codec->channel_layout);


    ret = avfilter_graph_create_filter(&buffersrc_ctx1, buffersrc, "in", args, NULL, filter_graph);

    if (ret < 0) 
       {
        printf("InitAudioFilter: Unable to create buffersrc\n");
        return -1;
       }

    ret = avfilter_graph_create_filter(&buffersink_ctx1, buffersink, "out", NULL, NULL, filter_graph);

    if (ret < 0) 
       {
        printf("InitAudioFilter: Unable to create buffersink\n");
        return ret;
       }

    // set opt SAMPLE FORMATS
    ret = av_opt_set_int_list(buffersink_ctx1, "sample_fmts", out_sample_fmts, -1, AV_OPT_SEARCH_CHILDREN);

    if (ret < 0) 
       {
        printf("InitAudioFilter: Cannot set output sample format\n");
        return ret;
       }

    // set opt CHANNEL LAYOUTS
    ret = av_opt_set_int_list(buffersink_ctx1, "channel_layouts", out_channel_layouts, -1, AV_OPT_SEARCH_CHILDREN);

    if (ret < 0) {
        printf("InitAudioFilter: Cannot set output channel layout\n");
        return ret;
    }

    // set opt OUT SAMPLE RATES
    ret = av_opt_set_int_list(buffersink_ctx1, "sample_rates", out_sample_rates, -1, AV_OPT_SEARCH_CHILDREN);

    if (ret < 0) 
       {
        printf("InitAudioFilter: Cannot set output sample rate\n");
        return ret;
       }

    /* Endpoints for the filter graph. */
    outputs -> name = av_strdup("in");
    outputs -> filter_ctx = buffersrc_ctx1;
    outputs -> pad_idx = 0;
    outputs -> next = NULL;

    /* Endpoints for the filter graph. */
    inputs -> name = av_strdup("out");
    inputs -> filter_ctx = buffersink_ctx1;
    inputs -> pad_idx = 0;
    inputs -> next = NULL;


    if ((ret = avfilter_graph_parse_ptr(filter_graph, filter_description1.toStdString().c_str(), &inputs, &outputs, NULL)) < 0) 
       {
        printf("InitAudioFilter: Could not add the filter to graph\n");
       }


    if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0) 
       {
        printf("InitAudioFilter: Could not configure the graph\n");
       }

    /* Print summary of the sink buffer
     * Note: args buffer is reused to store channel layout string */
    AVFilterLink *outlink = buffersink_ctx1->inputs[0];
    av_get_channel_layout_string(args, sizeof(args), -1, outlink->channel_layout);

    QString str = args;
    printf("Output: srate:%dHz fmt:%s chlayout: %s\n", (int) outlink->sample_rate, 
                                                      av_get_sample_fmt_name((AVSampleFormat) outlink->format),
                                                      str.toStdString().c_str());


    filterGraphInitialized_ = true; 
}


    


    And since I don't have much experience with filters or audio for that matter, I'm also probably missing something here. But Can't figure out what.

    


    Thanks

    


  • ffmpeg not converting via PHP script

    16 mars 2014, par user3331834

    Essentially, I have this code :

    if(in_array($ext,$audio)&&($ext!=="flac")){
       exec("ffmpeg -i -loglevel 'verbose' ".$fileName.".".$ext." ".$fileName.".flac null >/dev/null 2>/var/www/resources/ffmpegAudio.log &",$ffmpegOutput);
       print_r($ffmpegOutput);
       $editApproveStatus="Audio entry approved. File converted.";
    }

    Ultimately, my goal is to convert files and show a live progress of the conversion (or at least something that updates every few seconds), and running in the background, so that the same page can be used to convert further files.

    Now I'm already stuck, because the conversion just isn't working. I know that the preceding code should be fine, since it makes it all the way to this if statement above, and no errors are being throw up by the PHP. However, my log output shows :

    ffmpeg version 0.8.10-6:0.8.10-0ubuntu0.13.10.1, Copyright (c) 2000-2013 the Libav developers
     built on Feb  6 2014 20:59:46 with gcc 4.8.1
    *** THIS PROGRAM IS DEPRECATED ***
    This program is only provided for compatibility and will be removed in a future release. Please use avconv instead.
    -loglevel: No such file or directory

    Which also leads me to another question : If ffmpeg is deprecated, and avconv is the way to do, can I still use the exec code in my PHP as is (replacing the ffmpeg bit with avconv) ? From what I've seen so far on the avconv page, it looks similar, but I can't be certain that it's exactly the same.

    So my two questions : Why isn't the file being converted, and is there any change in the syntax between avconv and ffmpeg ?

  • Can't play rtp stream from ffmpeg/avconv, no data received

    6 mars 2014, par Foo Barazz

    I started avserver on my Raspberry Pi, webcam attached I read from /dev/video0 with

    pi@raspberrypi $ avconv -f video4linux2 -i /dev/video0 -vcodec mpeg2video -r 25 - pix_fmt yuv420p -me_method epzs -b 2600k -bt 256k -f rtp rtp://192.168.0.124:8090

    avconv version 0.8.6-6:0.8.6-1+rpi1, Copyright (c) 2000-2013 the Libav developers
     built on Mar 31 2013 13:58:10 with gcc 4.6.3
    [video4linux2 @ 0x17c1720] Estimating duration from bitrate, this may be inaccurate
    Input #0, video4linux2, from '/dev/video0':
     Duration: N/A, start: 615.594215, bitrate: 36864 kb/s
       Stream #0.0: Video: rawvideo, yuyv422, 320x240, 36864 kb/s, 30 tbr, 1000k tbn, 30 tbc
    [buffer @ 0x17c16e0] w:320 h:240 pixfmt:yuyv422
    [avsink @ 0x17c2f00] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
    [scale @ 0x17c34c0] w:320 h:240 fmt:yuyv422 -> w:320 h:240 fmt:yuv420p flags:0x4
    Output #0, rtp, to 'rtp://192.168.0.124:8090':
     Metadata:
       encoder         : Lavf53.21.1
       Stream #0.0: Video: mpeg2video, yuv420p, 320x240, q=2-31, 2600 kb/s, 90k tbn, 25 tbc
    Stream mapping:
     Stream #0:0 -> #0:0 (rawvideo -> mpeg2video)
    SDP:
    v=0
    o=- 0 0 IN IP4 127.0.0.1
    s=No Name
    c=IN IP4 192.168.0.124
    t=0 0
    a=tool:libavformat 53.21.1
    m=video 8090 RTP/AVP 32
    b=AS:2600

    Press ctrl-c to stop encoding
    frame=  576 fps= 25 q=2.0 size=    2133kB time=23.00 bitrate= 759.8kbits/s dup=390 drop=0    
    frame=  590 fps= 25 q=2.0 size=    2191kB time=23.56 bitrate= 762.0kbits/s dup=400 drop=0    
    frame= 1320 fps= 25 q=2.0 size=    4932kB time=52.76 bitrate= 765.8kbits/s dup=908 drop=0
    ...

    Seems to work fine, it reads data from the webcam.

    Now I'm trying to simply play with ffplay from my Mac with

    $ ffplay rtp://192.168.0.124:8090
    ffplay version 1.2.4 Copyright (c) 2003-2013 the FFmpeg developers
     built on Mar  1 2014 15:18:21 with Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
     configuration: --prefix=/usr/local/Cellar/ffmpeg/1.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-nonfree --enable-hardcoded-tables --enable-avresample --enable-vda --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libfaac --enable-libmp3lame --enable-libxvid --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-aacenc --enable-libass --enable-ffplay --enable-libspeex --enable-libschroedinger --enable-libfdk-aac --enable-libopus --enable-frei0r --enable-libopenjpeg --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.1/include/openjpeg-1.5 '
     libavutil      52. 18.100 / 52. 18.100
     libavcodec     54. 92.100 / 54. 92.100
     libavformat    54. 63.104 / 54. 63.104
     libavdevice    54.  3.103 / 54.  3.103
     libavfilter     3. 42.103 /  3. 42.103
     libswscale      2.  2.100 /  2.  2.100
     libswresample   0. 17.102 /  0. 17.102
     libpostproc    52.  2.100 / 52.  2.100
       nan A-V:  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0  
       nan A-V:  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0  
       nan A-V:  0.000 fd=   0 aq=    0KB vq=    0KB sq=    0B f=0/0
       ...

    The video doesn't open and it seems to not reading any data from the Raspberry Pi.

    I use the default configuration for avserver.
    The webcam is definitely working as I managed to just write out images with avconv from it.

    What did I miss ?