-
스프링과 스트리밍 서버프로젝트/미디어 스트리밍 서버 프로젝트 2022. 12. 23. 00:01반응형
https://junuuu.tistory.com/467
스트리밍 서버란?
스트리밍이란? 스트리밍이란 인터넷(네트워크)을 바탕으로 사용자에게 각종 비디오, 오디오등의 멀티미디어 디지털 정보를 제공하는 기술로 인터넷에서 영상 및 음향 등의 파일을 다운로드 없
junuuu.tistory.com
이전시간에 스트리밍 서버에 대해서 알아보고 멀티미디어 전송방식에 대해서 알아보았습니다.
개요
각 전송방식에 대해 스프링을 활용하여 어떻게 구현할 수 있는지 알아보겠습니다.
HTML5(video) + Spring Boot : Progressive download
HTML5 태그 중 VIDEO 태그를 사용하여 웹에서 동영상을 플레이하는 기능입니다.
HTML 소스에서는 아래와 같이 호출합니다.
... <video controls src="/download?fileName=test.mp4"> not use video </video> ...
Spring Boot에서는 StreamingResponseBody를 이용합니다.
... private final String DIR = "${FILE_DIR}/"; @GetMapping("/download") public StreamingResponseBody stream(HttpServletRequest req, @RequestParam("fileName") String fileName) throws Exception { File file = new File(DIR + fileName); final InputStream is = new FileInputStream(file); return os -> { readAndWrite(is, os); }; } private void readAndWrite(final InputStream is, OutputStream os) throws IOException { byte[] data = new byte[2048]; int read = 0; while ((read = is.read(data)) > 0) { os.write(data, 0, read); } os.flush(); } ...
서버에서는 요청시마다 전체 파일을 보내주고 video 태그에서는 점진적으로 필요한 만큼씩 OutputStream에서 읽어가게 됩니다.
StreamingResponseBody 클래스는 TaskExecutor를 이용하여 비동기 서블릿 실행을 지원합니다.
또한 Range 헤더를 사용하여 서버 파일의 특정 부분을 요청할 수 있습니다.
GET https://www.w3schools.com/html/mov_bbb.mp4 Range: bytes=0-99 ...
응답 헤더들은 다음과 같습니다.
Status: 206 Accept-ranges: bytes Content-Length: 100 Content-Range: bytes 0-99/788493
Spring WebFlux를 활용하여 Video Streaming을 할 수도 있습니다.
https://www.vinsguru.com/spring-webflux-video-streaming/
Spring WebFlux Video Streaming | Vinsguru
Lets build a simple application Spring WebFlux Video Streaming to serve video content.
www.vinsguru.com
https://www.youtube.com/watch?v=_PEPaWFs064
코루틴을 활용한 비동기 처리
https://appleg1226.tistory.com/16
코틀린(kotlin) + 스프링부트(springboot) + 웹플럭스(webflux) + 코루틴(coroutine) - 웹플럭스에서 코루틴
Non-Blocking Service 최근 웹 기술에는 많은 기술들이 화두가 되고 있지만, 그 중에서도 동시에 많은 요청을 처리하기 위한 기술들이 화두입니다. Java에는 RxJava, Reactor 등 Reactive Streams API를 구현한..
appleg1226.tistory.com
S3만을 사용할 때 단점
더 나은 비디오 로드 시간을 위해 S3와 함께 AWS CloudFront CDN을 사용할 수 있습니다.
하지만 비디오의 크기가 큰 경우가 많고 비디오 최적화 기능이 내장되어 있지 않습니다.
이 문제를 해결하기 위해서는 AWS Elemental Mediaconvert를 사용하여 모든 종류의 트랜스코딩과 최적화를 사용할 수 있습니다.
하지만 러닝 커브가 존재하며 관리가 복잡해집니다.
ImageKit를 사용하면 AWS S3에 저장된 비디오를 간단한 설정으로 최적화 및 변환할 수 있습니다.
시도한 방법
저장할 비디오를 S3에 저장 -> 저장하면서 반환된 URL을 DB에 저장 -> 사용자가 조회시 DB의 S3 URL제공 -> URL을 클라이언트에 넘겨주면 Player를 통해 재생
출처
https://derveljunit.tistory.com/311
HTTP Range Requests 를 이용한 스프링 비디오 스트리밍
HTTP range requests HTTP 범위 요청이란 HTTP 를 통해 일정한 부분을 서버에서 클라이언트로 보내는 것을 Accept하고 보내는 방법입니다. 범위를 알 수 있는 대형 미디어 파일을 나누어서 읽을 수 있습니
derveljunit.tistory.com
HTML5 VIDEO 스트리밍(STREAMING) 서버 프로그래밍 - JAVA
HTML5 VIDEO 스트리밍(STREAMING) 서버 프로그래밍 - JAVA 오늘은 HTML5 태그 중 VIDEO 기능에 대해 소개 하려고 합니다. VIDEO 태그는 웹에서 동영상을 플레이 하기 위한 기능입니다. 예전에는 active X 방식이
since.tistory.com
https://luvstudy.tistory.com/172
Spring MVC에서 video streaming 하기
Spring에서 mp4 동영상 같이 용량이 큰 파일을 내려보내 주려면 어떻게 해야 할까? 파일 읽어 들이고 내보내기 요청에 대해 응답으로 데이터를 내보내야 한다. 자바에서는 데이터를 InputStream으로
luvstudy.tistory.com
https://jistol.github.io/spring/2018/04/04/springboot-video-streaming/
HTML5(video) + Spring Boot(Tomcat)로 동영상 재생하기
jistol.github.io
https://saravanastar.medium.com/video-streaming-over-http-using-spring-boot-51e9830a3b8
Video Streaming over HTTP using Spring Boot
Have done a POC to stream video over the http and hard to find the details about the HTTP streaming using JAVA. So thought to share this…
saravanastar.medium.com
https://melgenek.github.io/spring-video-service
Building a video service using Spring Framework
Notes about software development
melgenek.github.io
https://css-tricks.com/streaming-optimized-videos-from-aws-s3-in-minutes/
Streaming Optimized Videos From AWS S3 in Minutes | CSS-Tricks
Videos appeal to humans in a way no other form of the content does. A video includes motion, music, still images, text, speech, and a few other elements, all
css-tricks.com
'프로젝트 > 미디어 스트리밍 서버 프로젝트' 카테고리의 다른 글
S3 pre-signed url 만들기(Kotlin + Spring) (0) 2023.01.06 Adaptive Bitrate와 MPD파일 (0) 2023.01.05 [Kotlin] AWS S3에 업로드하기 (0) 2022.12.19 AWS Foundation 기반 온디맨드 비디오 솔루션 구현 - 이론편 (0) 2022.12.12 OTT는 어떻게 콘텐츠를 보호할까? (0) 2022.12.08