Recherche avancée

Médias (3)

Mot : - Tags -/pdf

Autres articles (99)

  • Personnaliser en ajoutant son logo, sa bannière ou son image de fond

    5 septembre 2013, par

    Certains thèmes prennent en compte trois éléments de personnalisation : l’ajout d’un logo ; l’ajout d’une bannière l’ajout d’une image de fond ;

  • La file d’attente de SPIPmotion

    28 novembre 2010, par

    Une file d’attente stockée dans la base de donnée
    Lors de son installation, SPIPmotion crée une nouvelle table dans la base de donnée intitulée spip_spipmotion_attentes.
    Cette nouvelle table est constituée des champs suivants : id_spipmotion_attente, l’identifiant numérique unique de la tâche à traiter ; id_document, l’identifiant numérique du document original à encoder ; id_objet l’identifiant unique de l’objet auquel le document encodé devra être attaché automatiquement ; objet, le type d’objet auquel (...)

  • 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.

Sur d’autres sites (11162)

  • How to create a custom processor for audio files in Ruby on Rails(5) with Paperclip

    17 juillet 2017, par Thomas Roest

    So I’m trying to convert mp3 files into .flac with Paperclip custom processors and ffmpeg. The following code runs the ffmpeg command and creates a temporary flac file. However, it is not saved ? Currently only the original file is saved. What am I missing here ?

    class AudioFile < ApplicationRecord
     has_attached_file :raw_audio, processors: [:custom], styles: { original: {}}

    the custom processor

    module Paperclip
    class Custom < Processor

     def initialize(file, options = {}, attachment = nil)
       super
       @file = file
       @basename = File.basename(@file.path)
       @format = options[:format] || 'flac'
       @params = options[:params] || '-y -i'
     end

     def make
       source = @file
       output = Tempfile.new([@basename, ".#{@format}"])
       begin
         parameters = [@params, ':source',':dest'].join(' ')
         Paperclip.run('ffmpeg', parameters, :source => File.expand_path(source.path), :dest => File.expand_path(output.path), :sample_rate => @sample_rate, :bit_rate => @bit_rate)
       end
      output
     end

    end
    end
  • Javacv : Mat data becomes null after using methods

    5 avril 2017, par rarrouba

    I’m working on an android application for object detection and counting. For the image processing I am using JavaCV (Java wrapper for OpenCV and FFmpeg). After importing the library, I’m able to successfully use the FFmpegFrameGrabber to get the frames of a video.

    My problem : After I convert the Frame to a Mat object and perform some operation on that Mat object the data becomes null.

    Code :

    MainActivity

       public class MainActivity extends AppCompatActivity {



       OpenCVFrameConverter.ToMat converterToMat = new OpenCVFrameConverter.ToMat();


       private CountModule countModule;
       FFmpegFrameGrabber retriever;

       ArrayList frames;
       boolean frameloaded = false;

       File folder = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES);
       File video = new File(folder, "test.mp4");

       AndroidFrameConverter converterToBitmap = new AndroidFrameConverter();



       private static WebStreamer webStreamer;

       static {
           System.loadLibrary("native-lib");
       }

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


           final Button button = (Button) findViewById(R.id.btnLdFrames);
           final ImageView img = (ImageView) findViewById(R.id.imageView);


           button.setOnClickListener(new View.OnClickListener() {
               public void onClick(View v) {
                   ((TextView) button).setText("Loading");
                   new Thread(new Runnable() {
                       public void run() {

                           try {
                               button.setClickable(false);
                               button.setAlpha((float) 0.3);
                               LoadFrames();
                               button.setAlpha((float) 1);

                           } catch (FrameGrabber.Exception e) {
                               e.printStackTrace();
                           }
                       }
                   }).start();

               }
           });
       }
       private void LoadFrames() throws FrameGrabber.Exception {
           if (!frameloaded){



               frameloaded = true;

               retriever = new FFmpegFrameGrabber(video);
               frames = new ArrayList<>();
               Log.d("Frame",": Start of loop");

               retriever.start();
               final ImageView img = (ImageView) findViewById(R.id.imageView);
               for (int i=0;i<50;i++){//155430
                   retriever.setFrameNumber(i*100);
                   Frame temp = new Frame();
                   temp = retriever.grab();

                   frames.add(converterToMat.convert(temp));

                   Log.d("Frame",": " + i*100);



               }
               retriever.stop();

               countModule = new CountModule(frames);
               Log.d("Frame","CountModule instantiated");

           }
       }
    }

    Constructor of Countmodule

    public CountModule(ArrayList<mat> frames){

       fgGBG = new Mat(frames.get(0).rows(),frames.get(0).cols(),frames.get(0).type());
       gbg = createBackgroundSubtractorMOG2();
       Mat maTemp = new Mat(frames.get(0).rows(),frames.get(0).cols(),frames.get(0).type());

       median = new Mat(frames.get(0).rows(),frames.get(0).cols(),frames.get(0).type());
       frames.get(0).copyTo(median);
       ;
       median = getMedian(frames);
       kernel2 = Mat.ones(11,11,CV_8U).asMat();
       kernel = Mat.ones(3,1,CV_8U).asMat();
       gbg.apply(median,fgGBG,0.001);

    }
    </mat>

    Variables (images) :

    After convert from Frame to Mat. Data has values.

    Data=null when using the method frame.copyTo(median). Data of Mat also null when using method Mat.ones()


    As you can see everytime I use a OpenCV specific method, the returned Mat is not what is expected.

  • Error decoding a simple audio file using FFmpeg library

    29 mars 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 decode and play a simple mp3 file in Android without a success !
    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, &amp;
           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;

       av_init_packet( &amp; 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);
       }

       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) &lt; 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);
       }


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

       while (avpkt.size > 0) {
           int i, ch;
           int got_frame = 0;

           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);
               }
           }

           len = avcodec_decode_audio4(c, decoded_frame, &amp; got_frame, &amp; avpkt);
           if (len &lt; 0) {
               fprintf(stderr, "Error while decoding\n");
               LOGE("Error while decoding\n");
               exit(1);
           }
           if (got_frame) {
               /* if a frame has been decoded, output it */
               int data_size = av_get_bytes_per_sample(c - > sample_fmt);
               if (data_size &lt; 0) {
                   /* This should not occur, checking just for paranoia */
                   fprintf(stderr, "Failed to calculate data size\n");
                   LOGE("Failed to calculate data size\n");
                   exit(1);
               }
               if (data_size > 0) {

                   jbyte * bytes = ( * env) - > GetByteArrayElements(env, array, NULL);
                   memcpy(bytes, decoded_frame, got_frame); //
                   ( * env) - > ReleaseByteArrayElements(env, array, bytes, 0);
                   ( * env) - > CallVoidMethod(env, obj, play, array, got_frame);
                   LOGE("DECODING ERROR5");
               }
           }
           avpkt.size -= len;
           avpkt.data += len;
           avpkt.dts =
               avpkt.pts = AV_NOPTS_VALUE;
           if (avpkt.size &lt; 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( &amp; c);
       av_frame_free( &amp; 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];

           try {
               os = new FileOutputStream("/storage/emulated/0/Cloud Radio/a.out", false);
           } catch (FileNotFoundException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
           }
      audio_decode_example("/storage/emulated/0/Cloud Radio/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);

           try {
               os.write(buf, 0, size);
           } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
           }
       }
    }

    I always got this error : Error while decoding .
    i’ve tried to change the decoder "AV_CODEC_ID_MP3" no sucess !
    Thank you so much for your help.
    Kind regards