From 453e9482134c894ba4247950656a94909eaf3229 Mon Sep 17 00:00:00 2001 From: Andrew DeMaria Date: Thu, 25 May 2017 18:15:37 -0600 Subject: [PATCH] Created new transcoding for mp4 and use it for videos Signed-off-by: Andrew DeMaria --- .../controller/VideoPlayerController.java | 2 +- .../player/service/TranscodingService.java | 17 ++++- .../resources/liquibase/6.3/changelog.xml | 6 ++ .../resources/liquibase/6.3/mediaelement.xml | 18 +++++ .../main/resources/liquibase/db-changelog.xml | 1 + .../resources/liquibase/legacy/schema43.xml | 76 +++++++++---------- .../resources/liquibase/legacy/schema46.xml | 6 +- 7 files changed, 82 insertions(+), 44 deletions(-) create mode 100644 libresonic-main/src/main/resources/liquibase/6.3/changelog.xml create mode 100644 libresonic-main/src/main/resources/liquibase/6.3/mediaelement.xml diff --git a/libresonic-main/src/main/java/org/libresonic/player/controller/VideoPlayerController.java b/libresonic-main/src/main/java/org/libresonic/player/controller/VideoPlayerController.java index a559023a..fe8072af 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/controller/VideoPlayerController.java +++ b/libresonic-main/src/main/java/org/libresonic/player/controller/VideoPlayerController.java @@ -68,7 +68,7 @@ public class VideoPlayerController { Integer duration = file.getDurationSeconds(); String playerId = playerService.getPlayer(request, response).getId(); String url = NetworkService.getBaseUrl(request); - String streamUrl = url + "/stream?id=" + file.getId() + "&player=" + playerId; + String streamUrl = url + "/stream?id=" + file.getId() + "&player=" + playerId + "&format=mp4"; String coverArtUrl = url + "/coverArt.view?id=" + file.getId(); map.put("video", file); diff --git a/libresonic-main/src/main/java/org/libresonic/player/service/TranscodingService.java b/libresonic-main/src/main/java/org/libresonic/player/service/TranscodingService.java index af659b18..39858d56 100644 --- a/libresonic-main/src/main/java/org/libresonic/player/service/TranscodingService.java +++ b/libresonic-main/src/main/java/org/libresonic/player/service/TranscodingService.java @@ -22,7 +22,7 @@ package org.libresonic.player.service; import org.apache.commons.io.FileUtils; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.filefilter.PrefixFileFilter; -import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringUtils; import org.libresonic.player.controller.VideoPlayerController; import org.libresonic.player.dao.TranscodingDao; import org.libresonic.player.domain.*; @@ -393,7 +393,20 @@ public class TranscodingService { List applicableTranscodings = new LinkedList(); String suffix = mediaFile.getFormat(); - for (Transcoding transcoding : getTranscodingsForPlayer(player)) { + // This is what I'd like todo, but this will most likely break video transcoding as video transcoding is + // never expected to be null +// if(StringUtils.equalsIgnoreCase(preferredTargetFormat, suffix)) { +// LOG.debug("Target formats are the same, returning no transcoding"); +// return null; +// } + + List transcodingsForPlayer = getTranscodingsForPlayer(player); + for (Transcoding transcoding : transcodingsForPlayer) { + // special case for now as video must have a transcoding + if(mediaFile.isVideo() && StringUtils.equalsIgnoreCase(preferredTargetFormat, transcoding.getTargetFormat())) { + LOG.debug("Detected source to target format match for video"); + return transcoding; + } for (String sourceFormat : transcoding.getSourceFormatsAsArray()) { if (sourceFormat.equalsIgnoreCase(suffix)) { if (isTranscodingInstalled(transcoding)) { diff --git a/libresonic-main/src/main/resources/liquibase/6.3/changelog.xml b/libresonic-main/src/main/resources/liquibase/6.3/changelog.xml new file mode 100644 index 00000000..7e9ed807 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/6.3/changelog.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/libresonic-main/src/main/resources/liquibase/6.3/mediaelement.xml b/libresonic-main/src/main/resources/liquibase/6.3/mediaelement.xml new file mode 100644 index 00000000..ceb968c9 --- /dev/null +++ b/libresonic-main/src/main/resources/liquibase/6.3/mediaelement.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + name = 'mp4/h264 video' + + + + diff --git a/libresonic-main/src/main/resources/liquibase/db-changelog.xml b/libresonic-main/src/main/resources/liquibase/db-changelog.xml index 2af15cef..052fb226 100644 --- a/libresonic-main/src/main/resources/liquibase/db-changelog.xml +++ b/libresonic-main/src/main/resources/liquibase/db-changelog.xml @@ -9,4 +9,5 @@ + \ No newline at end of file diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema43.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema43.xml index ff7441f1..eadf978a 100644 --- a/libresonic-main/src/main/resources/liquibase/legacy/schema43.xml +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema43.xml @@ -23,97 +23,97 @@ - target_format = 'mp4' and source_format in ('avi', 'mpg', 'mpeg', 'mp4', 'm4v', 'mkv', 'mov', 'wmv', 'ogv') + target_format = 'flv' and source_format in ('avi', 'mpg', 'mpeg', 'mp4', 'm4v', 'mkv', 'mov', 'wmv', 'ogv') - + - - + + - insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'avi > mp4' + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'avi > flv' - + - - + + - insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mpg > mp4' + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mpg > flv' - + - - + + - insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mpeg > mp4' + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mpeg > flv' - - - - + + + + - insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'flv > mp4' + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mp4 > flv' - + - - + + - insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'm4v > mp4' + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'm4v > flv' - + - - + + - insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mkv > mp4' + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mkv > flv' - + - - + + - insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mov > mp4' + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'mov > flv' - + - - + + - insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'wmv > mp4' + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'wmv > flv' - + - - + + - insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'ogv > mp4' + insert into player_transcoding(player_id, transcoding_id) select p.id as player_id, t.id as transaction_id from player p, transcoding t where t.name = 'ogv > flv' diff --git a/libresonic-main/src/main/resources/liquibase/legacy/schema46.xml b/libresonic-main/src/main/resources/liquibase/legacy/schema46.xml index 54d02119..fd009415 100644 --- a/libresonic-main/src/main/resources/liquibase/legacy/schema46.xml +++ b/libresonic-main/src/main/resources/liquibase/legacy/schema46.xml @@ -47,10 +47,10 @@ - - + + - +