Recherche avancée

Médias (1)

Mot : - Tags -/copyleft

Autres articles (67)

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

    5 septembre 2013, par

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

  • Ecrire une actualité

    21 juin 2013, par

    Présentez les changements dans votre MédiaSPIP ou les actualités de vos projets sur votre MédiaSPIP grâce à la rubrique actualités.
    Dans le thème par défaut spipeo de MédiaSPIP, les actualités sont affichées en bas de la page principale sous les éditoriaux.
    Vous pouvez personnaliser le formulaire de création d’une actualité.
    Formulaire de création d’une actualité Dans le cas d’un document de type actualité, les champs proposés par défaut sont : Date de publication ( personnaliser la date de publication ) (...)

  • Publier sur MédiaSpip

    13 juin 2013

    Puis-je poster des contenus à partir d’une tablette Ipad ?
    Oui, si votre Médiaspip installé est à la version 0.2 ou supérieure. Contacter au besoin l’administrateur de votre MédiaSpip pour le savoir

Sur d’autres sites (11758)

  • ffmpeg in child process doesn't exit when parent closes pipe

    28 mars 2013, par user2221129

    This code snippet is from a pthread process. It is responsible for reading configuration/options to pass to ffmpeg. The data piped to ffmpeg is coming in on a ring buffer of video frames (as a proof of concept, in the final implementation these would be coming from a camera device). The parent writes to the child via a pipe established with dup2. The problem I'm having is that most of the time, the ffmpeg process doesn't seem to recognize the pipe has been closed by the parent (as strace shows the ffmpeg is in read). There are probably some unhandled mutex situations.

    #define CHILD_READ  writepipe[0]
    #define PARENT_WRITE    writepipe[1]
    #define MAX_VIDEO_BUFFERS 30

    static int last_frame_written = -1;
    static int buffer_size = -1;
    static void *video_buffer[MAX_VIDEO_BUFFERS];

    #define MAXTHREADS 2
    static pthread_t thread[MAXTHREADS];
    static int sigusr[MAXTHREADS];
    static int sigusr_thread[MAXTHREADS];

    #define MAXPARAMETERS 100

    void* encoder_thread(void *ptr)
    {
       int param;
       const char **parameters = new const char* [MAXPARAMETERS];
       ssize_t bytes_written_debug = 0;

       int writepipe[2] = {-1,-1};
       int last_frame_read = -1;
       pid_t   childpid;

       // xxx
       if ( 0 != pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) )
       {
           fprintf(stderr,"pthread_setcancelstate could not be set\n");
       }

       param = *(int*)ptr;
       fprintf(stderr,"param = %d\n", param);

       switch (param)
       {
           ...read config file and populate parameters for child call...
       }

       while ( last_frame_written == -1 )
       {
           fprintf(stderr,"ENCODER THREAD WAITING\n");
           sleep(1);
       }

       if ( pipe(writepipe) < 0 )
       {
           ...handle error case...
       }


       if ( (childpid = fork()) < 0)
       {
           fprintf(stderr,"child failed\n");
       }
       else if ( 0 == childpid )   /* in the child */
       {
           dup2(CHILD_READ,  STDIN_FILENO);
           //close(CHILD_READ); // doesn't seem to matter
           close(PARENT_WRITE);

           execv("/usr/bin/ffmpeg",(char **)parameters);
           return;
       }
       else                /* in the parent */
       {
           fprintf(stderr,"THREAD CHILD PID: %d\n",childpid);
           close(CHILD_READ);

           while ( last_frame_written > -1 && 0==sigusr_thread[param] )
           {
               if ( last_frame_read != last_frame_written )
               {
                   // send frame to child (ffmpeg)
                   last_frame_read = last_frame_written;
                   bytes_written_debug = write(PARENT_WRITE,video_buffer[last_frame_read], buffer_size);
                   if ( bytes_written_debug < 0 )
                   {
                       fprintf(stderr, "write error\n");
                       break;
                   }
               }

               usleep(10000); // assume ~100Hz rate
           }

    /// Problems begin now: no more data from main process,
    /// Shouldn't this close "close" the pipe created with dup2 and hence EOF ffmpeg?
           if ( close(PARENT_WRITE) )
           {
               fprintf(stderr,"\n\nclose failure! wtf?\n\n\n");
           }

    // debug sleep:
    // waiting 10 sec doesn't seem to help...
    // trying to give ffmpeg some time if it needs it
           sleep(10);

    // kill never fails here:
           if ( !kill(childpid,SIGINT) )
           {
               fprintf(stderr, "\n\nkill child %d\n", childpid);
           }
           else
           {
               fprintf(stderr, "\n\nkill failed for child %d\n", childpid);
           }

           fprintf(stderr,"\n\nwaiting\n\n\n");
           int status = 0;

    // wait forever (in most cases); ps -axw shows all the ffmpeg's
           wait(&status);
       }
    }




    int main()
    {
       ...
       for ( int i = 0; i < MAXTHREADS; ++i)
       {
           sigusr[i] = 0;
           sigusr_thread[i] = 0;
           param[i] = i;
           iret = pthread_create( &thread[i], NULL, encoder_thread, (void*) &param[i] );
       }
       ...

       // Maybe this is important to the pthread signaling?
       // Don't think so because thread's SIGINT isn't picked up by signal handler (not shown)
       sigemptyset(&set);
       sigaddset(&set, SIGHUP);
       sigaddset(&set, SIGINT);
       sigaddset(&set, SIGUSR1);
       sigaddset(&set, SIGUSR2);
       sigaddset(&set, SIGALRM);

       /* block out these signals */
       sigprocmask(SIG_BLOCK, &set, NULL);

       ...read file/populate frame buffer until file exhausted...

       fprintf(stderr, "waiting for threads to exit\n");

       for ( int i = 0; i < MAXTHREADS; ++i)
       {
           sigusr_thread[i] = 1;
           pthread_join( thread[i], NULL);
       }
       fprintf(stderr, "done waiting for threads to exit\n");

       ...

       return 0;
    }

    I've embedded comments and questions in the thread's parent code after the frame buffer read/write loop.

    Hope I've provided enough detail - stackoverflow posting noob ! Thank you.

  • rtmpdump not stopping live steam capture with -B option set

    16 janvier 2016, par Byron

    I have an rtmp url that, when I try to capture with the command rtmpdump -r "url" -B 5 -v -o test.flv, the program starts successfully, but does not exit after 5 seconds, even when the console output says "For duration : 5 seconds". If I break with ^C, the file is captured successfully.

    Note that the seconds output in this example must be the seconds since the stream started running not of the capture length time. console output

  • Android : Pass video path to FFmpeg

    7 janvier 2016, par marian

    I have developed an app that play video from gallery. I would like to add watermark using FFmpeg command in the video selected. But I do not know how to pass the path to the FFmpeg command. I could not find proper tutorials or reference regarding this. My coding are as follows :

    MainActivity.java :

    import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.DialogInterface;
    import android.content.Intent;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.Handler;
    import android.os.Message;
    import android.os.PowerManager;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.Toast;
    import android.widget.VideoView;

    import com.netcompss.ffmpeg4android.CommandValidationException;
    import com.netcompss.ffmpeg4android.GeneralUtils;
    import com.netcompss.ffmpeg4android.Prefs;
    import com.netcompss.ffmpeg4android.ProgressCalculator;
    import com.netcompss.loader.LoadJNI;

    public class MainActivity extends Activity {
    public ProgressDialog progressBar;

    String workFolder = null;
    String demoVideoFolder = null;
    String demoVideoPath = null;
    String vkLogPath = null;
    LoadJNI vk;
    private final int STOP_TRANSCODING_MSG = -1;
    private final int FINISHED_TRANSCODING_MSG = 0;
    private boolean commandValidationFailedFlag = false;

    Button button;
    VideoView videoView;
    private static final int PICK_FROM_GALLERY = 1;


    private void runTranscodingUsingLoader() {
       Log.i(Prefs.TAG, "runTranscodingUsingLoader started...");

       PowerManager powerManager = (PowerManager)MainActivity.this.getSystemService(Activity.POWER_SERVICE);
       PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "VK_LOCK");
       Log.d(Prefs.TAG, "Acquire wake lock");
       wakeLock.acquire();



       String[] complexCommand = {"ffmpeg","-y" ,"-i", "/sdcard/videokit/in.mp4","-strict","experimental",
               "-vf", "movie=/sdcard/videokit/watermark.png [watermark];" +
               " [in][watermark] overlay=main_w-overlay_w-10:10 [out]","-s",
               "320x240","-r", "30", "-b", "15496k", "-vcodec", "mpeg4","-ab",
               "48000", "-ac", "2", "-ar", "22050", "/sdcard/videokit/out1.mp4"};
       ///////////////////////////////////////////////////////////////////////


       vk = new LoadJNI();
       try {
           // running complex command with validation
           vk.run(complexCommand, workFolder, getApplicationContext());

           // running without command validation
           //vk.run(complexCommand, workFolder, getApplicationContext(), false);

           // running regular command with validation
           //vk.run(GeneralUtils.utilConvertToComplex(commandStr), workFolder, getApplicationContext());

           Log.i(Prefs.TAG, "vk.run finished.");
           // copying vk.log (internal native log) to the videokit folder
           GeneralUtils.copyFileToFolder(vkLogPath, demoVideoFolder);

       } catch (CommandValidationException e) {
           Log.e(Prefs.TAG, "vk run exeption.", e);
           commandValidationFailedFlag = true;

       } catch (Throwable e) {
           Log.e(Prefs.TAG, "vk run exeption.", e);
       }
       finally {
           if (wakeLock.isHeld()) {
               wakeLock.release();
               Log.i(Prefs.TAG, "Wake lock released");
           }
           else{
               Log.i(Prefs.TAG, "Wake lock is already released, doing nothing");
           }
       }

       // finished Toast
       String rc = null;
       if (commandValidationFailedFlag) {
           rc = "Command Vaidation Failed";
       }
       else {
           rc = GeneralUtils.getReturnCodeFromLog(vkLogPath);
       }
       final String status = rc;
       MainActivity.this.runOnUiThread(new Runnable() {
           public void run() {
               Toast.makeText(MainActivity.this, status, Toast.LENGTH_LONG).show();
               if (status.equals("Transcoding Status: Failed")) {
                   Toast.makeText(MainActivity.this, "Check: " + vkLogPath + " for more information.", Toast.LENGTH_LONG).show();
               }
           }
       });
    }


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

       button = (Button) findViewById(R.id.button);

       videoView = (VideoView) findViewById(R.id.videoview);

       button.setOnClickListener(new View.OnClickListener() {

           public void onClick(View v) {
               // TODO Auto-generated method stub
               Intent intent = new Intent();

               intent.setType("video/*");
               intent.setAction(Intent.ACTION_GET_CONTENT);

               startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_GALLERY);
           }
       });

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
       if (resultCode != RESULT_OK) return;

       if (requestCode == PICK_FROM_GALLERY) {
           Uri mVideoURI = data.getData();
           videoView.setVideoURI(mVideoURI);
           videoView.start();
           demoVideoFolder = mVideoURI.getPath();
           demoVideoPath = demoVideoFolder;
           savevideo(mVideoURI);

       }


    }
    private Handler handler = new Handler() {
       @Override
       public void handleMessage(Message msg) {
           Log.i(Prefs.TAG, "Handler got message");
           if (progressBar != null) {
               progressBar.dismiss();

               // stopping the transcoding native
               if (msg.what == STOP_TRANSCODING_MSG) {
                   Log.i(Prefs.TAG, "Got cancel message, calling fexit");
                   vk.fExit(getApplicationContext());


               }
           }
       }
    };

    public void runTranscoding() {
       progressBar = new ProgressDialog(MainActivity.this);
       progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
       progressBar.setTitle("FFmpeg4Android Direct JNI");
       progressBar.setMessage("Press the cancel button to end the operation");
       progressBar.setMax(100);
       progressBar.setProgress(0);

       progressBar.setCancelable(false);
       progressBar.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
               handler.sendEmptyMessage(STOP_TRANSCODING_MSG);
           }
       });

       progressBar.show();

       new Thread() {
           public void run() {
               Log.d(Prefs.TAG,"Worker started");
               try {
                   //sleep(5000);
                   runTranscodingUsingLoader();
                   handler.sendEmptyMessage(FINISHED_TRANSCODING_MSG);

               } catch(Exception e) {
                   Log.e("threadmessage",e.getMessage());
               }
           }
       }.start();

       // Progress update thread
       new Thread() {
           ProgressCalculator pc = new ProgressCalculator(vkLogPath);
           public void run() {
               Log.d(Prefs.TAG,"Progress update started");
               int progress = -1;
               try {
                   while (true) {
                       sleep(300);
                       progress = pc.calcProgress();
                       if (progress != 0 && progress < 100) {
                           progressBar.setProgress(progress);
                       }
                       else if (progress == 100) {
                           Log.i(Prefs.TAG, "==== progress is 100, exiting Progress update thread");
                           pc.initCalcParamsForNextInter();
                           break;
                       }
                   }

               } catch(Exception e) {
                   Log.e("threadmessage",e.getMessage());
               }
           }
       }.start();
    }

    public void savevideo (Uri mVideoURI){
       demoVideoFolder = mVideoURI.getPath();
       demoVideoPath = demoVideoFolder;
       Log.i(Prefs.TAG, getString(R.string.app_name) + " version: " + GeneralUtils.getVersionName(getApplicationContext()));

       Button invoke = (Button) findViewById(R.id.button);
       invoke.setOnClickListener(new View.OnClickListener() {
           public void onClick(View v) {
               Log.i(Prefs.TAG, "run clicked.");
               runTranscoding();
           }
       });

       workFolder = getApplicationContext().getFilesDir() + "/";
       Log.i(Prefs.TAG, "workFolder (license and logs location) path: " + workFolder);
       vkLogPath = workFolder + "vk.log";
       Log.i(Prefs.TAG, "vk log (native log) path: " + vkLogPath);
       GeneralUtils.copyLicenseFromAssetsToSDIfNeeded(this, workFolder);
       GeneralUtils.copyDemoVideoFromAssetsToSDIfNeeded(this, demoVideoFolder);
       int rc = GeneralUtils.isLicenseValid(getApplicationContext(), workFolder);
       Log.i(Prefs.TAG, "License check RC: " + rc);

    }
    }

    ffmpeg command :

    String[] complexCommand = {"ffmpeg","-y" ,"-i",  "/sdcard/videokit/in.mp4","-strict","experimental",
               "-vf", "movie=/sdcard/videokit/watermark.png [watermark];" +
               " [in][watermark] overlay=main_w-overlay_w-10:10 [out]","-s",
               "320x240","-r", "30", "-b", "15496k", "-vcodec", "mpeg4","-ab",
               "48000", "-ac", "2", "-ar", "22050", "/sdcard/videokit/out1.mp4"};

    Tis command is from a sample project. How do i pass the video path to this command ? I do not know how to edit the command to support my requirement. Can someone guide me through this. Any help will be really helpful. Thank you.