Recherche avancée

Médias (1)

Mot : - Tags -/copyleft

Sur d’autres sites (1907)

  • How to Kill ffmpeg process in node.js

    8 février 2017, par Sanjay

    I am using node.js code that convert Axis Ipcamera live stream into mp4 using FFMPEG

    var childProcess=require('child_process');
    var childArguments = [];
    var child=[];
    var cmd='ffmpeg -i rtsp://172.24.22.117:554/axis-media/media.amp -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -preset slower -crf 18 -vf "scale=trunc(in_w/2)*2:trunc(in_h/2)*2"'+' '+__dirname+'/uploads/ouput.mp4';

     child=childProcess.exec(      
           cmd,
           childArguments,
           {            
               env: process.env,
               silent:true
           },  function (err, stdout, stderr) {
               if (err) {
                   throw err;
               }
               console.log(stdout);

           });    

           //    here generate events for listen child process (works properly)
       // Listen for incoming(stdout) data
       child.stdout.on('data', function (data) {
           console.log("Got data from child: " + data);
       });

       // Listen for any errors:
       child.stderr.on('data', function (data) {
           console.log('There was an error: ' + data);
       });

       // Listen for exit event
       child.on('exit', function(code) {
           console.log('Child process exited with exit code ' + code);
           child.stdout.pause();
           child.kill();
       });

    my above code works perfectly. It gives the output as I want, but I am not able to kill(stop) the ffmpeg command. I am using the code below for stopping the process, but in background it still continues.

    child.kill("SIGTERM");

    I also used following commands : child.kill(’SIGUSR1’) ; child.kill("SIGHUP") ; child.kill("SIGINT") ;child.kill(’SIGUSR2’) ; for killing this process but it not works.

    Currently I forcefully kill the node application to stop ffmpeg command and generate mp4 file. I do not want this.
    But I want commands that stop ffmpeg process and generate mp4 file, without killing the node application.

  • Error : Package : perl-Git-1.8.2.1-1.el5.x86_64 (epel) Requires : perl(:MODULE_COMPAT_5.8.8)

    23 décembre 2014, par P C SAS3

    error in loading github lib tool

    i have tried to load the following dependencies to load ffmpeg from source when i try to run the following command i am getting errors as below

    yum install autoconf automake gcc gcc-c++ git libtool make nasm pkgconfig zlib-devel
    Loaded plugins: fastestmirror
    Loading mirror speeds from cached hostfile
    * base: mirrors.viethosting.vn
    * epel: ftp.cuhk.edu.hk
    * extras: mirrors.viethosting.vn
    * updates: mirrors.vinahost.vn
    base                                                     | 3.7 kB     00:00    
    epel                                                     | 3.7 kB     00:00    
    epel/primary_db                                          | 3.7 MB     00:18    
    extras                                                   | 3.4 kB     00:00    
    updates                                                  | 3.4 kB     00:00    
    updates/primary_db                                       | 1.5 MB     00:16    
    vz-base                                                  |  951 B     00:00    
    vz-updates                                               |  951 B     00:00    
    Setting up Install Process
    Package autoconf-2.63-5.1.el6.noarch already installed and latest version
    Package automake-1.11.1-4.el6.noarch already installed and latest version
    Package gcc-4.4.7-11.el6.x86_64 already installed and latest version
    Package gcc-c++-4.4.7-11.el6.x86_64 already installed and latest version
    Package 1:make-3.81-20.el6.x86_64 already installed and latest version
    Package 1:pkgconfig-0.23-9.1.el6.x86_64 already installed and latest version
    Package zlib-devel-1.2.3-29.el6.x86_64 already installed and latest version
    Resolving Dependencies
    --> Running transaction check
    ---> Package git.x86_64 0:1.8.2.1-1.el5 will be installed
    --> Processing Dependency: perl-Git = 1.8.2.1-1.el5 for package: git-1.8.2.1-1.el5.x86_64
    --> Processing Dependency: perl(Term::ReadKey) for package: git-1.8.2.1-1.el5.x86_64
    --> Processing Dependency: perl(Git) for package: git-1.8.2.1-1.el5.x86_64
    --> Processing Dependency: perl(Error) for package: git-1.8.2.1-1.el5.x86_64
    --> Processing Dependency: libssl.so.6()(64bit) for package: git-1.8.2.1-1.el5.x86_64
    --> Processing Dependency: libexpat.so.0()(64bit) for package: git-1.8.2.1-1.el5.x86_64
    --> Processing Dependency: libcurl.so.3()(64bit) for package: git-1.8.2.1-1.el5.x86_64
    --> Processing Dependency: libcrypto.so.6()(64bit) for package: git-1.8.2.1-1.el5.x86_64
    ---> Package libtool.x86_64 0:2.2.6-15.5.el6 will be installed
    ---> Package nasm.x86_64 0:2.07-7.el6 will be installed
    --> Running transaction check
    ---> Package compat-expat1.x86_64 0:1.95.8-8.el6 will be installed
    ---> Package git.x86_64 0:1.8.2.1-1.el5 will be installed
    --> Processing Dependency: libcurl.so.3()(64bit) for package: git-1.8.2.1-1.el5.x86_64
    ---> Package openssl098e.x86_64 0:0.9.8e-18.el6_5.2 will be installed
    ---> Package perl-Error.noarch 1:0.17015-4.el6 will be installed
    ---> Package perl-Git.x86_64 0:1.8.2.1-1.el5 will be installed
    --> Processing Dependency: perl(:MODULE_COMPAT_5.8.8) for package: perl-Git-1.8.2.1-1.el5.x86_64
    ---> Package perl-TermReadKey.x86_64 0:2.30-13.el6 will be installed
    --> Finished Dependency Resolution
    Error: Package: perl-Git-1.8.2.1-1.el5.x86_64 (epel)
              Requires: perl(:MODULE_COMPAT_5.8.8)
    Error: Package: git-1.8.2.1-1.el5.x86_64 (epel)
              Requires: libcurl.so.3()(64bit)
    You could try using --skip-broken to work around the problem
    You could try running: rpm -Va --nofiles --nodigest

    now i went into some solution on net which asked to check with disablerepo to rpmforge it also throw the following error

    # yum --disablerepo=rpmforge install git
    Loaded plugins: fastestmirror


    Error getting repository data for rpmforge, repository not found

    kindly help so that i can install all the dependencies so that i may not face any problem while configuring ffmpge

  • C# .net mvc Process return encoding progress (FFMpeg) to client initiated with ajax

    19 décembre 2014, par user1585895

    I am using FFMpeg to encode wav to mp3s, and on completion download the final .zip to the client.

    All works great, and I can Debug.WriteLine the progress of the encoding, but I would like to return _percentage back to the client to do some UI updates based on the value of _percentage and if all encoding is done, Im not sure how to approach this.

    My thinking is as follows :

    • ajax post to CreateAndDownloadAlbum(List trackIds, int productId)
    • loop through List and create a new Process, run
      — parse StdError to get encoding percentage in myProcess_ErrorData(object source, DataReceivedEventArgs e)
      — send _percentage value at timed intervals back to CreateAndDownloadAlbum
      — update UI based on value of _percentage, when all is complete break and call public ActionResult SendFileDownload()

    Any input would be great.

    Thanks !

    front end AJAX call to post list of file Ids to download

    var data = $('#downloadAlbum').serialize();
    $.ajax({
       url: "/Admin/CreateAndDownloadAlbum",
       method: "POST",
       data: data,
       dataType: 'json',
       success: function(result) {
            // wait here for _percentage
            // if not 100, call again to get new _percentage value
            // if 100, update UI, move to next file being encoded
            // if all encoding is complete, call SendFileDownload() in controller
       }
    });

    then the controller code

    [HttpPost]
       public void CreateAndDownloadAlbum(List<trackstodownload> trackIds, int productId)
       {
           _numTracksToDownload = trackIds.Count;
           var product = _productRepository.GetProductById(productId);
           var artist = _artistRepository.GetArtistById(product.ArtistId);

           var folderGuid = Guid.NewGuid();
           _zipFolder = string.Concat(artist.ArtistName.ToUpper().Replace(" ", "_"), "[", product.ProductName.ToUpper().Replace(" ", "_"), "].zip");
           _mp3FolderPath = Server.MapPath("/Files/" + productId + "/" + folderGuid);
           _zipDownloadPath = Server.MapPath("/Delivery/" + _zipFolder);

           if (!Directory.Exists(Server.MapPath("/Files/" + productId + "/" + folderGuid)))
           {
               Directory.CreateDirectory(Server.MapPath("/Files/" + productId + "/" + folderGuid));
           }

           foreach (var z in trackIds)
           {
               var track = _trackRepository.GetTrackById(z.TrackId);
               var process = new Process();
               var startInfo = new ProcessStartInfo
               {
                   WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden,
                   FileName = "F:\\Development\\ffmpeg\\ffmpeg.exe",
                   RedirectStandardOutput = true,
                   RedirectStandardError = true,
                   UseShellExecute = false
               };
               var startFile = Path.Combine("F:\\Development","Files", track.ProductId.ToString(), track.TrackFileName);
               var endFile = Path.Combine("F:\\Development", "Files", track.ProductId.ToString(), folderGuid.ToString(), track.TrackFileName.Replace(".wav", ".mp3"));

               startInfo.Arguments = "-i " + startFile + " -b:a 320k " + endFile + " -stats";
               process.StartInfo = startInfo;
               process.EnableRaisingEvents = true;
               process.Exited += myProcess_exited;
               process.OutputDataReceived += myProcess_OutputData;
               process.ErrorDataReceived += myProcess_ErrorData;

               try
               {
                   process.Start();
                   process.BeginOutputReadLine();
                   process.BeginErrorReadLine();

                   if (process.HasExited == false)
                   {
                       process.WaitForExit();
                   }
               }
               catch (Exception)
               {

                   throw;
               }
           }

           SendFileDownload();

       }

       public ActionResult SendFileDownload()
       {
           // zip and move to delivery folder
           using (var zip = new ZipFile())
           {
               zip.AddDirectory(_mp3FolderPath, _zipFolder);
               zip.Save(_zipDownloadPath);
           }

           // delete items in temp guid folder
           var downloadedMessageInfo = new DirectoryInfo(_mp3FolderPath);
           foreach (var f in downloadedMessageInfo.GetFiles())
           {
               f.Delete();
           }

           // delete temp folder
           Directory.Delete(_mp3FolderPath);

           // download file
           string file = _zipDownloadPath;
           return File(file, "application/force-download", Path.GetFileName(file));

       }

       public void myProcess_exited(Object source, EventArgs e)
       {
           Debug.WriteLine("myProcess_exited ===================================");
           _duration = new TimeSpan(0, 0, 0);
           _frameTime = new TimeSpan(0, 0, 0);
           _percentage = 0;
           _numEncodedTracks++; // using this to tell me if all tracks have been encoded
       }

       public void myProcess_OutputData(object source, DataReceivedEventArgs e)
       {
       }

       public void myProcess_ErrorData(object source, DataReceivedEventArgs e)
       {
           string strMessage = e.Data;

           if (!string.IsNullOrEmpty(strMessage) &amp;&amp; (strMessage.Contains("Duration: ") || strMessage.Contains("size=")))
           {
               if (_duration != null)
               {
                   if (strMessage.Contains("Duration: "))
                   {
                       _strDuration = strMessage.Substring(strMessage.IndexOf("Duration: ") + ("Duration: ").Length,
                           ("00:00:00.00").Length);

                       char[] d_delHrMn = new char[] { ':' };
                       string[] d_tempHrMn = _strDuration.Split(d_delHrMn, StringSplitOptions.RemoveEmptyEntries);

                       char[] d_delSec = new char[] { '.' };
                       string[] d_tempSec = d_tempHrMn[2].Split(d_delSec, StringSplitOptions.RemoveEmptyEntries);

                       var d_hour = d_tempHrMn[0] == "0" ? 0 : Convert.ToInt32(d_tempHrMn[0]);
                       var d_min = d_tempHrMn[1] == "0" ? 0 : Convert.ToInt32(d_tempHrMn[1]);
                       var d_sec = d_tempSec[0] == "0" ? 0 : Convert.ToInt32(d_tempSec[0]);

                       _duration = new TimeSpan(d_hour, d_min, d_sec);
                   }
               }

               if (strMessage.Contains("size="))
               {
                   _strFrameTime = strMessage.Substring(strMessage.IndexOf("time=") + ("time=").Length,
                       ("00:00:00.00").Length);

                   char[] f_delHrMn = new char[] { ':' };
                   string[] f_tempHrMn = _strFrameTime.Split(f_delHrMn, StringSplitOptions.RemoveEmptyEntries);

                   char[] f_delSec = new char[] { '.' };
                   string[] f_tempSec = f_tempHrMn[2].Split(f_delSec, StringSplitOptions.RemoveEmptyEntries);

                   var f_hour = f_tempHrMn[0] == "0" ? 0 : Convert.ToInt32(f_tempHrMn[0]);
                   var f_min = f_tempHrMn[1] == "0" ? 0 : Convert.ToInt32(f_tempHrMn[1]);
                   var f_sec = f_tempSec[0] == "0" ? 0 : Convert.ToInt32(f_tempSec[0]);

                   _frameTime = new TimeSpan(f_hour, f_min, f_sec);

               }

               if (_strDuration != "00:00:00.00" &amp;&amp; _strFrameTime != "00:00:00.00" &amp;&amp; _percentage &lt; 100)
               {
                   _percentage = _frameTime.TotalMilliseconds / _duration.TotalMilliseconds * 100;
                   Debug.WriteLine(_percentage + " || " + _frameTime + " " + _duration);
               }
           }
       }
    </trackstodownload>