mirror of https://github.com/OpenVidu/openvidu.git
openvidu-recording container: removed dynamic user selection
parent
b279e3adbb
commit
e752685b31
|
@ -2,7 +2,7 @@ FROM ubuntu:16.04
|
||||||
MAINTAINER openvidu@gmail.com
|
MAINTAINER openvidu@gmail.com
|
||||||
|
|
||||||
# Install Chrome
|
# Install Chrome
|
||||||
RUN apt-get update && apt-get -y upgrade && apt-get install -y wget
|
RUN apt-get update && apt-get -y upgrade && apt-get install -y wget sudo
|
||||||
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
|
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
|
||||||
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome.list && \
|
echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome.list && \
|
||||||
apt-get update && apt-get install -y google-chrome-stable
|
apt-get update && apt-get install -y google-chrome-stable
|
||||||
|
|
|
@ -1,13 +1,7 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
|
|
||||||
### Variables ###
|
### Variables ###
|
||||||
|
|
||||||
CURRENT_UID="$(id -u $USER)"
|
|
||||||
if [[ $CURRENT_UID != $USER_ID ]]; then
|
|
||||||
adduser --uid $USER_ID --disabled-password --gecos "" myuser
|
|
||||||
fi
|
|
||||||
|
|
||||||
URL=${URL:-https://www.youtube.com/watch?v=JMuzlEQz3uo}
|
URL=${URL:-https://www.youtube.com/watch?v=JMuzlEQz3uo}
|
||||||
RESOLUTION=${RESOLUTION:-1920x1080}
|
RESOLUTION=${RESOLUTION:-1920x1080}
|
||||||
FRAMERATE=${FRAMERATE:-25}
|
FRAMERATE=${FRAMERATE:-25}
|
||||||
|
@ -30,17 +24,9 @@ export RECORDING_JSON
|
||||||
|
|
||||||
### Store Recording json data ###
|
### Store Recording json data ###
|
||||||
|
|
||||||
function1() {
|
|
||||||
mkdir /recordings/$VIDEO_ID
|
mkdir /recordings/$VIDEO_ID
|
||||||
chmod 777 /recordings/$VIDEO_ID
|
chmod 777 /recordings/$VIDEO_ID
|
||||||
echo $RECORDING_JSON > /recordings/$VIDEO_ID/.recording.$VIDEO_ID
|
echo $RECORDING_JSON > /recordings/$VIDEO_ID/.recording.$VIDEO_ID
|
||||||
}
|
|
||||||
export -f function1
|
|
||||||
if [[ $CURRENT_UID != $USER_ID ]]; then
|
|
||||||
su myuser -c "bash -c function1"
|
|
||||||
else
|
|
||||||
function1
|
|
||||||
fi
|
|
||||||
|
|
||||||
### Get a free display identificator ###
|
### Get a free display identificator ###
|
||||||
|
|
||||||
|
@ -65,70 +51,26 @@ export DISPLAY_NUM
|
||||||
echo "First available display -> :$DISPLAY_NUM"
|
echo "First available display -> :$DISPLAY_NUM"
|
||||||
echo "----------------------------------------"
|
echo "----------------------------------------"
|
||||||
|
|
||||||
|
|
||||||
### Start pulseaudio ###
|
|
||||||
|
|
||||||
function2() {
|
|
||||||
pulseaudio -D
|
pulseaudio -D
|
||||||
}
|
|
||||||
export -f function2
|
|
||||||
if [[ $CURRENT_UID != $USER_ID ]]; then
|
|
||||||
su myuser -c "bash -c function2"
|
|
||||||
else
|
|
||||||
function2
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
### Start Chrome in headless mode with xvfb, using the display num previously obtained ###
|
### Start Chrome in headless mode with xvfb, using the display num previously obtained ###
|
||||||
|
|
||||||
touch xvfb.log
|
touch xvfb.log
|
||||||
chmod 777 xvfb.log
|
chmod 777 xvfb.log
|
||||||
|
|
||||||
function3() {
|
|
||||||
xvfb-run --server-num=${DISPLAY_NUM} --server-args="-ac -screen 0 ${RESOLUTION}x24 -noreset" google-chrome --start-maximized --no-sandbox --test-type --disable-infobars --window-size=$WIDTH,$HEIGHT --window-position=0,0 --no-first-run --ignore-certificate-errors --autoplay-policy=no-user-gesture-required --kiosk $URL &> xvfb.log &
|
xvfb-run --server-num=${DISPLAY_NUM} --server-args="-ac -screen 0 ${RESOLUTION}x24 -noreset" google-chrome --start-maximized --no-sandbox --test-type --disable-infobars --window-size=$WIDTH,$HEIGHT --window-position=0,0 --no-first-run --ignore-certificate-errors --autoplay-policy=no-user-gesture-required --kiosk $URL &> xvfb.log &
|
||||||
}
|
|
||||||
export -f function3
|
|
||||||
if [[ $CURRENT_UID != $USER_ID ]]; then
|
|
||||||
su myuser -c "bash -c function3"
|
|
||||||
else
|
|
||||||
function3
|
|
||||||
fi
|
|
||||||
|
|
||||||
touch stop
|
touch stop
|
||||||
chmod 777 /recordings
|
chmod 777 /recordings
|
||||||
|
|
||||||
sleep 2
|
sleep 2
|
||||||
|
|
||||||
|
|
||||||
### Start recording with ffmpeg ###
|
### Start recording with ffmpeg ###
|
||||||
|
|
||||||
function4() {
|
|
||||||
<./stop ffmpeg -y -f alsa -i pulse -f x11grab -draw_mouse 0 -framerate $FRAMERATE -video_size $RESOLUTION -i :$DISPLAY_NUM -c:a aac -c:v libx264 -preset ultrafast -crf 28 -refs 4 -qmin 4 -pix_fmt yuv420p -filter:v fps=$FRAMERATE "/recordings/$VIDEO_ID/$VIDEO_NAME.$VIDEO_FORMAT"
|
<./stop ffmpeg -y -f alsa -i pulse -f x11grab -draw_mouse 0 -framerate $FRAMERATE -video_size $RESOLUTION -i :$DISPLAY_NUM -c:a aac -c:v libx264 -preset ultrafast -crf 28 -refs 4 -qmin 4 -pix_fmt yuv420p -filter:v fps=$FRAMERATE "/recordings/$VIDEO_ID/$VIDEO_NAME.$VIDEO_FORMAT"
|
||||||
}
|
|
||||||
export -f function4
|
|
||||||
if [[ $CURRENT_UID != $USER_ID ]]; then
|
|
||||||
su myuser -c "bash -c function4"
|
|
||||||
else
|
|
||||||
function4
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
### Generate video report file ###
|
### Generate video report file ###
|
||||||
|
|
||||||
function5() {
|
|
||||||
ffprobe -v quiet -print_format json -show_format -show_streams /recordings/$VIDEO_ID/$VIDEO_NAME.$VIDEO_FORMAT > /recordings/$VIDEO_ID/$VIDEO_ID.info
|
ffprobe -v quiet -print_format json -show_format -show_streams /recordings/$VIDEO_ID/$VIDEO_NAME.$VIDEO_FORMAT > /recordings/$VIDEO_ID/$VIDEO_ID.info
|
||||||
}
|
|
||||||
export -f function5
|
|
||||||
if [[ $CURRENT_UID != $USER_ID ]]; then
|
|
||||||
su myuser -c "bash -c function5"
|
|
||||||
else
|
|
||||||
function5
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
### Update Recording json data ###
|
### Update Recording json data ###
|
||||||
|
|
||||||
function6() {
|
|
||||||
TMP=$(mktemp /recordings/$VIDEO_ID/.$VIDEO_ID.XXXXXXXXXXXXXXXXXXXXXXX.json)
|
TMP=$(mktemp /recordings/$VIDEO_ID/.$VIDEO_ID.XXXXXXXXXXXXXXXXXXXXXXX.json)
|
||||||
INFO=$(cat /recordings/$VIDEO_ID/$VIDEO_ID.info | jq '.')
|
INFO=$(cat /recordings/$VIDEO_ID/$VIDEO_ID.info | jq '.')
|
||||||
HAS_AUDIO_AUX=$(echo $INFO | jq '.streams[] | select(.codec_type == "audio")')
|
HAS_AUDIO_AUX=$(echo $INFO | jq '.streams[] | select(.codec_type == "audio")')
|
||||||
|
@ -139,25 +81,13 @@ function6() {
|
||||||
DURATION=$(echo $INFO | jq '.format.duration | tonumber')
|
DURATION=$(echo $INFO | jq '.format.duration | tonumber')
|
||||||
STATUS="stopped"
|
STATUS="stopped"
|
||||||
jq -c -r ".hasAudio=$HAS_AUDIO | .hasVideo=$HAS_VIDEO | .duration=$DURATION | .size=$SIZE | .status=\"$STATUS\"" "/recordings/$VIDEO_ID/.recording.$VIDEO_ID" > $TMP && mv $TMP /recordings/$VIDEO_ID/.recording.$VIDEO_ID
|
jq -c -r ".hasAudio=$HAS_AUDIO | .hasVideo=$HAS_VIDEO | .duration=$DURATION | .size=$SIZE | .status=\"$STATUS\"" "/recordings/$VIDEO_ID/.recording.$VIDEO_ID" > $TMP && mv $TMP /recordings/$VIDEO_ID/.recording.$VIDEO_ID
|
||||||
}
|
|
||||||
export -f function6
|
|
||||||
if [[ $CURRENT_UID != $USER_ID ]]; then
|
|
||||||
su myuser -c "bash -c function6"
|
|
||||||
else
|
|
||||||
function6
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
### Generate video thumbnail ###
|
### Generate video thumbnail ###
|
||||||
|
|
||||||
function7() {
|
|
||||||
MIDDLE_TIME=$(ffmpeg -i /recordings/$VIDEO_ID/$VIDEO_NAME.$VIDEO_FORMAT 2>&1 | grep Duration | awk '{print $2}' | tr -d , | awk -F ':' '{print ($3+$2*60+$1*3600)/2}')
|
MIDDLE_TIME=$(ffmpeg -i /recordings/$VIDEO_ID/$VIDEO_NAME.$VIDEO_FORMAT 2>&1 | grep Duration | awk '{print $2}' | tr -d , | awk -F ':' '{print ($3+$2*60+$1*3600)/2}')
|
||||||
THUMBNAIL_HEIGHT=$((480*$HEIGHT/$WIDTH))
|
THUMBNAIL_HEIGHT=$((480*$HEIGHT/$WIDTH))
|
||||||
ffmpeg -ss $MIDDLE_TIME -i /recordings/$VIDEO_ID/$VIDEO_NAME.$VIDEO_FORMAT -vframes 1 -s 480x$THUMBNAIL_HEIGHT /recordings/$VIDEO_ID/$VIDEO_ID.jpg
|
ffmpeg -ss $MIDDLE_TIME -i /recordings/$VIDEO_ID/$VIDEO_NAME.$VIDEO_FORMAT -vframes 1 -s 480x$THUMBNAIL_HEIGHT /recordings/$VIDEO_ID/$VIDEO_ID.jpg
|
||||||
}
|
|
||||||
export -f function7
|
### Change permissions to all generated files ###
|
||||||
if [[ $CURRENT_UID != $USER_ID ]]; then
|
|
||||||
su myuser -c "bash -c function7"
|
sudo chmod -R 777 /recordings/$VIDEO_ID
|
||||||
else
|
|
||||||
function7
|
|
||||||
fi
|
|
||||||
|
|
|
@ -57,7 +57,6 @@ import io.openvidu.server.config.OpenviduConfig;
|
||||||
import io.openvidu.server.core.Session;
|
import io.openvidu.server.core.Session;
|
||||||
import io.openvidu.server.recording.Recording;
|
import io.openvidu.server.recording.Recording;
|
||||||
import io.openvidu.server.recording.RecordingInfoUtils;
|
import io.openvidu.server.recording.RecordingInfoUtils;
|
||||||
import io.openvidu.server.utils.CommandExecutor;
|
|
||||||
|
|
||||||
public class ComposedRecordingService extends RecordingService {
|
public class ComposedRecordingService extends RecordingService {
|
||||||
|
|
||||||
|
@ -92,16 +91,6 @@ public class ComposedRecordingService extends RecordingService {
|
||||||
this.recordingManager.sessionHandler.setRecordingStarted(session.getSessionId(), recording);
|
this.recordingManager.sessionHandler.setRecordingStarted(session.getSessionId(), recording);
|
||||||
this.recordingManager.startingRecordings.put(recording.getId(), recording);
|
this.recordingManager.startingRecordings.put(recording.getId(), recording);
|
||||||
|
|
||||||
String uid = null;
|
|
||||||
try {
|
|
||||||
uid = System.getenv("MY_UID");
|
|
||||||
if (uid == null) {
|
|
||||||
uid = CommandExecutor.execCommand("/bin/sh", "-c", "id -u " + System.getProperty("user.name"));
|
|
||||||
}
|
|
||||||
} catch (IOException | InterruptedException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
String layoutUrl = this.getLayoutUrl(recording, this.getShortSessionId(session));
|
String layoutUrl = this.getLayoutUrl(recording, this.getShortSessionId(session));
|
||||||
|
|
||||||
envs.add("URL=" + layoutUrl);
|
envs.add("URL=" + layoutUrl);
|
||||||
|
@ -110,7 +99,6 @@ public class ComposedRecordingService extends RecordingService {
|
||||||
envs.add("VIDEO_ID=" + recordingId);
|
envs.add("VIDEO_ID=" + recordingId);
|
||||||
envs.add("VIDEO_NAME=" + properties.name());
|
envs.add("VIDEO_NAME=" + properties.name());
|
||||||
envs.add("VIDEO_FORMAT=mp4");
|
envs.add("VIDEO_FORMAT=mp4");
|
||||||
envs.add("USER_ID=" + uid);
|
|
||||||
envs.add("RECORDING_JSON=" + recording.toJson().toString());
|
envs.add("RECORDING_JSON=" + recording.toJson().toString());
|
||||||
|
|
||||||
log.info(recording.toJson().toString());
|
log.info(recording.toJson().toString());
|
||||||
|
@ -158,11 +146,13 @@ public class ComposedRecordingService extends RecordingService {
|
||||||
log.warn("Session closed while starting recording container");
|
log.warn("Session closed while starting recording container");
|
||||||
boolean containerClosed = false;
|
boolean containerClosed = false;
|
||||||
String containerIdAux;
|
String containerIdAux;
|
||||||
while (!containerClosed) {
|
int timeOut = 0;
|
||||||
|
while (!containerClosed && (timeOut < 30)) {
|
||||||
containerIdAux = this.sessionsContainers.remove(session.getSessionId());
|
containerIdAux = this.sessionsContainers.remove(session.getSessionId());
|
||||||
if (containerIdAux == null) {
|
if (containerIdAux == null) {
|
||||||
try {
|
try {
|
||||||
log.warn("Waiting for container to be launched...");
|
log.warn("Waiting for container to be launched...");
|
||||||
|
timeOut++;
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
Loading…
Reference in New Issue