Package: shot-detector
Table of ContentsWhat is thisHow to installWith condaWith pipFor developmentHow to startSource VideoPoint to Point StreamingSDP-file and RTP-streamFile StreamingVirtual DeviceCamera StreamingDesktop CapturingMPEG-TS StreamingMPEG-TS via UDPMPEG-TS via TCPStreaming with a ServerWhat is thisThis is a detector of video shots based ofPyAV.It is strongly under construction.Nowadays, the main purpose of it is to visualize different methods of
shot detection and near duplicate video retrieval.It works both for Python 2.7 and Python 3.4.How to installWith condaCheck this linkanaconda.org/w495/shot-detectorconda install shot-detector -c w495With pipCheck this linkpypi/shot-detectorpip install shot-detectorNote:pip installation likely will not work properly
due toPyAVis depends on platform.For developmentIt usescondaas package manager.
So to install it should run commands:Create new environment and install requirements from conda:conda create --name shot-detector-3.4 \
--file ./requirements/py34/requirements-conda-explicit.txtActivate your environmentsource activate shot-detector-3.4Install requirements from pip:pip install -r ./requirements/py34/requirements-pip.txtThe same forPython 2.7:Create new environment and install requirements from conda:conda create --name shot-detector-2.7 \
    --file ./requirements/py27/requirements-conda-explicit.txtActivate your environmentsource activate shot-detector-2.7Install requirements from pip:pip install -r ./requirements/py27/requirements-pip.txtSeeManaging environmentsfor more details.How to startpython ./main.py -i /path/to/file/or/streamOrpython -m shot_detector.tool -i /path/to/file/or/streamUse-hoption to get help.python ./main.py -hAlso checkhelp filefor this.Source VideoYou can use any video-file or video-device as an input for the Shot
