how to create mjpeg - usb

I can't understand how to create a .mjpeg file. As far as I understand it is simply a series of jpeg files. I searched online for a way to combine them into a single file, but didn't find any information. Some people said that one just needs to create a miniserver that would show one image after another.
I'm trying to use the following application, git://git.ideasonboard.org/uvc-gadget.git, to test UVC, and one of the options that it has is a path to the mjpeg file. I'm not very clear if it is possible to create a mjpeg file at all.
Would appreciate any help on how to create an mjpeg file so I could use it with the above mentioned application.

I had a difficult time searching for the same. It's especially misleading to read through mencoder's manpage when it supports various movie containers but not the UVC payload format.
This seemed to work for me to record a bytestream from a webcam on Ubuntu 16.04:
gst-launch-1.0 v4l2src device=/dev/video0 ! 'image/jpeg,width=1280,height=720,framerate=30/1' ! \
filesink buffer-size=0 location=mystream.mjpeg
where 1280x720 at 30 fps is what guvcview says my webcam supports.
Source: link
Edit: Later I learned about v4l2-ctl:
v4l2-ctl -d /dev/video0 --list-formats-ext # identify a proper resolution/format
v4l2-ctl --set-fmt-video=width=1280,height=720,pixelformat=1
v4l2-ctl --stream-mmap=1 --stream-count=30 --stream-to=mystream.mjpeg
When the stream-count is set to 1, it makes a regular JPEG file that can be viewed with xdg-open. Otherwise, run file mystream.mjpeg to confirm the output has a proper resolution and frame count.
Getting this data to actually work with uvc-gadget -i could be much more involved. Given it possibly requires the appropriate patches, kernel configuration, and debugging, so far I have only gotten the uncompressed format to work in isochronous on my Raspberry Pi Zero. Hopefully you're further along.

Related

How do I edit GNU Radio's file sink output?

I recorded a signal with GNU Radio using a file sink block which outputs a raw binary file that can be analyzed or used as a source of input into GNU Radio.
I want to edit this raw file so that when I use it as a source inside GNU Radio it transmits my changed file instead of the original. For example: The signal is very long and repeats a pattern, I want to edit the file to reduce the number of repeated signals and save it back to the raw format to transmit using gnuradio later.
I tried importing the file into Audacity as a raw file (selecting 32bit float with 1 channel and 48k as the sample rate). This works for me to see the signal as audio data and I can even edit it but I'm not sure if it's saving it correctly when I export it as raw data. Also, the time indices in audacity seem to be way off; the signal should only be microseconds but audacity is showing it as a total of several seconds!
Anyone have any luck with editing the raw file sink output from GNU Radio?
I was able to consistently make this work. There seemed to be 3 things preventing this from working properly.
1) I was doing it wrong! I needed to output both the Real and the Imaginary numbers to a 2 channel wav file.
2) Using a spectrum analyzer, I was able to see that audacity was doing something really weird with the wav file when you delete a section of audio, so to combat this I "silenced" the section of audio I wanted to delete.
3) There seems to be a bug with Gnuradio and the Osmocom Sink (yes, I have the latest version of both, from source). If you run your flow graph, start transmitting then stop the flow graph by clicking the red X in Gnuradio (Kill the flow graph) it keeps my device (HackRF) transmitting! If you try to transmit a new file or the same file again, it will not transmit that signal because it's already trying to transmit something. In order to stop the device from transmitting, just close the block popup window that appears when you run the flow graph.
The 3rd item might not be a bug because I might have been stopping my flow graphs incorrectly to begin with, but following Michael Ossmann's tutorial on using the HackRF with Gnuradio, he says to click the red X to properly shutdown the flow graph and clean everything up; this appears to NOT be the case.
In the gr-utils/octave folder of the GNU Radio source code there are several functions for Octave and Matlab. Some of them allow to retrieve and store raw binary files of the corresponding data type.
For example, if your signal is constructed from float samples you can use the read_float_binary function to import the samples stored by the file sink block into Octave/Matlab. Then make your modifications to the signal and store it back again using the write_float_binary function. The stored file can be the imported to your flowgraph using a file source block.

USB Image transfer Linux

In my project I want to receive/send images to a USB device gadget. For this host side USB driver needs to be written. According to my understanding an image file cannot be directly transferred by reading and storing the bytes one by one till we encounter an EOF(as is done in a normal text file). So how do we do it?
I got a relevant topic on this at the following link:
What is most appropriate USB class to handle images and video transfer and streaming?
but still things were not clear. Should I use libptp with libusb to transfer the image files? i could not get any sample/example code which could explain if its possible or how its done. Thanks for the help in advance!
Regards,
Shweta
Also, from some more investigation, i think LibMTP can be used for image transfer. But to eork for that i guess we need LibUSB aslo installed. Is my understanding correct?
Have a look at this link if you are familiar with python and pygame. Also you can convert image to string and transfer it to other device by pyusb package in python.

Record audio in OS X into FLAC using Cocoa

I am trying to record audio from a microphone/iSight camera from Mac to a NSData object.
I have tried to do it using QTKit, but I found out that you could only save it as a .mov file.
But the fact is that I want to recode the audio into a FLAC file. Is that posible, or I'll need to use another framework?.
Thanks.
Grab the source for VLC (if you can deal w/GPL -- it has limitations on use that many find onerous) and have a read. It does transcoding, amongst other things.
Beyond that, one dead simple approach is to save as AIFF and then use a command line tool (via NSTask) to do the conversion.
Or you could just go with Apple Lossless -- it is open source these days.
Of course, this also begs the question; why do you need lossless compression when recording voice [low bandwidth in the first place] via a relatively sub-par microphone?

H264 frame viewer

Do you know any application that will display me all the headers/parameters of a single H264 frame? I don't need to decode it, I just want to see how it is built up.
Three ways come to my mind (if you are looking for something free, otherwise google "h264 analysis" for paid options):
Download the h.264 parser from (from this thread # doom9 forums)
Download the h.264 reference software
libh264bitstream provides h.264 bitstream reading/writing
This should get you started. By the way, the h.264 bitstream is described in Annex. B. in the ITU specs.
I've created a Web version - https://mradionov.github.io/h264-bitstream-viewer/
Based on h264bitstream and inspired by H264Naked. Done by compiling h264bitstream into WebAssembly and building a simple UI on top of it. Output information for NAL units is taken from H264Naked at the moment. Also supports files of any size, just will take some time initially to load the file, but navigation throughout the stream should be seamless.
I had the same question. I tried h264 analysis, but it only supports windows. So I made a similar tool with Qt to support different platforms.Download H264Naked. This tool is essentially a wrapper around libh264bitstream

Webcam capture and convert to avi

I'm working on a project and i'm trying to capture a webcam and use a codex to save the file to the hard disk. but i can't find a program for it ?
It would be cool if the program is controllable from the outside but its not necessary.
(it has to capture the audio to)
vlc can do the recording and conversion directly if given the proper command line options (that however is not trivial but reasonably well documented).
Also there is the library libvlc that you can use to do anything that vlc does; I only used it for playback but I suppose that capturing and saving to file should be not too difficult.
You didn't tell your platform, but both vlc and libvlc are windows/linux/osx and so that shouldn't be a big problem.
This is for example a vlc command line I use to start recording from my webcam
vlc v4l2:// :v4l2-dev=/dev/video0 :v4l2-width=320 :v4l2-height=240
--sout "#transcode{vcodec=x264,acodec=mpga,vb=800,ab=128}
:standard{access=file,dst=capture.avi}"