Skip to content

Return time stamp and sequence number with video frame #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 258 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
258 commits
Select commit Hold shift + click to select a range
4760bf2
Construct a video device
TimSC Oct 20, 2013
5464d80
Move to use C++
TimSC Oct 20, 2013
4bd6a57
Create buffers
TimSC Oct 20, 2013
d0d944b
Start and stop functions but it segfaults
TimSC Oct 20, 2013
66faa42
Start and stop function works
TimSC Oct 20, 2013
105a30e
Fix segfault in stop
TimSC Oct 20, 2013
39b313f
Stopping and closing and restarting works
TimSC Oct 20, 2013
f86020d
Tidy code
TimSC Oct 20, 2013
0e05ba7
Tidy code
TimSC Oct 20, 2013
7139816
Properly do deinit
TimSC Oct 20, 2013
d59be19
Start on reading frame in worker thread
TimSC Oct 20, 2013
c55d5f3
Change license to GPL
TimSC Oct 20, 2013
74535a2
Problems reading frame
TimSC Oct 20, 2013
b123b54
Test function works, does all code need to be in worker?
TimSC Oct 20, 2013
6450b12
Moved functionality to worker but did not help
TimSC Oct 20, 2013
c93f455
Moved functionality to worker but did not help
TimSC Oct 20, 2013
83b5afe
Moved almost everything to oop design but errors still occur
TimSC Oct 20, 2013
ac7f2aa
Tidy code but still seg faulting
TimSC Oct 20, 2013
3927998
Still not found bug
TimSC Oct 20, 2013
8bbb2b4
Applied fix to main problem but now swamped by warnings
TimSC Oct 20, 2013
c98659a
Use select to check webcam ready
TimSC Oct 20, 2013
72cb6c8
Broke something, segfaults
TimSC Oct 20, 2013
f2fa97e
Set format works but remove sleeps cause segfault
TimSC Oct 20, 2013
a85cf9e
Update doc strings
TimSC Oct 20, 2013
9637f12
Control order of actions in worker thread
TimSC Oct 20, 2013
e3ddbbb
Move frame decode to separate func
TimSC Oct 21, 2013
44cdbe5
Move frame decode to separate func
TimSC Oct 21, 2013
14791b7
Change set format to be async
TimSC Oct 21, 2013
422464d
Move decode frame to separate function
TimSC Oct 21, 2013
83e31a0
Insert huffman table
TimSC Oct 21, 2013
f5b30e9
Using libjpeg but now segfaults
TimSC Oct 21, 2013
ace6198
MJpeg appears to decode
TimSC Oct 21, 2013
3790e09
Return image to python
TimSC Oct 21, 2013
73ff770
Remove or make debug statements conditional
TimSC Oct 21, 2013
718b291
Improve stability of worker thread
TimSC Oct 21, 2013
0c06294
Set format automagically
TimSC Oct 21, 2013
b9edfc8
Remove hard coded rgb
TimSC Oct 21, 2013
08e10b6
Add YUYV decoding
TimSC Oct 21, 2013
f297813
Skip conversion if not needed
TimSC Oct 21, 2013
3ddabe4
Pass meta data to python
TimSC Oct 21, 2013
bdbbf7c
Fix meta data
TimSC Oct 21, 2013
fc5bcbe
If frame cannot be decoded, return encoded frame
TimSC Oct 21, 2013
6d072e2
List available devices
TimSC Oct 21, 2013
0dfcea7
Added YUV2 but actually need YVU420
TimSC Oct 22, 2013
119a2b3
Remove original capture approach
TimSC Oct 22, 2013
eaa2a4b
Adding a class for video output
TimSC Oct 22, 2013
7ae8da1
Add low level function for video out
TimSC Oct 22, 2013
442d852
Add open and close methods
TimSC Oct 22, 2013
cb9e625
Start and stop worker thread
TimSC Oct 22, 2013
2ac1968
Adding actual v4l2loopback code to worker thread
TimSC Oct 23, 2013
24eb4be
Move pixel format conversion to separate file
TimSC Oct 23, 2013
ca21046
Create function to send frame
TimSC Oct 23, 2013
f67fb89
Pass meta data into video out manager
TimSC Oct 23, 2013
418387e
Add sending frame to buffer
TimSC Oct 23, 2013
144c717
Add timer polling
TimSC Oct 23, 2013
a3502bd
Convert current frame to appropriate format
TimSC Oct 23, 2013
628d29c
Convert current frame to appropriate format
TimSC Oct 23, 2013
2ade3e6
Set colour channels to grey
TimSC Oct 23, 2013
9e474d6
Fix yuyv colour transform
TimSC Oct 24, 2013
b7f612e
Allow configuration of pix format and output size
TimSC Oct 24, 2013
4d0665f
Reduce debug messages
TimSC Oct 24, 2013
3158a1c
Remove unnecessary padding
TimSC Oct 24, 2013
4d2f69e
Add libjpeg error handling
TimSC Oct 24, 2013
a5ae422
Added UYVY for skype
TimSC Oct 26, 2013
0d5887a
Fix null pointer deference
TimSC Oct 27, 2013
b5de181
List video devices
TimSC Nov 5, 2013
6a6ec23
Refactor code and rename to libvideolive
TimSC Nov 15, 2013
3ef4b8c
Use correct init function name
TimSC Nov 15, 2013
68482c9
Rename video input class
TimSC Nov 15, 2013
ddd20ae
Use a common video input base class
TimSC Nov 15, 2013
181a539
Use a common video input base class
TimSC Nov 15, 2013
be42357
Refactor video output
TimSC Nov 15, 2013
1c3d870
Refactor video out
TimSC Nov 15, 2013
ea5205e
Rename video in manager
TimSC Nov 15, 2013
1121f83
Video out code defined in terms of abstract class
TimSC Nov 15, 2013
b5cc35f
Move high level capture code to separate files
TimSC Nov 15, 2013
77311f3
Update readme
TimSC Nov 15, 2013
5a598f3
Create files for windows implementation
Nov 15, 2013
1c54c86
Compiles empty classes on windows
Nov 15, 2013
4551650
Adapt to use visual studio
Nov 15, 2013
a6cdf84
Add manifest option
Nov 15, 2013
bea0041
Update docs
Nov 15, 2013
dae34e0
Update linux classes to use base method
TimSC Nov 15, 2013
f130977
Move wmf implementation into separate source file
Nov 18, 2013
863f71a
Importing some source code and link against wmf
Nov 18, 2013
38222ea
Add test script
Nov 18, 2013
6921c01
Attempt to list sources
Nov 18, 2013
5cfb851
Attempt to list sources
Nov 18, 2013
487f5ef
Attempt to list sources
Nov 18, 2013
2f7624f
Attempt to list sources
Nov 18, 2013
325dc05
Avoid free null pointer
Nov 18, 2013
1b69ce5
Remove debug code
Nov 18, 2013
b1e9549
Remove debug code
Nov 18, 2013
29668c6
Thread start and stop code
Nov 18, 2013
c4f1413
Thread start and stop code
Nov 18, 2013
d571946
Camera is now active
Nov 18, 2013
c18d5d7
Merge branch 'master' of https://github.com/TimSC/libvideolive
Nov 18, 2013
20a9190
Update linux api
TimSC Nov 18, 2013
c311c0e
Stop device in a clean way
Nov 19, 2013
b6682a2
Merge branch 'master' of https://github.com/TimSC/libvideolive
Nov 19, 2013
92a15aa
Give camera time to stop
Nov 19, 2013
28edf7f
Remove old test scripts
Nov 19, 2013
b89479d
Frame is returned but not meta data
Nov 19, 2013
32497ea
Added meta data but enabled code crashes
Nov 19, 2013
b927971
Reorganise code but still crashes
Nov 19, 2013
48f3532
Forgot to lock the shared data
Nov 19, 2013
6af2bb6
Set correct pixel format
Nov 19, 2013
164e90e
Attempt conversion but not working yet
Nov 19, 2013
91bdbbf
Decode yuy2 as yuyv
Nov 19, 2013
7efd1a0
Change com init flags
Nov 19, 2013
fb12950
Save link to msdn
Nov 20, 2013
944ad32
Move mf video output implementation to cpp file
Nov 20, 2013
74b8b99
Add project to test windows video out
Nov 20, 2013
c6db39e
Initialise com
Nov 20, 2013
41279e6
Add msdn ball example for modification
Nov 22, 2013
04298a1
Attempting to compile and link
Nov 22, 2013
f8d4186
Now links
Nov 22, 2013
7d7b9c8
Video source is registered
Nov 22, 2013
7d50d53
Working on format negotiation
Nov 22, 2013
0943bcd
Still no luck
Nov 22, 2013
54586aa
Skype connects
Nov 22, 2013
e36e5e2
update headers and guids
Nov 22, 2013
ff9c9ad
Remove unnecessary files
Nov 22, 2013
cbc0c9b
Reinstate guid
Nov 22, 2013
96d08bd
Load test pattern into buffer
Nov 22, 2013
6f0910e
Dshow source connects to named pipe
Nov 22, 2013
f9198ca
Store current frame in memory
Nov 22, 2013
ce2401d
Suspect that there are multiple instances of the class
Nov 22, 2013
6f46020
Simple frame update triggered by named pipe
Nov 22, 2013
1575e73
Video finally responds to named pipe
Nov 22, 2013
f8d9e05
Send meta data to server
Nov 24, 2013
e8e9ca6
Add members for decoding named pipe messages
Nov 24, 2013
05f41b3
Clean dynamically allocated mem
Nov 24, 2013
6de1d9b
Copy rx to buffer
Nov 24, 2013
4292a6d
Decode buffer code enabled but does not work
Nov 24, 2013
380b262
Update display on received packet
Nov 24, 2013
b15dd2d
Visualise buffer size
Nov 24, 2013
8faf8f9
Prevent buffer being deleted while io pending
Nov 24, 2013
3ccc6aa
Decoding messages ok
Nov 24, 2013
276af81
Increase video size
Nov 25, 2013
a05bea6
Put named pipe tx and rx on separate timers
Nov 25, 2013
0bcb623
Keep unprocessed buffer data available
Nov 25, 2013
89d2846
Reuse rx buffer
Nov 25, 2013
cf05234
Some code disabled to try to find performance problem
Nov 25, 2013
6611404
Fill buffer every frame
Nov 25, 2013
10298da
Trying to optimise frame rate
Nov 25, 2013
b569d54
Found slow code
Nov 25, 2013
7e44928
Rename project files
Nov 25, 2013
a507d68
Update source name
Nov 25, 2013
69f0fb8
Connection to named pipe resumed if connection is lost
Nov 25, 2013
e8df2a9
Update class names
Nov 25, 2013
b597716
Set frame rate to 25 fps
Nov 25, 2013
656c801
Remove test code
Nov 25, 2013
5387ce0
Remove test code
Nov 25, 2013
18ef4b3
Add files for named pipe method
Dec 1, 2013
f00c6fb
First attempt at named pipe server
Dec 1, 2013
d96b1ce
Send frames using test script
Dec 1, 2013
1cc4393
Adding lock to protect memory
Dec 1, 2013
51dda5e
Pass objection pointer to connection thread
Dec 1, 2013
2ffae28
Return actual frame or at least a part
Dec 2, 2013
3ca2cf5
Prevent buffer overrun
Dec 2, 2013
0b02912
Fill buffer every iteration
Dec 2, 2013
9ef3bef
Prevent buffer overrun
Dec 2, 2013
a0a0a05
Convert to BGR24 pix fmt
Dec 2, 2013
75198f7
Add placeholder for resize function
Dec 2, 2013
cd91ecb
Crop image to fit buffer
Dec 2, 2013
3a8f1ac
Nearest neighbour image resize
Dec 2, 2013
5422099
Reduce buffers to reduce latency
Dec 3, 2013
358b821
Check if camera supports time per frame
TimSC Dec 13, 2013
d81b497
Problems getting exposure to manual mode, each has quirks
TimSC Dec 13, 2013
6f473d2
Add video file writer to python api
Dec 16, 2013
165acbb
Adapt video writer example to oop design
Dec 16, 2013
334df99
Move video open and close to separate methods
Dec 16, 2013
00b8f74
Randomize every frame in video out tes
Dec 16, 2013
3cf8b2e
Change randomisation and make faster
Dec 16, 2013
41a0a03
Find appropriate pixel layout for video file writer
Dec 16, 2013
0139446
Remove alpha channel from video writer
Dec 16, 2013
0c1166d
Remove alpha channel from video writer
Dec 16, 2013
d05e86c
Use common pix format code for video writer
Dec 16, 2013
a164c37
Add resize code but it does not work yet
Dec 16, 2013
4af5fe2
Fixed resize code
Dec 16, 2013
1092f92
Make static video out variables class members
Dec 17, 2013
611fbc3
Only bgr colour space is supported but code running slowly
Dec 17, 2013
e4ebd4c
Fix speed but still investigating
Dec 17, 2013
f33ad05
Set filename of video in constructor
Dec 17, 2013
8d8be49
Disable frame rate
Dec 17, 2013
226128f
Lena test image works fine
Dec 17, 2013
d925b84
Set framerate via python
Dec 17, 2013
cd49b8c
Add real time clock to video out
Dec 17, 2013
052abfe
Trap and return error in video writer
Dec 17, 2013
df8564f
Print more error info with hr result
Dec 17, 2013
f31fd1b
Progress on encoding h264 but rate rate must be set
Dec 17, 2013
08e0cd1
Add method to set real time frame encoding
Dec 17, 2013
7a499dc
H264 greyscale sort of working
Dec 18, 2013
4388180
Fix formula typo
Dec 18, 2013
8801b65
Colour I420 now working
Dec 18, 2013
297501b
Reorganise pixel format code
Dec 18, 2013
3f338a5
Colour I420 now working
Dec 18, 2013
f9f9afc
Change default colour encoding and function params
Dec 18, 2013
d9ec39f
Support different container formats
Dec 18, 2013
ee99a47
Catch decode exception and convert to python exception
Dec 18, 2013
aaa70ff
Remember to initialise buffer len to zero
Dec 18, 2013
c054835
Change types to be linux compatible
TimSC Dec 18, 2013
032098e
Check start of jpeg
TimSC Dec 18, 2013
32db39b
Disable unnecessary code
Dec 18, 2013
cc3efdf
Dropped frames were leaking memory
Dec 18, 2013
93404f7
Remove debug messages
Dec 18, 2013
f5897f4
Exceptions should return null not none
Dec 18, 2013
203d61e
Exceptions should return null not none
Dec 18, 2013
29bce84
Set default frame rate for video out
Dec 19, 2013
66404fe
Change exceptions to use PyErr_SetString
TimSC Dec 19, 2013
147c8a7
Change from self timing frames to use arguments for function
Dec 19, 2013
aba20a6
Change input type to duble
Dec 19, 2013
5a6d2dc
Catch out of range error but unsure if this is a good approach
Dec 19, 2013
243abba
Close file when finished
Dec 19, 2013
572c344
Support both byte arrays and strings for input images
Dec 19, 2013
4a10afa
Simplify time stamp in python api
Dec 19, 2013
c0a5315
Read exposure of webcam
Dec 21, 2013
5a4826b
Trying to set exposure but makes little difference
Dec 21, 2013
fd71cdd
Hack to set exposure
Dec 21, 2013
697f694
Disable test code
Dec 21, 2013
812eec1
Vertical flip of webcam input
Dec 31, 2013
fbd36f1
Use external clock with linux
TimSC Jan 1, 2014
ac116b7
Use external clock with linux
TimSC Jan 1, 2014
878baff
Attempting to fix lingering linux mjpeg decode bug
TimSC Jan 1, 2014
ab3d93b
Decoding fails in interactive mode as expected
TimSC Jan 1, 2014
160bde5
Initialise mem
TimSC Jan 1, 2014
9ae1fa7
Fix memory size
TimSC Jan 2, 2014
a800ecc
Fixed type of var
TimSC Jan 2, 2014
d895471
Reuse buffer in decoding
TimSC Jan 2, 2014
11f1c25
Remove debug code
TimSC Jan 2, 2014
9d473f5
Add warning for file writer not implemented on posix
TimSC Jan 4, 2014
4059379
Remove debug code
TimSC Jan 4, 2014
da4ae77
Attempting to decode jpeg of unknown size
TimSC Jan 9, 2014
d3bd8bd
Cant find cause of exception err
TimSC Jan 9, 2014
a5340ee
PyErr is set in an unusual way
TimSC Jan 9, 2014
6eaa11a
PyErr is set in an unusual way
TimSC Jan 9, 2014
09d660c
Using wrong function to get type of bytearray
TimSC Jan 9, 2014
4b73c6a
Using wrong function to get type of bytearray
TimSC Jan 9, 2014
6ee51af
Optional argument for meta data
TimSC Jan 9, 2014
c8fc201
Fix type in decode func
Jan 10, 2014
72a9194
Deallocate video out buffer when done
Jan 11, 2014
312ff6c
Do not overwrite buffer size
Jan 11, 2014
4fc41e0
Add build commands as comments
Jan 13, 2014
37d5d43
Update video in example
Jan 30, 2014
56feea5
Fixed one memory leak, suspect more leaks are present
Jan 30, 2014
4b9124e
Hacked version with minimal or no leak
Jan 30, 2014
890abfd
Another fairly non leaky version with more enabled
Jan 30, 2014
7eeef9b
Found another memory leak
Jan 31, 2014
12965ad
Remove test code
Jan 31, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ capture_picture.py
capture_picture_delayed.py
list_devices.py
setup.py
v4l2capture.c
v4l2capture.cpp
57 changes: 28 additions & 29 deletions README
Original file line number Diff line number Diff line change
@@ -1,57 +1,56 @@
python-v4l2capture 1.4.x
Python extension to capture video with video4linux2
libvideolive
Capture and stream video in python