Detector. But in some cases it is required to use on-the-fly video
stream.You can get video-stream from third-party source or generate it
yourself. There are several ways to generate your own input video
stream:from a file;from your camera;from your desktop;from a virtual device.More over you can implement it with different schemes of streaming:point to point streaming;streaming with server (ffserver).Point to Point StreamingThis is the simplest way to reproduce on-the-fly video stream. In this
case you generate stream only for one reader. If you use your stream for
the Shot Detector, you cannot check it without stopping the Shot
Detector. But in this stream embodiment you wont deal with latency.SDP-file and RTP-streamIn this case we useRTP Streaming Protocol. The main
limitation of it is that only one stream supported in the RTP muxer. So
you can stream only video without audio or audio without video.File StreamingCreate a SDP-file and RTP-stream withffmpeg. For a file stream
it looks like this:ffmpeg -re -i input-file.mp4 -an -f rtp rtp://127.0.0.1:1236 > file-stream.sdpWhere:-re— is a flag that makesffmpegread input at native
frame rate. In this case it is used to simulate a stream from a
device. Without this flag, your stream will be handled as a simple
file. It is required only if you work with static file but not
real stream.-iinput-file.mp4— is a name of input file.-an— is a flag that makes ffmpeg ignore audio streams. The
reason of this flag is that RTP doesn’t support more than one
stream. Moreover, if your file contains several video streams,
your should choose one and remove odd video streams.-frtp— is an output format —RTP.rtp://127.0.0.1:1234— an address for receiving stream of
virtual device../file-stream.sdp— is a is a streamsession descriptionfile.Check the./file-stream.sdp. In this case it contains following
text:SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 55.33.1000
m=video 1234 RTP/AVP 96
b=AS:2000
a=rtpmap:96 MP4V-ES/90000
a=fmtp:96 profile-level-id=1Check the stream. Runffplaywith./file-stream.sdpas an
arguments.ffplay ./file-stream.sdpYou get a window with video from your file-stream.More over you can use any another player that supports RTP. Forexample:mplayer ./file-stream.sdpStopffplayand then use./file-stream.sdpfile name as input
URI for the Shot DetectorNote:RTP uses UDP, so the receiver can start up any time, but you
can get packet loss.Virtual DeviceCreate a SDP-file and RTP-stream withffmpeg. For a virtual
device it looks like this:ffmpeg -f lavfi -i mandelbrot -f rtp rtp://127.0.0.1:1234 > virtual-device.sdpWhere:-flavfi— is format oflibavfilterinputvirtual devices.
This input device reads data from the open output pads
of a libavfilter filtergraph.-imandelbrot— is a filter that draws theMandelbrot set.
CheckFancy Filtering Examplesin
FFmpeg documentaion for another filter types.-frtp— is an output format —RTP.rtp://127.0.0.1:1234— an address for receiving stream
of a virtual device../virtual-device.sdp— is a streamsession descriptionfile.Usevirtual-device.sdpas discussed above.Camera StreamingCreate a SDP-file and RTP-stream withffmpeg. For a camera it looks
like this:ffmpeg -f v4l2 -i /dev/video0 -f rtp rtp://127.0.0.1:1234 > camera.sdpWhere:-fv4l2— is an input device-format for a camera. The full name
of it is — [video4linux2]
(https://www.ffmpeg.org/ffmpeg-devices.html#video4linux2_002c-v4l2)It works only for linux.For another systems, please, check this
page: [FFmpeg Streaming Guide]
(https://trac.ffmpeg.org/wiki/StreamingGuide“Streaming Guide”)-i/dev/video0— is a path to device.-frtp— is an output format —RTP.rtp://127.0.0.1:1234— an address for receiving camera’s stream../camera.sdp— is a file with a description of yourstream session.After that usecamera.sdpas discussed above.Desktop CapturingFor a Linux display ffmpeg-command looks like this:ffmpeg -f x11grab -video_size wxga  -i :0.0  -f rtp rtp://127.0.0.1:1234 > desktop.sdpWhere:-fx11grab— is an input format for aX11-display.-video_sizewxga— size of your display. In this case we use the
full size of desktop. CheckFFmpeg Capture/Desktoppage for other options-i:0.0— is a desktop name.-frtp— is an output formatrtp://127.0.0.1:1234— an address for receiving camera’s stream../desktop.sdp— is a stream session description file.After that usedesktop.sdpas discussed above.MPEG-TS StreamingWithMPEG-TSyou can generate both and audio and video.MPEG-TS via UDPIn this case we useUDP. So, you still
can get packet loss. They are likely to reveal if you stream via
Internet.Here is example for a camera. For another devices they are the same.Startffmpegto generateMPEG-TSstream via udp.ffmpeg -f v4l2 -i /dev/video0 -f mpegts udp://127.0.0.1:1234Where:-fv4l2— is an input device-format for a camera. It works
only for linux. For another systems, please, check this page:FFmpeg Streaming Guide.-i/dev/video0— is a path to device.-fmpegts— is an output format — MPEG transport stream.udp://127.0.0.1:1234— an address for receiving camera’s
stream.Check it withffplay:ffplay  -fflags nobuffer  udp://127.0.0.1:1234Where:-fflagsnobuffer— is a flag that makes ffplay don’t cache
input stream. We set it to reduce latency.Useudp://127.0.0.1:1234as input video URI for the Shot
  Detector.
| More over, you can startffmpegand the Shot Detector in any
  order.Note:The time in the Shot Detector is a time of a video stream.Also you can use both video and audio.ffmpeg -f v4l2 -i /dev/video0 -f alsa -i hw:0 -f mpegts udp://127.0.0.1:1234Where:-falsa— is an input device-format for a microphone.-ihw:0— is a name of a microphone device. SeeCapture/ALSAfor more details.MPEG-TS via TCPAnother option is to use TCP connections for MPEG-TS streaming. In this
case you don’t get packet loss. But you should guarantee that a reader
will be started before a writer. So, reader become a server and writer
become a client.For example:Startffplayas a serverffplay -fflags nobuffer  tcp://127.0.0.1:1234?listenWhere:-fflagsnobuffer— is a flag that makes ffplay don’t cache
input stream. We set it to reduce latency.tcp://127.0.0.1:1234?listen— is a host for sending camera’s
stream whithlistenoption. A writer should send stream totcp://127.0.0.1:1234.Startffmpegas a clientffmpeg -f v4l2 -i /dev/video0  -f mpegts tcp://127.0.0.1:1234Where:-fv4l2— is an input device-format for a camera. It works
only for linux. For another systems, please, check this page:FFmpeg Streaming Guide.-i/dev/video0— is a path to device.-fmpegts— is an output format — MPEG transport stream.tcp://127.0.0.1:1234— an address for sending camera’s stream.So, you can passtcp://127.0.0.1:1234?listenas an input video URI
for the Shot Detector. But you should start it beforeffmpeg, Do not
forget to stopffplay, before it.Streaming with a ServerIn this scheme you send the video-stream to a server. And then any
client can get your stream from it. The simplest way to achive this is
to useffserver.Start ffserver with certain configuration file.sudo /usr/bin/ffserver -f ./etc/input/ffserver.confCheckFFServer Configuration.Send input stream to server.For example, for linux-camera you should run:ffmpeg -f v4l2 -i /dev/video0 -f alsa -i hw:0 -tune zerolatency http://localhost:8090/feed1.ffmWhere:-fv4l2— is an input device-format for a camera. It works
only for linux. For another systems, please, check this page:FFmpeg Streaming Guide.-i/dev/video0— is a path to device.-falsa— is an input device-format for a microphone.-ihw:0— is a name of a microphone device.
SeeCapture/ALSAfor more details.-tunezerolatency— is a flag that makesffmpegto change
settings to minimize latency. This is not a flag of ffmpeg, this
is H.264 option. SeeEncode/H.264 Choose a presetfor
more details.http://localhost:8090/feed1.ffm— an address for sending
camera’s stream.For desktop it is the same:ffmpeg -f x11grab -i :0.0 -f alsa -i hw:0 -tune zerolatency http://localhost:8090/feed1.ffmCheck it withffplay:ffplay -fflags nobuffer http://localhost:8090/live.flvWhere:-fflagsnobuffer— is a flag that makes ffplay don’t cache
input stream. We set it to reduce latency.http://localhost:8090/live.flv— is an address to get a video
stream. It is specified inetc/input/ffserver.conf.Passhttp://localhost:8090/live.flvas an input video URI for the
Shot Detector. In this case you may not stopffplay.As for me it is the best way to simulate streaming for the Shot
Detector.