Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restful-based video streaming

Using spring boot, I want to make RESTful-based video player. I have my .mp4 extension videos in my file browser. How can I serve these videos on the frontend side by creating a rest endpoint?

I've tried this method. The video can be started or stopped. But it can not be done backwards or forwards. Can not get it to the desired minute and start.

like image 802
Erdem Aydemir Avatar asked Jan 11 '18 06:01

Erdem Aydemir


People also ask

What is streaming in REST API?

Streaming APIs updates are sent to the consumer when an event happens. REST APIs operate in a client-server architecture. This comes down to a flow of “request and response.” A basic ongoing talk between servers: a user makes a request, and the server comes back with the information you are seeking.

What is video streaming API?

Streaming APIs are integrated into the application to enable them to stream media content and other data their host servers. They extract the data from the servers and makes it available to the developed application software.

Is API video good?

"Good Overall API-Centric Video Streaming Platform" api. video is cost-effective, works well, and provides excellent technical support.

What is opposite of REST API?

Streaming APIs are almost an exact opposite of the REST ethos. In its most basic state, Streaming APIs invert the conversational nature of REST, where a request is made and a response is given, and instead has the server send information to a client when an update is ready.


1 Answers

Spring Content supports video streaming out of the box. Using Spring Content for the file-system (FS) you would be able to create yourself a video store backed by the filesystem, put your video(s) in that store, and using the companion library Spring Content REST to serve them over HTTP to any front-end video player.

Create a new Spring Boot project via start.spring.io or via your IDE spring project wizard (Spring Boot 1.5.10 at time of writing). Add the following Spring Content dependencies so you end up with these:-

<dependencies>
    <!-- Standard Spring Boot -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.3</version>
    </dependency>

    <!-- Spring Content -->
    <dependency>
        <groupId>com.github.paulcwarren</groupId>
        <artifactId>spring-content-fs-boot-starter</artifactId>
        <version>0.0.9</version>
    </dependency>
    <dependency>
        <groupId>com.github.paulcwarren</groupId>
        <artifactId>spring-content-rest-boot-starter</artifactId>
        <version>0.0.9</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

In your Spring Boot Application class, create a VideoStore. Annotate it as a Store REST resource. This causes Spring Content to inject an implementation (of this interface for the file-system) as well add REST endpoints for this interface too saving you from having to write any of it yourself:-

    @SpringBootApplication 
    public class DemoApplication {

        public static void main(String[] args) {        
           SpringApplication.run(DemoApplication.class, args);  
        }

        @StoreRestResource(path="videos")   
        public interface VideoStore extends Store<String> {} 
    }

By default Spring Content will create a store under java.io.tmpdir. So you will also need to set the SPRING_CONTENT_FS_FILESYSTEM_ROOT environment variable to point to the root of your "store".

Copy your video into this "root" location. Start the application and your video(s) will be streamable from:-

/videos/MyVideo.mp4

like image 52
Paul Warren Avatar answered Nov 16 '22 02:11

Paul Warren