Recherche avancée

Médias (0)

Mot : - Tags -/metadatas

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

Autres articles (47)

  • Multilang : améliorer l’interface pour les blocs multilingues

    18 février 2011, par

    Multilang est un plugin supplémentaire qui n’est pas activé par défaut lors de l’initialisation de MediaSPIP.
    Après son activation, une préconfiguration est mise en place automatiquement par MediaSPIP init permettant à la nouvelle fonctionnalité d’être automatiquement opérationnelle. Il n’est donc pas obligatoire de passer par une étape de configuration pour cela.

  • 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

  • HTML5 audio and video support

    13 avril 2011, par

    MediaSPIP uses HTML5 video and audio tags to play multimedia files, taking advantage of the latest W3C innovations supported by modern browsers.
    The MediaSPIP player used has been created specifically for MediaSPIP and can be easily adapted to fit in with a specific theme.
    For older browsers the Flowplayer flash fallback is used.
    MediaSPIP allows for media playback on major mobile platforms with the above (...)

Sur d’autres sites (8190)

  • Playing Mp3 file using FFmpeg on Android

    2 avril 2017, par satyres

    This question has been asked a lot but no code has worked for me . i’ve been able to play a file decoded with ffmpeg on Android but it’s noisy and glitchy.
    i’ve found code in book called "linux sound programming" using latest ffmpeg version to decode an mp3 file.
    the code tries to decode an mp3 file to pcm and then put it in a file called output.
    what i want to do is to get the byte decoded on the fly and send them to AudioTrack in Java.

    void JNICALL Java_com_example_home_hellondk_MainActivity_loadFile
           (JNIEnv* env, jobject obj,jstring file,jbyteArray array)
    {

    jboolean isfilenameCopy;
            const char * filename = (*env)->GetStringUTFChars(env, file,
                    &isfilenameCopy);
    jclass cls = (*env)->GetObjectClass(env, obj);
            jmethodID play = (*env)->GetMethodID(env, cls, "playSound", "([BI)V");
       AVCodec *codec;
       AVCodecContext *c= NULL;
       int len;
       FILE *f, *outfile;
       uint8_t inbuf[AUDIO_INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
       AVPacket avpkt;
       AVFrame *decoded_frame = NULL;
    AVFormatContext* container=NULL;
       av_init_packet(&avpkt);
    int num_streams = 0;
       int sample_size = 0;
       printf("Decode audio file %s \n", filename);
    LOGE("Decode audio file %s\n", filename);
       /* find the MPEG audio decoder */
     /*  codec = avcodec_find_decoder(AV_CODEC_ID_MP3);
       if (!codec) {
           fprintf(stderr, "Codec not found\n");
           LOGE("Codec not found\n");
           exit(1);
       }*/
    int lError;
            if ((lError = avformat_open_input(&container, filename, NULL, NULL))
                    != 0) {
                LOGE("Error open source file: %d", lError);
                exit(1);
            }
            if ((lError =  avformat_find_stream_info(container,NULL)) < 0) {
                LOGE("Error find stream information: %d", lError);
                exit(1);
            }
            LOGE("Stage 1.5");
           LOGE("audio format: %s", container->iformat->name);
          LOGE("audio bitrate: %llu", container->bit_rate);

       int stream_id = -1;
           // To find the first audio stream. This process may not be necessary
           // if you can gurarantee that the container contains only the desired
           // audio stream
              LOGE("nb_streams: %d", container->nb_streams);
           int i;
           for (i = 0; i < container->nb_streams; i++) {
               if (container->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
                   stream_id = i;
                    LOGE("stream_id: %d", stream_id);
                   break;
               }
           }

           AVCodecContext* codec_context = container->streams[stream_id]->codec;
           codec = avcodec_find_decoder(codec_context->codec_id);
            LOGE("stream_id: %d", stream_id);
           LOGE("codec %s", codec->name);
           if (!codec) {
               fprintf(stderr, "codec not found\n");
               exit(1);
           }

       c = avcodec_alloc_context3(codec);
       if (!c) {
           fprintf(stderr, "Could not allocate audio codec context\n");
             LOGE("Could not allocate audio codec context\n");
           exit(1);
       }

       /* open it */
       if (avcodec_open2(c, codec, NULL) < 0) {
           fprintf(stderr, "Could not open codec\n");
            LOGE("Could not open codec\n");
           exit(1);
       }

       f = fopen(filename, "rb");
       if (!f) {
           fprintf(stderr, "Could not open %s\n", filename);
           LOGE("Could not open %s\n",filename);
           exit(1);
       }
       const char *outfilename;
    outfile = fopen(outfilename, "wb");
       if (!outfile) {
           av_free(c);
           exit(1);
       }


           avpkt.data = inbuf;
           avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);
           LOGE("Stage 5");
       /* decode until eof */

        while (avpkt.size > 0) {
              int got_frame = 0;
              if (!decoded_frame) {
                  if (!(decoded_frame = av_frame_alloc())) {
                      fprintf(stderr, "out of memory\n");
                      exit(1);
                  }
                  } else {
                              av_frame_unref(decoded_frame);
                          }
                          printf("Stream idx %d\n", avpkt.stream_index);
                          len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt);
                          if (len < 0) {
                              fprintf(stderr, "Error while decoding\n");
                              exit(1);
                          }
                          if (got_frame) {
                              printf("Decoded frame nb_samples %d, format %d\n",
                                     decoded_frame->nb_samples,
                                     decoded_frame->format);
                              if (decoded_frame->data[1] != NULL)
                                  printf("Data[1] not null\n");
                              else
                                  printf("Data[1] is null\n");
                              /* if a frame has been decoded, output it */
                              int data_size = av_samples_get_buffer_size(NULL, c->channels,
                                                                         decoded_frame->nb_samples,
                                                                         c->sample_fmt, 1);
                              // first time: count the number of  planar streams
                              if (num_streams == 0) {
                                  while (num_streams < AV_NUM_DATA_POINTERS &&
                                         decoded_frame->data[num_streams] != NULL)
                                      num_streams++;
                                  printf("Number of streams %d\n", num_streams);
                              }
                              // first time: set sample_size from 0 to e.g 2 for 16-bit data
                              if (sample_size == 0) {
                                  sample_size =
                                      data_size / (num_streams * decoded_frame->nb_samples);
                              }
                              int m, n;

                              for (n = 0; n < decoded_frame->nb_samples; n++) {
                                  // interleave the samples from the planar streams
                                  for (m = 0; m < num_streams; m++) {
                                     fwrite(&decoded_frame->data[m][n*sample_size],
                                             1, sample_size, outfile);

                                  }
                              }

                   /*            jbyte *bytes = (*env)->GetByteArrayElements(env, array, NULL);
                               memcpy(bytes, decoded_frame->data[1], data_size);
                               (*env)->ReleaseByteArrayElements(env, array, bytes, 0);
                              (*env)->CallVoidMethod(env, obj, play, array, data_size);

    */
                          }
                          avpkt.size -= len;
                          avpkt.data += len;
                          if (avpkt.size < AUDIO_REFILL_THRESH) {
                              /* Refill the input buffer, to avoid trying to decode
                               * incomplete frames. Instead of this, one could also use
                               * a parser, or use a proper container format through
                                 * libavformat. */
                                           memmove(inbuf, avpkt.data, avpkt.size);
                                           avpkt.data = inbuf;
                                           len = fread(avpkt.data + avpkt.size, 1,
                                                       AUDIO_INBUF_SIZE - avpkt.size, f);
                                           if (len > 0)
                                               avpkt.size += len;
                                       }
                                   }

       fclose(f);

       avcodec_free_context(&c);
    av_frame_free(&decoded_frame);

    }

    the decoded bytes are in this section
    fwrite(&decoded_frame->data[m][n*sample_size],                                           1, sample_size, outfile);

    the code that let you send bytes to java is this :

     jbyte *bytes = (*env)->GetByteArrayElements(env, array, NULL);
     memcpy(bytes, decoded_frame->data[0], data_size);
    (*env)->ReleaseByteArrayElements(env, array, bytes, 0);
    (*env)->CallVoidMethod(env, obj, play, array, data_size);

    i’ve been working on it now for more than a week and nothing worked for me.

    Thank you in advance for your help

  • Decoding an mp3 file using FFmpeg but sound is glitchy

    28 avril 2017, par satyres

    After successfuly compiling the latest version of FFmpeg library and generated .a library in Ubuntu I’ve been struggling now for more than a week to play a simple mp3 file in Android without a success !
    The sound on my S4 working but it’s glitchy and stuttering
    I’ve followed this tutorial given by FFmpeg team in Github i’ve tried to use it in Android but no luck !
    here is the Native code.

    void Java_com_example_home_hellondk_MainActivity_audio_1decode_1example(JNIEnv * env, jobject obj, jstring file, jbyteArray array) {
           jboolean isfilenameCopy;
            const char * filename = (*env)->GetStringUTFChars(env, file,
                    &isfilenameCopy);
    jclass cls = (*env)->GetObjectClass(env, obj);
            jmethodID play = (*env)->GetMethodID(env, cls, "playSound", "([BI)V");
       AVCodec *codec;
       AVCodecContext *c= NULL;
       int len;
       FILE *f, *outfile;
       uint8_t inbuf[AUDIO_INBUF_SIZE + AV_INPUT_BUFFER_PADDING_SIZE];
       AVPacket avpkt;
       AVFrame *decoded_frame = NULL;
    AVFormatContext* container=NULL;
       av_init_packet(&avpkt);

       printf("Decode audio file %s \n", filename);
    LOGE("Decode audio file %s\n", filename);
       /* find the MPEG audio decoder */
     /*  codec = avcodec_find_decoder(AV_CODEC_ID_MP3);
       if (!codec) {
           fprintf(stderr, "Codec not found\n");
           LOGE("Codec not found\n");
           exit(1);
       }*/
    int lError;
            if ((lError = avformat_open_input(&container, filename, NULL, NULL))
                    != 0) {
                LOGE("Error open source file: %d", lError);
                exit(1);
            }
            if ((lError =  avformat_find_stream_info(container,NULL)) < 0) {
                LOGE("Error find stream information: %d", lError);
                exit(1);
            }
            LOGE("Stage 1.5");
           LOGE("audio format: %s", container->iformat->name);
          LOGE("audio bitrate: %llu", container->bit_rate);

       int stream_id = -1;
           // To find the first audio stream. This process may not be necessary
           // if you can gurarantee that the container contains only the desired
           // audio stream
              LOGE("nb_streams: %d", container->nb_streams);
           int i;
           for (i = 0; i < container->nb_streams; i++) {
               if (container->streams[i]->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
                   stream_id = i;
                    LOGE("stream_id: %d", stream_id);
                   break;
               }
           }

           AVCodecContext* codec_context = container->streams[stream_id]->codec;
           codec = avcodec_find_decoder(codec_context->codec_id);
            LOGE("stream_id: %d", stream_id);
           LOGE("codec %s", codec->name);
           if (!codec) {
               fprintf(stderr, "codec not found\n");
               exit(1);
           }

       c = avcodec_alloc_context3(codec);
       if (!c) {
           fprintf(stderr, "Could not allocate audio codec context\n");
             LOGE("Could not allocate audio codec context\n");
           exit(1);
       }

       /* open it */
       if (avcodec_open2(c, codec, NULL) < 0) {
           fprintf(stderr, "Could not open codec\n");
            LOGE("Could not open codec\n");
           exit(1);
       }

       f = fopen(filename, "rb");
       if (!f) {
           fprintf(stderr, "Could not open %s\n", filename);
           LOGE("Could not open %s\n",filename);
           exit(1);
       }



           avpkt.data = inbuf;
           avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);
           LOGE("Stage 5");
       /* decode until eof */

       while (1) {

       if ((len = av_read_frame(container, &avpkt)) < 0)
                          break;

           if (avpkt.stream_index == stream_id)
                        {
         if (!decoded_frame) {
                                                if (!(decoded_frame = av_frame_alloc())) {
                                                    fprintf(stderr, "Could not allocate audio frame\n");
                                                     LOGE("Could not allocate audio frame\n");
                                                    exit(1);
                                                }
                                            }
                               int got_frame = 0;
                                 len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt);
                                LOGE("len=%d",len);
                                if (len < 0)
                                {
                                    LOGE("Error decoding audio\n");
                                    continue;
                                }

                                if (got_frame)
                                {
                                     LOGE("begin frame decode\n");
                                     int data_size = av_samples_get_buffer_size(NULL, c->channels,decoded_frame->nb_samples,c->sample_fmt, 1);
                                   if (data_size>0)
                                   {
                                     LOGE("after frame decode %d\n",data_size);

                                    jbyte *bytes = (*env)->GetByteArrayElements(env, array, NULL);
                                     memcpy(bytes, decoded_frame->data[0], data_size);
                                     (*env)->ReleaseByteArrayElements(env, array, bytes, 0);
                                     (*env)->CallVoidMethod(env, obj, play, array, data_size);

                                    }
                                    else
                                    {
                                    fprintf(stderr, "Failed to calculate data size\n");
                                     exit(1);

                                    }

                                }

                                avpkt.size -= len;
                                avpkt.data += len;
                                avpkt.pts = AV_NOPTS_VALUE;
                               if (avpkt.size < AUDIO_REFILL_THRESH)
                               {
                                   memmove(inbuf, avpkt.data, avpkt.size);
                                   avpkt.data = inbuf;
                                   len = fread(avpkt.data + avpkt.size, 1, AUDIO_INBUF_SIZE - avpkt.size, f);
                                   if (len > 0)
                                       avpkt.size += len;
                               }

                          }




       }


       fclose(f);

       avcodec_free_context(&c);
    av_frame_free(&decoded_frame);
       }

    The Java code :

    package com.example.home.hellondk;

    import android.media.AudioFormat;
    import android.media.AudioManager;
    import android.media.AudioTrack;
    import android.media.MediaPlayer;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.util.Log;

    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;

    public class MainActivity extends AppCompatActivity {
       static {
           System.loadLibrary("MyLibraryPlayer");
       }
       public native void createEngine();

       public native void audio_decode_example(String outfilename, byte[] array);



       private AudioTrack track;
       private FileOutputStream os;

       @Override
       protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.activity_main);
           createEngine();

    /*        MediaPlayer mp = new MediaPlayer();
           mp.start();*/

           int bufSize = AudioTrack.getMinBufferSize(32000,
                   AudioFormat.CHANNEL_CONFIGURATION_STEREO,
                   AudioFormat.ENCODING_PCM_16BIT);

           track = new AudioTrack(AudioManager.STREAM_MUSIC,
                   32000,
                   AudioFormat.CHANNEL_CONFIGURATION_STEREO,
                   AudioFormat.ENCODING_PCM_16BIT,
                   bufSize,
                   AudioTrack.MODE_STREAM);

           byte[] bytes = new byte[bufSize];


      audio_decode_example("/storage/emulated/0/test.mp3", bytes);

       }

       void playSound(byte[] buf, int size) {
           //android.util.Log.v("ROHAUPT", "RAH Playing");
           if (track.getPlayState() != AudioTrack.PLAYSTATE_PLAYING)
               track.play();
           track.write(buf, 0, size);


       }
    }

    Thank you so much for your help.
    Kind regards

  • How can I see the IP Camera on my phone

    11 janvier 2013, par Pike

    I try to use ffmpeg on android and want to see IP Camera
    but somethings wrong
    avformat_open_input(&gFormatCtx, "rtsp ://root:root@111.111.111.111/profile1/media.smp",NULL,NULL)
    av_open_input_file(&gFormatCtx,"rtsp ://root:root@111.111.111.111/profile1/media.smp", NULL, 0, NULL)

    two function can't return handle

    so add —enable-network —enable-protocol=tcp —enable-demuxer=rtsp —enable-decoder=h264 option

    then

    C:/Work/FFmpegBasic/obj/local/armeabi-v7a/libavformat.a(rtpdec.o): in function av_register_rtp_dynamic_payload_handlers:C:/Work/FFmpegBasic/jni/ffmpeg/libavformat/rtpdec.c:89: error: undefined reference to 'ff_g726_16_dynamic_handler'
    C:/Work/FFmpegBasic/obj/local/armeabi-v7a/libavformat.a(rtpdec.o): in function av_register_rtp_dynamic_payload_handlers:C:/Work/FFmpegBasic/jni/ffmpeg/libavformat/rtpdec.c:89: error: undefined reference to 'ff_g726_24_dynamic_handler'
    C:/Work/FFmpegBasic/obj/local/armeabi-v7a/libavformat.a(rtpdec.o): in function av_register_rtp_dynamic_payload_handlers:C:/Work/FFmpegBasic/jni/ffmpeg/libavformat/rtpdec.c:89: error: undefined reference to 'ff_g726_32_dynamic_handler'
    C:/Work/FFmpegBasic/obj/local/armeabi-v7a/libavformat.a(rtpdec.o): in function av_register_rtp_dynamic_payload_handlers:C:/Work/FFmpegBasic/jni/ffmpeg/libavformat/rtpdec.c:89: error: undefined reference to 'ff_g726_40_dynamic_handler'
    C:/Work/FFmpegBasic/obj/local/armeabi-v7a/libavcodec.a(allcodecs.o): in function avcodec_register_all:C:/Work/FFmpegBasic/jni/ffmpeg/libavcodec/allcodecs.c:346: error: undefined reference to 'ff_libaacplus_encoder'
    C:/Work/FFmpegBasic/obj/local/armeabi-v7a/libavcodec.a(allcodecs.o): in function avcodec_register_all:C:/Work/FFmpegBasic/jni/ffmpeg/libavcodec/allcodecs.c:346: error: undefined reference to 'ff_libspeex_encoder'
    collect2: ld returned 1 exit status
    /cygdrive/c/android-ndk-r8d/build/core/build-binary.mk:397: recipe for target `/cygdrive/c/Work/FFmpegBasic/obj/local/armeabi-v7a/libbasicplayer.so' failed
    make: *** [/cygdrive/c/Work/FFmpegBasic/obj/local/armeabi-v7a/libbasicplayer.so] Error 1

    what's the problem ? ff ?
    how can I solve ?