Skip to content

Commit

Permalink
feat: 인코딩된 동영상 url을 저장하는 필드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
SJ70 committed Oct 12, 2024
1 parent 9baac40 commit af2f0ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main/java/com/j9/bestmoments/domain/Video.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

Expand All @@ -32,8 +31,12 @@ public class Video {

@Id
private UUID id;

private String videoUrl;
private String thumbnailUrl;
@Lob
private List<String> encodedVideoUrls;

private String title;
@Lob
private String description;
Expand All @@ -60,6 +63,7 @@ public Video(Member uploader, String title, String description, VideoStatus vide
this.description = description;
this.videoStatus = videoStatus;
this.isDeleted = false;
this.encodedVideoUrls = new ArrayList<>();
}

public void softDelete() {
Expand Down Expand Up @@ -90,6 +94,10 @@ public void setVideoUrl(String videoUrl) {
this.videoUrl = videoUrl;
}

public void addEncodedVideoUrl(String videoUrl) {
this.encodedVideoUrls.add(videoUrl);
}

public void setThumbnailUrl(String thumbnailUrl) {
this.thumbnailUrl = thumbnailUrl;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/j9/bestmoments/service/VideoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public Video upload(Member member, VideoCreateDto createDto) {
// 원본 사이즈 인코딩
String resolution = ffmpegService.getVideoResolution(originVideoUrl);
String encodedVideoUrl = uploadEncodedVideo(originVideoUrl, resolution);
video.addEncodedVideoUrl(encodedVideoUrl);

// 1/2 사이즈 인코딩
String halfResolution = Arrays.stream(resolution.split("x"))
Expand All @@ -57,6 +58,7 @@ public Video upload(Member member, VideoCreateDto createDto) {
.mapToObj(String::valueOf)
.collect(Collectors.joining("x"));
String halfEncodedVideoUrl = uploadEncodedVideo(originVideoUrl, halfResolution);
video.addEncodedVideoUrl(halfEncodedVideoUrl);

// 1/4 사이즈 인코딩
String quarterResolution = Arrays.stream(resolution.split("x"))
Expand All @@ -65,6 +67,7 @@ public Video upload(Member member, VideoCreateDto createDto) {
.mapToObj(String::valueOf)
.collect(Collectors.joining("x"));
String quarterEncodedVideoUrl = uploadEncodedVideo(originVideoUrl, quarterResolution);
video.addEncodedVideoUrl(quarterEncodedVideoUrl);

videoRepository.save(video);
return video;
Expand Down

0 comments on commit af2f0ad

Please sign in to comment.