DEV Community

Masui Masanori
Masui Masanori

Posted on

[FFmpeg] Play streaming videos


When I tried playing videos what were gotten from web applications, I could play them only after finishing downloading.

This time, I will try playing streaming videos again.


Actually, I can play streaming just by using the WebM videos I created last time.


<!DOCTYPE html>
<html lang="en">
        <title>Play Video</title>
        <meta charset="utf-8">
        <video controls muted autoplay>
            <!-- Play published static files -->
            <source src="/video/sample.webm" type="video/webm">
Enter fullscreen mode Exit fullscreen mode

Play on Unity applications

I also can play on Unity applications by "VideoPlayer".
It only can play specific video and audio codec for WebM.

  • Video Codec: VP8
  • Audio Codec: Vorbis

Image description

Convert to WebM

To do this, I want to convert mp4 files to WebM files.
This time I use FFmpeg.

It converts video files with options.
I think the easiest way is adding "-lossless 1".

ffmpeg -i "./wwwroot/video/sample.mp4" -c:a libvorbis -lossless 1 ./wwwroot/video/sample_vp8_mp4_lossless.webm
Enter fullscreen mode Exit fullscreen mode

But the converted file size becomes more than 10 times larger.

So I

ffmpeg -i "./wwwroot/video/sample.mp4" -c:v libvpx -c:a libvorbis -crf 10 -b:v 100M -g 300 ./wwwroot/video/sample_vp8_mp4.webm
Enter fullscreen mode Exit fullscreen mode
  • -c:v => Video codec
  • -c:a => Audio codec
  • -crf => For a constant quality mode(range 4-63)
  • -b:v => For setting bit rate on average(I set 100MBit/s). If I set this value larger, the quality will become higher. But the file size also will become larger.
  • -g => GOP size(add 10 intra frames per second at 30fps)

  • ffmpeg Documentation

  • Encode/VP8 - FFmpeg

  • Encode/VP9 - FFmpeg

Top comments (0)