I
I
Interface2020-05-20 13:29:36
JavaScript
Interface, 2020-05-20 13:29:36

How to support more formats in webplayer?

Introduction:
There is some service that involves working with videos of different formats. As well as playing them online. For simplicity, let's say that this is a YouTube clone (it's not, but it doesn't matter).

That is, you can upload a video of an arbitrary format there and expect the opportunity to view it online.

The HTML-5 player ( <video>) works quite well in this role, but it supports very few formats. As far as I understand, only mp4, webm and ogg are more or less supported.

At the same time, I would like to have support for avi, mkv (specifically, there were problems with audio (as far as I can tell, the ac3 codec is not supported by browsers)) and other things.

The only solution I found at the moment is to transcode the video to compatible codecs, for example in webm:

ffmpeg -y \
    -progress - \
    -fflags \
    +genpts \
    -i input.avi \
    -c:v libvpx \
    -c:a libvorbis \
    output.webm

or also there is an option to transcode audio only if video works:
ffmpeg -y \
    -progress - \
    -fflags \
    +genpts \
    -i input.avi \
    -c:v copy \
    -c:a aac \
    output.mp4


The problem with this approach is that transcoding is a heavy operation. On my (not the fastest hardware) this operation is performed at a speed of about 80 fps for the first option and 400 fps for the second. Which is quite slow and resource intensive.

If I have an error in the code - I will be grateful for advice.

As far as I understand, there used to be flash players that supported more formats / codecs (did they?), but now the position of flash makes it not a good candidate for solutions.

Actually the question is: if I want to play an arbitrary video (of popular formats) on a web page, do I have an alternative to transcoding?

Perhaps you can recode somehow faster? (for example, my sample code with audio transcoding is much faster, but I don't know how good this solution is) Maybe it makes sense to use something instead of ffmpeg? Or am I using it without hardware acceleration and have to turn it on manually? (I've read that ffmpeg can be GPU friendly, but that doesn't work for me as the machine won't have a separate GPU)

Are there alternative web players? (webgl? I doubt it, of course)

Cross-browser compatibility is not particularly needed, the latest Chrome versions are enough, Firefox would be nice, support for IE, Edge, Safari and other things is not of interest at all.

I came across player extensions for the browser - I would like to avoid using them.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Drno, 2020-05-20
@Drno

Well, faster only if you reduce the quality. For example, the -ultrafast parameter
In general, all services render videos for themselves, only then they are available for upload

A
Alexander, 2020-05-20
@NeiroNx

I would prohibit accepting videos of inappropriate formats.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question