
Advanced search
Other articles (18)
-
Ajouter notes et légendes aux images
7 February 2011, byPour pouvoir ajouter notes et légendes aux images, la première étape est d’installer le plugin "Légendes".
Une fois le plugin activé, vous pouvez le configurer dans l’espace de configuration afin de modifier les droits de création / modification et de suppression des notes. Par défaut seuls les administrateurs du site peuvent ajouter des notes aux images.
Modification lors de l’ajout d’un média
Lors de l’ajout d’un média de type "image" un nouveau bouton apparait au dessus de la prévisualisation (...) -
XMP PHP
13 May 2011, byDixit Wikipedia, XMP signifie :
Extensible Metadata Platform ou XMP est un format de métadonnées basé sur XML utilisé dans les applications PDF, de photographie et de graphisme. Il a été lancé par Adobe Systems en avril 2001 en étant intégré à la version 5.0 d’Adobe Acrobat.
Étant basé sur XML, il gère un ensemble de tags dynamiques pour l’utilisation dans le cadre du Web sémantique.
XMP permet d’enregistrer sous forme d’un document XML des informations relatives à un fichier : titre, auteur, historique (...) -
Les formats acceptés
28 January 2010, byLes commandes suivantes permettent d’avoir des informations sur les formats et codecs gérés par l’installation local de ffmpeg :
ffmpeg -codecs ffmpeg -formats
Les format videos acceptés en entrée
Cette liste est non exhaustive, elle met en exergue les principaux formats utilisés : h264 : H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 m4v : raw MPEG-4 video format flv : Flash Video (FLV) / Sorenson Spark / Sorenson H.263 Theora wmv :
Les formats vidéos de sortie possibles
Dans un premier temps on (...)
On other websites (4651)
-
WebM live streaming via DASH
23 February 2017, by ewackI am following the instructions here to try to make WebM live streaming via DASH. My input is from an Axis camera and it is streaming as h264 encoding. I am using node to spin up the ffmpeg processes. I am able to create the .hdr file and the .chk files. The .mpd file is even created but it’s empty and I get an error saying:
Could not write header for output file #0 (incorrect codec parameters ?): Operation not permittedStream mapping: Stream #0:0 -> #0:0 (copy)
Here’s all of my code:
var express = require('express');
spawn = require('child_process').spawn;
var app = express();
app.use(express.static(__dirname + '/public'));
app.listen(8080);
console.log("Running on Port 8080");
var ffmpeg1 = spawn('ffmpeg', [
'-y',
//video
'-i', 'rtsp://admin:password@192.168.1.54:554/axis-media/media.amp?videocodec=h264&resolution=1280x720',
'-map', '0:0',
'-pix_fmt', 'yuv420p',
'-color_range', '2',
'-c:v', 'libvpx-vp9',
'-s', '1280x720',
'-keyint_min', '25',
'-g', '25',
// //VP9_LIVE_PARAMS
'-speed', '6',
'-tile-columns', '4',
'-frame-parallel', '1',
'-threads', '8',
'-static-thresh', '0',
'-max-intra-rate', '300',
'-deadline', 'realtime',
'-lag-in-frames', '0',
'-error-resilient', '1',
'-f', 'webm_chunk',
'-header', 'public/glass_360.hdr',
'-chunk_start_index', '1',
'public/glass_360_%d.chk',
]);
setTimeout(()=> {
var ffmpeg2 = spawn('ffmpeg', [
'-y',
'-f', 'webm_dash_manifest',
'-live', '1',
'-i', 'public/glass_360.hdr',
'-c', 'copy',
'-map', '0',
'-r', '25',
'-framerate', '25',
'-f', 'webm_dash_manifest',
'-live', '1',
'-adaptation_sets', '"id=0,streams=0"',
'-chunk_start_index', '1',
'-chunk_duration_ms', '2000',
'-time_shift_buffer_depth', '7200',
'-minimum_update_period', '7200',
'public/glass_live_manifest.mpd'
]);
ffmpeg2.stdout.on('data',
function (data) {
console.log('ff2std: ' + data);
}
);
ffmpeg2.stderr.on('data',
function (data) {
console.log('ff2err: ' + data);
}
);
}, 5000);
ffmpeg1.stdout.on('data',
function (data) {
console.log('ff1std: ' + data);
}
);
ffmpeg1.stderr.on('data',
function (data) {
console.log('ff1err: ' + data);
}
);Here is all of my output:
Running on Port 8080
ff1err: ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.1.2/include/openjpeg-2.1 --enable-nonfree --enable-vda
ff1err: libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
ff1err: Input #0, rtsp, from 'rtsp://admin:password@192.168.1.54:554/axis-media/media.amp?videocodec=h264&resolution=1280x720':
Metadata:
title : Session streamed with GStreamer
comment : rtsp-server
Duration: N/A, start: 0.033344
ff1err: , bitrate: N/A
Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1280x720 [SAR 1:1 DAR 16:9], 30 fps, 30 tbr, 90k tbn, 180k tbc
ff1err: [swscaler @ 0x7f8df281bc00] deprecated pixel format used, make sure you did set range correctly
ff1err: [libvpx-vp9 @ 0x7f8df2800600] v1.6.1
ff1err: Output #0, webm_chunk, to 'public/glass_360_%d.chk':
Metadata:
title : Session streamed with GStreamer
comment : rtsp-server
encoder : Lavf57.56.101
ff1err: Stream #0:0: Video: vp9 (libvpx-vp9), yuv420p(pc), 1280x720 [SAR 1:1 DAR 16:9], q=-1--1, 200 kb/s, 25 fps, 1k tbn, 25 tbc
Metadata:
encoder : Lavc57.64.101 libvpx-vp9
Side data:
cpb: bitrate max/min/avg: 0/0/0 buffer size: 0 vbv_delay: -1
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> vp9 (libvpx-vp9))
Press [q] to stop, [?] for help
ff1err: frame= 10 fps=0.0 q=0.0 size=N/A time=00:00:00.36 bitrate=N/A speed=0.71x
ff1err: frame= 25 fps= 25 q=0.0 size=N/A time=00:00:00.96 bitrate=N/A speed=0.946x
ff1err: frame= 40 fps= 26 q=0.0 size=N/A time=00:00:01.56 bitrate=N/A speed=1.03x
ff1err: frame= 55 fps= 27 q=0.0 size=N/A time=00:00:02.16 bitrate=N/A speed=1.07x
ff1err: frame= 70 fps= 28 q=0.0 size=N/A time=00:00:02.76 bitrate=N/A speed=1.09x
ff1err: frame= 85 fps= 28 q=0.0 size=N/A time=00:00:03.36 bitrate=N/A speed=1.11x
ff2err: ffmpeg version 3.2.4 Copyright (c) 2000-2017 the FFmpeg developers
built with Apple LLVM version 6.0 (clang-600.0.57) (based on LLVM 3.5svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/3.2.4 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-frei0r --enable-libass --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-opencl --disable-lzma --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags=-I/usr/local/Cellar/openjpeg/2.1.2/include/openjpeg-2.1 --enable-nonfree --enable-vda
ff2err: libavutil 55. 34.101 / 55. 34.101
libavcodec 57. 64.101 / 57. 64.101
libavformat 57. 56.101 / 57. 56.101
libavdevice 57. 1.100 / 57. 1.100
libavfilter 6. 65.100 / 6. 65.100
libavresample 3. 1. 0 / 3. 1. 0
libswscale 4. 2.100 / 4. 2.100
libswresample 2. 3.100 / 2. 3.100
libpostproc 54. 1.100 / 54. 1.100
ff2err: [webm_dash_manifest @ 0x7fbc5b80b400] Could not find codec parameters for stream 0 (Video: vp9, none, 1280x720): unspecified pixel format
Consider increasing the value for the 'analyzeduration' and 'probesize' options
ff2err: Input #0, webm_dash_manifest, from 'public/glass_360.hdr':
Metadata:
title : Session streamed with GStreamer
encoder : Lavf57.56.101
Duration: N/A, bitrate: N/A
Stream #0:0: Video: vp9, none, 1280x720
ff2err: , SAR 1:1 DAR 16:9, 25 fps, 25 tbr, 1k tbn, 1k tbc (default)
Metadata:
webm_dash_manifest_file_name: glass_360.hdr
webm_dash_manifest_track_number: 1
ff2err: Could not write header for output file #0 (incorrect codec parameters ?): Operation not permittedStream mapping:
Stream #0:0 -> #0:0 (copy)
ff2err: Last message repeated 1 times
ff1err: frame= 101 fps= 29 q=0.0 size=N/A time=00:00:04.00 bitrate=N/A speed=1.13x
ff1err: frame= 116 fps= 29 q=0.0 size=N/A time=00:00:04.60 bitrate=N/A speed=1.14x
ff1err: frame= 131 fps= 29 q=0.0 size=N/A time=00:00:05.20 bitrate=N/A speed=1.15x
ff1err: frame= 146 fps= 29 q=0.0 size=N/A time=00:00:05.80 bitrate=N/A speed=1.15x
ff1err: frame= 161 fps= 29 q=0.0 size=N/A time=00:00:06.40 bitrate=N/A speed=1.15x
ff1err: frame= 177 fps= 29 q=0.0 size=N/A time=00:00:07.04 bitrate=N/A speed=1.16x
ff1err: frame= 192 fps= 29 q=0.0 size=N/A time=00:00:07.64 bitrate=N/A speed=1.16x
ff1err: frame= 207 fps= 29 q=0.0 size=N/A time=00:00:08.24 bitrate=N/A speed=1.16x
ff1err: frame= 222 fps= 29 q=0.0 size=N/A time=00:00:08.84 bitrate=N/A speed=1.17x
ff1err: frame= 237 fps= 29 q=0.0 size=N/A time=00:00:09.44 bitrate=N/A speed=1.17x
ff1err: frame= 252 fps= 29 q=0.0 size=N/A time=00:00:10.04 bitrate=N/A speed=1.17xWhy is ffmpeg creating an empty .mpd file?
-
bash script to install / update ffmpeg static builds
1 March 2017, by JoakimHi I’m trying to make my first "real" bash script to do some real work than can be executed both manually and through cron jobs.
The script should download and install the ffmpeg-static-build from https://johnvansickle.com/ffmpeg
Here is what I’ve got so far:
#!/bin/bash
# Still to come, see if the script runs with root privileges else exit
#Download FFMPEG static daily build and it's md5
cd ~
wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz | tar -xf
#wget https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz.md5
curl -L https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz.md5 | tar -xf | tee -a https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz | cut -d\ -f1 | md5sum > md5sum.txt
#Chech the md5 is currect
#md5sum -c MD5SUMS
file1="md5sum.txt"
file2="ffmpeg-git-64bit-static.tar.xz.md5"
if ! cmp --silent "$file1" "$file2"; then
echo "md5sum doesn't match...\n exit" >&2
exit 1
fi
#tar -xf ffmpeg-*.tar.xz
cp ffmpeg-*-static/ff* /usr/bin/
cp ffmpeg-*-static/ff* /usr/local/bin/
cp ffmpeg-*-static/qt-faststart /usr/bin/
cp ffmpeg-*-static/qt-faststart /usr/local/bin/
# Consider change second location to use ln -s
# Remove downloads and do some clean up
rm -fr ffmpeg-*
#EOFAs you can see in the script i would like to add the md5sum check but it fails (got the md5sum check part from Compare md5 sums in bash script)
If i remove the md5sum part the script is working, but right now the script fails at the | tar -xf | part with this code
2017-02-28 00:10:24 (617 KB/s) - ‘ffmpeg-git-64bit-static.tar.xz’ saved [17564756/17564756]
tar: option requires an argument -- 'f'
Try 'tar --help' or 'tar --usage' for more information.
tee: 'https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz': No such file or directory
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 65 100 65 0 0 87 0 --:--:-- --:--:-- --:--:-- 87
(23) Failed writing body
md5sum doesn't match...
exitAs this is my first, I would appreciate any "I’m 4 years old" advices and why
update
Have made some changes to the script based on the suggestions in this thread, but my problem is I have no output what so ever at this state :( So I think it’s time to ask for the next clue
#!/bin/bash
# version 0.3z
## Download FFMPEG static daily build and it's md5
##
## To make this script working you might need to change the below values
## based on whether you are using a 32bit or 64 bit OS
## to obtain the right links you have to have a look @ https://johnvansickle.com/ffmpeg/
## and then change those below
##
## If you are running on a shared server or dowsn't have root priviliges you might need to uncomment
## point 5.
# a "~" means running users home folder :) and should be different from destination dir
download_dir=~
# as this can change if the ffmpeg is to be stored on ex. shared server
dest_dir=/usr/bin/
# The version it equal the filename from above link
version=ffmpeg-git-64bit-static.tar.xz
## Do not change anything below here!!
source_url=https://johnvansickle.com/ffmpeg/builds/${version}
md5_url=https://johnvansickle.com/ffmpeg/builds/${version}.md5
# Still to come, see if the script runs with write privileges else exit
# 1. Can we enter download directory else exit
cd ${download_dir} ||
printf "%s\n" "You can't enter this folder.\nPlease chage download_dir in this script..." >&2
exit 1
# 2. Check the md5 is correct or have changed from last check
## instead of downloading ffmpeg-git-64bit-static.tar.xz every time,
## regardless if it is new or not, I recommend only downloading it
## if the md5 does not match. Would save John some bandwidth at least
## thx for the idea to @LordNeckbeard
## So somehow i'll guess some sed or grep only first part is nessesary :(
## This is getting more advance than expected for a first time script :/
if ! diff <(md5sum ${version}) <(curl -s ${md5_url})
then
printf "%s\n" "md5sum doesn't match...\n
Downloading new version" >&2
rm -f ${version} >&2
curl ${source_url} -o ${download_dir}/${version} >&2
#exit 2
elif
diff <(md5sum ${version}) <(curl -s ${md5_url})
printf "%s\n" "Nothing new to download" >&2
exit 3
fi
# 3. untar
tar -xf ffmpeg-git-*-static.tar.xz
# 4. Move builds to destination directories
mv ${download_dir}/ffmpeg-*-static/ff* ${dest_dir}/
mv ${download_dir}/ffmpeg-*-static/qt-faststart ${dest_dir}/
# 5. Make soft links to static builds
ln -sfn ${dest_dir}/qt-faststart /usr/local/bin/qt-faststart
ln -sfn ${dest_dir}/ffmpeg /usr/local/bin/ffmpeg
ln -sfn ${dest_dir}/ffmpeg-10bit /usr/local/bin/ffmpeg-10bit
ln -sfn ${dest_dir}/ffprobe /usr/local/bin/ffprobe
ln -sfn ${dest_dir}/ffserver /usr/local/bin/ffserver
# Remove unzipped folder to do some clean up
rm -fr ffmpeg-git-*-static/
#EOFnote: do to some more in depth answering of why not compile from source:
1. This precompiled is usable on all Linux variations, despite distro and version
2. It usable on shared hosting servers with ssh accessUPDATE 2
#!/bin/bash
# version 0.4z
## Download FFMPEG static daily build and it's md5
##
## To make this script working you might need to change the below values
## based on whether you are using a 32bit or 64 bit OS
## to obtain the right links you have to have a look @ https://johnvansickle.com/ffmpeg/
## and then change those below
##
## Finished and working script should be distributed under GPLv3: free as in freedom
##
## If you are running on a shared server or dowsn't have root priviliges you might need to uncomment
## point 5.
# a "~" means running users home folder :) and should be different from destination dir
download_dir=~
# as this can change if the ffmpeg is to be stored on ex. shared server
dest_dir=/usr/bin/
# The version it equal the filename from above link
version=ffmpeg-git-64bit-static.tar.xz
## Do not change anything below here!!
source_url=https://johnvansickle.com/ffmpeg/builds/${version}
md5="curl -s https://johnvansickle.com/ffmpeg/builds/${version}.md5"
# Still to come, see if the script runs with write privileges else exit
# 1. Can we enter download directory else exit
cd ${download_dir} ||
printf "%s\n" "You can't enter this folder.\nPlease chage download_dir in this script..." >&2
exit 1
# 2. Check the md5 is correct or have changed from last check
## instead of downloading ffmpeg-git-64bit-static.tar.xz every time,
## regardless if it is new or not, I recommend only downloading it
## if the md5 does not match. Would save John some bandwidth at least
## thx for the idea to @LordNeckbeard
## This is getting more advance than expected for a first time script :/
if diff <(md5sum ${version}) <(${md5})
then
printf "%s\n" "No new version availeble" >&2
exit 1
elif ! diff <(md5sum ${version}) <(${md5})
then
rm -f ${version}
curl ${source_url} > ${version}
exit 0
#only proceed if downloaded version match it's md5
if ! diff <(md5sum ${version}) <(${md5})
then
rm -f ${version}
printf "%s\n" "Downloaded version is damaged, try later\ndamaged version have been deleted" >&2
exit 1
fi
# 3. untar
tar -xf ffmpeg-git-*-static.tar.xz
# 4. Move builds to destination directories
mv ${download_dir}/ffmpeg-*-static/ff* ${dest_dir}/
mv ${download_dir}/ffmpeg-*-static/qt-faststart ${dest_dir}/
# 5. Make soft links to static builds
ln -sfn ${dest_dir}/qt-faststart /usr/local/bin/qt-faststart
ln -sfn ${dest_dir}/ffmpeg /usr/local/bin/ffmpeg
ln -sfn ${dest_dir}/ffmpeg-10bit /usr/local/bin/ffmpeg-10bit
ln -sfn ${dest_dir}/ffprobe /usr/local/bin/ffprobe
ln -sfn ${dest_dir}/ffserver /usr/local/bin/ffserver
# Remove unzipped folder to do some clean up
rm -fr ffmpeg-git-*-static/
printf "%s\n" "Going to install new version" >&2
exit 1
fi
#EOFBut still having some issues :(
- Running this script returns: a blanc shell, but I’ve expected one of the printf statements
- When I’m trying to narrow down the problem and going back to basic and trying to run the script with only the "if" part it fails with 44: Syntax error: "(" unexpected
-
running the very same "if" part typed directly into the shell/terminal itself it’s all happy!!
if diff <(md5sum ffmpeg-git-64bit-static.tar.xz) <(curl -s "https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz.md5"); then printf "%s\n" "No new version availeble" >&2; elif ! diff <(md5sum ffmpeg-git-64bit-static.tar.xz) <(curl -s "https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz.md5"); then rm -f ffmpeg-git-64bit-static.tar.xz; curl https://johnvansickle.com/ffmpeg/builds/ffmpeg-git-64bit-static.tar.xz > ffmpeg-git-64bit-static.tar.xz; printf "%s\n" "Going to install new version" >&2; fi
-
I’m confused
-
RTP packets detected as UDP
28 February 2017, by user3172852Here is what I am trying to do:
WebRTC endpoint > RTP Endpoint > ffmpeg > RTMP server.
This is what my SDP file looks like.
var cm_offer = "v=0\n" +
"o=- 3641290734 3641290734 IN IP4 127.0.0.1\n" +
"s=nginx\n" +
"c=IN IP4 127.0.0.1\n" +
"t=0 0\n" +
"m=audio 60820 RTP/AVP 0\n" +
"a=rtpmap:0 PCMU/8000\n" +
"a=recvonly\n" +
"m=video 59618 RTP/AVP 101\n" +
"a=rtpmap:101 H264/90000\n" +
"a=recvonly\n";What’s happening is that wireshark can detect the incoming packets at port 59618, but not as RTP packets but UDP packets. I am trying to capture the packets using ffmpeg with the following command:
ubuntu@ip-132-31-40-100:~$ ffmpeg -i udp://127.0.0.1:59618 -vcodec copy stream.mp4
ffmpeg version git-2017-01-22-f1214ad Copyright (c) 2000-2017 the FFmpeg developers
built with gcc 4.8 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
configuration: --extra-libs=-ldl --prefix=/opt/ffmpeg --mandir=/usr/share/man --enable-avresample --disable-debug --enable-nonfree --enable-gpl --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-decoder=amrwb --enable-libpulse --enable-libfreetype --enable-gnutls --enable-libx264 --enable-libx265 --enable-libfdk-aac --enable-libvorbis --enable-libmp3lame --enable-libopus --enable-libvpx --enable-libspeex --enable-libass --enable-avisynth --enable-libsoxr --enable-libxvid --enable-libvidstab --enable-libwavpack --enable-nvenc
libavutil 55. 44.100 / 55. 44.100
libavcodec 57. 75.100 / 57. 75.100
libavformat 57. 63.100 / 57. 63.100
libavdevice 57. 2.100 / 57. 2.100
libavfilter 6. 69.100 / 6. 69.100
libavresample 3. 2. 0 / 3. 2. 0
libswscale 4. 3.101 / 4. 3.101
libswresample 2. 4.100 / 2. 4.100
libpostproc 54. 2.100 / 54. 2.100All I get is a blinking cursor and The stream.mp4 file is not written to disk after I exit (ctrl+c).
So can you help me figure out:
- why wireshark cannot detect the packets as RTP (I suspect it has something to do with SDP)
- How to handle SDP answer when the RTP endpoint is pushing to ffmpeg which doesn’t send an answer back.
Here is the entire code (hello world tutorial modified)
/*
* (C) Copyright 2014-2015 Kurento (http://kurento.org/)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
function getopts(args, opts)
{
var result = opts.default || {};
args.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function($0, $1, $2, $3) { result[$1] = decodeURI($3); });
return result;
};
var args = getopts(location.search,
{
default:
{
ws_uri: 'wss://' + location.hostname + ':8433/kurento',
ice_servers: undefined
}
});
function setIceCandidateCallbacks(webRtcPeer, webRtcEp, onerror)
{
webRtcPeer.on('icecandidate', function(candidate) {
console.log("Local candidate:",candidate);
candidate = kurentoClient.getComplexType('IceCandidate')(candidate);
webRtcEp.addIceCandidate(candidate, onerror)
});
webRtcEp.on('OnIceCandidate', function(event) {
var candidate = event.candidate;
console.log("Remote candidate:",candidate);
webRtcPeer.addIceCandidate(candidate, onerror);
});
}
function setIceCandidateCallbacks2(webRtcPeer, rtpEp, onerror)
{
webRtcPeer.on('icecandidate', function(candidate) {
console.log("Localr candidate:",candidate);
candidate = kurentoClient.getComplexType('IceCandidate')(candidate);
rtpEp.addIceCandidate(candidate, onerror)
});
}
window.addEventListener('load', function()
{
console = new Console();
var webRtcPeer;
var pipeline;
var webRtcEpt;
var videoInput = document.getElementById('videoInput');
var videoOutput = document.getElementById('videoOutput');
var startButton = document.getElementById("start");
var stopButton = document.getElementById("stop");
startButton.addEventListener("click", function()
{
showSpinner(videoInput, videoOutput);
var options = {
localVideo: videoInput,
remoteVideo: videoOutput
};
if (args.ice_servers) {
console.log("Use ICE servers: " + args.ice_servers);
options.configuration = {
iceServers : JSON.parse(args.ice_servers)
};
} else {
console.log("Use freeice")
}
webRtcPeer = kurentoUtils.WebRtcPeer.WebRtcPeerSendrecv(options, function(error)
{
if(error) return onError(error)
this.generateOffer(onOffer)
});
function onOffer(error, sdpOffer)
{
if(error) return onError(error)
kurentoClient(args.ws_uri, function(error, client)
{
if(error) return onError(error);
client.create("MediaPipeline", function(error, _pipeline)
{
if(error) return onError(error);
pipeline = _pipeline;
pipeline.create("WebRtcEndpoint", function(error, webRtc){
if(error) return onError(error);
webRtcEpt = webRtc;
setIceCandidateCallbacks(webRtcPeer, webRtc, onError)
webRtc.processOffer(sdpOffer, function(error, sdpAnswer){
if(error) return onError(error);
webRtcPeer.processAnswer(sdpAnswer, onError);
});
webRtc.gatherCandidates(onError);
webRtc.connect(webRtc, function(error){
if(error) return onError(error);
console.log("Loopback established");
});
});
pipeline.create("RtpEndpoint", function(error, rtp){
if(error) return onError(error);
//setIceCandidateCallbacks2(webRtcPeer, rtp, onError)
var cm_offer = "v=0\n" +
"o=- 3641290734 3641290734 IN IP4 127.0.0.1\n" +
"s=nginx\n" +
"c=IN IP4 127.0.0.1\n" +
"t=0 0\n" +
"m=audio 60820 RTP/AVP 0\n" +
"a=rtpmap:0 PCMU/8000\n" +
"a=recvonly\n" +
"m=video 59618 RTP/AVP 101\n" +
"a=rtpmap:101 H264/90000\n" +
"a=recvonly\n";
rtp.processOffer(cm_offer, function(error, cm_sdpAnswer){
if(error) return onError(error);
//webRtcPeer.processAnswer(cm_sdpAnswer, onError);
});
//rtp.gatherCandidates(onError);
webRtcEpt.connect(rtp, function(error){
if(error) return onError(error);
console.log("RTP endpoint connected to webRTC");
});
});
});
});
}
});
stopButton.addEventListener("click", stop);
function stop() {
if (webRtcPeer) {
webRtcPeer.dispose();
webRtcPeer = null;
}
if(pipeline){
pipeline.release();
pipeline = null;
}
hideSpinner(videoInput, videoOutput);
}
function onError(error) {
if(error)
{
console.error(error);
stop();
}
}
})
function showSpinner() {
for (var i = 0; i < arguments.length; i++) {
arguments[i].poster = 'img/transparent-1px.png';
arguments[i].style.background = "center transparent url('img/spinner.gif') no-repeat";
}
}
function hideSpinner() {
for (var i = 0; i < arguments.length; i++) {
arguments[i].src = '';
arguments[i].poster = 'img/webrtc.png';
arguments[i].style.background = '';
}
}
/**
* Lightbox utility (to display media pipeline image in a modal dialog)
*/
$(document).delegate('*[data-toggle="lightbox"]', 'click', function(event) {
event.preventDefault();
$(this).ekkoLightbox();
});