2009, 2010, 2011 Fredrik Portstrom
2011 Joakim Gebart
2013 Tim Sheerman-Chase

I, the copyright holder of this file, hereby release it into the
public domain. This applies worldwide. In case this is not legally
possible: I grant anyone the right to use this work for any purpose,
without any conditions, unless such conditions are required by law.
This software may be used and redistributed under the terms of the GPL v2 (or later) license.

Introduction
============

python-v4l2capture is a slim and easy to use Python extension for
capturing video with video4linux2. It supports libv4l to convert any
image format to RGB or YUV420.
libvideolive is a slim and easy to use Python extension for
capturing and streaming video.

this fork of python-v4l2capture: https://github.com/gebart/python-v4l2capture

original python-v4l2capture: http://fredrik.jemla.eu/v4l2capture

libv4l: http://freshmeat.net/projects/libv4l

Installation
============
Installation on Linux
=====================

libvideolive on linux requires libv4l by default. You can do so by erasing ', libraries = ["v4l2"]'
in setup.py and erasing '#define USE_LIBV4L' in v4l2capture.cpp.

libvideolive uses distutils to compile. For Linux:

./setup.py build
sudo ./setup.py install

Installation on Windows
=====================

v4l2capture requires libv4l by default. You can compile v4l2capture
without libv4l, but that reduces image format support to YUYV input
and RGB output only. You can do so by erasing ', libraries = ["v4l2"]'
in setup.py and erasing '#define USE_LIBV4L' in v4l2capture.c.
Modify setup.py to specify locations of libjpeg and pthread external libraries.

