Recherche avancée

Médias (1)

Mot : - Tags -/embed

Autres articles (56)

  • Pas question de marché, de cloud etc...

    10 avril 2011

    Le vocabulaire utilisé sur ce site essaie d’éviter toute référence à la mode qui fleurit allègrement
    sur le web 2.0 et dans les entreprises qui en vivent.
    Vous êtes donc invité à bannir l’utilisation des termes "Brand", "Cloud", "Marché" etc...
    Notre motivation est avant tout de créer un outil simple, accessible à pour tout le monde, favorisant
    le partage de créations sur Internet et permettant aux auteurs de garder une autonomie optimale.
    Aucun "contrat Gold ou Premium" n’est donc prévu, aucun (...)

  • Gestion de la ferme

    2 mars 2010, par

    La ferme est gérée dans son ensemble par des "super admins".
    Certains réglages peuvent être fais afin de réguler les besoins des différents canaux.
    Dans un premier temps il utilise le plugin "Gestion de mutualisation"

  • Possibilité de déploiement en ferme

    12 avril 2011, par

    MediaSPIP peut être installé comme une ferme, avec un seul "noyau" hébergé sur un serveur dédié et utilisé par une multitude de sites différents.
    Cela permet, par exemple : de pouvoir partager les frais de mise en œuvre entre plusieurs projets / individus ; de pouvoir déployer rapidement une multitude de sites uniques ; d’éviter d’avoir à mettre l’ensemble des créations dans un fourre-tout numérique comme c’est le cas pour les grandes plate-formes tout public disséminées sur le (...)

