public static void stitchImage2Video()
        {
            string videoname = "Video_VIRAT_S_010005_02_000177_000203";
            string dir       = @"C:\research\MSRDVA\temp\0efdc91e-62e2-4a70-b5fd-18720c170e03\AggregatedStitched\Video_VIRAT_S_010005_02_000177_000203\";

            FFMpegWrappers.generateVideoFromFolderofFrames(videoname, dir);
        }
        public static void generateVideoForEvaluation(List <Image> Images, List <DateTime> dateTimeList, MultiObjectTrackingResult ctts, String videoName, String directory)
        {
            List <Image> imagesWithTracks = new List <Image>();

            for (int i = 0; i < Images.Count; i++)
            {
                List <BoundingBox> locations = new List <BoundingBox>();
                List <string>      labels    = new List <string>();
                Dictionary <string, List <bool> > attributes = new Dictionary <string, List <bool> >();
                attributes.Add("occlusion", new List <bool>());

                if (ctts.tracks.Count != 0)
                {
                    foreach (string key in ctts.tracks[0].booleanAttributeTracks.Keys)
                    {
                        if (!attributes.ContainsKey(key))
                        {
                            attributes.Add(key, new List <bool>());
                        }
                    }
                }

                List <int> idx = new List <int>();

                for (int j = 0; j < ctts.tracks.Count; j++)
                {
                    CompressedTrack ct = ctts.tracks[j];
                    SpaceTime       st = ct.getSpaceTimeAt(dateTimeList[i]);

                    BooleanAttribute outofview_attr = ct.getAttributeAt("outofview", dateTimeList[i]);
                    if (st != null && outofview_attr != null && !outofview_attr.value)
                    {
                        BoundingBox l = st.region;
                        locations.Add(l);
                        labels.Add(ctts.tracks[j].label);
                        foreach (string key in attributes.Keys)
                        {
                            attributes[key].Add(ct.getAttributeAt(key, dateTimeList[i]).value);
                        }

                        idx.Add(j);
                    }
                }
                Image new_image = generateTrackImage(Images[i], labels, locations, attributes, idx);
                imagesWithTracks.Add(new_image);
            }

            Console.WriteLine("Saving " + directory + "\\" + videoName);
            FFMpegWrappers.generateVideoFromFrames(imagesWithTracks, videoName, directory);

            //Directory.CreateDirectory(directory + "\\" + videoName);
            //Console.WriteLine("Saving " + directory + "\\" + videoName);
            //for (int i = 0; i < imagesWithTracks.Count; i++)
            //{

            //    imagesWithTracks[i].Save(directory + "\\" + videoName + "\\img" + i.ToString("000") + ".jpg");
            //}
            //Console.WriteLine("done");
        }
        public static void testAVI2MP4()
        {
            string ffmpeg     = DirectoryConstants.ffmpeg;
            string srcFolder  = @"C:\research\dataset\UCF101\demoSet";
            string destFolder = @"C:\research\dataset\UCF101\demoSetMp4";

            FFMpegWrappers.ConvertLocalVideoFolderToMP4(ffmpeg, srcFolder, destFolder);
        }
        public static void TestExtractFrame()
        {
            string dataPath = @"C:\research\dataset\TomLaPorta\";

            string[] files = Directory.GetFiles(dataPath);
            foreach (string f in files)
            {
                string   fn           = URIUtilities.filenameFromDirectory(f);
                string[] ff           = fn.Split('.');
                string   fname        = ff[0];
                string   outputFolder = dataPath + fname + "\\";
                if (!Directory.Exists(outputFolder))
                {
                    Directory.CreateDirectory(outputFolder);
                }
                FFMpegWrappers.ExtractFrames(ffmpeg, f,
                                             outputFolder, fname, DateTime.MinValue, 0.1);
            }
        }