python-v4l2capture uses distutils.
To build: ./setup.py build
To build and install: ./setup.py install
With Visual Studio 2010:

SET VS90COMNTOOLS=%VS100COMNTOOLS%
python setup.py build -c msvc
python setup.py install

Remember to put the libjpeg and pthread dlls somewhere appropriate.

Example
=======

See capture_picture.py, capture_picture_delayed.py and list_devices.py.
To do

Change log
==========

(see git log for latest changes)

1.4 (2011-03-18) - Added support for YUV420 output.

1.3 (2010-07-21) - Added set of capabilities to the return value of
get_info. Updated list_devices.py.

1.2 (2010-04-01) - Forked example script into capture_picture.py and
capture_picture_delayed.py.

1.1 (2009-11-03) - Updated URL and documentation.

1.0 (2009-02-28) - Initial release.
91 changes: 91 additions & 0 deletions base.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@

#ifndef BASE_H
#define BASE_H

#include <string>

class FrameMetaData
{
public:
std::string fmt;
int width;
int height;
unsigned buffLen;
unsigned long sequence;
unsigned long tv_sec;
unsigned long tv_usec;

FrameMetaData()
{
width = 0;
height = 0;
buffLen = 0;
sequence = 0;
tv_sec = 0;
tv_usec = 0;
}

FrameMetaData(const FrameMetaData &in)
{
FrameMetaData::operator=(in);
}

const FrameMetaData &operator=(const FrameMetaData &in)
{
width = in.width;
height = in.height;
fmt = in.fmt;
buffLen = in.buffLen;
sequence = in.sequence;
tv_sec = in.tv_sec;
tv_usec = in.tv_usec;
return *this;
}

};