Sur d’autres sites (6855)

  • FFmpeg on Azure Function call running slowly and producing an empty output file

    7 novembre 2017, par The Lemon

    I’m trying to make a function which uses ffmpeg, so far I haven’t been able to get anything other than the -version command to work properly. When I try to run a simple ffmpeg -i {input file path} {output file path} command, the function seems to get stuck for 3-4 minutes (in the process creating an empty output file), then try again and produce the error ’file already exists’. I’ve tried switching between the 64 bit ffmpeg.exe and the 32 bit ffmpeg.exe with the function running as both a 32 and 64 bit function. My code and the associated logs from trying to run the code are included below, if anyone can tell me what I’m doing wrong or how to get the process to work it would be greatly appreciated. Thanks in advance, Cuan

    edit : The process works on kudu with the same files, the output is shown at the bottom. On kudu the process ran in under half a minute, clearly something is causing the function process to hang, if anyone has advice it would be greatly appreciated. Thanks again, Cuan.

    second edit : I tried adding the -y to the end of my command, this works in that it no longer complains about overwriting, but alas it now just hangs twice due to timeout. (output at the bottom)

    edit the third : azure has a way to let you run functions locally, my function ran into the same issues on the local version but : as it turns out the actual processing is done within a few seconds, it just takes forever to decide to write to a file - if you terminate the process manually after the process had been running for 10 seconds the file immediately gets written. Again, any help is appreciated. Cuan.

    Run.csx :

    using System.Net;
    using System;
    using System.Diagnostics;
    using System.ComponentModel;
    public static async Task<httpresponsemessage> Run(HttpRequestMessage req, TraceWriter log)
    {
       log.Info("C# HTTP trigger function processed a request.");
       Process process = new Process();
       process.StartInfo.FileName = @"D:\home\site\wwwroot\HttpTestFunction\ffmpeg64.exe";
       string tmp = String.Format("-i \"" + "Airdocs Background Video.mp4" + "\" \"" + "tmpOut2.mp4" + "\"");
       log.Info("ffmpeg argument is: "+tmp);
       process.StartInfo.Arguments = tmp;
       process.StartInfo.UseShellExecute = false;
       process.StartInfo.RedirectStandardOutput = true;
       process.StartInfo.RedirectStandardError = true;
       process.StartInfo.WorkingDirectory = @"D:\home\site\wwwroot\HttpTestFunction";
       process.Start();
       log.Info("process started");
       string output = process.StandardOutput.ReadToEnd();
       string err = process.StandardError.ReadToEnd();
       log.Info("output:" + output);
       log.Info("error:"+err);
       process.WaitForExit();
    }
    </httpresponsemessage>

    Logs :

    2017-10-14T02:17:10.514 Function started (Id=e4ec7d1e-2bcb-4b74-8af2-15124f1576fb)
    2017-10-14T02:17:10.639 C# HTTP trigger function processed a request.
    2017-10-14T02:17:10.639 ffmpeg argument is: -i "Airdocs Background Video.mp4" "tmpOut2.mp4"
    2017-10-14T02:17:10.779 process started
    2017-10-14T02:18:15  No new trace in the past 1 min(s).
    2017-10-14T02:19:15  No new trace in the past 2 min(s).
    2017-10-14T02:20:15  No new trace in the past 3 min(s).
    2017-10-14T02:21:02.188 Function started (Id=b2ae9b59-8933-42e3-986c-fd26a6886285)
    2017-10-14T02:21:02.188 C# HTTP trigger function processed a request.
    2017-10-14T02:21:02.188 ffmpeg argument is: -i "Airdocs Background Video.mp4" "tmpOut2.mp4"
    2017-10-14T02:21:02.252 process started
    2017-10-14T02:21:02.377 output:
    2017-10-14T02:21:02.377 error:ffmpeg version N-87353-g183fd30 Copyright (c) 2000-2017 the FFmpeg developers
     built with gcc 7.2.0 (GCC)
     configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib
     libavutil      55. 76.100 / 55. 76.100
     libavcodec     57.106.101 / 57.106.101
     libavformat    57. 82.101 / 57. 82.101
     libavdevice    57.  8.101 / 57.  8.101
     libavfilter     6.105.100 /  6.105.100
     libswscale      4.  7.103 /  4.  7.103
     libswresample   2.  8.100 /  2.  8.100
     libpostproc    54.  6.100 / 54.  6.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Airdocs Background Video.mp4':
     Metadata:
       major_brand     : mp42
       minor_version   : 0
       compatible_brands: mp41isom
       creation_time   : 2017-09-08T11:55:11.000000Z
     Duration: 00:00:24.02, start: 0.000000, bitrate: 105 kb/s
       Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 104 kb/s, 30.30 fps, 30.30 tbr, 30k tbn, 60 tbc (default)
       Metadata:
         creation_time   : 2017-09-08T11:55:11.000000Z
         handler_name    : VideoHandler
         encoder         : AVC Coding
    File 'tmpOut2.mp4' already exists. Overwrite ? [y/N] Not overwriting - exiting
    2017-10-14T02:21:02.392 Function completed (Success, Id=b2ae9b59-8933-42e3-986c-fd26a6886285, Duration=205ms)
    2017-10-14T02:22:10.563 Function completed (Failure, Id=e4ec7d1e-2bcb-4b74-8af2-15124f1576fb, Duration=300047ms)
    2017-10-14T02:22:10.610 Microsoft.Azure.WebJobs.Host: Timeout value of 00:05:00 was exceeded by function: Functions.HttpTestFunction.

    Kudu code (just running the ffmpeg command directly, not the run.csx file) :

    D:\home\site\wwwroot\HttpTestFunction>ffmpeg -i "Airdocs Background Video.mp4" tmpout3.mp4


    ffmpeg version N-87196-g6cadbb1 Copyright (c) 2000-2017 the FFmpeg developers
     built with gcc 7.1.0 (GCC)
     configuration: --enable-gpl --enable-version3 --enable-cuda --enable-cuvid --enable-d3d11va --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-zlib
     libavutil      55. 74.100 / 55. 74.100
     libavcodec     57.105.100 / 57.105.100
     libavformat    57. 81.100 / 57. 81.100
     libavdevice    57.  8.100 / 57.  8.100
     libavfilter     6.101.100 /  6.101.100
     libswscale      4.  7.103 /  4.  7.103
     libswresample   2.  8.100 /  2.  8.100
     libpostproc    54.  6.100 / 54.  6.100
    Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'Airdocs Background Video.mp4':
     Metadata:
       major_brand     : mp42
       minor_version   : 0
       compatible_brands: mp41isom
       creation_time   : 2017-09-08T11:55:11.000000Z
     Duration: 00:00:24.02, start: 0.000000, bitrate: 105 kb/s
       Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 104 kb/s, 30.30 fps, 30.30 tbr, 30k tbn, 60 tbc (default)
       Metadata:
         creation_time   : 2017-09-08T11:55:11.000000Z
         handler_name    : VideoHandler
         encoder         : AVC Coding
    Stream mapping:
     Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
    Press [q] to stop, [?] for help
    [libx264 @ 00000000005fc5a0] using SAR=1/1
    [libx264 @ 00000000005fc5a0] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
    [libx264 @ 00000000005fc5a0] profile High, level 3.2
    [libx264 @ 00000000005fc5a0] 264 - core 152 r2851 ba24899 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=2 b_adapt=1 b_bias=0 direct=1 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
    Output #0, mp4, to 'tmpout3.mp4':
     Metadata:
       major_brand     : mp42
       minor_version   : 0
       compatible_brands: mp41isom
       encoder         : Lavf57.81.100
       Stream #0:0(und): Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 30.30 fps, 16k tbn, 30.30 tbc (default)
       Metadata:
         creation_time   : 2017-09-08T11:55:11.000000Z
         handler_name    : VideoHandler
         encoder         : Lavc57.105.100 libx264
       Side data:
         cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
    frame=  728 fps= 39 q=29.0 Lsize=      62kB time=00:00:23.92 bitrate=  21.1kbits/s speed=1.28x    
    video:52kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 17.915474%
    [libx264 @ 00000000005fc5a0] frame I:4     Avg QP:12.46  size:  6102
    [libx264 @ 00000000005fc5a0] frame P:184   Avg QP:16.94  size:    45
    [libx264 @ 00000000005fc5a0] frame B:540   Avg QP:20.50  size:    37
    [libx264 @ 00000000005fc5a0] consecutive B-frames:  1.1%  0.0%  0.0% 98.9%
    [libx264 @ 00000000005fc5a0] mb I  I16..4: 66.3% 30.4%  3.3%
    [libx264 @ 00000000005fc5a0] mb P  I16..4:  0.0%  0.0%  0.0%  P16..4:  0.0%  0.0%  0.0%  0.0%  0.0%    skip:100.0%
    [libx264 @ 00000000005fc5a0] mb B  I16..4:  0.0%  0.0%  0.0%  B16..8:  0.0%  0.0%  0.0%  direct: 0.0%  skip:100.0%  L0:12.3% L1:87.7% BI: 0.0%
    [libx264 @ 00000000005fc5a0] 8x8 transform intra:30.5% inter:14.3%
    [libx264 @ 00000000005fc5a0] coded y,uvDC,uvAC intra: 2.3% 2.2% 2.1% inter: 0.0% 0.0% 0.0%
    [libx264 @ 00000000005fc5a0] i16 v,h,dc,p: 93%  6%  2%  0%
    [libx264 @ 00000000005fc5a0] i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 41% 31%  0%  0%  0%  0%  0%  0%
    [libx264 @ 00000000005fc5a0] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 39% 17% 16%  5%  4%  5%  6%  3%  5%
    [libx264 @ 00000000005fc5a0] i8c dc,h,v,p: 93%  6%  1%  0%
    [libx264 @ 00000000005fc5a0] Weighted P-Frames: Y:0.0% UV:0.0%
    [libx264 @ 00000000005fc5a0] ref B L1: 98.2%  1.8%
    [libx264 @ 00000000005fc5a0] kb/s:17.57



    D:\home\site\wwwroot\HttpTestFunction>

    Output on azure with the -y command

    2017-10-25T04:34:45.519 Compilation succeeded.
    2017-10-25T04:34:46.160 Function started (Id=18880991-c93a-42a3-96b6-7df283e3bdb4)
    2017-10-25T04:34:46.300 C# HTTP trigger function processed a request.
    2017-10-25T04:34:46.300 ffmpeg argument is: -i "Airdocs Background Video.mp4" "tmpOut2.mp4" -y
    2017-10-25T04:34:46.394 process started
    2017-10-25T04:36:46  No new trace in the past 1 min(s).
    2017-10-25T04:37:46  No new trace in the past 2 min(s).
    2017-10-25T04:38:37.947 Function started (Id=c7f7f768-c53b-4074-a0c2-8391848bbd80)
    2017-10-25T04:38:37.963 C# HTTP trigger function processed a request.
    2017-10-25T04:38:37.963 ffmpeg argument is: -i "Airdocs Background Video.mp4" "tmpOut2.mp4" -y
    2017-10-25T04:38:38.025 process started
    2017-10-25T04:39:46  No new trace in the past 1 min(s).
    2017-10-25T04:39:46.258 Function completed (Failure, Id=18880991-c93a-42a3-96b6-7df283e3bdb4, Duration=300079ms)
    2017-10-25T04:39:46.321 Microsoft.Azure.WebJobs.Host: Timeout value of 00:05:00 was exceeded by function: Functions.HttpTestFunction.
  • NoMethodFoundException when trying to load native methods from jar file

    20 février 2018, par Anuran Barman

    I am trying to load ffmpeg methods in android. My requirement is that I dont want to pack the .so files within the apk.Only if the user wants then only I will download the jar file and load the ffmpeg native methods.After searching I think that loading .so files at run time is not possible.So what I did that I made the so file and created a different android application with only one class FFMPEG.java whose only duty is to call the native methods from ffmpeg library.so I made the jar file and loaded that into my main application with ClassLoader. Constructor is getting called so it means class is loaded but methods are not getting loaded though they are declared public in the jar file. I am trying to stream RTSP video with FFMPEG.Below are my jar file and main application codes.

    public class FFMPEG {

       public FFMPEG(){
           Log.d(FFMPEG.class.getSimpleName(),"constructor called");
       }

       public static native int naInit(String pFileName);
       public static native int[] naGetVideoRes();
       public static native void naSetSurface(Surface pSurface);
       public static native int naSetup(int pWidth, int pHeight);
       public static native void naPlay();
       public static native void naStop();

       public static boolean loadedLibraries;

       static {
           try {
               System.loadLibrary("avutil");
               System.loadLibrary("avcodec");
               System.loadLibrary("avformat");
               System.loadLibrary("swscale");
               System.loadLibrary("avfilter");
               System.loadLibrary("ffmpeg-jni");
               loadedLibraries = true;
           } catch (Throwable e) {
               e.printStackTrace();
           }
       }

       public int libInit(String filename){
           return  naInit(filename);
       }

       public int[] libGetVideoRes(){
           return  naGetVideoRes();
       }
       public void libSetSurface(Surface surface){
           naSetSurface(surface);
       }
       public int libSetup(int width,int height){
           return naSetup(width,height);
       }
       public void libPlay(){
           naPlay();
       }
       public void libStop(){
           naStop();
       }
    }

    My main application activity code.The jar file location in my sdcard named camlib.jar

    @SuppressWarnings("JniMissingFunction")
    public class MainActivity extends AppCompatActivity implements SurfaceHolder.Callback {

       private SurfaceView surfaceView;
       private ProgressBar progressBar;
       private final String TAG=MainActivity.class.getSimpleName();

       private boolean isPlaying;
       private boolean isClassLoaded;
       private boolean isInitialized;
       private String url="";
       Method libInit,libGetVideoRes,libSetSurface,libSetup,libPlay,libStop;
       Object myInstance;
       @Override
       protected void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
           setContentView(R.layout.activity_main);
           surfaceView = (SurfaceView) findViewById(R.id.surfaceView);
           progressBar = ((ProgressBar) findViewById(R.id.progressBar));
           surfaceView.getHolder().addCallback(this);
           int permission= ActivityCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
           if(permission== PackageManager.PERMISSION_GRANTED){
               loadClass();
           }else{
               ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},200);
           }

       }

       @Override
       public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
           super.onRequestPermissionsResult(requestCode, permissions, grantResults);
           if(requestCode==200){
               if(grantResults.length>0){
                   if (grantResults[0]==PackageManager.PERMISSION_GRANTED){
                       loadClass();
                   }else{
                       ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},200);
                   }
               }
           }
       }

       public void loadClass(){
           try {
               final String libPath = Environment.getExternalStorageDirectory() + "/camlib.jar";
               final File tmpDir = getDir("dex", 0);

               final DexClassLoader classloader = new DexClassLoader(libPath, tmpDir.getAbsolutePath(), null, this.getClass().getClassLoader());
               final Class classToLoad = (Class) classloader.loadClass("com.myeglu.obbapplication.FFMPEG");

                myInstance  = classToLoad.newInstance();
                libInit= classToLoad.getMethod("libInit");
                libGetVideoRes=classToLoad.getMethod("libGetVideoRes");
                libSetSurface=classToLoad.getMethod("libSetSurface");
                libSetup=classToLoad.getMethod("libSetup");
                libPlay=classToLoad.getMethod("libPlay");
                libStop=classToLoad.getMethod("libStop");
                isClassLoaded=true;
                new PlayVideo().execute();

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

       private void postInit() {
           if (isInitialized) {
               initPlay();
               progressBar.setVisibility(View.GONE);
           } else {
               finish();
           }
       }

       private void initPlay() {
           try {
               int[] res = (int[])libGetVideoRes.invoke(myInstance);
               Log.d("ANURAN", "res width " + res[0] + ": height " + res[1]);
               if (res[0] &lt;= 0) {
                   res[0] = 480;
               }
               if (res[1] &lt;= 0) {
                   res[1] = 320;
               }
               int[] screenRes = getScreenRes();
               int width, height;
               float widthScaledRatio = screenRes[0] * 1.0f / res[0];
               float heightScaledRatio = screenRes[1] * 1.0f / res[1];
               if (widthScaledRatio > heightScaledRatio) {
                   //use heightScaledRatio
                   width = (int) (res[0] * heightScaledRatio);
                   height = screenRes[1];
               } else {
                   //use widthScaledRatio
                   width = screenRes[0];
                   height = (int) (res[1] * widthScaledRatio);
               }
               Log.d(TAG, "width " + width + ",height:" + height);
               updateSurfaceView(width, height);
               libSetup.invoke(myInstance,width,height);
               playMedia();
           }catch (Exception e){

           }
       }

       private void playMedia() {
           try {
               if (progressBar.getVisibility() == View.VISIBLE) {
                   progressBar.setVisibility(View.GONE);
               }
               libPlay.invoke(myInstance);
               isPlaying = true;
           }catch (Exception e){

           }
       }
       private void updateSurfaceView(int pWidth, int pHeight) {
           //update surfaceview dimension, this will cause the native window to change
           Log.d("ANURAN UPDATE SURFACE", "width " + pWidth + ",height:" + pHeight);
           FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) surfaceView.getLayoutParams();
           params.width = pWidth;
           params.height = pHeight;
           surfaceView.setLayoutParams(params);
       }

       @SuppressLint("NewApi")
       private int[] getScreenRes() {
           int[] res = new int[2];
           Display display = getWindowManager().getDefaultDisplay();
           Point size = new Point();
           display.getSize(size);
           res[0] = size.x;
           res[1] = size.y;
           return res;
       }

       @Override
       protected void onStop() {
           super.onStop();
           Toast.makeText(MainActivity.this,"onStop called",Toast.LENGTH_SHORT).show();
           stopPlaying();
           finish();
       }

       @Override
       public void onBackPressed() {
           stopPlaying();
           finish();
       }

       private void stopPlaying() {
           isPlaying = false;
           try{
               libStop.invoke(myInstance);
           }catch (Exception e){

           }
       }

       @Override
       protected void onDestroy() {
           super.onDestroy();
           stopPlaying();
           finish();
       }



       @Override
       protected void onRestart() {
           super.onRestart();
           Toast.makeText(MainActivity.this,"onRestart called",Toast.LENGTH_SHORT).show();
           progressBar.setVisibility(View.VISIBLE);

       }


       @Override
       public void surfaceChanged(SurfaceHolder holder, int format, int width,
                                  int height) {

           if(isClassLoaded){
               try {
                   libSetSurface.invoke(myInstance,holder.getSurface());
               } catch (IllegalAccessException e) {
                   e.printStackTrace();
               } catch (InvocationTargetException e) {
                   e.printStackTrace();
               }
           }

       }

       @Override
       public void surfaceCreated(SurfaceHolder holder) {

       }

       @Override
       public void surfaceDestroyed(SurfaceHolder holder) {
           if(isClassLoaded) {
               try {
                   libSetSurface.invoke(myInstance, null);
               } catch (IllegalAccessException e) {
                   e.printStackTrace();
               } catch (InvocationTargetException e) {
                   e.printStackTrace();
               }
           }
       }



       private class PlayVideo extends AsyncTask {

           @Override
           protected Void doInBackground(Void... voids) {
               try {
                   int temp=(int)libInit.invoke(myInstance,url);
                   isInitialized=(temp==0);
               } catch (IllegalAccessException e) {
                   e.printStackTrace();
               } catch (InvocationTargetException e) {
                   e.printStackTrace();
               }
               return null;
           }

           @Override
           protected void onPostExecute(Void aVoid) {
               super.onPostExecute(aVoid);
               postInit();
               this.cancel(true);
           }
       }
    }
  • Why i'm getting strange video file when using ffmpeg and pipes to create video file in real time ?

    30 juin 2015, par Brubaker Haim

    The goal here is to create a compressed mp4 video file in real time.
    I’m saving screenshots as bitmaps type on my hard disk.
    And i want to create mp4 file and compress the mp4 video file in real time.

    The problem is the end the video file i get looks very strange.
    This is the result : Strange Video File

    The class that i’m using the ffmpeg with arguments.

    using System;
    using System.Windows.Forms;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Drawing;
    using System.IO.Pipes;
    using System.Runtime.InteropServices;
    using System.Diagnostics;
    using System.IO;
    using DannyGeneral;

    namespace Youtube_Manager
    {
       class Ffmpeg
       {
           NamedPipeServerStream p;
           String pipename = "mytestpipe";
           System.Diagnostics.Process process;
           string ffmpegFileName = "ffmpeg.exe";
           string workingDirectory;

           public Ffmpeg()
           {
               workingDirectory = Path.GetDirectoryName(Application.ExecutablePath);
               Logger.Write("workingDirectory: " + workingDirectory);
               if (!Directory.Exists(workingDirectory))
               {
                   Directory.CreateDirectory(workingDirectory);
               }
               ffmpegFileName = Path.Combine(workingDirectory, ffmpegFileName);
               Logger.Write("FfmpegFilename: " + ffmpegFileName);
           }

           public void Start(string pathFileName, int BitmapRate)
           {
               try
               {

                   string outPath = pathFileName;
                   p = new NamedPipeServerStream(pipename, PipeDirection.Out, 1, PipeTransmissionMode.Byte);

                   ProcessStartInfo psi = new ProcessStartInfo();
                   psi.WindowStyle = ProcessWindowStyle.Hidden;
                   psi.UseShellExecute = false;
                   psi.CreateNoWindow = false;
                   psi.FileName = ffmpegFileName;
                   psi.WorkingDirectory = workingDirectory;
                   psi.Arguments = @"-f rawvideo -pix_fmt yuv420p -video_size 1920x1080 -i \\.\pipe\mytestpipe -map 0 -c:v mpeg4 -r " + BitmapRate + " " + outPath;
                   //psi.Arguments = @"-framerate 1/5 -i -c:v libx264 -r 30 -pix_fmt yuv420p \\.\pipe\mytestpipe -map 0 -c:v mpeg4 -r" + BitmapRate + " " + outPath;
                   process = Process.Start(psi);
                   process.EnableRaisingEvents = false;
                   psi.RedirectStandardError = true;
                   p.WaitForConnection();
               }
               catch (Exception err)
               {
                   Logger.Write("Exception Error: " + err.ToString());
               }
           }

           public void PushFrame(Bitmap bmp)
           {
               try
               {
                   int length;
                   // Lock the bitmap's bits.
                   //bmp = new Bitmap(1920, 1080);
                   Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
                   //Rectangle rect = new Rectangle(0, 0, 1280, 720);
                   System.Drawing.Imaging.BitmapData bmpData =
                       bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadOnly,
                       bmp.PixelFormat);

                   int absStride = Math.Abs(bmpData.Stride);
                   // Get the address of the first line.
                   IntPtr ptr = bmpData.Scan0;

                   // Declare an array to hold the bytes of the bitmap.
                   //length = 3 * bmp.Width * bmp.Height;
                   length = absStride * bmpData.Height;
                   byte[] rgbValues = new byte[length];

                   //Marshal.Copy(ptr, rgbValues, 0, length);
                   int j = bmp.Height - 1;
                   for (int i = 0; i &lt; bmp.Height; i++)
                   {
                       IntPtr pointer = new IntPtr(bmpData.Scan0.ToInt32() + (bmpData.Stride * j));
                       System.Runtime.InteropServices.Marshal.Copy(pointer, rgbValues, absStride * (bmp.Height - i - 1), absStride);
                       j--;
                   }
                   p.Write(rgbValues, 0, length);
                   bmp.UnlockBits(bmpData);
               }
               catch(Exception err)
               {
                   Logger.Write("Error: " + err.ToString());
               }

           }

           public void Close()
           {
               p.Close();
           }
       }
    }

    Then i’m using the method PushFrame here in this class :

    public Bitmap GetScreenShot(string folder, string name)
       {
           _screenShot = new Bitmap(GetScreen());
           System.GC.Collect();
           System.GC.WaitForPendingFinalizers();
           string ingName = folder + name +  images.counter.ToString("D6") + ".bmp";
           _screenShot.Save(ingName,System.Drawing.Imaging.ImageFormat.Bmp);
           fmpeg.PushFrame(_screenShot);
           _screenShot.Dispose();

           return _screenShot;
       }

    The Bitmaps on the hard disk are fine i can edit/open see them.
    When using command prompt and manually type ffmpeg command it does compress and create a mp4 video file.

    But when using the Ffmpeg class i did with the PushFrame method it’s creating this strange video file.

    This is a link for my OneDrive with 10 screenshots images files for testing :

    screenshots rar

    Sample screenshot from the video file when playing the video file :
    Looks very choppy. The Bitmaps on the hard disk each one is 1920x1080 and Bit depth 32

    But it dosen’t look like that in the video file :

    choppy image

    This is the arguments i’m using :

    psi.Arguments = @"-f rawvideo -vcodec rawvideo -pix_fmt rgb24 -video_size 1920x1080 -i \\.\pipe\mytestpipe -map 0 -c:v mpeg4 -r " + BitmapRate + " " + outPath;

    The video size is very small 1.24 MB