Example #5
0
        public static bool ProcessAndUploadToAzureBlob(SatyamJobSubmissionsTableAccessEntry jobEntry)
        {
            // Assumpltion:  the input is a folder videos, convert to mp4, and upload to satyam blob

            SatyamJobStorageAccountAccess satyamStorage = new SatyamJobStorageAccountAccess();
            string    satyamContainerName = SatyamTaskGenerator.JobTemplateToSatyamContainerNameMap[jobEntry.JobTemplateType];
            string    GUID = jobEntry.JobGUID;
            string    satyamDirectoryName = GUID;
            SatyamJob job = JSonUtils.ConvertJSonToObject <SatyamJob>(jobEntry.JobParametersString);
            SingleObjectLabelingSubmittedJob jobParams = JSonUtils.ConvertJSonToObject <SingleObjectLabelingSubmittedJob>(job.JobParameters);

            BlobContainerManager bcm = new BlobContainerManager();
            string        status     = bcm.Connect(job.azureInformation.AzureBlobStorageConnectionString);
            List <string> FileTypes  = SatyamTaskGenerator.ValidFileTypesByTemplate[job.JobTemplateType];

            if (status != "SUCCESS")
            {
                return(false);
            }

            string guidFolder = DirectoryConstants.defaultTempDirectory + "\\" + GUID;

            Directory.CreateDirectory(guidFolder);

            //var client = new WebClient();
            List <string> videoUrls = bcm.getURLList(job.azureInformation.AzureBlobStorageContainerName, job.azureInformation.AzureBlobStorageContainerDirectoryName);

            foreach (string video in videoUrls)
            {
                FFMpegWrappers.ConvertVideoURLToMP4(DirectoryConstants.ffmpeg, video, guidFolder);
            }

            satyamStorage.uploadALocalFolder(guidFolder, satyamContainerName, satyamDirectoryName);

            return(true);
        }
Example #6
0
        /// <summary>
        /// Input should be a folder of videos and corresponding annotation file with the same name
        /// </summary>
        /// <param name="jobEntry"></param>
        public static bool ProcessAndUploadToAzureBlob(SatyamJobSubmissionsTableAccessEntry jobEntry)
        {
            // if the input is a folder of folders of frames, then copy directly
            SatyamJobStorageAccountAccess satyamStorage = new SatyamJobStorageAccountAccess();
            string    satyamContainerName = SatyamTaskGenerator.JobTemplateToSatyamContainerNameMap[jobEntry.JobTemplateType];
            string    GUID = jobEntry.JobGUID;
            string    satyamDirectoryName = GUID;
            SatyamJob job = JSonUtils.ConvertJSonToObject <SatyamJob>(jobEntry.JobParametersString);
            MultiObjectTrackingSubmittedJob jobParams = JSonUtils.ConvertJSonToObject <MultiObjectTrackingSubmittedJob>(job.JobParameters);

            BlobContainerManager bcm = new BlobContainerManager();
            string        status     = bcm.Connect(job.azureInformation.AzureBlobStorageConnectionString);
            List <string> FileTypes  = SatyamTaskGenerator.ValidFileTypesByTemplate[job.JobTemplateType];

            if (status != "SUCCESS")
            {
                return(false);
            }

            string guidFolder = DirectoryConstants.defaultTempDirectory + "\\" + GUID;

            Directory.CreateDirectory(guidFolder);
            int    chunkLength  = jobParams.ChunkDuration; // sec
            int    outputFPS    = jobParams.FrameRate;
            double chunkOverlap = jobParams.ChunkOverlap;  // sec

            var client = new WebClient();

            // sample to frames
            int           noFramePerChunk = (int)(chunkLength * outputFPS);
            int           noFrameOverlap  = (int)(chunkOverlap * outputFPS);
            List <string> videoUrls       = bcm.getURLList(job.azureInformation.AzureBlobStorageContainerName, job.azureInformation.AzureBlobStorageContainerDirectoryName);


            Dictionary <string, List <string> > videos = new Dictionary <string, List <string> >();

            foreach (string videolink in videoUrls)
            {
                string videoName = URIUtilities.filenameFromURINoExtension(videolink);

                if (!videos.ContainsKey(videoName))
                {
                    videos.Add(videoName, new List <string>());
                }
                videos[videoName].Add(videolink);
            }

            foreach (string videoName in videos.Keys)
            {
                // filter out those that doesn't provide a annotation file with it....
                if (videos[videoName].Count != 2)
                {
                    Console.WriteLine("Warning: Not 2 files provided for {0}.", videoName);
                    //Directory.Delete(guidFolder, true);
                    //return false;
                    continue;
                }

                string videoURL      = "";
                string annotationURL = "";
                foreach (string fileLink in videos[videoName])
                {
                    string extension = URIUtilities.fileExtensionFromURI(fileLink);
                    if (extension != "txt")
                    {
                        videoURL = fileLink;
                    }
                    else
                    {
                        annotationURL = fileLink;
                    }
                }

                string outputDirectory = guidFolder + "\\" + videoName;
                Directory.CreateDirectory(outputDirectory);

                string videoNameWithExtension = URIUtilities.filenameFromURI(videoURL);
                client.DownloadFile(videoURL, outputDirectory + "\\" + videoNameWithExtension);
                FFMpegWrappers.ExtractFrames(DirectoryConstants.ffmpeg, outputDirectory + "\\" + videoNameWithExtension, outputDirectory, videoName, DateTime.Now, outputFPS);

                File.Delete(outputDirectory + "\\" + videoNameWithExtension);


                List <string> chunkFolders = TrackingDataPreprocessor.GroupFramesIntoChunks(outputDirectory, noFramePerChunk);

                //parse VIRAT annotation file
                string annotationNameWithExtension = URIUtilities.filenameFromURI(annotationURL);
                client.DownloadFile(annotationURL, outputDirectory + "\\" + annotationNameWithExtension);

                parseAnnotationFileIntoChunkFolders(chunkFolders,
                                                    outputDirectory + "\\" + annotationNameWithExtension,
                                                    noFramePerChunk, outputFPS);

                //upload
                for (int i = 0; i < chunkFolders.Count; i++)
                {
                    string subDir = chunkFolders[i];
                    satyamStorage.uploadALocalFolder(subDir, satyamContainerName, satyamDirectoryName + "/Video_" + videoName + "_startingFrame_" + noFramePerChunk * i);
                }

                Directory.Delete(outputDirectory, true);
            }
            return(true);
        }
