Commit afde9ba1 authored by Ben Gamari's avatar Ben Gamari
Browse files

Fix encoding of mjpeg output

parent 04c61a1a
......@@ -39,6 +39,8 @@ args = parser.parse_args()
logging.basicConfig(level=args.verbose)
multipart_boundary = "ThisRandomString"
async def watch_bus(bus):
while True:
while True:
......@@ -113,7 +115,7 @@ class Source(object):
async def add_mjpeg_sink(self, fd):
if self.mjpeg_bin is None:
desc = 'videorate name=in ! video/x-raw,framerate={rate}/1 ! videoscale ! video/x-raw,width={width},height={height} ! queue ! jpegenc ! multifdsink name=sink'.format(rate=args.mjpeg_framerate, width=args.mjpeg_width, height=args.mjpeg_height)
desc = 'videorate name=in ! video/x-raw,framerate={rate}/1 ! videoscale ! video/x-raw,width={width},height={height} ! queue ! jpegenc ! multipartmux boundary={boundary} ! multifdsink name=sink'.format(rate=args.mjpeg_framerate, width=args.mjpeg_width, height=args.mjpeg_height, boundary=multipart_boundary)
self.mjpeg_bin = Gst.parse_bin_from_description(desc, False)
self.mjpeg_sink = MultiFdSink(self.mjpeg_bin.get_by_name('sink'), name='mjpeg')
self.pipeline.add(self.mjpeg_bin)
......@@ -196,7 +198,7 @@ src = Source(loop, pipeline_desc)
loop.create_task(src.start())
async def handle_stream(request):
logging.debug('request: %s' % request)
logging.debug('request: %s %s' % (request, id(request)))
resp = web.StreamResponse()
resp.content_length = -1
#resp.force_close()
......@@ -214,8 +216,10 @@ async def handle_stream(request):
async def handle_mjpeg(request):
logging.debug('request: %s' % request)
resp = web.StreamResponse()
resp.content_type = 'video/mjpeg'
#resp.content_type = 'video/x-motion-jpeg'
resp.content_type = 'multipart/x-mixed-replace;boundary=%s' % multipart_boundary
resp.content_length = -1
resp.force_close()
await resp.prepare(request)
await resp.drain()
fd = request.transport._sock_fd
......@@ -246,6 +250,7 @@ app.router.add_get('/snapshot.jpeg', handle_jpeg)
app.router.add_get('/stream.mjpeg', handle_mjpeg)
app.router.add_get('/mjpeg.html', serve_static('mjpeg.html'))
app.router.add_get('/webm.html', serve_static('webm.html'))
app.router.add_get('/test.html', serve_static('test.html'))
app.router.add_get('/', serve_static('index.html'))
try:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment