Exemple #1
0
        static void Main(string[] args)
        {
            TimelapseVideoInfo info = new TimelapseVideoInfo();

            string result = "  Duration: 00:00:00.20, start: 0.000000, bitrate: 879 kb/s, yuv420p, 640x480, q=2-31, 200 kb/s, 90k tbn, 5 tbc (default) frame=    1 fps=0.0 q=0.0 Lsize=N/A time=00:00:00.20 bitrate=N/A ";
            int index1 = result.IndexOf("Duration: ", StringComparison.Ordinal);
            int index2 = index1 + 8;
            if (index1 >= 0 && index2 >= 0)
                info.Duration = result.Substring(index1 + ("Duration: ").Length, index2 - index1);

            if (result.Contains("SAR"))
            {
                index2 = result.IndexOf("SAR", StringComparison.Ordinal) - 1;
                index1 = index2 - 10;
                info.Resolution = result.Substring(index1, index2 - index1).Trim();
            }
            else if (result.Contains("yuv420p"))
            {
                index1 = result.IndexOf("yuv420p, ", StringComparison.Ordinal) + ("yuv420p, ").Length;
                index2 = result.IndexOf(", ", index1);
                info.Resolution = result.Substring(index1, index2 - index1).Trim();
            }

            info.Resolution = info.Resolution.Replace(",", "");
            info.Resolution = info.Resolution.Replace(" ", "");

            index1 = result.LastIndexOf("frame=", StringComparison.Ordinal) + ("frame= ").Length;
            index2 = result.IndexOf("fps", index1, StringComparison.Ordinal) - 1;
            if (index1 >= 0 && index2 >= 0)
                info.SnapsCount = int.Parse(result.Substring(index1, index2 - index1).Trim());
        }
        public static bool UpdateFileInfo(string code, TimelapseVideoInfo info)
        {
            if (info.Duration == "" && info.FileSize == 0 && info.Resolution == "" && info.SnapsCount == 0)
                return false;   // empty info posted

            string query = @"UPDATE [dbo].[Timelapses] " +
                           "SET [SnapsCount] = @SnapsCount, [FileSize] = @FileSize, [Resolution] = @Resolution, [Duration] = @Duration " +
                           "WHERE (Code = '" + code + "')";
            try
            {
                var p1 = new SqlParameter("@SnapsCount", info.SnapsCount);
                var p2 = new SqlParameter("@FileSize", info.FileSize);
                var p3 = new SqlParameter("@Resolution", info.Resolution);
                var p4 = new SqlParameter("@Duration", info.Duration);
                //var p5 = new SqlParameter("@LastSnapDT", info.SnapshotDate);
                var list = new[] { p1, p2, p3, p4 };

                var cmd = new SqlCommand { CommandText = query, CommandType = CommandType.Text };
                cmd.Parameters.AddRange(list);
                Connection.OpenConnection();
                cmd.Connection = Connection.DbConnection;
                int result = cmd.ExecuteNonQuery();
                Connection.CloseConnection();
                cmd.Dispose();
                return result > 0;
            }
            catch (Exception ex)
            {
                Utils.FileLog("TimelapseDao long UpdateFileInfo(string code, TimelapseVideoInfo info) " + ex.Message);
                return false;
            }
            finally
            { Connection.CloseConnection(); }
        }
