Ejemplo n.º 1
0
        //async void SendDMToMyAunt()
        //{
        //    string username = "******".ToLower();
        //    //long userPK = 123;
        //    var message = "Hello my auntie";

        //    // remove \r characters, since windows is adding it to new lines
        //    message = message.Replace("\r", "");

        //    var inbox = await InstaApi.MessagingProcessor.GetDirectInboxAsync(PaginationParameters.MaxPagesToLoad(1));

        //    if (inbox.Succeeded)
        //    {

        //        // Act as Instagram>
        //        // search throw ranked recipients:
        //        // manipulate instagram by searching like real instagram:
        //        await InstaApi.MessagingProcessor.GetRankedRecipientsByUsernameAsync(username.Substring(0, 2));
        //        await InstaApi.MessagingProcessor.GetRankedRecipientsByUsernameAsync(username.Substring(0, 4));
        //        var rankedRecipients = await InstaApi.MessagingProcessor.GetRankedRecipientsByUsernameAsync(username);
        //        if (rankedRecipients.Succeeded)
        //        {
        //            var threadId = string.Empty;
        //            long userPk = -1;
        //            if (rankedRecipients.Value?.Threads?.Count > 0)
        //            {
        //                var byThread = rankedRecipients.Value.Threads.FirstOrDefault(x => x.Users.Count == 1 && x.Users.FirstOrDefault()?.UserName.ToLower() == username);
        //                if (byThread != null)
        //                    threadId = byThread.ThreadId;
        //            }
        //            else
        //            {
        //                var byUser = rankedRecipients.Value.Users.FirstOrDefault(x =>  x.UserName.ToLower() == username);
        //                if (byUser != null)
        //                    userPk = byUser.Pk;

        //            }

        //            // now send message:

        //            if (userPk != -1) // via user public key (user id PK) if exists
        //            {
        //                var dm = await InstaApi.MessagingProcessor.SendDirectTextAsync(userPk.ToString(), null, message);

        //            }
        //            else if (!string.IsNullOrEmpty(threadId)) // with thread id if exists
        //            {
        //                var dm = await InstaApi.MessagingProcessor.SendDirectTextAsync(null, threadId, message);

        //            }
        //            else
        //                Console.WriteLine("WHAT THE F**K?! NO THREAD OR PK FOUND");

        //        }
        //    }
        //}

        //async Task<InstaDirectInboxThread> GetThread(InstaDirectInboxContainer inbox, long userPK)
        //{
        //    if (inbox?.Inbox?.Threads?.Count > 0)
        //    {
        //        var exists = inbox.Inbox.Threads.FirstOrDefault(x => x.Users.Count == 1 && x.Users.FirstOrDefault()?.Pk == userPK);
        //        if (exists != null)
        //            return exists;
        //        var getThreadByParticipants = await Helper.InstaApi.MessagingProcessor.GetThreadByParticipantsAsync(inbox.SeqId, new long[] { userPK });
        //        if (getThreadByParticipants.Succeeded)
        //            return getThreadByParticipants.Value;
        //    }
        //    return null;
        //}
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary
            };

            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".bmp");
            //openPicker.FileTypeFilter.Add(".gif");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".mp4");
            var file = await openPicker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }

            var stream = await file.OpenAsync(FileAccessMode.Read);

            var grabber = await FrameGrabber.CreateFromStreamAsync(stream);

            var frame = await grabber
                        .ExtractVideoFrameAsync(TimeSpan.FromSeconds(4.5), false);

            int ix        = 1;
            var savedFile = await KnownFolders.MusicLibrary.CreateFileAsync(ix + ".jpg", CreationCollisionOption.GenerateUniqueName);

            var oStream = await savedFile.OpenAsync(FileAccessMode.ReadWrite);

            await frame.EncodeAsJpegAsync(oStream);

            oStream.Dispose();

            for (int i = 0; i < 100; i++)
            {
                //var frame2 = await grabber .ExtractNextVideoFrameAsync();
                //var savedFile2 = await KnownFolders.MusicLibrary.CreateFileAsync(ix + ".jpg", CreationCollisionOption.GenerateUniqueName);
                //var oStream2 = await savedFile2.OpenAsync(FileAccessMode.ReadWrite);
                //await frame2.EncodeAsJpegAsync(oStream2);
                //oStream2.Dispose();

                //var img = new Image
                //{
                //    Height = 150,
                //    Width = 150,
                //    Name = ix.ToString()
                //};
                //img.Source
                //LV.Children.Add(img);
            }
        }