class Base_Video_In
{
public:
Base_Video_In() {};
virtual ~Base_Video_In() {};

virtual void Stop() {};
virtual void WaitForStop() {};
virtual void OpenDevice() {};
virtual void SetFormat(const char *fmt, int width, int height) {};
virtual void StartDevice(int buffer_count) {};
virtual void StopDevice() {};
virtual void CloseDevice() {};
virtual int GetFrame(unsigned char **buffOut, class FrameMetaData *metaOut) {return 0;};

void Run() {};
};

// **********************************************************************

class Base_Video_Out
{
public:
Base_Video_Out() {};
virtual ~Base_Video_Out() {};

virtual void SendFrame(const char *imgIn,
unsigned imgLen,
const char *pxFmt,
int width,
int height,
unsigned long tv_sec = 0,
unsigned long tv_usec = 0) {};
virtual void Stop() {};
virtual int WaitForStop() {return 1;};
virtual void SetOutputSize(int width, int height) {};
virtual void SetOutputPxFmt(const char *fmt) {};
virtual void SetFrameRate(unsigned int frameRateIn) {};
virtual void SetVideoCodec(const char *codec, unsigned int bitrate) {};

void Run() {};
};

#endif //BASE_H

47 changes: 0 additions & 47 deletions capture_picture.py

This file was deleted.

54 changes: 0 additions & 54 deletions capture_picture_delayed.py

This file was deleted.

Loading