Exemple #3
0
        public TimelapseVideoInfo UpdateVideoInfo(string movieName)
        {
            string result = "";
            try
            {
                var p = new Process();
                string fileargs = " -threads 1 -i " + movieName + " -f null /dev/null ";

                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

                p.StartInfo.FileName = FfmpegExePath;
                p.StartInfo.Arguments = fileargs;

                p.Start();
                result = p.StandardError.ReadToEnd();

                Utils.KillProcess(p.Id, 0);

                TimelapseVideoInfo info = new TimelapseVideoInfo();

                int index1 = result.IndexOf("Duration: ", StringComparison.Ordinal);
                int index2 = index1 + 8;
                if (index1 >= 0 && index2 >= 0)
                    info.Duration = result.Substring(index1 + ("Duration: ").Length, index2 - index1);

                if (result.Contains("SAR"))
                {
                    index2 = result.IndexOf("SAR", StringComparison.Ordinal) - 1;
                    index1 = index2 - 10;
                    info.Resolution = result.Substring(index1, index2 - index1).Trim();
                }
                else if (result.Contains("yuv420p"))
                {
                    index1 = result.IndexOf("yuv420p, ", StringComparison.Ordinal) + ("yuv420p, ").Length;
                    index2 = result.IndexOf(", ", index1);
                    info.Resolution = result.Substring(index1, index2 - index1).Trim();
                }

                info.Resolution = info.Resolution.Replace(",", "");
                info.Resolution = info.Resolution.Replace(" ", "");

                //index1 = result.LastIndexOf("frame=", StringComparison.Ordinal) + ("frame= ").Length;
                //index2 = result.IndexOf("fps", index1, StringComparison.Ordinal) - 1;
                //if (index1 >= 0 && index2 >= 0)
                //    info.SnapsCount = int.Parse(result.Substring(index1, index2 - index1).Trim());

                // directly setting frames count equals to images count in directory
                DirectoryInfo d = new DirectoryInfo(Program.DownPath);
                info.SnapsCount = d.GetFiles("*.jpg").Length;

                FileInfo fi = new FileInfo(movieName);
                info.FileSize = fi.Length;

                TimelapseDao.UpdateFileInfo(timelapse.Code, info);

                return info;
            }
            catch (Exception ex)
            {
                Utils.TimelapseLog(timelapse, "ERR: UpdateVideoInfo(" + movieName + "): " + ex.ToString());
                // file is un-readable may be causing error like 'Invalid data found when processing input'
                // so move this bad copy of to /temp/ folder for backup and clean the space for new file
                string errVideoFileName = Path.Combine(Program.TempPath, "err" + timelapse.Code + ".mp4");
                if (File.Exists(errVideoFileName))
                    File.Delete(errVideoFileName);

                Utils.TimelapseLog(timelapse, "ERR: UpdateVideoInfo(" + movieName + "): " + Environment.NewLine + "Output: " + result);

                return new TimelapseVideoInfo();
            }
        }
Exemple #4
0
        public TimelapseVideoInfo UpdateVideoInfo(string movieName)
        {
            string result = "";
            try
            {
                TimelapseVideoInfo info = new TimelapseVideoInfo();
                DirectoryInfo d = new DirectoryInfo(Program.DownPath);
                FileInfo[] filelist = d.GetFiles("*.jpg");
                int snapsCount = filelist.Length;
                if (snapsCount > 0)
                {
                    FileInfo file = new FileInfo(Path.Combine(Program.DownPath, (snapsCount - 1) + ".jpg"));
                    long fileSize = snapsCount * file.Length;

                    Image image = Image.FromFile(file.FullName);
                    string resolution = image.Width + "x" + image.Height;
                    info.FileSize = fileSize;
                    info.Resolution = resolution;
                    info.SnapsCount = snapsCount;
                    info.Duration = "00:00";
                    TimelapseDao.UpdateFileInfo(timelapse.Code, info);
                }
                return info;
            }
            catch (Exception ex)
            {
                Utils.TimelapseLog(timelapse, "ERR: UpdateVideoInfo(" + movieName + "): " + ex.ToString());
                // file is un-readable may be causing error like 'Invalid data found when processing input'
                // so move this bad copy of to /temp/ folder for backup and clean the space for new file
                string errVideoFileName = Path.Combine(Program.TempPath, "err" + timelapse.Code + ".mp4");
                if (File.Exists(errVideoFileName))
                    File.Delete(errVideoFileName);

                Utils.TimelapseLog(timelapse, "ERR: UpdateVideoInfo(" + movieName + "): " + Environment.NewLine + "Output: " + result);

                return new TimelapseVideoInfo();
            }
        }