Recherche avancée

Médias (91)

Autres articles (69)

  • List of compatible distributions

    26 avril 2011, par

    The table below is the list of Linux distributions compatible with the automated installation script of MediaSPIP. Distribution nameVersion nameVersion number Debian Squeeze 6.x.x Debian Weezy 7.x.x Debian Jessie 8.x.x Ubuntu The Precise Pangolin 12.04 LTS Ubuntu The Trusty Tahr 14.04
    If you want to help us improve this list, you can provide us access to a machine whose distribution is not mentioned above or send the necessary fixes to add (...)

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

  • Le profil des utilisateurs

    12 avril 2011, par

    Chaque utilisateur dispose d’une page de profil lui permettant de modifier ses informations personnelle. Dans le menu de haut de page par défaut, un élément de menu est automatiquement créé à l’initialisation de MediaSPIP, visible uniquement si le visiteur est identifié sur le site.
    L’utilisateur a accès à la modification de profil depuis sa page auteur, un lien dans la navigation "Modifier votre profil" est (...)

Sur d’autres sites (5049)

  • Issue in recording video

    16 novembre 2015, par human123

    I am trying to record video in 480*480 resolution like in vine using javacv. As a starting point I used the sample provided in https://github.com/bytedeco/javacv/blob/master/samples/RecordActivity.java Video is getting recorded (but not in the desired resolution) and saved.

    But the issue is that 480*480 resolution is not supported natively in android. So some pre processing needs to be done to get the video in desired resolution.

    So once I was able to record video using code sample provided by javacv, next challenge was on how to pre process the video. On research it was found that efficient cropping is possible when final image width required is same as recorded image width. Such a solution was provided in the SO question,Recording video on Android using JavaCV (Updated 2014 02 17). I changed onPreviewFrame method as suggested in that answer.

       @Override
       public void onPreviewFrame(byte[] data, Camera camera) {
           if (audioRecord == null || audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
               startTime = System.currentTimeMillis();
               return;
           }
           if (RECORD_LENGTH > 0) {
               int i = imagesIndex++ % images.length;
               yuvImage = images[i];
               timestamps[i] = 1000 * (System.currentTimeMillis() - startTime);
           }
           /* get video data */
           imageWidth = 640;
           imageHeight = 480    
           int finalImageHeight = 360;
           if (yuvImage != null && recording) {
               ByteBuffer bb = (ByteBuffer)yuvImage.image[0].position(0); // resets the buffer
               final int startY = imageWidth*(imageHeight-finalImageHeight)/2;
               final int lenY = imageWidth*finalImageHeight;
               bb.put(data, startY, lenY);
               final int startVU = imageWidth*imageHeight + imageWidth*(imageHeight-finalImageHeight)/4;
               final int lenVU = imageWidth* finalImageHeight/2;
               bb.put(data, startVU, lenVU);
               try {
                   long t = 1000 * (System.currentTimeMillis() - startTime);
                   if (t > recorder.getTimestamp()) {
                       recorder.setTimestamp(t);
                   }
                   recorder.record(yuvImage);
               } catch (FFmpegFrameRecorder.Exception e) {
                   Log.e(LOG_TAG, "problem with recorder():", e);
               }
           }


       }
    }

    Please also note that this solution was provided for an older version of javacv. The resulting video had a yellowish overlay covering 2/3rd part. Also there was empty section on left side as the video was not cropped correctly.

    So my question is what is the most appropriate solution for cropping videos using latest version of javacv ?

    Code after making change as suggested by Alex Cohn

       @Override
       public void onPreviewFrame(byte[] data, Camera camera) {
           if (audioRecord == null || audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
               startTime = System.currentTimeMillis();
               return;
           }
           if (RECORD_LENGTH > 0) {
               int i = imagesIndex++ % images.length;
               yuvImage = images[i];
               timestamps[i] = 1000 * (System.currentTimeMillis() - startTime);
           }
           /* get video data */
           imageWidth = 640;
           imageHeight = 480;      
           destWidth = 480;

           if (yuvImage != null && recording) {
               ByteBuffer bb = (ByteBuffer)yuvImage.image[0].position(0); // resets the buffer
               int start = 2*((imageWidth-destWidth)/4); // this must be even
               for (int row=0; row2; row++) {
                   bb.put(data, start, destWidth);
                   start += imageWidth;
               }
               try {
                   long t = 1000 * (System.currentTimeMillis() - startTime);
                   if (t > recorder.getTimestamp()) {
                       recorder.setTimestamp(t);
                   }
                   recorder.record(yuvImage);
               } catch (FFmpegFrameRecorder.Exception e) {
                   Log.e(LOG_TAG, "problem with recorder():", e);
               }
           }


       }

    Screen shot from video generated with this code (destWidth 480) is

    video resolution 480*480

    Next I tried capturing a video with destWidth speciified as 639. The result is

    639*480

    When destWidth is 639 video is repeating contents twice. When it is 480, contents are repeated 5 times and the green overlay and distortion is more.

    Also When the destWidth = imageWidth, video is captured properly. ie, for 640*480 there is no repetition of video contents and no green overlay.

    Converting frame to IplImage

    When this question was asked first, I missed to mention that the record method in FFmpegFrameRecorder is now accepting object of type Frame whereas earlier it was IplImage object. So I tried to apply Alex Cohn’s solution by converting Frame to IplImage.

    //---------------------------------------
    // initialize ffmpeg_recorder
    //---------------------------------------
    private void initRecorder() {

       Log.w(LOG_TAG,"init recorder");

       imageWidth = 640;
       imageHeight = 480;

       if (RECORD_LENGTH > 0) {
           imagesIndex = 0;
           images = new Frame[RECORD_LENGTH * frameRate];
           timestamps = new long[images.length];
           for (int i = 0; i < images.length; i++) {
               images[i] = new Frame(imageWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
               timestamps[i] = -1;
           }
       } else if (yuvImage == null) {
           yuvImage = new Frame(imageWidth, imageHeight, Frame.DEPTH_UBYTE, 2);
           Log.i(LOG_TAG, "create yuvImage");
           OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();
           yuvIplimage = converter.convert(yuvImage);

       }

       Log.i(LOG_TAG, "ffmpeg_url: " + ffmpeg_link);
       recorder = new FFmpegFrameRecorder(ffmpeg_link, imageWidth, imageHeight, 1);
       recorder.setFormat("flv");
       recorder.setSampleRate(sampleAudioRateInHz);
       // Set in the surface changed method
       recorder.setFrameRate(frameRate);

       Log.i(LOG_TAG, "recorder initialize success");

       audioRecordRunnable = new AudioRecordRunnable();
       audioThread = new Thread(audioRecordRunnable);
       runAudioThread = true;
    }



    @Override
       public void onPreviewFrame(byte[] data, Camera camera) {
           if (audioRecord == null || audioRecord.getRecordingState() != AudioRecord.RECORDSTATE_RECORDING) {
               startTime = System.currentTimeMillis();
               return;
           }
           if (RECORD_LENGTH > 0) {
               int i = imagesIndex++ % images.length;
               yuvImage = images[i];
               timestamps[i] = 1000 * (System.currentTimeMillis() - startTime);
           }
           /* get video data */
           int destWidth = 640;

           if (yuvIplimage != null && recording) {
               ByteBuffer bb = yuvIplimage.getByteBuffer(); // resets the buffer
               int start = 2*((imageWidth-destWidth)/4); // this must be even
               for (int row=0; row2; row++) {
                   bb.put(data, start, destWidth);
                   start += imageWidth;
               }
               try {
                   long t = 1000 * (System.currentTimeMillis() - startTime);
                   if (t > recorder.getTimestamp()) {
                       recorder.setTimestamp(t);
                   }
                   recorder.record(yuvImage);
               } catch (FFmpegFrameRecorder.Exception e) {
                   Log.e(LOG_TAG, "problem with recorder():", e);
               }
           }


       }

    But the videos generated with this method contained only green frames.

  • FFMPEG android is processing slow

    23 novembre 2015, par jpc

    I’m using https://github.com/WritingMinds/ffmpeg-android-java as my framework for FFMPEG

    I’m trying to convert an image to a video using this command

    ffmpeg -y -loop 1 -i input.jpg -strict -2 -vcodec mpeg4 -t 5 -pix_fmt yuv420p out.mp4

    It took about 32 seconds to finish the process which is very slow for my requirements.

    Is there a way to speed this up ? I’m thinking of something around 5 seconds, perhaps approximately equal to the specified length of the video

    here’s the log btw

    11-23 12:12:13.587 4228-4228/com.lo.and.dev W/com.lo.and.util: WARNING: linker: /data/data/com.lo.and.dev/files/ffmpeg has text relocations. This is wasting memory and prevents security hardening. Please fix.
    11-23 12:12:13.607 4228-4228/com.lo.and.dev W/com.lo.and.util: ffmpeg version n2.4.2 Copyright (c) 2000-2014 the FFmpeg developers
    11-23 12:12:13.607 4228-4228/com.lo.and.dev W/com.lo.and.util:   built on Oct  7 2014 15:08:46 with gcc 4.8 (GCC)
    11-23 12:12:13.607 4228-4228/com.lo.and.dev W/com.lo.and.util:   configuration: --target-os=linux --cross-prefix=/home/sb/Source-Code/ffmpeg-android/toolchain-android/bin/arm-linux-androideabi- --arch=arm --cpu=cortex-a8 --enable-runtime-cpudetect --sysroot=/home/sb/Source-Code/ffmpeg-android/toolchain-android/sysroot --enable-pic --enable-libx264 --enable-libass --enable-libfreetype --enable-libfribidi --enable-fontconfig --enable-pthreads --disable-debug --disable-ffserver --enable-version3 --enable-hardcoded-tables --disable-ffplay --disable-ffprobe --enable-gpl --enable-yasm --disable-doc --disable-shared --enable-static --pkg-config=/home/sb/Source-Code/ffmpeg-android/ffmpeg-pkg-config --prefix=/home/sb/Source-Code/ffmpeg-android/build/armeabi-v7a-neon --extra-cflags='-I/home/sb/Source-Code/ffmpeg-android/toolchain-android/include -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 -fno-strict-overflow -fstack-protector-all -mfpu=neon' --extra-ldflags='-L/home/sb/Source-Code/ffmpeg-android/toolchain-android/lib -Wl,-z,relro -Wl,-z,now -pie' --extra-libs='-lpng -lexpat -lm' --extra-cxxflags=
    11-23 12:12:13.607 4228-4228/com.lo.and.dev W/com.lo.and.util:   libavutil      54.  7.100 / 54.  7.100
    11-23 12:12:13.607 4228-4228/com.lo.and.dev W/com.lo.and.util:   libavcodec     56.  1.100 / 56.  1.100
    11-23 12:12:13.607 4228-4228/com.lo.and.dev W/com.lo.and.util:   libavformat    56.  4.101 / 56.  4.101
    11-23 12:12:13.607 4228-4228/com.lo.and.dev W/com.lo.and.util:   libavdevice    56.  0.100 / 56.  0.100
    11-23 12:12:13.607 4228-4228/com.lo.and.dev W/com.lo.and.util:   libavfilter     5.  1.100 /  5.  1.100
    11-23 12:12:13.617 4228-4228/com.lo.and.dev W/com.lo.and.util:   libswscale      3.  0.100 /  3.  0.100
    11-23 12:12:13.617 4228-4228/com.lo.and.dev W/com.lo.and.util:   libswresample   1.  1.100 /  1.  1.100
    11-23 12:12:13.617 4228-4228/com.lo.and.dev W/com.lo.and.util:   libpostproc    53.  0.100 / 53.  0.100
    11-23 12:12:13.707 4228-4228/com.lo.and.dev W/com.lo.and.util: Input #0, image2, from '/storage/emulated/0/DCIM/Camera/20151122_172809.jpg':
    11-23 12:12:13.707 4228-4228/com.lo.and.dev W/com.lo.and.util:   Duration: 00:00:00.04, start: 0.000000, bitrate: 95165 kb/s
    11-23 12:12:13.717 4228-4228/com.lo.and.dev W/com.lo.and.util:     Stream #0:0: Video: mjpeg, yuvj422p(pc, bt470bg), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 25 tbr, 25 tbn, 25 tbc
    11-23 12:12:13.727 4228-4228/com.lo.and.dev W/com.lo.and.util: [swscaler @ 0xb5d89000] deprecated pixel format used, make sure you did set range correctly
    11-23 12:12:13.777 4228-4228/com.lo.and.dev W/com.lo.and.util: Output #0, mp4, to '/storage/emulated/0/DCIM/out.mp4':
    11-23 12:12:13.777 4228-4228/com.lo.and.dev W/com.lo.and.util:   Metadata:
    11-23 12:12:13.777 4228-4228/com.lo.and.dev W/com.lo.and.util:     encoder         : Lavf56.4.101
    11-23 12:12:13.777 4228-4228/com.lo.and.dev W/com.lo.and.util:     Stream #0:0: Video: mpeg4 ( [0][0][0] / 0x0020), yuv420p, 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 25 fps, 12800 tbn, 25 tbc
    11-23 12:12:13.777 4228-4228/com.lo.and.dev W/com.lo.and.util:     Metadata:
    11-23 12:12:13.777 4228-4228/com.lo.and.dev W/com.lo.and.util:       encoder         : Lavc56.1.100 mpeg4
    11-23 12:12:13.777 4228-4228/com.lo.and.dev W/com.lo.and.util: Stream mapping:
    11-23 12:12:13.777 4228-4228/com.lo.and.dev W/com.lo.and.util:   Stream #0:0 -> #0:0 (mjpeg (native) -> mpeg4 (native))
    11-23 12:12:13.777 4228-4228/com.lo.and.dev W/com.lo.and.util: Press [q] to stop, [?] for help
    11-23 12:12:14.707 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=    3 fps=0.0 q=2.0 size=     343kB time=00:00:00.12 bitrate=23400.5kbits/s    
    11-23 12:12:15.247 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=    5 fps=4.2 q=4.9 size=     345kB time=00:00:00.20 bitrate=14125.9kbits/s    
    11-23 12:12:15.737 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=    7 fps=4.0 q=10.2 size=     347kB time=00:00:00.28 bitrate=10149.8kbits/s    
    11-23 12:12:16.467 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   10 fps=4.1 q=18.9 size=     350kB time=00:00:00.40 bitrate=7167.7kbits/s    
    11-23 12:12:17.037 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   12 fps=4.0 q=24.8 size=     352kB time=00:00:00.48 bitrate=6007.9kbits/s    
    11-23 12:12:17.567 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   14 fps=3.9 q=27.8 size=     403kB time=00:00:00.56 bitrate=5893.7kbits/s    
    11-23 12:12:18.337 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   17 fps=4.0 q=31.0 size=     406kB time=00:00:00.68 bitrate=4891.5kbits/s    
    11-23 12:12:18.847 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   19 fps=3.9 q=31.0 size=     408kB time=00:00:00.76 bitrate=4398.6kbits/s    
    11-23 12:12:19.607 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   22 fps=3.9 q=31.0 size=     411kB time=00:00:00.88 bitrate=3827.4kbits/s    
    11-23 12:12:20.107 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   24 fps=3.9 q=31.0 size=     413kB time=00:00:00.96 bitrate=3525.9kbits/s    
    11-23 12:12:20.637 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   26 fps=3.9 q=31.0 size=     460kB time=00:00:01.04 bitrate=3624.3kbits/s    
    11-23 12:12:21.157 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   28 fps=3.9 q=31.0 size=     462kB time=00:00:01.12 bitrate=3381.1kbits/s    
    11-23 12:12:21.667 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   30 fps=3.9 q=31.0 size=     464kB time=00:00:01.20 bitrate=3169.7kbits/s    
    11-23 12:12:22.167 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   32 fps=3.9 q=31.0 size=     466kB time=00:00:01.28 bitrate=2984.6kbits/s    
    11-23 12:12:22.897 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   35 fps=3.9 q=31.0 size=     469kB time=00:00:01.40 bitrate=2746.8kbits/s    
    11-23 12:12:23.657 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   38 fps=3.9 q=31.0 size=     517kB time=00:00:01.52 bitrate=2788.3kbits/s    
    11-23 12:12:24.387 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   41 fps=4.0 q=31.0 size=     521kB time=00:00:01.64 bitrate=2600.1kbits/s    
    11-23 12:12:24.887 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   43 fps=3.9 q=31.0 size=     523kB time=00:00:01.72 bitrate=2488.9kbits/s    
    11-23 12:12:25.417 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   45 fps=3.9 q=31.0 size=     525kB time=00:00:01.80 bitrate=2387.6kbits/s    
    11-23 12:12:25.967 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   47 fps=3.9 q=31.0 size=     527kB time=00:00:01.88 bitrate=2294.9kbits/s    
    11-23 12:12:26.477 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   49 fps=3.9 q=24.8 size=     572kB time=00:00:01.96 bitrate=2390.0kbits/s    
    11-23 12:12:27.297 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   52 fps=3.9 q=31.0 size=     577kB time=00:00:02.08 bitrate=2271.5kbits/s    
    11-23 12:12:27.987 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   55 fps=3.9 q=31.0 size=     580kB time=00:00:02.20 bitrate=2159.1kbits/s    
    11-23 12:12:28.737 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   58 fps=3.9 q=31.0 size=     583kB time=00:00:02.32 bitrate=2058.2kbits/s    
    11-23 12:12:29.247 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   60 fps=3.9 q=31.0 size=     585kB time=00:00:02.40 bitrate=1996.6kbits/s    
    11-23 12:12:30.017 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   63 fps=3.9 q=31.0 size=     633kB time=00:00:02.52 bitrate=2057.7kbits/s    
    11-23 12:12:30.557 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   65 fps=3.9 q=31.0 size=     635kB time=00:00:02.60 bitrate=2000.8kbits/s    
    11-23 12:12:31.057 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   67 fps=3.9 q=31.0 size=     637kB time=00:00:02.68 bitrate=1947.4kbits/s    
    11-23 12:12:31.627 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   69 fps=3.9 q=31.0 size=     639kB time=00:00:02.76 bitrate=1897.0kbits/s    
    11-23 12:12:32.167 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   71 fps=3.9 q=31.0 size=     641kB time=00:00:02.84 bitrate=1849.5kbits/s    
    11-23 12:12:32.927 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   74 fps=3.9 q=31.0 size=     689kB time=00:00:02.96 bitrate=1907.2kbits/s    
    11-23 12:12:33.407 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   76 fps=3.9 q=31.0 size=     691kB time=00:00:03.04 bitrate=1862.8kbits/s    
    11-23 12:12:34.157 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   79 fps=3.9 q=31.0 size=     694kB time=00:00:03.16 bitrate=1800.0kbits/s    
    11-23 12:12:34.657 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   81 fps=3.9 q=31.0 size=     696kB time=00:00:03.24 bitrate=1760.7kbits/s    
    11-23 12:12:35.217 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   83 fps=3.9 q=31.0 size=     698kB time=00:00:03.32 bitrate=1723.3kbits/s    
    11-23 12:12:35.777 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   85 fps=3.9 q=24.8 size=     744kB time=00:00:03.40 bitrate=1791.6kbits/s    
    11-23 12:12:36.297 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   87 fps=3.9 q=31.0 size=     747kB time=00:00:03.48 bitrate=1759.6kbits/s    
    11-23 12:12:36.827 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   89 fps=3.9 q=31.0 size=     750kB time=00:00:03.56 bitrate=1724.8kbits/s    
    11-23 12:12:37.547 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   92 fps=3.9 q=31.0 size=     753kB time=00:00:03.68 bitrate=1675.4kbits/s    
    11-23 12:12:38.297 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   95 fps=3.9 q=31.0 size=     756kB time=00:00:03.80 bitrate=1629.1kbits/s    
    11-23 12:12:38.797 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=   97 fps=3.9 q=24.8 size=     801kB time=00:00:03.88 bitrate=1690.8kbits/s    
    11-23 12:12:39.547 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=  100 fps=3.9 q=31.0 size=     806kB time=00:00:04.00 bitrate=1650.2kbits/s    
    11-23 12:12:40.047 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=  102 fps=3.9 q=31.0 size=     808kB time=00:00:04.08 bitrate=1621.9kbits/s    
    11-23 12:12:40.807 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=  105 fps=3.9 q=31.0 size=     811kB time=00:00:04.20 bitrate=1581.6kbits/s    
    11-23 12:12:41.267 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=  107 fps=3.9 q=31.0 size=     813kB time=00:00:04.28 bitrate=1555.9kbits/s    
    11-23 12:12:42.057 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=  110 fps=3.9 q=31.0 size=     861kB time=00:00:04.40 bitrate=1602.8kbits/s    
    11-23 12:12:42.557 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=  112 fps=3.9 q=31.0 size=     863kB time=00:00:04.48 bitrate=1578.1kbits/s    
    11-23 12:12:43.307 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=  115 fps=3.9 q=31.0 size=     866kB time=00:00:04.60 bitrate=1542.4kbits/s    
    11-23 12:12:43.817 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=  117 fps=3.9 q=31.0 size=     868kB time=00:00:04.68 bitrate=1519.6kbits/s    
    11-23 12:12:44.517 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=  120 fps=3.9 q=31.0 size=     871kB time=00:00:04.80 bitrate=1486.8kbits/s    
    11-23 12:12:45.277 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=  123 fps=3.9 q=31.0 size=     919kB time=00:00:04.92 bitrate=1530.6kbits/s    
    11-23 12:12:45.987 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=  125 fps=3.9 q=31.0 size=     921kB time=00:00:05.00 bitrate=1509.4kbits/s    
    11-23 12:12:45.987 4228-4228/com.lo.and.dev W/com.lo.and.util: frame=  125 fps=3.9 q=31.0 Lsize=     923kB time=00:00:05.00 bitrate=1511.6kbits/s    
    11-23 12:12:45.987 4228-4228/com.lo.and.dev W/com.lo.and.util: video:921kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.148301%
  • Unable to merge videos in Android using JavaCV ("Sample Description" Error)

    15 décembre 2015, par San

    I am creating a video from images via FFMPEG and I am able to get the video from images. I am also making use of JavaCV to merge two videos and I am able to join videos using JavaCV without any issues provided both the videos are taken via camera, i.e, a video actually recorded via mobile camera.

    Issue that I’m facing :

    I am not able to merge the video that was generated from FFMPEG using the images along with the video user has chosen which will mostly be a video that was not generated and taken via mobile camera.

    CODE :
    Code to generate Video via Images :

                     FFmpegFrameRecorder recorder = new FFmpegFrameRecorder(path + "/" + "dec16.mp4", 800, 400);
                               try {
                                   recorder.setVideoCodec(avcodec.AV_CODEC_ID_MPEG4);
                                   //recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);
                                   recorder.setVideoCodecName("H264");
                                   recorder.setVideoOption("preset", "ultrafast");
                                   recorder.setFormat("mp4");
                                   recorder.setFrameRate(frameRate);
                                   recorder.setVideoBitrate(60);
                                   recorder.setPixelFormat(avutil.AV_PIX_FMT_YUV420P);
                                   startTime = System.currentTimeMillis();
                                   recorder.start();
                                   for(int j=0;j recorder.getTimestamp()) {

                                           recorder.setTimestamp(t);
                                           recorder.record(image);
                                       }
                                   }
                                   recorder.stop();
                               } catch (Exception e) {
                                   e.printStackTrace();
                               }

    Code to merge Videos :

    int count = file_path.size();
               System.out.println("final_joined_list size " + file_path.size());
               if (file_path.size() != 1) {
                   try {
                       Movie[] inMovies = new Movie[count];
                       mediaStorageDir = new File(
                               Environment.getExternalStorageDirectory()
                                       + "/Pictures");

                       for (int i = 0; i < count; i++) {
                           File file = new File(file_path.get(i));
                           System.out.println("fileeeeeeeeeeeeeeee " + file);
                           System.out.println("file exists!!!!!!!!!!");

                           FileInputStream fis = new FileInputStream(file);
                           FileChannel fc = fis.getChannel();
                           inMovies[i] = MovieCreator.build(fc);
                           fis.close();
                           fc.close();

                       }
                       List<track> videoTracks = new LinkedList<track>();
                       List<track> audioTracks = new LinkedList<track>();
                       Log.d("Movies length", "isss  " + inMovies.length);
                       if (inMovies.length != 0) {

                           for (Movie m : inMovies) {

                               for (Track t : m.getTracks()) {
                                   if (t.getHandler().equals("soun")) {
                                       audioTracks.add(t);
                                   }
                                   if (t.getHandler().equals("vide")) {
                                       videoTracks.add(t);
                                   }
                                   if (t.getHandler().equals("")) {

                                   }
                               }

                           }
                       }

                       Movie result = new Movie();

                       System.out.println("audio and videoo tracks : "
                               + audioTracks.size() + " , " + videoTracks.size());
                       if (audioTracks.size() > 0) {
                           result.addTrack(new AppendTrack(audioTracks
                                   .toArray(new Track[audioTracks.size()])));
                       }
                       if (videoTracks.size() > 0) {
                           result.addTrack(new AppendTrack(videoTracks
                                   .toArray(new Track[videoTracks.size()])));
                       }
                       IsoFile out = null;
                       try {
                           out = (IsoFile) new DefaultMp4Builder().build(result);
                       } catch (Exception e) {
                           // TODO Auto-generated catch block
                           e.printStackTrace();
                       }

                       long timestamp = new Date().getTime();
                       String timestampS = "" + timestamp;

                       File storagePath = new File(mediaStorageDir
                               + File.separator);
                       storagePath.mkdirs();
                       File myMovie = new File(storagePath, String.format("%s.mp4", timestampS));
                       FileOutputStream fos = new FileOutputStream(myMovie);
                       FileChannel fco = fos.getChannel();
                       fco.position(0);
                       out.getBox(fco);
                       fco.close();
                       fos.close();

                   } catch (FileNotFoundException e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
                   } catch (IOException e) {
                       // TODO Auto-generated catch block
                       e.printStackTrace();
                   }
                   String mFileName = Environment.getExternalStorageDirectory()
                           .getAbsolutePath();
                   // mFileName += "/output.mp4";

                   File sdCardRoot = Environment.getExternalStorageDirectory();
                   File yourDir = new File(mediaStorageDir + File.separator);
                   for (File f : yourDir.listFiles()) {
                       if (f.isFile())
                           name = f.getName();
                       // make something with the name
                   }
                   mFileName = mediaStorageDir.getPath() + File.separator
                           + "output-%s.mp4";
                   System.out.println("final filename : "
                           + mediaStorageDir.getPath() + File.separator
                           + "output-%s.mp4" + "names of files : " + name);
                   single_video = false;
                   return name;
               } else {
                   single_video = true;
                   name = file_path.get(0);
                   return name;
               }
    </track></track></track></track>

    Error :

    The Error that I am facing while trying to merge the videos generated via Images and a normal video is

    12-15 12:26:06.155  26022-26111/? W/System.err﹕ java.io.IOException: Cannot append com.googlecode.mp4parser.authoring.Mp4TrackImpl@45417c38 to com.googlecode.mp4parser.authoring.Mp4TrackImpl@44ffac60 since their Sample Description Boxes differ
    12-15 12:26:06.155  26022-26111/? W/System.err﹕ at com.googlecode.mp4parser.authoring.tracks.AppendTrack.<init>(AppendTrack.java:48)
    </init>

    Fix that I tried :

    Google advised me to change the CODEC in JavaCV from avcodec.AV_CODEC_ID_MPEG4 to avcodec.AV_CODEC_ID_H264. But when I did that, I am not able to get the video from images thereby throwing the following error :

    12-15 12:26:05.840  26022-26089/? W/linker﹕ libavcodec.so has text relocations. This is wasting memory and is a security risk. Please fix.
    12-15 12:26:05.975  26022-26089/? W/System.err﹕ com.googlecode.javacv.FrameRecorder$Exception: avcodec_open2() error -1: Could not open video codec.
    12-15 12:26:05.975  26022-26089/? W/System.err﹕ at com.googlecode.javacv.FFmpegFrameRecorder.startUnsafe(FFmpegFrameRecorder.java:492)
    12-15 12:26:05.975  26022-26089/? W/System.err﹕ at com.googlecode.javacv.FFmpegFrameRecorder.start(FFmpegFrameRecorder.java:267)

    What I need :

    Creating video from Images is inevitable and that video will definitely be used to merge with other videos which might have any Codec Formats. So I need to find a way to merge any kind of videos irrespective of their Codecs or any other parameters. I am trying to keep it simple by just using the Jars and SO files and I dont want to drive myself crazy by going on a full scale implementation of FFMPEG Library. That being said, I am also ready to look into that library if I dont have any other ways to achieve what I want but a solid resource with an ALMOST working code would be much appreciated. Cheers.

    Update :
    I looked upon the issues mentioned at GitHub of OpenCV, but didnt find anything solid from it.
    OpenCV Issues