Decoding Video Data Per Pixel / Per Frame - html5-video

Are there some suggestions on decoding video data from a webcam in raw format, I would like the per pixel raster data frame per frame.

Use libraw to load and decode RAW data. If the html5-video tag was intended and it means what I think, there is no way of doing this in a browser, besides compiling it to Javascript, if you feel really adventurous.

Related

Handling Dynamic Sample Rates when Saving Audio File

So, I am recording a WAVE file using 16-bit PCM samples that are received from a widget that streams them over in real time. Pretty basic stuff, right? Except the problem is that the widget might dynamically change the sample rate of the audio data that it is sending.
It might start out at a nice 44.1 kHz stream but then might change to a 23 kHz sample rate, or vice-versa. My understanding is that conventional WAVE files do not handle varying sample rates like this, so I am trying to determine the best way to handle the situation.
One approach I came up with was to put something like a ResamplerDmoStream in front of the WaveFileWriter, locking the WaveFileWriter to a sample rate of 44.1 kHz, and just resampling all incoming data to 44.1 kHz.
Another idea that might work is to find a supported output file format that may have native support for varying sample rates, write all the data to that file and then perform a post-process resampling step to create a conventional 44.1 kHz WAVE file.
Anyone else out there had to deal with this kind of situation and has a better idea?
Thanks!
Peace!

Get GPS data from MOV (quicktime) video file

Please help to get GPS track with time from .mov file.
The file is fom car camera and consists GPS data because its viewer shows car position.
What is right way to do that?
You don't say if you're looking for a programming solution to parse the file and read the GPS metadata yourself, or whether you're looking for a tool that will display the data.
It also depends very much on the specific camera that recorded the file as they embed data in different formats. If you have an iPhone, for example, it records GPS data in a mdta metadata atom with key "com.apple.quicktime.location.ISO6709", but other formats exist too, especially if you mean real time varying GPS data embedded in each frame, rather in the header for the movie as a whole.
Tools that will read such data from the movie header include ExifTool and CatDV (though the latter is a commercial product).
I found that ffprobe from the ffmpeg project was able to extract the com.apple.quicktime.location.ISO6709 tag.

extracting motion-compensated frames during HEVC encoding

I am trying to analyze H.265 coding performance. Is there a way to export the predicted frames for H.265/HEVC encoding? Specifically, how should I obtain reconstructed frames after compensating with the motion vectors, but before applying the residual? Is there a way to do this with ffmpeg, or any other codec analysis tool?
Yes you can do it with HM decoder.
What you need to do is to find the exact line of the code in the TDecCu.cpp file, where two pointers piResi and piPred are accessed to be added and reconstruct the block. There, you may print piPred alone.

nvenc: no i-frames during encoding

I am using nvenc to encode a series of frames to a h.264 video on the GPU. My example is quite synthetic where I simply repeat the same frame. The encoding works fine and I was looking at figuring out what is going on:
One thing I notice is that the beginning frame is an IDR frame (NV_ENC_PIC_TYPE_IDR) and the rest of the frames are all forward predicted frames (NV_ENC_PIC_TYPE_P). I thought this is perhaps because every frame is the same. So, I generated frames where each frame is completely random. In that case, it is the same as well.
So, my question is whether there is something in the configuration which makes all the frames P-frames and there are no B or I frames. Under what conditions would these frames be generated?

How to detect silence and cut mp3 file without re-encoding using NAudio and .NET

I've been looking for an answer everywhere and I was only able to find some bits and pieces. What I want to do is to load multiple mp3 files (kind of temporarily merge them) and then cut them into pieces using silence detection.
My understanding is that I can use Mp3FileReader for this but the questions are:
1. How do I read say 20 seconds of audio from an mp3 file? Do I need to read 20 times reader.WaveFormat.AverageBytesPerSecond? Or maybe keep on reading frames until the sum of Mp3Frame.SampleCount / Mp3Frame.SampleRate exceeds 20 seconds?
2. How do I actually detect the silence? I would look at an appropriate number of the consecutive samples to check if they are all below some threshold. But how do I access the samples regardless of them being 8 or 16bit, mono or stereo etc.? Can I directly decode an MP3 frame?
3. After I have detected silence at say sample 10465, how do I map it back to the mp3 frame index to perform the cutting without re-encoding?
Here's the approach I'd recommend (which does involve re-encoding)
Use AudioFileReader to get your MP3 as floating point samples directly in the Read method
Find an open source noise gate algorithm, port it to C#, and use that to detect silence (i.e. when noise gate is closed, you have silence. You'll want to tweak threshold and attack/release times)
Create a derived ISampleProvider that uses the noise gate, and in its Read method, does not return samples that are in silence
Either: Pass the output into WaveFileWriter to create a WAV File and and encode the WAV file to MP3
Or: use NAudio.Lame to encode directly without a WAV step. You'll probably need to go from SampleProvider back down to 16 bit WAV provider first
BEFORE READING BELOW: Mark's answer is far easier to implement, and you'll almost certainly be happy with the results. This answer is for those who are willing to spend an inordinate amount of time on it.
So with that said, cutting an MP3 file based on silence without re-encoding or full decoding is actually possible... Basically, you can look at each frame's side info and each granule's gain & huffman data to "estimate" the silence.
Find the silence
Copy all the frames from before the silence to a new file
now it gets tricky...
Pull the audio data from the frames after the silence, keeping track of which frame header goes with what audio data.
Start writing the second new file, but as you write out the frames, update the main_data_begin field so the bit reservoir is in sync with where the audio data really is.
MP3 is a compressed audio format. You can't just cut bits out and expect the remainder to still be a valid MP3 file. In fact, since it's a DCT-based transform, the bits are in the frequency domain instead of the time domain. There simply are no bits for sample 10465. There's a frame which contains sample 10465, and there's a set of bits describing all frequencies in that frame.
Plain cutting the audio at sample 10465 and continuing with some random other sample probably causes a discontinuity, which means the number of frequencies present in the resulting frame skyrockets. So that definitely means a full recode. The better way is to smooth the transition, but that's not a trivial operation. And the result is of course slightly different than the input, so it still means a recode.
I don't understand why you'd want to read 20 seconds of audio anyway. Where's that number coming from? You usually want to read everything.
Sound is a wave; it's entirely expected that it crosses zero. So being close to zero isn't special. For a 20 Hz wave (threshold of hearing), zero crossings happen 40 times per second, but each time you'll have multiple samples near zero. So you basically need multiple samples that are all close to zero, but on both sides. 5 6 7 isn't much for 16 bits sounds, but it might very well be part of a wave that will have a maximum at 10000. You really should check for at least 0.05 seconds to catch those 20 Hz sounds.
Since you detected silence in a 50 millisecond interval, you have a "position" that's approximately several hundred samples wide. With any bit of luck, there's a frame boundary in there. Cut there. Else it's time for reencoding.