Example #7
0
        public static bool ProcessAndUploadToAzureBlob(SatyamJobSubmissionsTableAccessEntry jobEntry)
        {
            // if the input is a folder of folders of frames, then copy directly
            SatyamJobStorageAccountAccess satyamStorage = new SatyamJobStorageAccountAccess();
            string    satyamContainerName = SatyamTaskGenerator.JobTemplateToSatyamContainerNameMap[jobEntry.JobTemplateType];
            string    GUID = jobEntry.JobGUID;
            string    satyamDirectoryName = GUID;
            SatyamJob job = JSonUtils.ConvertJSonToObject <SatyamJob>(jobEntry.JobParametersString);
            MultiObjectTrackingSubmittedJob jobParams = JSonUtils.ConvertJSonToObject <MultiObjectTrackingSubmittedJob>(job.JobParameters);

            BlobContainerManager bcm = new BlobContainerManager();
            string        status     = bcm.Connect(job.azureInformation.AzureBlobStorageConnectionString);
            List <string> FileTypes  = SatyamTaskGenerator.ValidFileTypesByTemplate[job.JobTemplateType];

            if (status != "SUCCESS")
            {
                return(false);
            }

            string guidFolder = DirectoryConstants.defaultTempDirectory + "\\" + GUID;

            Directory.CreateDirectory(guidFolder);
            int    chunkLength  = jobParams.ChunkDuration; // sec
            int    outputFPS    = jobParams.FrameRate;
            double chunkOverlap = jobParams.ChunkOverlap;  // sec

            var client = new WebClient();

            if (jobParams.DataSrcFormat == DataFormat.Video)
            {
                // sample to frames
                int           noFramePerChunk = (int)(chunkLength * outputFPS);
                int           noFrameOverlap  = (int)(chunkOverlap * outputFPS);
                List <string> videoUrls       = bcm.getURLList(job.azureInformation.AzureBlobStorageContainerName, job.azureInformation.AzureBlobStorageContainerDirectoryName);
                foreach (string video in videoUrls)
                {
                    string videoName          = URIUtilities.filenameFromURINoExtension(video);
                    string videonameExtension = URIUtilities.filenameFromURI(video);
                    string outputDirectory    = guidFolder + "\\" + videoName;
                    Directory.CreateDirectory(outputDirectory);
                    client.DownloadFile(video, outputDirectory + "\\" + videonameExtension);
                    FFMpegWrappers.ExtractFrames(DirectoryConstants.ffmpeg, outputDirectory + "\\" + videonameExtension, outputDirectory, videoName, DateTime.Now, outputFPS);
                    Console.WriteLine("deleting downloaded file...");
                    File.Delete(outputDirectory + "\\" + videonameExtension);
                    GroupFramesIntoChunksAndUploadChunks(videoName, outputDirectory, noFramePerChunk, noFrameOverlap, satyamContainerName, satyamDirectoryName);
                    Directory.Delete(outputDirectory, true);
                }
            }

            if (jobParams.DataSrcFormat == DataFormat.VideoFrame)
            {
                int noFramePerChunk = (int)(chunkLength * outputFPS);//just use one fps for now, assume input should've already downsampled
                int noFrameOverlap  = (int)(chunkOverlap * outputFPS);
                // chunk according to parameters
                List <string> frameUrls = bcm.getURLList(job.azureInformation.AzureBlobStorageContainerName, job.azureInformation.AzureBlobStorageContainerDirectoryName);
                Dictionary <string, List <string> > framesPerVideo = new Dictionary <string, List <string> >();
                foreach (string url in frameUrls)
                {
                    // assumed hierarchy: blob/directory.../videoname/frameid.jpg
                    //string frameName = URIUtilities.filenameFromURINoExtension(url);
                    string[] urlparts  = url.Split('/');
                    string   videoName = urlparts[urlparts.Length - 2];
                    if (!framesPerVideo.ContainsKey(videoName))
                    {
                        framesPerVideo.Add(videoName, new List <string>());
                    }
                    framesPerVideo[videoName].Add(url);
                }

                foreach (string video in framesPerVideo.Keys)
                {
                    string outputDirectory = guidFolder + "\\" + video;
                    Directory.CreateDirectory(outputDirectory);
                    foreach (string frameURL in framesPerVideo[video])
                    {
                        string frameName = URIUtilities.filenameFromURI(frameURL);
                        client.DownloadFile(frameURL, outputDirectory + "\\" + frameName);
                    }
                    GroupFramesIntoChunksAndUploadChunks(video, outputDirectory, noFramePerChunk, noFrameOverlap, satyamContainerName, satyamDirectoryName);
                    Directory.Delete(outputDirectory, true);
                }
            }
            return(true);
        }
        // if the stitched video is too long
        public static void generateVideoFramesForEvaluation(List <string> ImageURLs, MultiObjectTrackingResult ctts, String directory, String videoName, int fps)
        {
            if (Directory.Exists(directory + "\\" + videoName))
            {
                return;
            }

            Directory.CreateDirectory(directory + "\\" + videoName);
            Console.WriteLine("Saving " + directory + "\\" + videoName);

            //List<Image> imageList = new List<Image>();
            var wc = new WebClient();


            //List<DateTime> frameTimes = new List<DateTime>();
            double frameTimeSpanInMiliseconds = (double)1000 / (double)fps;
            //double frameTimeSpanInMiliseconds = (double)(ChunkDuration) / (double)(ImageURLs.Count) * 1000;
            DateTime start = ctts.VideoSegmentStartTime;

            for (int i = 0; i < ImageURLs.Count; i++)
            {
                DateTime t;
                t = start.AddMilliseconds(frameTimeSpanInMiliseconds * i);
                //frameTimes.Add(t);

                Image x = Image.FromStream(wc.OpenRead(ImageURLs[i]));
                //imageList.Add(x);

                List <BoundingBox> locations = new List <BoundingBox>();
                List <string>      labels    = new List <string>();
                Dictionary <string, List <bool> > attributes = new Dictionary <string, List <bool> >();
                attributes.Add("occlusion", new List <bool>());

                List <int> idx = new List <int>();

                if (ctts.tracks.Count != 0)
                {
                    foreach (string key in ctts.tracks[0].booleanAttributeTracks.Keys)
                    {
                        if (!attributes.ContainsKey(key))
                        {
                            attributes.Add(key, new List <bool>());
                        }
                    }
                }

                for (int j = 0; j < ctts.tracks.Count; j++)
                {
                    CompressedTrack ct = ctts.tracks[j];
                    SpaceTime       st = ct.getSpaceTimeAt(t);

                    BooleanAttribute outofview_attr = ct.getAttributeAt("outofview", t);
                    if (st != null && outofview_attr != null && !outofview_attr.value)
                    {
                        BoundingBox l = st.region;
                        locations.Add(l);
                        labels.Add(ctts.tracks[j].label);
                        //attributes["occlusion"].Add(ct.getAttributeAt("occlusion", t).value);
                        foreach (string key in attributes.Keys)
                        {
                            attributes[key].Add(ct.getAttributeAt(key, t).value);
                        }
                        idx.Add(j);
                    }
                }
                Image new_image = generateTrackImage(x, labels, locations, attributes, idx);
                new_image.Save(directory + "\\" + videoName + "\\img" + i.ToString("000") + ".jpg");
            }

            FFMpegWrappers.generateVideoFromFolderofFrames(videoName, directory + "\\" + videoName + "\\");
            Console.WriteLine("done");
        }