public override void ReadBlock(FlvContext context) { base.ReadBlock(context); var br = context.Reader; var dat = br.ReadBytes((int)this.Header.DataLength); data = new VideoData(dat); this.Size += this.Header.DataLength; context.CurrentPostion += this.Size; }
/// <summary> /// Adds the new video object to the queue to be processed /// </summary> /// <param name="videoData">Object with new data</param> /// <returns>Outstanding requests in the queue</returns> public int AddToQueue(VideoData videoData) { //Decrement the semaphore to make sure the spot is available this.requestVideoData.WaitOne(); lock (_threadLock) { dataQueue.Enqueue(videoData); } //Increament the semaphore to indicate there is work to do int previousCount = handleRequests.Release(); return previousCount; }
public PlaylistEntry(YoutubeDL ydl, VideoData metadata, OptionSet overrideOptions = null) : base(ydl, metadata, overrideOptions) { }
static ByteBuffer EncodeVideoData(RtmpContext context, VideoData videoData) { ByteBuffer output = videoData.Data; return(output); }
// public object getallTags(string ID) { // About the Function //Input :{ Video Id } This video Id is produced by Microsoft API //Output : { Json object with Tags } // The response consists of Meta Data retrieved from Microsoft API response // Video Id , Video Name, Tags, Appearences of Tags // Youtube Mapping URL // Decalre Variables // MongoDb Connection Parameters var ConnectionString = "mongodb://*****:*****@ds161175.mlab.com:61175/tagdatabase"; var Mongoclient = new MongoClient(ConnectionString); var db = Mongoclient.GetDatabase("tagdatabase"); var vidCol = db.GetCollection <BsonDocument>("videoCollection"); var tagCol = db.GetCollection <BsonDocument>("tagCollection"); // Microsoft API Connnection Parameters var client = new HttpClient(); var queryString = HttpUtility.ParseQueryString(string.Empty); List <MetaTag> tags = new List <MetaTag>(); var VideoData = new VideoData(); //Check if the video is already been analysed var VideoData_DB = vidCol.Find(new BsonDocument() { { "id", ID } }); // Request parameters queryString["language"] = "en-US"; var uri = "https://videobreakdown.azure-api.net/Breakdowns/Api/Partner/Breakdowns/" + ID; // Request headers // Request Microsoft API to get the tags client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "39dc76f4c2ec4fb38831bb1fe2de6d9e"); var response = client.GetAsync(uri).Result; var json = response.Content.ReadAsStringAsync().Result; JToken json_obj = JObject.Parse(json); // Retrieve VideoID VideoData.VideoId = VideoData.videoId = (string)json_obj.SelectToken("id"); VideoData.videoName = (string)json_obj.SelectToken("name"); JObject firstItemSnippet = JObject.Parse(json_obj["summarizedInsights"].ToString()); VideoData.videoURL = getUrl(VideoData.videoId); var topics = (JArray)firstItemSnippet.SelectToken("topics"); // var list = new List<>(); foreach (var item in topics) { var Tag = new MetaTag(); Tag.tagName = item["name"].ToString(); var appears = item["appearances"]; List <TagAppearances> AppearList = new List <TagAppearances>(); foreach (var app in appears) { var Appearance = new TagAppearances(); Appearance.startTime = app["startSeconds"].ToString(); Appearance.endTime = app["endSeconds"].ToString(); AppearList.Add(Appearance); } Tag.Appearances = AppearList; tags.Add(Tag); } VideoData.Tags = tags; string json_response = JsonConvert.SerializeObject(VideoData); BsonDocument document = VideoData.ToBsonDocument(); vidCol.InsertOne(document); Console.WriteLine(VideoData); return(json_response); }
public void DropPacket(RtmpMessage message) { IRtmpEvent packet = message.body; if (!(packet is VideoData)) { // Only check video packets. return; } VideoData video = packet as VideoData; FrameType type = video.FrameType; switch (_state) { case FrameDropperState.SEND_ALL: if (type == FrameType.DisposableInterframe) { // Remain in state, packet is safe to drop. return; } else if (type == FrameType.Interframe) { // Drop all frames until the next keyframe. _state = FrameDropperState.SEND_KEYFRAMES; return; } else if (type == FrameType.Keyframe) { // Drop all frames until the next keyframe. _state = FrameDropperState.SEND_KEYFRAMES; return; } break; case FrameDropperState.SEND_INTERFRAMES: if (type == FrameType.Interframe) { // Drop all frames until the next keyframe. _state = FrameDropperState.SEND_KEYFRAMES_CHECK; return; } else if (type == FrameType.Keyframe) { // Drop all frames until the next keyframe. _state = FrameDropperState.SEND_KEYFRAMES; return; } break; case FrameDropperState.SEND_KEYFRAMES: // Remain in state. break; case FrameDropperState.SEND_KEYFRAMES_CHECK: if (type == FrameType.Keyframe) { // Switch back to sending keyframes, but don't move to SEND_INTERFRAMES afterwards. _state = FrameDropperState.SEND_KEYFRAMES; return; } break; default: break; } }
public void DeleteVideo(VideoData video) { File.Delete(GetVideoPath(video)); }
private void RetrieveOSTVideoData() { BeatmapLevelSO[] levels = Resources.FindObjectsOfTypeAll <BeatmapLevelSO>().Where(x => x.GetType() != typeof(CustomLevel)).ToArray(); Action job = delegate { try { float i = 0; foreach (var level in levels) { i++; var videoFileName = level.songName; // strip invlid characters foreach (var c in Path.GetInvalidFileNameChars()) { videoFileName = videoFileName.Replace(c, '-'); } videoFileName = videoFileName.Replace('\\', '-'); videoFileName = videoFileName.Replace('/', '-'); var songPath = Path.Combine(Environment.CurrentDirectory, "CustomSongs", "_OST", videoFileName); if (!Directory.Exists(songPath)) { continue; } var results = Directory.GetFiles(songPath, "video.json", SearchOption.AllDirectories); if (results.Length == 0) { continue; } var result = results[0]; try { var i1 = i; HMMainThreadDispatcher.instance.Enqueue(delegate { if (_loadingCancelled) { return; } VideoData video = LoadVideo(result, level.difficultyBeatmapSets[0].difficultyBeatmaps[0].level); if (video != null) { AddVideo(video); } }); } catch (Exception e) { Console.WriteLine("[MVP] Failed to load song folder: " + result); Console.WriteLine(e.ToString()); } } } catch (Exception e) { Console.WriteLine("[MVP] RetrieveOSTVideoData failed:"); Console.WriteLine(e.ToString()); } }; Action finish = delegate { AreVideosLoaded = true; AreVideosLoading = false; _loadingTask = null; VideosLoadedEvent?.Invoke(); }; _loadingTask = new HMTask(job, finish); _loadingTask.Run(); }
public async Task <InsertStatus> UpsertVideo(VideoData data) => await Upsert(Videos, data);
private IEnumerator DownloadVideo() { Plugin.logger.Debug($"Starting Download"); downloading = true; Plugin.logger.Debug($"Starting Download"); if (!updated) { yield return(new WaitUntil(() => updated)); } Plugin.logger.Debug($"Starting Download2"); VideoDownload download = videoQueue.Peek(); Plugin.logger.Debug($"Starting Download3"); VideoData video = download.video; Plugin.logger.Debug($"Starting Download with {download.video.title}"); if (video.downloadState == DownloadState.Cancelled || download.downloadAttempts > MaxRetries) { // skip videoQueue.Dequeue(); if (videoQueue.Count > 0) { Plugin.logger.Debug($"Starting Next Download"); // Start next download DownloadVideo(); } else { Plugin.logger.Debug($"Done Download"); // queue empty downloading = false; yield break; } } Plugin.logger.Info("Downloading: " + video.title); StopCoroutine(Countdown(download)); Plugin.logger.Debug($"Counting"); video.downloadState = DownloadState.Downloading; downloadProgress?.Invoke(video); Plugin.logger.Debug($"Invoked"); download.Update(); Plugin.logger.Debug($"Updated"); ydl = MakeYoutubeProcessAndReturnIt(video); Plugin.logger.Debug($"yt command: {ydl.StartInfo.FileName} {ydl.StartInfo.Arguments}"); ydl.Start(); // Hook up our output to console ydl.BeginOutputReadLine(); ydl.BeginErrorReadLine(); ydl.OutputDataReceived += (sender, e) => { if (e.Data != null) { Regex rx = new Regex(@"(\d*).\d%+"); Match match = rx.Match(e.Data); if (match.Success) { video.downloadProgress = float.Parse(match.Value.Substring(0, match.Value.Length - 1)) / 100; downloadProgress?.Invoke(video); download.Update(); if (video.downloadState == DownloadState.Cancelled) { (sender as Process).Kill(); } } Plugin.logger.Info(e.Data); } }; ydl.ErrorDataReceived += (sender, e) => { if (e.Data.Length < 3) { return; } //TODO: check these errors are problems - re-download or skip file when an error occurs //video.downloadState = DownloadState.Cancelled; downloadProgress?.Invoke(video); download.Update(); }; ydl.Exited += (sender, e) => { StopCoroutine(Countdown(download)); if (video.downloadState == DownloadState.Cancelled) { Plugin.logger.Debug("Cancelled"); VideoLoader.Instance.DeleteVideo(video); } else { video.downloadState = DownloadState.Downloaded; VideoLoader.SaveVideoToDisk(video); StartCoroutine(VerifyDownload(video)); } videoQueue.Dequeue(); if (videoQueue.Count > 0) { // Start next download Plugin.logger.Debug("Starting Next Download"); DownloadVideo(); } else { // queue empty downloading = false; } ydl.Dispose(); }; }
public void TryDisplayVideo() { if (available) { available = false; inputField.interactable = false; inputField.text = inputField.text.ToLower().Trim(); if (videoDictionary.ContainsKey(inputField.text)) { List <VideoData> allDatasAvailable = videoDictionary[inputField.text]; currentVideoData = allDatasAvailable[Random.Range(0, allDatasAvailable.Count)]; manager.SendEntry(currentVideoData.unique_id); // Debug.Log(allDatasAvailable.Count); string path; if (local) { path = Application.streamingAssetsPath + "/processed" + currentVideoData.video_id + "_compressed_sobel_bw.mp4"; } else { path = "https://psycho.sandgardeners.com/kitchen/processed" + currentVideoData.video_id + "_compressed_sobel_bw"; if (manager.quality == 1) { path += "_md"; } else if (manager.quality == 2) { path += "_sd"; } path += ".mp4"; } player.url = path; Debug.Log(path); timer = Time.time; fb.GoodFeedback( () => { available = true; inputField.gameObject.SetActive(false); // player.Play(); actionsCount++; bgMusic.DOFade(1f, 1.5f); // targetStartFrame = currentVideoData.start_frame; // int frameDuration = currentVideoData.stop_frame-targetStartFrame; // Debug.Log(string.Format("frame duration : {0} ", frameDuration)); // if(frameDuration < minimumFrames) // { // int difference = minimumFrames-frameDuration; // Debug.Log(string.Format("difference : {0} - {1} = {2}", minimumFrames,frameDuration,difference)); // targetStartFrame = (int)Mathf.Max(0,targetStartFrame-difference*0.5f); // Debug.Log(string.Format("new start frame : {0} (previously {1})", targetStartFrame,currentVideoData.start_frame)); // } ppvolume.weight = 1f; player.Prepare(); inputField.text = string.Empty; }); } else { fb.WrongFeedback( () => { inputField.interactable = true; inputField.ActivateInputField(); available = true; }); } } }
public void PushMessage(IPipe pipe, IMessage message) { if (message is ResetMessage) { _timeStamper.Reset(); } else if (message is StatusMessage) { StatusMessage statusMsg = message as StatusMessage; _data.SendStatus(statusMsg.body as StatusASO); } else if (message is RtmpMessage) { // Make sure chunk size has been sent if (!_chunkSizeSent) { SendChunkSize(); } RtmpMessage rtmpMsg = message as RtmpMessage; IRtmpEvent msg = rtmpMsg.body; int eventTime = msg.Timestamp; #if !SILVERLIGHT if (log.IsDebugEnabled) { log.Debug(string.Format("Message timestamp: {0}", eventTime)); } #endif if (eventTime < 0) { #if !SILVERLIGHT if (log.IsDebugEnabled) { log.Debug(string.Format("Message has negative timestamp: {0}", eventTime)); } #endif return; } byte dataType = msg.DataType; // Create a new header for the consumer RtmpHeader header = _timeStamper.GetTimeStamp(dataType, eventTime); switch (msg.DataType) { case Constants.TypeStreamMetadata: Notify notify = new Notify((msg as Notify).Data); notify.Header = header; notify.Timestamp = header.Timer; _data.Write(notify); break; case Constants.TypeFlexStreamEnd: // TODO: okay to send this also to AMF0 clients? FlexStreamSend send = new FlexStreamSend((msg as Notify).Data); send.Header = header; send.Timestamp = header.Timer; _data.Write(send); break; case Constants.TypeVideoData: VideoData videoData = new VideoData((msg as VideoData).Data); videoData.Header = header; videoData.Timestamp = header.Timer; _video.Write(videoData); break; case Constants.TypeAudioData: AudioData audioData = new AudioData((msg as AudioData).Data); audioData.Header = header; audioData.Timestamp = header.Timer; _audio.Write(audioData); break; case Constants.TypePing: Ping ping = new Ping((msg as Ping).PingType, (msg as Ping).Value2, (msg as Ping).Value3, (msg as Ping).Value4); ping.Header = header; _connection.Ping(ping); break; case Constants.TypeBytesRead: BytesRead bytesRead = new BytesRead((msg as BytesRead).Bytes); bytesRead.Header = header; bytesRead.Timestamp = header.Timer; _connection.GetChannel((byte)2).Write(bytesRead); break; default: _data.Write(msg); break; } } }
private void QueueDownload(VideoData video) { YouTubeDownloader.Instance.EnqueueVideo(video); VideoDownloaderDownloadProgress(video); }
private void VideoFlowCoordinatorFinished(VideoData video) { UpdateVideoButton(video); }
public void InitWith(VideoData videoData, Callback <VideoData> onClick) { this.videoData = videoData; this.onClick = onClick; gameObject.GetComponent <RawImage>().texture = ResourcesMgr.Instance.GetTextureWithName(videoData.imgurl); }
private void UpdateParent() { var data = new VideoData (); data.At = this.CurrentPosition; data.Duration = this.Duration; data.State = this.ParentElement.State; this.ParentElement.Info = data; }
public void AddVideo(VideoData video) { AddVideo(video, video.level); }
void Start() { data = VideoData.FromJson(jsonData.text); vlist = data.Data.Vlist; }
public void RemoveVideo(VideoData video) { videos.Remove(video.level); }
public void SetLatest(VideoData v) { History.Add(Latest.Stats); Latest = v; }
private void RetrieveCustomLevelVideoData(SongLoader songLoader, List <CustomLevel> levels) { Action job = delegate { try { float i = 0; foreach (CustomLevel level in levels) { i++; var songPath = level.customSongInfo.path; var results = Directory.GetFiles(songPath, "video.json", SearchOption.AllDirectories); if (results.Length == 0) { continue; } var result = results[0]; try { var i1 = i; HMMainThreadDispatcher.instance.Enqueue(delegate { if (_loadingCancelled) { return; } VideoData video = LoadVideo(result, level.difficultyBeatmapSets[0].difficultyBeatmaps[0].level); if (video != null) { AddVideo(video); } }); } catch (Exception e) { Console.WriteLine("[MVP] Failed to load song folder: " + result); Console.WriteLine(e.ToString()); } } } catch (Exception e) { Console.WriteLine("[MVP] RetrieveCustomLevelVideoData failed:"); Console.WriteLine(e.ToString()); } }; Action finish = delegate { AreVideosLoaded = true; AreVideosLoading = false; _loadingTask = null; VideosLoadedEvent?.Invoke(); }; _loadingTask = new HMTask(job, finish); _loadingTask.Run(); }
public void Setup(VideoData videoData) { videoLengthTime = videoData.lengthTimeInSeconds; ResetVideo(); isPlaying = true; }
public string GetVideoPath(VideoData video) { return(Path.Combine(GetLevelPath(video.level), video.videoPath)); }
public VideoDownload(VideoData video) { this.video = video; downloadAttempts = 0; timeSinceLastUpdate = 0; }
public bool CanSendPacket(RtmpMessage message, long pending) { IRtmpEvent packet = message.body; if (!(packet is VideoData)) { // We currently only drop video packets. return(true); } VideoData video = packet as VideoData; FrameType type = video.FrameType; bool result = false; switch (_state) { case FrameDropperState.SEND_ALL: // All packets will be sent. result = true; break; case FrameDropperState.SEND_INTERFRAMES: // Only keyframes and interframes will be sent. if (type == FrameType.Keyframe) { if (pending == 0) { // Send all frames from now on. _state = FrameDropperState.SEND_ALL; } result = true; } else if (type == FrameType.Interframe) { result = true; } break; case FrameDropperState.SEND_KEYFRAMES: // Only keyframes will be sent. result = (type == FrameType.Keyframe); if (result && pending == 0) { // Maybe switch back to SEND_INTERFRAMES after the next keyframe _state = FrameDropperState.SEND_KEYFRAMES_CHECK; } break; case FrameDropperState.SEND_KEYFRAMES_CHECK: // Only keyframes will be sent. result = (type == FrameType.Keyframe); if (result && pending == 0) { // Continue with sending interframes as well _state = FrameDropperState.SEND_INTERFRAMES; } break; default: break; } return(result); }
public void DequeueVideo(VideoData video) { video.downloadState = DownloadState.Cancelled; downloadProgress?.Invoke(video); }
public void SetContent(VideoData video) { selectedVideo = video; }
private IEnumerator DownloadVideo() { downloading = true; if (!updated) { yield return(new WaitUntil(() => updated)); } VideoDownload download = videoQueue.Peek(); VideoData video = download.video; if (video.downloadState == DownloadState.Cancelled || download.downloadAttempts > MaxRetries) { // skip videoQueue.Dequeue(); if (videoQueue.Count > 0) { // Start next download DownloadVideo(); } else { // queue empty downloading = false; yield break; } } StopCoroutine(Countdown(download)); video.downloadState = DownloadState.Downloading; downloadProgress?.Invoke(video); download.Update(); string levelPath = VideoLoader.GetLevelPath(video.level); if (!Directory.Exists(levelPath)) { Directory.CreateDirectory(levelPath); } string videoFileName = video.title; // Strip invalid characters foreach (var c in Path.GetInvalidFileNameChars()) { videoFileName = videoFileName.Replace(c, '-'); } videoFileName = videoFileName.Replace('\\', '-'); videoFileName = videoFileName.Replace('/', '-'); video.videoPath = videoFileName + ".mp4"; // Download the video via youtube-dl ydl = new Process(); ydl.StartInfo.FileName = Environment.CurrentDirectory + "\\Youtube-dl\\youtube-dl.exe"; ydl.StartInfo.Arguments = "https://www.youtube.com" + video.URL + " -f \"" + VideoQualitySetting.Format(quality) + "\"" + // Formats " --no-cache-dir" + // Don't use temp storage " -o \"" + levelPath + $"\\{videoFileName}.%(ext)s\"" + " --no-playlist" + // Don't download playlists, only the first video " --no-part"; // Don't store download in parts, write directly to file ydl.StartInfo.RedirectStandardOutput = true; ydl.StartInfo.RedirectStandardError = true; ydl.StartInfo.UseShellExecute = false; ydl.StartInfo.CreateNoWindow = true; ydl.EnableRaisingEvents = true; ydl.Start(); // Hook up our output to console ydl.BeginOutputReadLine(); ydl.BeginErrorReadLine(); ydl.OutputDataReceived += (sender, e) => { if (e.Data != null) { Regex rx = new Regex(@"(\d*).\d%+"); Match match = rx.Match(e.Data); if (match.Success) { video.downloadProgress = float.Parse(match.Value.Substring(0, match.Value.Length - 1)) / 100; downloadProgress?.Invoke(video); download.Update(); } } }; ydl.ErrorDataReceived += (sender, e) => { if (e.Data.Length < 3) { return; } //to do: check these errors are problems - redownload or skip file when an error occurs //video.downloadState = DownloadState.Cancelled; downloadProgress?.Invoke(video); download.Update(); }; ydl.Exited += (sender, e) => { StopCoroutine(Countdown(download)); if (video.downloadState == DownloadState.Cancelled) { VideoLoader.Instance.DeleteVideo(video); } else { video.downloadState = DownloadState.Downloaded; VideoLoader.SaveVideoToDisk(video); StartCoroutine(VerifyDownload(video)); } videoQueue.Dequeue(); if (videoQueue.Count > 0) { // Start next download DownloadVideo(); } else { // queue empty downloading = false; } ydl.Dispose(); }; }
public MediaEntry(YoutubeDL ydl, VideoData metadata) { this.ydl = ydl; this.Metadata = metadata; this.progress = new Progress <DownloadProgress>(p => RaiseDownloadStateChanged(p)); }
public void ModifyVariableValues(VideoData videoData) { // List<int> IDList; // List<int> valueList; // ModifyLoveVariableValue(IDList, valueList, qteActionDataData.id); }
public void SetData(Repetitions repetitions) { returns = VideoData.GetOutResult(repetitions.ID); bindingSource1.DataSource = returns; }
public void DeleteVideo(VideoData video) { RemoveVideo(video); File.Delete(Path.Combine(GetLevelPath(video.level), "video.json")); File.Delete(GetVideoPath(video)); }
private void UpdateParent() { var data = new VideoData (); data.At = this.CurrentPosition; data.Duration = this.Duration; this.RootPlayer.FireChange (data); }
public void AddVideo(VideoData video) { videos.Add(video.level, video); }
public override void OnDataReceived(object sender, VideoData data) { SendData(data); }
/// <summary> /// This function displays the current image on the screen passed from Kinect event /// </summary> /// <param name="newVideoData">Object containing the new Image frame</param> /// <returns>result code for failure or success </returns> private int ProcessNewVideoData(VideoData newVideoData) { try { if (newVideoData == null) { return (int)ResultCodes.OutOfMemory; } PlanarImage latestImage = newVideoData.ImageFrame.Image; videoStreamToForm.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send /*Send - the highest priority for the dispatcher*/, TimeSpan.FromSeconds(1), new Action( () => { try { videoStreamToForm.Source = BitmapSource.Create( latestImage.Width, latestImage.Height, 96, 96, PixelFormats.Bgr32, null, latestImage.Bits, latestImage.Width * latestImage.BytesPerPixel); } catch { } })); } catch { return (int)ResultCodes.VideoProcessorFailed; } return (int)ResultCodes.Success; }