Recherche avancée

Médias (2)

Mot : - Tags -/doc2img

Autres articles (39)

  • Personnaliser les catégories

    21 juin 2013, par

    Formulaire de création d’une catégorie
    Pour ceux qui connaissent bien SPIP, une catégorie peut être assimilée à une rubrique.
    Dans le cas d’un document de type catégorie, les champs proposés par défaut sont : Texte
    On peut modifier ce formulaire dans la partie :
    Administration > Configuration des masques de formulaire.
    Dans le cas d’un document de type média, les champs non affichés par défaut sont : Descriptif rapide
    Par ailleurs, c’est dans cette partie configuration qu’on peut indiquer le (...)

  • 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

  • Contribute to documentation

    13 avril 2011

    Documentation is vital to the development of improved technical capabilities.
    MediaSPIP welcomes documentation by users as well as developers - including : critique of existing features and functions articles contributed by developers, administrators, content producers and editors screenshots to illustrate the above translations of existing documentation into other languages
    To contribute, register to the project users’ mailing (...)

Sur d’autres sites (6552)

  • Decoding and resampling audio with FFmpeg for output with libao

    13 mai 2020, par DoctorSelar

    I'm trying to write a program to read and play an audio file using FFmpeg and libao. I've been following the procedure outlined in the FFmpeg documentation for decoding audio using the new avcodec_send_packet and avcodec_receive_frame functions, but the examples I've been able to find are few and far between (the ones in the FFmpeg documentation either don't use libavformat or use the deprecated avcodec_decode_audio4). I've based a lot of my program off of the transcode_aac.c example (up to init_resampler) in the FFmpeg documentation, but that also uses the deprecated decoding function.

    



    I believe I have the decoding part of the program working, but I need to resample the audio in order to convert it into an interleaved format to send to libao, for which I'm attempting to use libswresample. Whenever the program is run in its current state, it outputs (many times) "Error resampling : Output changed". The test file I've been using is just a YouTube rip that I had on hand. ffprobe reports the only stream as :

    



    Stream #0:0(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 125 kb/s (default)


    



    This is my first program with FFmpeg (and I'm still relatively new to C), so any advice on how to improve/fix other parts of the program would be welcome.

    



    #include&#xA;#include<libavcodec></libavcodec>avcodec.h>&#xA;#include<libavformat></libavformat>avformat.h>&#xA;#include<libavutil></libavutil>avutil.h>&#xA;#include<libswresample></libswresample>swresample.h>&#xA;#include<ao></ao>ao.h>&#xA;&#xA;#define OUTPUT_CHANNELS 2&#xA;#define OUTPUT_RATE 44100&#xA;#define BUFFER_SIZE 192000&#xA;#define OUTPUT_BITS 16&#xA;#define OUTPUT_FMT AV_SAMPLE_FMT_S16&#xA;&#xA;static char *errtext (int err) {&#xA;    static char errbuff[256];&#xA;    av_strerror(err,errbuff,sizeof(errbuff));&#xA;    return errbuff;&#xA;}&#xA;&#xA;static int open_audio_file (const char *filename, AVFormatContext **context, AVCodecContext **codec_context) {&#xA;    AVCodecContext *avctx;&#xA;    AVCodec *codec;&#xA;    int ret;&#xA;    int stream_id;&#xA;    int i;&#xA;&#xA;    // Open input file&#xA;    if ((ret = avformat_open_input(context,filename,NULL,NULL)) &lt; 0) {&#xA;        fprintf(stderr,"Error opening input file &#x27;%s&#x27;: %s\n",filename,errtext(ret));&#xA;        *context = NULL;&#xA;        return ret;&#xA;    }&#xA;&#xA;    // Get stream info&#xA;    if ((ret = avformat_find_stream_info(*context,NULL)) &lt; 0) {&#xA;        fprintf(stderr,"Unable to find stream info: %s\n",errtext(ret));&#xA;        avformat_close_input(context);&#xA;        return ret;&#xA;    }&#xA;&#xA;    // Find the best stream&#xA;    if ((stream_id = av_find_best_stream(*context,AVMEDIA_TYPE_AUDIO,-1,-1,&amp;codec,0)) &lt; 0) {&#xA;        fprintf(stderr,"Unable to find valid audio stream: %s\n",errtext(stream_id));&#xA;        avformat_close_input(context);&#xA;        return stream_id;&#xA;    }&#xA;&#xA;    // Allocate a decoding context&#xA;    if (!(avctx = avcodec_alloc_context3(codec))) {&#xA;        fprintf(stderr,"Unable to allocate decoder context\n");&#xA;        avformat_close_input(context);&#xA;        return AVERROR(ENOMEM);&#xA;    }&#xA;&#xA;    // Initialize stream parameters&#xA;    if ((ret = avcodec_parameters_to_context(avctx,(*context)->streams[stream_id]->codecpar)) &lt; 0) {&#xA;        fprintf(stderr,"Unable to get stream parameters: %s\n",errtext(ret));&#xA;        avformat_close_input(context);&#xA;        avcodec_free_context(&amp;avctx);&#xA;        return ret;&#xA;    }&#xA;&#xA;    // Open the decoder&#xA;    if ((ret = avcodec_open2(avctx,codec,NULL)) &lt; 0) {&#xA;        fprintf(stderr,"Could not open codec: %s\n",errtext(ret));&#xA;        avformat_close_input(context);&#xA;        avcodec_free_context(&amp;avctx);&#xA;        return ret;&#xA;    }&#xA;&#xA;    *codec_context = avctx;&#xA;    return 0;&#xA;}&#xA;&#xA;static void init_packet (AVPacket *packet) {&#xA;    av_init_packet(packet);&#xA;    packet->data = NULL;&#xA;    packet->size = 0;&#xA;}&#xA;&#xA;static int init_resampler (AVCodecContext *codec_context, SwrContext **resample_context) {&#xA;    int ret;&#xA;&#xA;    // Set resampler options&#xA;    *resample_context = swr_alloc_set_opts(NULL,&#xA;                                           av_get_default_channel_layout(OUTPUT_CHANNELS),&#xA;                                           OUTPUT_FMT,&#xA;                                           codec_context->sample_rate,&#xA;                                           av_get_default_channel_layout(codec_context->channels),&#xA;                                           codec_context->sample_fmt,&#xA;                                           codec_context->sample_rate,&#xA;                                           0,NULL);&#xA;    if (!(*resample_context)) {&#xA;        fprintf(stderr,"Unable to allocate resampler context\n");&#xA;        return AVERROR(ENOMEM);&#xA;    }&#xA;&#xA;    // Open the resampler&#xA;    if ((ret = swr_init(*resample_context)) &lt; 0) {&#xA;        fprintf(stderr,"Unable to open resampler context: %s\n",errtext(ret));&#xA;        swr_free(resample_context);&#xA;        return ret;&#xA;    }&#xA;&#xA;    return 0;&#xA;}&#xA;&#xA;static int init_frame (AVFrame **frame) {&#xA;    if (!(*frame = av_frame_alloc())) {&#xA;        fprintf(stderr,"Could not allocate frame\n");&#xA;        return AVERROR(ENOMEM);&#xA;    }&#xA;    return 0;&#xA;}&#xA;&#xA;int main (int argc, char *argv[]) {&#xA;    AVFormatContext *context = 0;&#xA;    AVCodecContext *codec_context;&#xA;    SwrContext *resample_context = NULL;&#xA;    AVPacket packet;&#xA;    AVFrame *frame = 0;&#xA;    AVFrame *resampled = 0;&#xA;    int16_t *buffer;&#xA;    int ret, packet_ret, finished;&#xA;&#xA;    ao_device *device;&#xA;    ao_sample_format format;&#xA;    int default_driver;&#xA;&#xA;    if (argc != 2) {&#xA;        fprintf(stderr,"Usage: %s <filename>\n",argv[0]);&#xA;        return 1;&#xA;    }&#xA;&#xA;    av_register_all();&#xA;    printf("Opening file...\n");&#xA;    if (open_audio_file(argv[1],&amp;context,&amp;codec_context) &lt; 0)&#xA;        return 1;&#xA;&#xA;    printf("Initializing resampler...\n");&#xA;    if (init_resampler(codec_context,&amp;resample_context) &lt; 0) {&#xA;        avformat_close_input(&amp;context);&#xA;        avcodec_free_context(&amp;codec_context);&#xA;        return 1;&#xA;    }&#xA;&#xA;    // Setup libao&#xA;    printf("Starting audio device...\n");&#xA;    ao_initialize();&#xA;    default_driver = ao_default_driver_id();&#xA;    format.bits = OUTPUT_BITS;&#xA;    format.channels = OUTPUT_CHANNELS;&#xA;    format.rate = codec_context->sample_rate;&#xA;    format.byte_format = AO_FMT_NATIVE;&#xA;    format.matrix = 0;&#xA;    if ((device = ao_open_live(default_driver,&amp;format,NULL)) == NULL) {&#xA;        fprintf(stderr,"Error opening audio device\n");&#xA;        avformat_close_input(&amp;context);&#xA;        avcodec_free_context(&amp;codec_context);&#xA;        swr_free(&amp;resample_context);&#xA;        return 1;&#xA;    }&#xA;&#xA;    // Mainloop&#xA;    printf("Beginning mainloop...\n");&#xA;    init_packet(&amp;packet);&#xA;    // Read packets until done&#xA;    while (1) {&#xA;        packet_ret = av_read_frame(context,&amp;packet);&#xA;        // Send a packet&#xA;        if ((ret = avcodec_send_packet(codec_context,&amp;packet)) &lt; 0)&#xA;            fprintf(stderr,"Error sending packet to decoder: %s\n",errtext(ret));&#xA;&#xA;        av_packet_unref(&amp;packet);&#xA;&#xA;        while (1) {&#xA;            if (!frame)&#xA;                frame = av_frame_alloc();&#xA;&#xA;            ret = avcodec_receive_frame(codec_context,frame);&#xA;            if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) // Need more input&#xA;                break;&#xA;            else if (ret &lt; 0) {&#xA;                fprintf(stderr,"Error receiving frame: %s\n",errtext(ret));&#xA;                break;&#xA;            }&#xA;            // We have a valid frame, need to resample it&#xA;            if (!resampled)&#xA;                resampled = av_frame_alloc();&#xA;&#xA;            resampled->channel_layout = av_get_default_channel_layout(OUTPUT_CHANNELS);&#xA;            resampled->sample_rate = codec_context->sample_rate;&#xA;            resampled->format = OUTPUT_FMT;&#xA;&#xA;            if ((ret = swr_convert_frame(resample_context,resampled,frame)) &lt; 0) {&#xA;                fprintf(stderr,"Error resampling: %s\n",errtext(ret));&#xA;            } else {&#xA;                ao_play(device,(char*)resampled->extended_data[0],resampled->linesize[0]);&#xA;            }&#xA;            av_frame_unref(resampled);&#xA;            av_frame_unref(frame);&#xA;        }&#xA;&#xA;        if (packet_ret == AVERROR_EOF)&#xA;            break;&#xA;    }&#xA;&#xA;    printf("Closing file and freeing contexts...\n");&#xA;    avformat_close_input(&amp;context);&#xA;    avcodec_free_context(&amp;codec_context);&#xA;    swr_free(&amp;resample_context);&#xA;&#xA;    printf("Closing audio device...\n");&#xA;    ao_close(device);&#xA;    ao_shutdown();&#xA;&#xA;    return 0;&#xA;}&#xA;</filename>

    &#xA;&#xA;

    UPDATE : I've got it playing sound now, but it sounds like samples are missing (and MP3 files warn that "Could not update timestamps for skipped samples"). The issue was that the resampled frame needed to have certain attributes set before being passed to swr_convert_frame. I've also added av_packet_unref and av_frame_unref, but I'm still unsure as to where to best locate them.

    &#xA;

  • run ffmpeg commands from my own project

    28 octobre 2013, par bruno

    I'm starting a project where I want ppl to upload videos of a talk and a the video of slides for that talk and want to merge them (to play at the same time) and then show results.

    My question is :
    Is it possible to do that from code ? if it is, can you point me to the right doc ?
    I was able to do it running command line, but as I want this to run on a server with different ppl uploading their videos I think this would not be the best approach.
    I have a preference for Java if it's possible to do it, but I can manage to use other languages what do you guys suggest ?

    The idea would be to have a service where I can point the urls of the videos stored in my server and it would merge them and save file where I can later stream. With different ppl uploading videos at the same time and being able to watch the result in a reasonable amount of time.

    I used this tutorial to test :
    https://trac.ffmpeg.org/wiki/Create%20a%20mosaic%20out%20of%20several%20input%20videos

    Thanks for your time

  • avcodec/x86/videodsp : Small speedups in ff_emulated_edge_mc x86 SIMD.

    26 octobre 2013, par Ronald S. Bultje
    avcodec/x86/videodsp : Small speedups in ff_emulated_edge_mc x86 SIMD.
    

    Don’t use word-size multiplications if size == 2, and if we’re using
    SIMD instructions (size >= 8), complete leftover 4byte sets using movd,
    not mov. Both of these changes lead to minor speedups.

    Signed-off-by : Michael Niedermayer <michaelni@gmx.at>

    • [DH] libavcodec/x86/videodsp.asm