Recherche avancée

Médias (16)

Mot : - Tags -/mp3

Autres articles (78)

  • Websites made ​​with MediaSPIP

    2 mai 2011, par

    This page lists some websites based on MediaSPIP.

  • MediaSPIP v0.2

    21 juin 2013, par

    MediaSPIP 0.2 est la première version de MediaSPIP stable.
    Sa date de sortie officielle est le 21 juin 2013 et est annoncée ici.
    Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
    Comme pour la version précédente, 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 (...)

  • Creating farms of unique websites

    13 avril 2011, par

    MediaSPIP platforms can be installed as a farm, with a single "core" hosted on a dedicated server and used by multiple websites.
    This allows (among other things) : implementation costs to be shared between several different projects / individuals rapid deployment of multiple unique sites creation of groups of like-minded sites, making it possible to browse media in a more controlled and selective environment than the major "open" (...)

Sur d’autres sites (13657)

  • How to parallelize this for loop for rapidly converting YUV422 to RGB888 ?

    16 avril 2015, par vineet

    I am using v4l2 api to grab images from a Microsoft Lifecam and then transferring these images over TCP to a remote computer. I am also encoding the video frames into a MPEG2VIDEO using ffmpeg API. These recorded videos play too fast which is probably because not enough frames have been captured and due to incorrect FPS settings.

    The following is the code which converts a YUV422 source to a RGB888 image. This code fragment is the bottleneck in my code as it takes nearly 100 - 150 ms to execute which means I can’t log more than 6 - 10 FPS at 1280 x 720 resolution. The CPU usage is 100% as well.

    for (int line = 0; line < image_height; line++) {
       for (int column = 0; column < image_width; column++) {
           *dst++ = CLAMP((double)*py + 1.402*((double)*pv - 128.0));                                                  // R - first byte          
           *dst++ = CLAMP((double)*py - 0.344*((double)*pu - 128.0) - 0.714*((double)*pv - 128.0));    // G - next byte
           *dst++ = CLAMP((double)*py + 1.772*((double)*pu - 128.0));                                                            // B - next byte

           vid_frame->data[0][line * frame->linesize[0] + column] = *py;

           // increment py, pu, pv here

       }

    ’dst’ is then compressed as jpeg and sent over TCP and ’vid_frame’ is saved to the disk.

    How can I make this code fragment faster so that I can get atleast 30 FPS at 1280x720 resolution as compared to the present 5-6 FPS ?

    I’ve tried parallelizing the for loop across three threads using p_thread, processing one third of the rows in each thread.

    for (int line = 0; line < image_height/3; line++) // thread 1
    for (int line = image_height/3; line < 2*image_height/3; line++) // thread 2
    for (int line = 2*image_height/3; line < image_height; line++) // thread 3

    This gave me only a minor improvement of 20-30 milliseconds per frame.
    What would be the best way to parallelize such loops ? Can I use GPU computing or something like OpenMP ? Say spwaning some 100 threads to do the calculations ?

    I also noticed higher frame rates with my laptop webcam as compared to the Microsoft USB Lifecam.

    Here are other details :

    • Ubuntu 12.04, ffmpeg 2.6
    • AMG-A8 quad core processor with 6GB RAM
    • Encoder settings :
      • codec : AV_CODEC_ID_MPEG2VIDEO
      • bitrate : 4000000
      • time_base : (AVRational)1, 20
      • pix_fmt : AV_PIX_FMT_YUV420P
      • gop : 10
      • max_b_frames : 1
  • FFMPEG MP3 decode and encode audio distortion

    5 avril 2016, par user3450380

    I’m trying to make a program that successfully decodes MP3 to PCM. To test this I’ve been re-encoding to MP3 to see if the audio matches up. The problem is when I play the re-encoded audio the songs are 30 seconds shorter than the original and at a noticeably higher pitch. However, if I decode and encode this new audio (the distorted one I just encoded), I get the exact same audio. The only thing I can think of is maybe I’m missing something in the header ? Thanks for any help ! Sorry for the weird code blocks, the trying to tab to make code blocks skipped across the web page.

    #define AUDIO_INBUF_SIZE 20480
    #define AUDIO_REFILL_THRESH 4096
    #define STD_SAMPLE_RATE 44100


    //check if given sample format is accepted by given codec
    static int check_sample_format(AVCodec* avco, enum AVSampleFormat sample_fmt)

    {

    const enum AVSampleFormat* p = avco->sample_fmts;

    while(*p != AV_SAMPLE_FMT_NONE)
    {
       if(*p == sample_fmt)
       {
           return 1;
       }
       p++;
    }
    return 0;
    }

    //if no sample rates in codec, selects the standard rate of 44100.

    //otherwise, highest suported sample rate is chosen
    static int select_sample_rate(AVCodec* avco)

    {

    const int* p;
    int best_sample_rate = 0;

    if(!(avco->supported_samplerates))
    {
       return STD_SAMPLE_RATE;
    }

    p = avco->supported_samplerates;

    while(*p)
    {
       best_sample_rate = FFMAX(*p, best_sample_rate);
       p++;
    }

    return best_sample_rate;
    }

    //select layout with the highest channel count

    static int select_channel_layout(AVCodec* codec)

    {

    const uint64_t* p;
    uint64_t best_ch_layout = 0;
    int best_nb_channels = 0;

    if(!codec->channel_layouts)
    {
       return AV_CH_LAYOUT_STEREO;
    }

    p = codec->channel_layouts;
    while(*p)
    {
       int nb_channels = av_get_channel_layout_nb_channels(*p);

       if(nb_channels > best_nb_channels)
       {
           best_ch_layout = *p;
           best_nb_channels = nb_channels;
       }
       p++;
    }
    return best_ch_layout;

    }

    static int file_format_check(AVFormatContext* pFormatCtx, const char* song_path, FILE* infile)

    {

    AVCodecContext* codecCtx = NULL;
    AVCodec* inputCodec = NULL;
    int audioStreamIndex, i = 0;

    //open audio file
    if(avformat_open_input(&pFormatCtx, song_path, NULL, NULL) != 0)
    {
       return -1;
    }

    //open binary file for reading
    infile = fopen(song_path, "rb");


    if(!infile)
    {
       fprintf(stderr, "Input file not opened!");
       return -1;
    }


    if(avformat_find_stream_info(pFormatCtx, NULL))
    {
       fprintf(stderr, "Stream info not found!");
       return -1;
    }

    //dumps info about format context to standard error
    av_dump_format(pFormatCtx, 0, /*argv[1]*/0, 0);

    //find audio stream
    for(i = 0; i < pFormatCtx->nb_streams; i++){
       if(pFormatCtx->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO)
       {
           audioStreamIndex = i;
           printf("Audio Stream Found!\n");
           break;
       }
    }

    if(audioStreamIndex == -1)
    {
       return -1;
    }

    //set codec context pointer to codec context of audio stream
    codecCtx = pFormatCtx->streams[audioStreamIndex]->codec;
    //find decodeder for audio stream
    inputCodec = avcodec_find_decoder(codecCtx->codec_id);
    if (inputCodec == NULL)
    {
       fprintf(stderr, "Unsupported codec!\n");
       return -1;
    }

    //open codec
    if(avcodec_open2(codecCtx, inputCodec, NULL) < 0)
    {
       fprintf(stderr, "Codec could not be opened!");
       return -1;
    }


    return audioStreamIndex;

    }

    int main(int argc, const char * argv[])
    {

    //refister all available file formats and codecs
    av_register_all();

    FILE *infile, *outfile;
    int i, len, ret, audioStreamIndex = -1;
    const char* song_path = "/Users/timothyrice/Dropbox/audio-experimentation/audio_playground/audio_playground/Monsters.mp3";
    const char* new_format_path = "/Users/timothyrice/Dropbox/audio-experimentation/audio_playground/audio_playground/new_audio.mp3";


    AVFormatContext* inputFormat = avformat_alloc_context();
    AVFormatContext* outputFormat = avformat_alloc_context();

    AVCodecContext* decodeCodecCtx;
    AVPacket decodingPacket;
    AVFrame* decodedFrame = NULL;

    AVCodec* encodeCodec = NULL;
    AVCodecContext* encodeCodecCtx = NULL;
    AVPacket encodingPacket;


    audioStreamIndex = file_format_check(inputFormat, song_path, infile);

    if(audioStreamIndex < 0)
    {
       return -1;
    }

    av_init_packet(&decodingPacket);

    //allocate frame
    if(!decodedFrame)
    {
       if(!(decodedFrame = av_frame_alloc()))
       {
           fprintf(stderr, "Could not allocate audio frame\n");
           return -1;
       }

    }

    //set decoding codec context to audio stream index's codec
    decodeCodecCtx = inputFormat->streams[audioStreamIndex]->codec;

    //set up encoding audio codec
    encodeCodec = avcodec_find_encoder(AV_CODEC_ID_MP3);
    if(!encodeCodec)
    {
       fprintf(stderr, "Could not find encoder codec!\n");
       return -1;
    }
    encodeCodecCtx = avcodec_alloc_context3(encodeCodec);

    encodeCodecCtx->bit_rate = decodeCodecCtx->bit_rate;
    encodeCodecCtx->sample_fmt = decodeCodecCtx->sample_fmt;
    encodeCodecCtx->frame_size = decodeCodecCtx->frame_size;

    if(!check_sample_format(encodeCodec, encodeCodecCtx->sample_fmt))
    {
       fprintf(stderr, "Sample format %s not supported by encoding codec!\n", av_get_sample_fmt_name(encodeCodecCtx->sample_fmt));
       return -1;
    }

    //encoder codec context setup
    encodeCodecCtx->sample_rate = select_sample_rate(encodeCodec);
    encodeCodecCtx->channel_layout = select_channel_layout(encodeCodec);
    encodeCodecCtx->channels = av_get_channel_layout_nb_channels(encodeCodecCtx->channel_layout);

    if(avcodec_open2(encodeCodecCtx, encodeCodec, 0) < 0)
    {
       fprintf(stderr, "Could not open encoder codec\n");
       return -1;
    }

    outfile = fopen(new_format_path, "wb");

    if(!outfile)
    {
       fprintf(stderr, "Output file not opened!\n");
       return -1;
    }

    //printf("Outside function format-duration = %lld\n", inputFormat->duration);
    int c = 0, sum = 0;// max = 0;
    while (av_read_frame(inputFormat, &decodingPacket) == 0)
    {
       //CHECK LATER:# of samples decoded = # encoded?
       //PLANAR????

       int ch, got_frame, got_packet = 0;
       int j = 0;
       //printf("Frame #%d\n", ++c);

       //make sure stream indexes match, rarely necessary but can prevent a crash
       if(decodingPacket.stream_index == audioStreamIndex)
       {

           int bl = 0; //temporary to see performance of while loop

           while (decodingPacket.size > 0) {
               got_frame = 0;

               if(bl++ > 1)
               {
                   printf("while loop repeat!!!!\n\n\n");
               }

               //decodes next frame from stream inside decodingPacket and stores it in decodedFrame
               //len < 0 if the decoding didn't work
               len = avcodec_decode_audio4(decodeCodecCtx, decodedFrame, &got_frame, &decodingPacket);



               if(got_frame && len >= 0)
               {


                   ret = avcodec_encode_audio2(encodeCodecCtx, &encodingPacket, decodedFrame, &got_packet);

                   if(ret < 0)
                   {
                       fprintf(stderr, "Error encoding raw audio frame!\n");
                       return -1;
                   }


                   if(got_packet)
                   {

                       fwrite(encodingPacket.data, 1, encodingPacket.size, outfile);
                       av_free_packet(&encodingPacket);


                       //if encoder needs to be flushed
                       if(encodeCodecCtx->codec->capabilities == CODEC_CAP_DELAY)
                       {
                           av_init_packet(&encodingPacket);

                           got_frame = 0;
                           while(avcodec_encode_audio2(encodeCodecCtx, &encodingPacket, NULL, &got_packet) >= 0 && got_frame)
                           {
                               fwrite(encodingPacket.data, 1, encodingPacket.size, outfile);
                               av_free_packet(&encodingPacket);
                           }
                       }
                   }


                   //if decoder needs to be flushed
                   if(decodeCodecCtx->codec->capabilities == CODEC_CAP_DELAY)
                   {
                       av_init_packet(&decodingPacket);

                       got_frame = 0;
                       while(avcodec_decode_audio4(decodeCodecCtx, decodedFrame, &got_frame, &decodingPacket) >= 0 && got_frame)
                       {
                           av_free_packet(&decodingPacket);
                       }
                   }
               }
               else
               {
                   fprintf(stderr, "Error while decoding\n");
                   return -1;

               }

           decodingPacket.size -= len;
           decodingPacket.data += len;
           decodingPacket.dts = AV_NOPTS_VALUE;
           decodingPacket.pts = AV_NOPTS_VALUE;

           }

           av_free_packet(&decodingPacket);
       }

    }


    //open audio file
    if(avformat_open_input(&outputFormat, new_format_path, NULL, NULL) != 0)
    {
       return -1;
    }

    //open binary file for reading
    outfile = fopen(new_format_path, "rb");


    if(!outfile)
    {
       fprintf(stderr, "Input file not opened!");
       return -1;
    }


    if(avformat_find_stream_info(outputFormat, NULL))
    {
       fprintf(stderr, "Stream info not found!");
       return -1;
    }

    //dumps info about format context to standard error
    av_dump_format(outputFormat, 0, /*argv[1]*/0, 0);

    fclose(infile);
    fclose(outfile);

    avcodec_close(decodeCodecCtx);
    av_free(decodeCodecCtx);
    av_frame_free(&decodedFrame);




    return 0;

    }

  • Why menconder fps rate does not work ?

    2 mars 2016, par ACR

    I’m using mencoder to create a video out of some .png files. The problem is that the frame rate doesn’t change, regardless of the -fps flag. The output video has different time lengths (in their properties), but the video’s size and speed are always the same (regardless of the FPS chosen).

    I just want to create a shorted video by using higher FPS rates. In short, a "time-lapse" of my original set of images. What am I doing wrong with mencoder ? I’m using the following command :

    mencoder mf://./IMG/images*.png -mf w=800:h=600:fps=20:type=png -ovc copy -oac copy -o video.avi