Recherche avancée

Médias (0)

Mot : - Tags -/page unique

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

Autres articles (13)

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

  • 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

  • Gestion des droits de création et d’édition des objets

    8 février 2011, par

    Par défaut, beaucoup de fonctionnalités sont limitées aux administrateurs mais restent configurables indépendamment pour modifier leur statut minimal d’utilisation notamment : la rédaction de contenus sur le site modifiables dans la gestion des templates de formulaires ; l’ajout de notes aux articles ; l’ajout de légendes et d’annotations sur les images ;

Sur d’autres sites (2199)

  • FFmpeg H264 parsing

    20 mai 2015, par Yoohoo

    I am using FFmpeg to decoding H.264 video, for the following program :

       #include
       #include
       #include
       #include

       #include <sys></sys>time.h>
       #include

    #include <libavcodec></libavcodec>avcodec.h>
    #include <libavutil></libavutil>mathematics.h>

    #include <sdl></sdl>SDL.h>

    void sigint_handler(int signal) {
       printf("\n");
       exit(0);
    }

    const char *window_title;
    SDL_Surface *screen;
    SDL_Overlay *yuv_overlay;

    #define INBUF_SIZE 80000

    /*
    * Video decoding example
    */

    static long get_time_diff(struct timeval time_now) {
      struct timeval time_now2;
      gettimeofday(&amp;time_now2,0);
      return time_now2.tv_sec*1.e6 - time_now.tv_sec*1.e6 + time_now2.tv_usec - time_now.tv_usec;
    }

    int video_open(AVCodecContext *avctx, const char *filename){
       int flags = SDL_HWSURFACE|SDL_ASYNCBLIT|SDL_HWACCEL;
       int w,h;

       flags |= SDL_RESIZABLE;

       if (avctx->width){
           w = avctx->width;
           h = avctx->height;
       } else {
           w = 640;
           h = 480;
       }

       if(SDL_Init(SDL_INIT_VIDEO) &lt; 0) {
       fprintf(stderr, "SDL_INIT_VIDEO failed!\n");
       exit(1);
       }

       screen = SDL_SetVideoMode(w, h, 0, flags);

       if (!screen) {
           fprintf(stderr, "SDL: could not set video mode - exiting\n");
           return -1;
       }
       if (!window_title)
           window_title = filename;
       SDL_WM_SetCaption(window_title, window_title);

       yuv_overlay = SDL_CreateYUVOverlay(w, h, SDL_YV12_OVERLAY, screen);

       if (yuv_overlay->hw_overlay) {
       fprintf(stderr, "Using hardware overlay!\n");
       }

       return 0;
    }

    int main(int argc, char **argv) {
       AVCodec *codec;
       AVCodecContext *c= NULL;
       AVCodecParserContext *parser = NULL;
       int frame, got_picture, len2, len;
       const char *filename;
       FILE *f;
       AVFrame *picture;
       char *arghwtf = malloc(INBUF_SIZE);
       char *luma = NULL;
       char *chroma = NULL;
       int i=0;
       uint64_t in_len;
       int pts, dts;
       struct timeval t;
       float inv_fps = 1e6/23.98;
       AVPacket avpkt;
       SDL_Rect rect;


       /* register all the codecs */
       avcodec_register_all();

       filename = argv[1];

       av_init_packet(&amp;avpkt);

       printf("Decoding file %s...\n", filename);

       /* find the H.264 video decoder */
       codec = avcodec_find_decoder(CODEC_ID_H264);
       if (!codec) {
           fprintf(stderr, "codec not found\n");
           exit(1);
       }

       c = avcodec_alloc_context3(codec);
       picture = avcodec_alloc_frame();

       c->skip_loop_filter = 48; // skiploopfilter=all

       if (avcodec_open(c, codec) &lt; 0) {
           fprintf(stderr, "could not open codec\n");
           exit(1);
       }

       /* the codec gives us the frame size, in samples */
       parser = av_parser_init(c->codec_id);
       parser->flags |= PARSER_FLAG_ONCE;

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

       frame = 0;
       gettimeofday(&amp;t, 0);
       if(fread(arghwtf, 1, INBUF_SIZE, f) == 0) {
       exit(1);
       }
       in_len = 80000;
           while (in_len > 0 &amp;&amp; !feof(f)) {
           len = av_parser_parse2(parser, c, &amp;avpkt.data, &amp;avpkt.size, arghwtf, in_len,
                                      pts, dts, AV_NOPTS_VALUE);

               len2 = avcodec_decode_video2(c, picture, &amp;got_picture, &amp;avpkt);
               if (len2 &lt; 0) {
                   fprintf(stderr, "Error while decoding frame %d\n", frame);
                   exit(1);
               }
               if (got_picture) {
           if(!screen) {
               video_open(c, filename);

               rect.x = 0;
               rect.y = 0;
               rect.w = c->width;
               rect.h = c->height;
               inv_fps = av_q2d(c->time_base);
               fprintf(stderr, "w:%i h:%i\n", rect.w, rect.h);

               luma = malloc(c->width*c->height);
               chroma = malloc(c->width*c->height/4);

               SDL_DisplayYUVOverlay(yuv_overlay, &amp;rect);

               signal(SIGINT, sigint_handler);
           }
                   fprintf(stderr, "\rDisplaying %c:frame %3d (%02d:%02d)...", av_get_pict_type_char(picture->pict_type), frame, frame/1440, (frame/24)%60);
                   fflush(stderr);

           SDL_LockYUVOverlay(yuv_overlay);

                   for(i=0;iheight;i++) {
                     memcpy(luma + i * c->width, picture->data[0] + i * picture->linesize[0], c->width);
                   }
           memcpy(yuv_overlay->pixels[0], luma, c->width * c->height);
                   for(i=0;iheight/2;i++) {
                     memcpy(chroma + i * c->width/2, picture->data[2] + i * picture->linesize[2], c->width/2);
                   }
           memcpy(yuv_overlay->pixels[1], chroma, c->width * c->height / 4);
                   for(i=0;iheight/2;i++) {
                     memcpy(chroma + i * c->width/2, picture->data[1] + i * picture->linesize[1], c->width/2);
                   }
           memcpy(yuv_overlay->pixels[2], chroma, c->width * c->height / 4);

           SDL_UnlockYUVOverlay(yuv_overlay);
           SDL_DisplayYUVOverlay(yuv_overlay, &amp;rect);

           while(get_time_diff(t) &lt; inv_fps) {
               sleep(1000);
           }
                   frame++;
           gettimeofday(&amp;t, 0);
               }
           memcpy(arghwtf, arghwtf + len, 80000-len);
           fread(arghwtf + 80000 - len, 1, len, f);
           }

       /* some codecs, such as MPEG, transmit the I and P frame with a
          latency of one frame. You must do the following to have a
          chance to get the last frame of the video */
       avpkt.data = NULL;
       avpkt.size = 0;
       len = avcodec_decode_video2(c, picture, &amp;got_picture, &amp;avpkt);
       if (got_picture) {
           printf("saving last frame %3d\n", frame);
           fflush(stdout);

       /* Display last frame here, same code as in the decoding loop above. */

           frame++;
       }

       fclose(f);

       avcodec_close(c);
       av_free(c);
       av_free(picture);
       printf("\n");
    }

    It gives error :

    ||=== H264_decoding, Debug ===|
    /home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp||In function ‘int main(int, char**)’:|
    /home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|107|error: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]|
    /home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|136|warning: ‘AVFrame* avcodec_alloc_frame()’ is deprecated (declared at /home/yoohoo/ffmpeg_build/include/libavcodec/avcodec.h:3629) [-Wdeprecated-declarations]|
    /home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|136|warning: ‘AVFrame* avcodec_alloc_frame()’ is deprecated (declared at /home/yoohoo/ffmpeg_build/include/libavcodec/avcodec.h:3629) [-Wdeprecated-declarations]|
    /home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|138|error: invalid conversion from ‘int’ to ‘AVDiscard’ [-fpermissive]|
    /home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|140|error: ‘avcodec_open’ was not declared in this scope|
    /home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|163|error: invalid conversion from ‘char*’ to ‘const uint8_t* {aka const unsigned char*}’ [-fpermissive]|
    /home/yoohoo/ffmpeg_build/include/libavcodec/avcodec.h|4465|error:   initializing argument 5 of ‘int av_parser_parse2(AVCodecParserContext*, AVCodecContext*, uint8_t**, int*, const uint8_t*, int, int64_t, int64_t, int64_t)’ [-fpermissive]|
    /home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|181|error: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]|
    /home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|182|error: invalid conversion from ‘void*’ to ‘char*’ [-fpermissive]|
    /home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|188|error: ‘av_get_pict_type_char’ was not declared in this scope|
    /home/yoohoo/codeblocks/Real-time video streaming/H264_decoding/main.cpp|210|error: ‘sleep’ was not declared in this scope|
    ||=== Build finished: 9 errors, 2 warnings ===|

    I am wondering it is an incompatible problem due to I move this C program to C++, but I finally need to use it in C++. How to solve these invalid conversion problem ? Thanks in advance !

  • Cannot save animation in matplotlib : Windows permission denied

    13 mai 2015, par Vladimir

    I’ve been trying for a day long to sort this out, checking similar threads but with no success.
    Stretch’s Cannot save matplotlib animation with ffmpeg helped with previous errors (I had ffmpeg path wrong), but I kept getting Access denied after fixing it.

    My ffmpeg binary is on C:\ffmpeg\bin

    A nice alternative would be to able to export gif files, but I keep getting an ascii error with imagemagick. I think both problems are related, so I wanted to sort out the ffmpeg first.

    I think the problem might have to do with the fact I’m working with Canopy (in Windows 8 64bit), which pretty much hegemonized my path variable and broke some things along the way (e.g. I can’t open IDLE since I installed Canopy, didn’t tried to fix that yet). As I fixed things along the way I found at least 3 distinct path variables, all of which I updated : windows advanced settings path (set manually), windows console path (set via console with setx), and sys.path (set or checked at runtime), adding ";C:\ffmpeg\bin", where ffmpeg effectively is. Regardless I sort out the problem or not, I would like to learn which of these environment variables are relevant for what, I find it very confusing.

    The code is the following :

    # -*- coding: utf-8 -*-
    import sys
    import numpy as np
    from matplotlib import pyplot as plt
    from matplotlib import animation
    plt.rcParams['animation.ffmpeg_path'] = r'C:\ffmpeg\bin'
    if r'C:\ffmpeg\bin' not in sys.path: sys.path.append(r'C:\ffmpeg\bin')

    fig = plt.figure()
    ax = plt.axes(xlim=(0, 2), ylim=(-2, 2))
    line, = ax.plot([], [], lw=2)

    def init():
       line.set_data([], [])
       return line,

    def animate(i):
       x = np.linspace(0, 2, 1000)
       y = np.sin(2 * np.pi * (x - 0.01 * i))
       line.set_data(x, y)
       return line,

    anim = animation.FuncAnimation(fig, animate, init_func=init, frames=200, interval=20, blit=True)
    plt.show()

    # This case generates Windows err: Access Denied
    FFwriter = animation.FFMpegWriter()
    # anim.save(r'C:\basic_animation.mp4', writer = FFwriter, fps=30)

    # This case generates UnicodeDecodeError:'ascii' codec can't decode byte 0xa0 in position 3
    # anim.save(r'C:\animation.gif', writer='imagemagick', fps=30)

    The traceback for anim.save(r'C:\basic_animation.mp4', writer = FFwriter, fps=30) :

    %run "C:\Users\Yahveh\Documents\Vlad\Investigacion\animation saving.py"
    ---------------------------------------------------------------------------
    WindowsError                              Traceback (most recent call last)
    C:\Users\Yahveh\Documents\Vlad\Investigacion\animation saving.py in <module>()
        27 # This case generates Windows err: Access Denied
        28 FFwriter = animation.FFMpegWriter()
    ---> 29 anim.save(r'C:\basic_animation.mp4', writer = FFwriter, fps=30)
        30
        31 # This case generates UnicodeDecodeError:'ascii' codec can't decode byte 0xa0 in position 3

    C:\Users\Yahveh\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\animation.pyc in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs)
       759         # since GUI widgets are gone. Either need to remove extra code to
       760         # allow for this non-existant use case or find a way to make it work.
    --> 761         with writer.saving(self._fig, filename, dpi):
       762             for data in zip(*[a.new_saved_frame_seq()
       763                               for a in all_anim]):

    C:\Users\Yahveh\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.2.2785.win-x86_64\lib\contextlib.pyc in __enter__(self)
        15     def __enter__(self):
        16         try:
    ---> 17             return self.gen.next()
        18         except StopIteration:
        19             raise RuntimeError("generator didn't yield")

    C:\Users\Yahveh\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\animation.pyc in saving(self, *args)
       184         '''
       185         # This particular sequence is what contextlib.contextmanager wants
    --> 186         self.setup(*args)
       187         yield
       188         self.finish()

    C:\Users\Yahveh\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\animation.pyc in setup(self, fig, outfile, dpi, *args)
       174         # Run here so that grab_frame() can write the data to a pipe. This
       175         # eliminates the need for temp files.
    --> 176         self._run()
       177
       178     @contextlib.contextmanager

    C:\Users\Yahveh\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\animation.pyc in _run(self)
       202                                       stdout=output, stderr=output,
       203                                       stdin=subprocess.PIPE,
    --> 204                                       creationflags=subprocess_creation_flags)
       205
       206     def finish(self):

    C:\Users\Yahveh\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.2.2785.win-x86_64\lib\subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
       707                                 p2cread, p2cwrite,
       708                                 c2pread, c2pwrite,
    --> 709                                 errread, errwrite)
       710         except Exception:
       711             # Preserve original exception in case os.close raises.

    C:\Users\Yahveh\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.5.2.2785.win-x86_64\lib\subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
       955                                          env,
       956                                          cwd,
    --> 957                                          startupinfo)
       958             except pywintypes.error, e:
       959                 # Translate pywintypes.error to WindowsError, which is

    WindowsError: [Error 5] Acceso denegado
    </module>

    The traceback for anim.save(r'C:\animation.gif', writer='imagemagick', fps=30) :

    In [8]: %run "C:\Users\Yahveh\Documents\Vlad\Investigacion\animation saving.py"
    ---------------------------------------------------------------------------
    UnicodeDecodeError                        Traceback (most recent call last)
    C:\Users\Yahveh\Documents\Vlad\Investigacion\animation saving.py in <module>()
        30
        31 # This case generates UnicodeDecodeError:'ascii' codec can't decode byte 0xa0 in position 3
    ---> 32 anim.save(r'C:\animation.gif', writer='imagemagick', fps=30)

    C:\Users\Yahveh\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\animation.pyc in save(self, filename, writer, fps, dpi, codec, bitrate, extra_args, metadata, extra_anim, savefig_kwargs)
       765                     # TODO: Need to see if turning off blit is really necessary
       766                     anim._draw_next_frame(d, blit=False)
    --> 767                 writer.grab_frame(**savefig_kwargs)
       768
       769         # Reconnect signal for first draw if necessary

    C:\Users\Yahveh\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\animation.pyc in grab_frame(self, **savefig_kwargs)
       225             verbose.report('MovieWriter -- Error '
       226                            'running proc:\n%s\n%s' % (out,
    --> 227                                                       err), level='helpful')
       228             raise
       229

    UnicodeDecodeError: 'ascii' codec can't decode byte 0xa0 in position 3: ordinal not in range(128)
    </module>

    Stared at them for a while.

    Thanks for your time !

    UPDATE : I followed the steps in this post for granting access to both C :\ffmpeg and destination folder, but no luck :(

  • Android FFmpeg Video Recording Delete Last Recorded Part

    17 avril 2015, par user3587194

    I’m trying to do exactly what this picture shows.

    Anyway, how can I delete part of a video ? The code I was testing is on github.

    It uses a progress bar so that when you record the progress bar will move, and keep them in separate segments. What is confusing to me is trying to figure out where and how to grab each segment to see if I want to delete that segment or not.

    @Override
    public void onPreviewFrame(byte[] data, Camera camera) {

       long frameTimeStamp = 0L;

       if (mAudioTimestamp == 0L &amp;&amp; firstTime > 0L)
           frameTimeStamp = 1000L * (System.currentTimeMillis() - firstTime);

       else if (mLastAudioTimestamp == mAudioTimestamp)
           frameTimeStamp = mAudioTimestamp + frameTime;

       else {
           long l2 = (System.nanoTime() - mAudioTimeRecorded) / 1000L;
           frameTimeStamp = l2 + mAudioTimestamp;
           mLastAudioTimestamp = mAudioTimestamp;
       }

       synchronized (mVideoRecordLock) {
           //Log.e("recorder", "mVideoRecordLock " + mVideoRecordLock);

           if (recording &amp;&amp; rec &amp;&amp; lastSavedframe != null &amp;&amp; lastSavedframe.getFrameBytesData() != null &amp;&amp; yuvIplImage != null) {

               if (isFirstFrame) {
                   isFirstFrame = false;
                   firstData = data;
               }

               totalTime = System.currentTimeMillis() - firstTime - pausedTime - ((long) (1.0 / (double) frameRate) * 1000);

               if (lastSavedframe != null &amp;&amp; !deleteEnabled) {
                   deleteEnabled = true;
                   deleteBtn.setVisibility(View.VISIBLE);
                   cancelBtn.setVisibility(View.GONE);
               }

               if (!nextEnabled &amp;&amp; totalTime >= recordingChangeTime) {
                   Log.e("recording", "totalTime >= recordingChangeTime " + totalTime + " " + recordingChangeTime);
                   nextEnabled = true;
                   nextBtn.setVisibility(View.VISIBLE);
               }

               if (nextEnabled &amp;&amp; totalTime >= recordingMinimumTime) {
                   mHandler.sendEmptyMessage(5);
               }

               if (currentRecorderState == RecorderState.PRESS &amp;&amp; totalTime >= recordingChangeTime) {
                   currentRecorderState = RecorderState.LOOSEN;
                   mHandler.sendEmptyMessage(2);
               }              
               mVideoTimestamp += frameTime;

               if (lastSavedframe.getTimeStamp() > mVideoTimestamp)
                   mVideoTimestamp = lastSavedframe.getTimeStamp();

               try {
                   yuvIplImage.getByteBuffer().put(lastSavedframe.getFrameBytesData());
                   videoRecorder.setTimestamp(lastSavedframe.getTimeStamp());
                   videoRecorder.record(yuvIplImage);

               } catch (com.googlecode.javacv.FrameRecorder.Exception e) {
                       e.printStackTrace();
               }

           }
           byte[] tempData = rotateYUV420Degree90(data, previewWidth, previewHeight);

           if (cameraSelection == 1)
               tempData = rotateYUV420Degree270(data, previewWidth, previewHeight);
           lastSavedframe = new SavedFrames(tempData, frameTimeStamp);
           //Log.e("recorder", "lastSavedframe " + lastSavedframe);
           }
       }
    }






    public class Util {

    public static ContentValues videoContentValues = null;

    public static String getRecordingTimeFromMillis(long millis) {

       String strRecordingTime = null;

       int seconds = (int) (millis / 1000);
       int minutes = seconds / 60;
       int hours = minutes / 60;

       if (hours >= 0 &amp;&amp; hours &lt; 10)
           strRecordingTime = "0" + hours + ":";
       else
           strRecordingTime = hours + ":";

       if (hours > 0)
           minutes = minutes % 60;

       if (minutes >= 0 &amp;&amp; minutes &lt; 10)
           strRecordingTime += "0" + minutes + ":";
       else
           strRecordingTime += minutes + ":";

       seconds = seconds % 60;

       if (seconds >= 0 &amp;&amp; seconds &lt; 10)
           strRecordingTime += "0" + seconds ;
       else
           strRecordingTime += seconds ;

       return strRecordingTime;
    }

    public static int determineDisplayOrientation(Activity activity, int defaultCameraId) {

       int displayOrientation = 0;

       if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
           CameraInfo cameraInfo = new CameraInfo();
           Camera.getCameraInfo(defaultCameraId, cameraInfo);

           int degrees  = getRotationAngle(activity);

           if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
               displayOrientation = (cameraInfo.orientation + degrees) % 360;
               displayOrientation = (360 - displayOrientation) % 360;

           } else {
               displayOrientation = (cameraInfo.orientation - degrees + 360) % 360;
           }
       }
       return displayOrientation;
    }

    public static int getRotationAngle(Activity activity) {

       int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
       int degrees  = 0;

       switch (rotation) {
       case Surface.ROTATION_0:
           degrees = 0;
           break;

       case Surface.ROTATION_90:
           degrees = 90;
           break;

       case Surface.ROTATION_180:
           degrees = 180;
           break;

       case Surface.ROTATION_270:
           degrees = 270;
           break;
       }
       return degrees;
    }

    public static int getRotationAngle(int rotation) {

       int degrees  = 0;

       switch (rotation) {
       case Surface.ROTATION_0:
           degrees = 0;
           break;

       case Surface.ROTATION_90:
           degrees = 90;
           break;

       case Surface.ROTATION_180:
           degrees = 180;
           break;

       case Surface.ROTATION_270:
           degrees = 270;
           break;
       }
       return degrees;
    }

    public static String createImagePath(Context context){
       long dateTaken = System.currentTimeMillis();
       String title = Constants.FILE_START_NAME + dateTaken;
       String filename = title + Constants.IMAGE_EXTENSION;

       String dirPath = Environment.getExternalStorageDirectory()+"/Android/data/" + context.getPackageName()+"/video";
       File file = new File(dirPath);

       if(!file.exists() || !file.isDirectory())
           file.mkdirs();

       String filePath = dirPath + "/" + filename;
       return filePath;
    }

    public static String createFinalPath(Context context) {
       Log.e("util", "createFinalPath");
       long dateTaken = System.currentTimeMillis();
       String title = Constants.FILE_START_NAME + dateTaken;
       String filename = title + Constants.VIDEO_EXTENSION;
       String filePath = genrateFilePath(context, String.valueOf(dateTaken), true, null);

       ContentValues values = new ContentValues(7);
       values.put(Video.Media.TITLE, title);
       values.put(Video.Media.DISPLAY_NAME, filename);
       values.put(Video.Media.DATE_TAKEN, dateTaken);
       values.put(Video.Media.MIME_TYPE, "video/3gpp");
       values.put(Video.Media.DATA, filePath);
       videoContentValues = values;

       Log.e("util", "filePath " + filePath);
       return filePath;
    }

    public static void deleteTempVideo(Context context) {
       final String filePath = Environment.getExternalStorageDirectory() + "/Android/data/" + context.getPackageName() + "/video";
       new Thread(new Runnable() {

           @Override
           public void run() {
               File file = new File(filePath);
               if (file != null &amp;&amp; file.isDirectory()) {
                   Log.e("util", "file.isDirectory() " + file.isDirectory());
                   for (File file2 : file.listFiles()) {
                       Log.e("util", "file.listFiles() " + file.listFiles());
                       file2.delete();
                   }
               }
           }
       }).start();
    }

    private static String genrateFilePath(Context context,String uniqueId, boolean isFinalPath, File tempFolderPath) {
       String fileName = Constants.FILE_START_NAME + uniqueId + Constants.VIDEO_EXTENSION;
       String dirPath = Environment.getExternalStorageDirectory() + "/Android/data/" + context.getPackageName() + "/video";

       if (isFinalPath) {
           File file = new File(dirPath);
           if (!file.exists() || !file.isDirectory())
               file.mkdirs();
       } else
           dirPath = tempFolderPath.getAbsolutePath();
       String filePath = dirPath + "/" + fileName;
       return filePath;
    }

    public static String createTempPath(Context context, File tempFolderPath ) {
       long dateTaken = System.currentTimeMillis();
       String filePath = genrateFilePath(context,String.valueOf(dateTaken), false, tempFolderPath);
       return filePath;
    }

    public static File getTempFolderPath() {
       File tempFolder = new File(Constants.TEMP_FOLDER_PATH +"_" +System.currentTimeMillis());
       return tempFolder;
    }

    public static List getResolutionList(Camera camera) {
       Parameters parameters = camera.getParameters();
       List previewSizes = parameters.getSupportedPreviewSizes();
       return previewSizes;
    }

    public static RecorderParameters getRecorderParameter(int currentResolution) {
       RecorderParameters parameters = new RecorderParameters();
       if (currentResolution ==  Constants.RESOLUTION_HIGH_VALUE) {
           parameters.setAudioBitrate(128000);
           parameters.setVideoQuality(0);

       } else if (currentResolution ==  Constants.RESOLUTION_MEDIUM_VALUE) {
           parameters.setAudioBitrate(128000);
           parameters.setVideoQuality(5);

       } else if (currentResolution == Constants.RESOLUTION_LOW_VALUE) {
           parameters.setAudioBitrate(96000);
           parameters.setVideoQuality(20);
       }
       return parameters;
    }

    public static int calculateMargin(int previewWidth, int screenWidth) {

       int margin = 0;

       if (previewWidth &lt;= Constants.RESOLUTION_LOW) {
           margin = (int) (screenWidth*0.12);

       } else if (previewWidth > Constants.RESOLUTION_LOW &amp;&amp; previewWidth &lt;= Constants.RESOLUTION_MEDIUM) {
           margin = (int) (screenWidth*0.08);

       } else if (previewWidth > Constants.RESOLUTION_MEDIUM &amp;&amp; previewWidth &lt;= Constants.RESOLUTION_HIGH) {
           margin = (int) (screenWidth*0.08);
       }
       return margin;
    }

    public static int setSelectedResolution(int previewHeight) {

       int selectedResolution = 0;

       if(previewHeight &lt;= Constants.RESOLUTION_LOW) {
           selectedResolution = 0;

       } else if (previewHeight > Constants.RESOLUTION_LOW &amp;&amp; previewHeight &lt;= Constants.RESOLUTION_MEDIUM) {
           selectedResolution = 1;

       } else if (previewHeight > Constants.RESOLUTION_MEDIUM &amp;&amp; previewHeight &lt;= Constants.RESOLUTION_HIGH) {
           selectedResolution = 2;
       }
       return selectedResolution;
    }

    public static class ResolutionComparator implements Comparator {

       @Override
       public int compare(Camera.Size size1, Camera.Size size2) {

           if(size1.height != size2.height)
               return size1.height -size2.height;
           else
               return size1.width - size2.width;
       }
    }


    public static void concatenateMultipleFiles(String inpath, String outpath)
    {
       File Folder = new File(inpath);
       File files[];
       files = Folder.listFiles();

       if(files.length>0)
       {
           for(int i = 0;ilibencoding.so";
    }

    private static HashMap getMetaData()
    {
       HashMap localHashMap = new HashMap();
       localHashMap.put("creation_time", new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss_SSSZ").format(new Date()));
       return localHashMap;
    }

    public static int getTimeStampInNsFromSampleCounted(int paramInt) {
       return (int)(paramInt / 0.0441D);
    }

    /*public static void saveReceivedFrame(SavedFrames frame) {

       File cachePath = new File(frame.getCachePath());
       BufferedOutputStream bos;

       try {
           bos = new BufferedOutputStream(new FileOutputStream(cachePath));
           if (bos != null) {
               bos.write(frame.getFrameBytesData());
               bos.flush();
               bos.close();
           }

       } catch (FileNotFoundException e) {
           e.printStackTrace();
           cachePath = null;

       } catch (IOException e) {
           e.printStackTrace();
           cachePath = null;
       }
    }*/

    public static Toast showToast(Context context, String textMessage, int timeDuration) {

       if (null == context) {
           return null;
       }

       textMessage = (null == textMessage ? "Oops! " : textMessage.trim());
       Toast t = Toast.makeText(context, textMessage, timeDuration);
       t.show();
       return t;
    }

    public static void showDialog(Context context, String title, String content, int type, final Handler handler) {
       final Dialog dialog = new Dialog(context, R.style.Dialog_loading);
       dialog.setCancelable(true);

       LayoutInflater inflater = LayoutInflater.from(context);
       View view = inflater.inflate(R.layout.global_dialog_tpl, null);

       Button confirmButton = (Button) view.findViewById(R.id.setting_account_bind_confirm);
       Button cancelButton = (Button) view.findViewById(R.id.setting_account_bind_cancel);

       TextView dialogTitle = (TextView) view.findViewById(R.id.global_dialog_title);

       View line_hori_center = view.findViewById(R.id.line_hori_center);
       confirmButton.setVisibility(View.GONE);
       line_hori_center.setVisibility(View.GONE);
       TextView textView = (TextView) view.findViewById(R.id.setting_account_bind_text);

       Window dialogWindow = dialog.getWindow();
       WindowManager.LayoutParams lp = dialogWindow.getAttributes();
       lp.width = (int) (context.getResources().getDisplayMetrics().density*288);
       dialogWindow.setAttributes(lp);

       if(type != 1 &amp;&amp; type != 2){
           type = 1;
       }
       dialogTitle.setText(title);
       textView.setText(content);

       if(type == 1 || type == 2){
           confirmButton.setVisibility(View.VISIBLE);
           confirmButton.setOnClickListener(new OnClickListener(){
               @Override
               public void onClick(View v){
                   if(handler != null){
                       Message msg = handler.obtainMessage();
                       msg.what = 1;
                       handler.sendMessage(msg);
                   }
                   dialog.dismiss();
               }
           });
       }
       // 取消按钮事件
       if(type == 2){
           cancelButton.setVisibility(View.VISIBLE);
           line_hori_center.setVisibility(View.VISIBLE);
           cancelButton.setOnClickListener(new OnClickListener(){
               @Override
               public void onClick(View v){
                   if(handler != null){
                       Message msg = handler.obtainMessage();
                       msg.what = 0;
                       handler.sendMessage(msg);
                   }
                   dialog.dismiss();
               }
           });
       }
       dialog.addContentView(view, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
       dialog.setCancelable(true);// 点击返回键关闭
       dialog.setCanceledOnTouchOutside(true);// 点击外部关闭
       dialog.show();
    }

    public IplImage getFrame(String filePath) {
       Log.e("util", "getFrame" + filePath);
       CvCapture capture = cvCreateFileCapture(filePath);
       Log.e("util", "capture " + capture);
       IplImage image = cvQueryFrame(capture);
       Log.e("util", "image " + image);
       return image;
    }