Progress Encode

4 views
Skip to first unread message

Yaima President

unread,
Aug 5, 2024, 12:10:55 PM8/5/24
to prodhelmcalink
Whats the best way to encode a URL in progress. I want to build an encoded URL and don't want to write my own encoding function. Is there a command that can be run or a function that someone else already wrote?

I've written a whole system in PHP and bash on the server to convert and stream videos in HTML5 on my VPS. The conversion is done by ffmpeg in the background and the contents is output to block.txt.


You can have this as the only piece of text echoed out to a page, and from another page you can perform an AJAX request using jQuery to grab this piece of text and output it into a div, for example, to update on your page every 10 seconds. :)


Before you start encoding you can get the total frames, and a lot of other info with this (this is what would be done with bash. I'm a Perl programmer so I don't know how you'd get the info into your PHP script).


The output to the progress file is added to approximately once a second. Content, after the encoding is finished, looks like the following. In my script, once a second I am putting the file into an array, and traversing the array in reverse order, using only what is between the first [last before reversal] two "progress" lines I find, so that I am using the most recent info from the end of the file. There may be better ways. This is from an mp4 with no audio so there is only one stream.




In webspeed, cgiutils.i contains several utility functions for dealing with encoded strings. In addition to html-encode there are also url-encode and url-decode. These two functions are probably what you are looking for.


Progress, Telerik, Ipswitch and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.


By default, a 2d numpy array with shape [num_inputs, output_dimension] is returned.If only one string input is provided, then the output is a 1d array with shape [output_dimension]. If convert_to_tensor,a torch Tensor is returned instead. If self.truncate_dim


Encodes a list of sentences using multiple processes and GPUs viaSentenceTransformer.encode.The sentences are chunked into smaller packages and sent to individual processes, which encode them on differentGPUs or CPUs. This method is only suitable for encoding large sets of sentences.


Deprecated training method from before Sentence Transformers v3.0, it is recommended to useSentenceTransformerTrainer instead. This method usesSentenceTransformerTrainer behind the scenes, but doesnot provide as much flexibility as the Trainer itself.


This training approach uses a list of DataLoaders and Loss functions to train the model. Each DataLoaderis sampled in turn for one batch. We sample only as many batches from each DataLoader as there are in thesmallest one to make sure of equal training with each dataset, i.e. round robin sampling.


This method should produce equivalent results in v3.0+ as before v3.0, but if you encounter any issueswith your existing training scripts, then you may wish to useSentenceTransformer.old_fit instead.That uses the old training method from before v3.0.


Deprecated training method from before Sentence Transformers v3.0, it is recommended to usesentence_transformers.trainer.SentenceTransformerTrainer instead. This method shouldonly be used if you encounter issues with your existing training scripts after upgrading to v3.0+.


Compute the similarity between two collections of embeddings. The output will be a matrix with the similarityscores between all embeddings from the first parameter and all embeddings from the second parameter. Thisdiffers from similarity_pairwise which computes the similarity between each pair of embeddings.


This method is recommended if you want to encode on multiple GPUs or CPUs. It is advisedto start only one process per GPU. This method works together with encode_multi_processand stop_multi_process_pool.


Its signature is similar to torch.Tensor.to(), but only acceptsfloating point or complex dtypes. In addition, this method willonly cast the floating point or complex parameters and buffers to dtype(if given). The integral parameters and buffers will be moveddevice, if that is given, but with dtypes unchanged. Whennon_blocking is set, it tries to convert/move asynchronouslywith respect to the host if possible, e.g., moving CPU Tensors withpinned memory to CUDA devices.


The pairwise similarity function returns the diagonal vector from the similarity matrix, i.e. it onlycomputes the similarity(a[i], b[i]) for each i in the range of the input tensors, rather thancomputing the similarity between all pairs of a and b.


It's not pretty but it works, mostly. Open a video file or drag it to the preview window, hit the play button to preview, or Save to write out a "pdv" file to disk. That also extracts the audio and saves that separately, which I'll explain later. It saves from the current position (set with slider) to the end of the file, or when you hit Stop. I can't decide if that makes more sense than starting from the beginning.. You can change the different settings during preview to see how they affect the output.


fwd bias is a weird one. That's how much a pixel resists flipping, if it can avoid it. This reduces flicker and also improves compression, but too much of it causes ghosting and jumbled pixels. I think 30 is a reasonable value? It probably depends on the video.


iframe every x frames: Since the fwd bias carries error forward we need a clean frame ("iframe", for some reason) every once in a while to reset things. And since it flips more pixels than a biased frame (delta frame, or "dframe"), the iframe can produce a noticeable flicker, especially on the device screen. Changing the rate at which iframes occur affects the flicker in unpredictable ways. Play around with it, see what works! Iframes are less compressible than dframes so more iframes equals bigger files.


add reverse step to iframes: The video api lets you grab frames at random from the file, but is optimized for playing in forward order. If you'll be playing backwards as well as forwards, this setting adds an extra dframe to generate the previous frame from an iframe.


So about that audio file.. The pdv format does not (yet) contain audio data. To play a video file synced with audio, you play the audio file in the normal way, then use its current position to figure out which frame to show. The audio file the tool saves isn't in a format the playdate compiler recognizes so you'll have to convert it to aif or wav yourself. (Sorry! I'll see what it takes to make it save aif instead..) Here's a simple video player:


(In retrospect I shouldn't have used a time lapse video, but that's what I had at hand and it's late and I want to post this and go to bed. The sped up time isn't a glitch, it's supposed to look like that.)


But now let's talk about file size. The pdv in that sample there is only 15 seconds of 30 fps video and it's 2.4 MB. (The audio is 44kHz mono, 1.3 MB uncompressed but would be 1/4 that if I'd ADPCMed it.) If you push the bias up and compress the audio, that's around 10MB per minute of 30 fps video. That's.. not insignificant! I'm putting this tool out there as something you can play with if you're interested, not to suggest you should be making giant FMV games.


Do i remember correctly that @Nic concluded Blue Nosie gave the "best" video quality? (most stable? highest fidelity?) But I see that it also produces larger output than Stucki or Bayer (I didn't test any others), which is contrary to my expectations.


That's really weird that the blue noise dither made larger files. I'd expect it to be pretty much identical to Bayer on that front, and better than Stucki. I'll check that out. I had Nic's scheme working but that code was in a weird broken state when I dug this tool out of storage it, so I rolled that back. I'll go back and find my conversation with him and see if I can get it going again.


Blue noise works really well for smooth gradients, but like with Bayer you lose fine detail. As a compromise, Nic's algorithm checks the local gradient at each pixel; below a threshold it uses blue noise, above it uses error-diffusing.


Also, I was thinking about the savings that can be made by optimising GIFs (eg. 2.9MB became 259KB in my situation) but those kind of optimisations will only pay back with video that has a lot of common pixels frame-to-frame.


I tried it on a video of La Linea with really good results. Around 3MB (video only) for 2 minutes 40 seconds. This is kind of the perfect content to have good compression but still, this is really good.


I had no problem playing back with lua but I also tried with C and I couldn't use useScreenContext(). I only had a black screen (clearing the screen showed that the frames were properly read for some reason). I had to render the frame in a bitmap to make it work.


fwd bias changes the threshold for the pixel for the next frame to bias it against flipping. If an output pixel is black in the current frame and the fwd bias is 40, on the next frame that pixel's input value needs to be over 167 instead of 127 for the output to be white.


The video format is reverse engineered here: GitHub - cranksters/playdate-reverse-engineering: Panic Playdate reverse-engineering notes/tools - covers file formats, server API and USB commands (unofficial resource)


Looks like he got almost everything. That unknown 1 at offset 28 is actually the pointer to the first frame, offset=0 and type=1. With the other formats I avoided redundant data like that but I think by the time I got to video I wasn't that worried about saving 4 bytes. So it looks like his frame type is off by one--a 2 in the type field at offset 32 in the file means the second frame has a P-frame, not the first. Frames can also have type=3, in which case the frame data is a uint16 length followed by an I-frame data of that length then a P-frame. This is so you can step backwards from an I-frame without having to jump to the previous I-frame then apply P-frames all the way forward.

3a8082e126
Reply all
Reply to author
Forward
0 new messages