Reputation:
I am writing a preview portion for video management system, it works like a charm in chrome with standard tag but firefox does not recognize MIME type for some reason and it bugs me a lot.
Here is my stream class:
class Stream:
run = False
FNULL = open(os.devnull, 'w')
overlay = ffmpeg.input("somelogo.png")
def __init__(self, camid):
camUtil = CameraUtil()
self.camid = camid
self.streamurl = camUtil.get_stream_from_id(self.camid)['streamURL']
print(self.streamurl)
self.args = ffmpeg.input(self.streamurl)
# vcodec="libvpx",
# acodec="libvorbis",
self.args = ffmpeg.output(self.args, "-",
f="matroska",
vcodec="copy",
acodec="copy",
blocksize="1024",
# strftime="1",
# segment_time="60",
# segment_format="matroska"
preset="ultrafast",
metadata="title='test'"
)
self.args = ffmpeg.get_args(self.args)
print(self.args)
self.pipe = subprocess.Popen(['ffmpeg'] + self.args,
stdout=subprocess.PIPE,)
#stderr=self.FNULL)
def dep_stream(self):
def gen():
try:
f = self.pipe.stdout
byte = f.read(1024)
while byte:
yield byte
byte = f.read(1024)
finally:
self.pipe.kill()
return Response(gen(), status=200,
mimetype='video/webm',
headers={'Access-Control-Allow-Origin': '*',
"Content-Type": "video/webm",
})
My html playback portion:
<video id="live_page_player" id="video" preload="auto" autoplay width="1280" height="720">
<source src="/stream/{{ camid }}" type='video/webm;codecs="vp8, vorbis"'/>
YOUR BROWSER DOES NOT SUPPORT HTML5, WHAT YEAR ARE YOU FROM?!
</video>
Firefox says "No video with supported format and MIME type found" and in console it says
error: Error Code: NS_ERROR_DOM_MEDIA_METADATA_ERR (0x806e0006)
Did I do something dumb?! Or am I missing something, because it works google chrome like a charm
I need fresh eyes.
Help plez
Upvotes: 1
Views: 1741
Reputation:
So after bashing my head around, I decided to check out the console(yes I know)
I found that firefox throws NS_ERROR_DOM_MEDIA_METADATA_ERR, after vigorous googling I have found that raw matroska is not supported by firefox(or rather they don't let you play it for some reason) while google chrome does support it.
The solution was actually pretty simple, you gotta re-encode the stream with vcodec libvpx-vp9 or vp8 and acoded libopus or libvorbis
The ffmpeg for python syntax would look like this:
self.args = ffmpeg.output(self.args, "-",
f="webm",
vcodec="libvpx-vp9",
acodec="loboupus",
blocksize="1024",
# strftime="1",
# segment_time="60",
# segment_format="matroska"
preset="ultrafast",
metadata="title='test'"
)
Note that this eats the CPU quite heavily, Im still playing around with it but this is the solution!
Upvotes: 2