Ejemplo n.º 2
0
        private async Task InitAsync()
        {
            var stream = await file.OpenAsync(FileAccessMode.Read);

            grabber = await FrameGrabber.CreateFromStreamAsync(stream);

            DecodedPixelWidth  = (int)Math.Round(videoPropsViewModel.Width * percentageOfResolution / 100);
            DecodedPixelHeight = (int)Math.Round(videoPropsViewModel.Height * percentageOfResolution / 100);

            grabber.DecodePixelWidth  = DecodedPixelWidth;
            grabber.DecodePixelHeight = DecodedPixelHeight;
        }
Ejemplo n.º 3
0
        private async void ExtractFrame(object sender, RoutedEventArgs e)
        {
            if (currentFile == null || mediaPlayer.PlaybackSession == null)
            {
                await DisplayErrorMessage("Please open a video file first.");
            }
            else
            {
                try
                {
                    var stream = await currentFile.OpenAsync(FileAccessMode.Read);

                    bool exactSeek    = grabFrameExactSeek.IsOn;
                    var  frameGrabber = await FrameGrabber.CreateFromStreamAsync(stream);

                    var frame = await frameGrabber.ExtractVideoFrameAsync(mediaPlayer.PlaybackSession.Position, exactSeek);

                    var filePicker = new FileSavePicker();
                    filePicker.SuggestedStartLocation       = PickerLocationId.VideosLibrary;
                    filePicker.DefaultFileExtension         = ".jpg";
                    filePicker.FileTypeChoices["Jpeg file"] = new[] { ".jpg" }.ToList();

                    var file = await filePicker.PickSaveFileAsync();

                    if (file != null)
                    {
                        var outputStream = await file.OpenAsync(FileAccessMode.ReadWrite);

                        await frame.EncodeAsJpegAsync(outputStream);

                        outputStream.Dispose();
                        bool launched = await Windows.System.Launcher.LaunchFileAsync(file, new LauncherOptions()
                        {
                            DisplayApplicationPicker = false
                        });

                        if (!launched)
                        {
                            await DisplayErrorMessage("File has been created:\n" + file.Path);
                        }
                    }
                }
                catch (Exception ex)
                {
                    await DisplayErrorMessage(ex.Message);
                }
            }
        }
Ejemplo n.º 4
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            FrameGrabber frameGrabber;

            frameGrabber = await FrameGrabber.CreateFromStreamAsync(stream);

            sw.Restart();
            int        counter = 0;
            VideoFrame frame   = await frameGrabber.ExtractVideoFrameAsync(TimeSpan.Zero, true);

            do
            {
                frame = await frameGrabber.ExtractNextVideoFrameAsync();

                Debug.WriteLine($"Frame (#{counter++}) from {frame?.Timestamp.TotalSeconds} sec. Elapsed:{sw.Elapsed.TotalSeconds} seconds");
            } while (frame != null);

            Debug.WriteLine($"All ({counter}) in {sw.Elapsed.TotalSeconds} seconds");
        }
Ejemplo n.º 5
0
        public async Task TestExtractVideoFrameAsync()
        {
            Uri uri = new Uri(Constants.DownloadUriSource);

            Assert.IsNotNull(uri);

            StorageFile file = await StorageFile.CreateStreamedFileFromUriAsync(Constants.DownloadStreamedFileName, uri, null);

            Assert.IsNotNull(file);

            IRandomAccessStream readStream = await file.OpenAsync(FileAccessMode.Read);

            Assert.IsNotNull(readStream);

            // CreateFromStreamAsync should return valid FFmpegInteropMSS object which generates valid MediaStreamSource object
            var frameGrabber = await FrameGrabber.CreateFromStreamAsync(readStream);

            var frame = await frameGrabber.ExtractVideoFrameAsync(TimeSpan.Zero);

            Assert.IsNotNull(frame);

            using (var stream = new InMemoryRandomAccessStream())
            {
                // encode as jpeg
                await frame.EncodeAsJpegAsync(stream);

                stream.Seek(0);

                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(stream);

                var bitmap = await decoder.GetFrameAsync(0);

                Assert.IsNotNull(bitmap);

                // encode as png
                stream.Seek(0);
                stream.Size = 0;
                await frame.EncodeAsPngAsync(stream);

                stream.Seek(0);

                decoder = await BitmapDecoder.CreateAsync(stream);

                bitmap = await decoder.GetFrameAsync(0);

                Assert.IsNotNull(bitmap);

                // encode as bmp
                stream.Seek(0);
                stream.Size = 0;
                await frame.EncodeAsBmpAsync(stream);

                stream.Seek(0);

                decoder = await BitmapDecoder.CreateAsync(stream);

                bitmap = await decoder.GetFrameAsync(0);

                Assert.IsNotNull(bitmap);
            }
        }