
Recherche avancée
Médias (91)
-
Spitfire Parade - Crisis
15 mai 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Audio
-
Wired NextMusic
14 mai 2011, par
Mis à jour : Février 2012
Langue : English
Type : Video
-
Video d’abeille en portrait
14 mai 2011, par
Mis à jour : Février 2012
Langue : français
Type : Video
-
Sintel MP4 Surround 5.1 Full
13 mai 2011, par
Mis à jour : Février 2012
Langue : English
Type : Video
-
Carte de Schillerkiez
13 mai 2011, par
Mis à jour : Septembre 2011
Langue : English
Type : Texte
-
Publier une image simplement
13 avril 2011, par ,
Mis à jour : Février 2012
Langue : français
Type : Video
Autres articles (23)
-
L’utiliser, en parler, le critiquer
10 avril 2011La première attitude à adopter est d’en parler, soit directement avec les personnes impliquées dans son développement, soit autour de vous pour convaincre de nouvelles personnes à l’utiliser.
Plus la communauté sera nombreuse et plus les évolutions seront rapides ...
Une liste de discussion est disponible pour tout échange entre utilisateurs. -
MediaSPIP version 0.1 Beta
16 avril 2011, parMediaSPIP 0.1 beta est la première version de MediaSPIP décrétée comme "utilisable".
Le fichier zip ici présent contient uniquement les sources de MediaSPIP en version standalone.
Pour avoir une installation fonctionnelle, il est nécessaire d’installer manuellement l’ensemble des dépendances logicielles sur le serveur.
Si vous souhaitez utiliser cette archive pour une installation en mode ferme, il vous faudra également procéder à d’autres modifications (...) -
Soumettre bugs et patchs
10 avril 2011Un logiciel n’est malheureusement jamais parfait...
Si vous pensez avoir mis la main sur un bug, reportez le dans notre système de tickets en prenant bien soin de nous remonter certaines informations pertinentes : le type de navigateur et sa version exacte avec lequel vous avez l’anomalie ; une explication la plus précise possible du problème rencontré ; si possibles les étapes pour reproduire le problème ; un lien vers le site / la page en question ;
Si vous pensez avoir résolu vous même le bug (...)
Sur d’autres sites (3416)
-
Lost in converting hardware accelarated ffmpeg decoder to raw loopback device
5 septembre 2019, par MikeynlBefore reaching out, i googled enough, tried many different docker containers, building, compiling etc etc.
What I am looking for is a hardware accelerated conversion from a rtsp stream to a /dev/video0 device. I have a working v4l2loopback kernel module, and the following command is working :
ffmpeg -loglevel panic -hide_banner -i "rtsp://192.168.0.17/user=admin&password=&channel=1&stream=0.dsp?real_stream" -f v4l2 -pix_fmt yuv420p /dev/video0
I can test the /dev/video0 device to take a screenshot :
ffmpeg -f video4linux2 -i /dev/video0 -ss 0:0:2 -frames 1 /var/www/html/out.png
Above is working, but taking around 30 / 50% cpu usage to decode/encoding.
I have a fully working test environment with a GeForce GTX 1050. All cuda / nvidia related drivers are in place. ffmpeg is compiled with the following options :
configuration: --enable-nonfree --disable-shared --enable-nvenc --enable-cuda --enable-cuvid --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/cuda/lib64
My last attempt was :
ffmpeg -hwaccel cuvid -c:v h264_cuvid -i "rtsp://192.168.0.17/user=admin&password=&channel=1&stream=0.dsp?real_stream" -c:v rawvideo -pix_fmt yuv420p -f v4l2 /dev/video0
It gives me an error :
Impossible to convert between the formats supported by the filter ’Parsed_null_0’ and the filter ’auto_scaler_0’
Error reinitializing filters !
Failed to inject frame into filter network : Function not implemented
Error while processing the decoded data for stream #0:0I have at the moment absolute no idea anymore how to solve this.
Thanks in advance !
//added information
root@localhost:~# ffmpeg -i "rtsp://192.168.0.17/user=admin&password=&channel=1&stream=0.dsp?real_stream" -c copy -f v4l2 /dev/video0
ffmpeg version N-91067-g1c2e5fc Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609
configuration: --enable-nonfree --disable-shared --enable-nvenc --enable-cuda --enable-cuvid --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/cuda/lib64
libavutil 56. 18.102 / 56. 18.102
libavcodec 58. 19.101 / 58. 19.101
libavformat 58. 13.102 / 58. 13.102
libavdevice 58. 4.100 / 58. 4.100
libavfilter 7. 22.100 / 7. 22.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
Input #0, rtsp, from 'rtsp://192.168.0.17/user=admin&password=&channel=1&stream=0.dsp?real_stream':
Metadata:
title : RTSP Session
Duration: N/A, start: 2.300000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1920x1080, 10 fps, 10 tbr, 90k tbn, 20 tbc
[v4l2 @ 0x31a7f00] V4L2 output device supports only a single raw video stream
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Last message repeated 1 times
root@localhost:~#
root@localhost:~# ffmpeg -i "rtsp://192.168.0.17/user=admin&password=&channel=1&stream=0.dsp?real_stream" -f v4l2 -pix_fmt yuv420p /dev/video0 ffmpeg version N-91067-g1c2e5fc Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 5.4.0 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 20160609
configuration: --enable-nonfree --disable-shared --enable-nvenc --enable-cuda --enable-cuvid --enable-libnpp --extra-cflags=-I/usr/local/cuda/include --extra-cflags=-I/usr/local/include --extra-ldflags=-L/usr/local/cuda/lib64
libavutil 56. 18.102 / 56. 18.102
libavcodec 58. 19.101 / 58. 19.101
libavformat 58. 13.102 / 58. 13.102
libavdevice 58. 4.100 / 58. 4.100
libavfilter 7. 22.100 / 7. 22.100
libswscale 5. 2.100 / 5. 2.100
libswresample 3. 2.100 / 3. 2.100
Input #0, rtsp, from 'rtsp://192.168.0.17/user=admin&password=&channel=1&stream=0.dsp?real_stream':
Metadata:
title : RTSP Session
Duration: N/A, start: 2.300000, bitrate: N/A
Stream #0:0: Video: h264 (Main), yuvj420p(pc, bt709, progressive), 1920x1080, 10 fps, 10 tbr, 90k tbn, 20 tbc
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> rawvideo (native))
Press [q] to stop, [?] for help
[swscaler @ 0x2821240] deprecated pixel format used, make sure you did set range correctly
Output #0, v4l2, to '/dev/video0':
Metadata:
title : RTSP Session
encoder : Lavf58.13.102
Stream #0:0: Video: rawvideo (I420 / 0x30323449), yuv420p, 1920x1080, q=2-31, 248832 kb/s, 10 fps, 10 tbn, 10 tbc
Metadata:
encoder : Lavc58.19.101 rawvideo
frame= 85 fps= 13 q=-0.0 Lsize=N/A time=00:00:08.50 bitrate=N/A dup=0 drop=4 speed=1.31x
video:258188kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown -
Delphi FFMPEG CUDA hardware accelerated video decoding generating shadows
30 janvier 2023, par EdimarI'm trying to use cuda hardware accelerated video decoding, loading from a .mp4 file, according to the code bellow, but getting the image with shadows


Specification :
FFMPEG 4.3
Delphi 10.3
NVIDIA GeForce RTX 3050 Laptop GPU 4Gb DDR6
Intel Core i5 11400H 16 Gb RAM


unit UVideoDecoding;

interface

uses
 Vcl.Graphics, Winapi.Windows,
 System.SysUtils, System.Classes,
 libavcodec, libavdevice,
 libavfilter, libswresample, libavformat, libavutil,
 libswscale;

type
 TDecoder = class
 protected
 fFormatCtx: PAVFormatContext;
 fCodec: PAVCodec;
 fCodecParams, fLocalCodecParams: PAVCodecParameters;
 fCodecCtx: libavcodec.PAVCodecContext;
 fPacket: PAVPacket;
 fFrameIn, fFrameOut: PAVFrame;
 fScaler: PSwsContext;
 fVideoStreamIndex: Integer;
 fHWPixelFormat: AVPixelFormat;
 fOutputWidth: Integer;
 fOutputHeight: Integer;

 function DecodeVideoPacket: Integer;
 public
 function Load(pFileName: string): Integer;

 end;
implementation

function TDecoder.Load(pFileName: string): Integer;
var
 vCount: Integer;
 vLocalCodec: PAVCodec;
 vFileName: AnsiString;
 vType: AVHWDeviceType;
 vDecPackResponse: Integer;
begin

 vType := av_hwdevice_find_type_by_name('cuda');
 {vType = AV_HWDEVICE_TYPE_CUDA}

 fFormatCtx := avformat_alloc_context;

 vFileName := AnsiString(pFileName);
 avformat_open_input(fFormatCtx, PAnsiChar(vFileName), nil, nil);

 avformat_find_stream_info(fFormatCtx, nil);

 for vCount := 0 to fFormatCtx.nb_streams - 1 do
 begin
 fLocalCodecParams := fFormatCtx.streams[vCount].codecpar;

 case fLocalCodecParams.codec_id of
 AVCodecID.AV_CODEC_ID_H264: vLocalCodec := avcodec_find_decoder_by_name('h264_cuvid');
 AVCodecID.AV_CODEC_ID_HEVC: vLocalCodec := avcodec_find_decoder_by_name('hevc_cuvid');
 AVCodecID.AV_CODEC_ID_MJPEG: vLocalCodec := avcodec_find_decoder_by_name('mjpeg_cuvid');
 AVCodecID.AV_CODEC_ID_MPEG4: vLocalCodec := avcodec_find_decoder_by_name('mpeg4_cuvid');
 else
 vLocalCodec := avcodec_find_decoder(fLocalCodecParams.codec_id);
 end;

 if fLocalCodecParams.codec_type = AVMEDIA_TYPE_VIDEO then
 begin
 fVideoStreamIndex := vCount;
 fCodec := vLocalCodec;
 fCodecParams := fLocalCodecParams;
 end;
 end;

 {fCodec.name = h264_cuvid} 

 fCodecCtx := avcodec_alloc_context3(fCodec);


 var vHWDeviceCtx: PAVBufferRef;
 try
 if av_hwdevice_ctx_create(vHWDeviceCtx, vType, nil, nil, 0) >= 0 then
 fCodecCtx.hw_device_ctx := av_buffer_ref(vHWDeviceCtx);
 finally
 av_buffer_unref(vHWDeviceCtx);
 end;

 avcodec_open2(fCodecCtx, fCodec, nil);
 {
 fCodecCtx.codec_id = AV_CODEC_ID_H264
 fCodecCtx.pix_fmt = AV_PIX_FMT_MMAL
 }

 fFrameIn := av_frame_alloc;
 fFrameOut := av_frame_alloc;
 fFrameOut.format := Integer(AV_PIX_FMT_BGRA);
 fFrameOut.width := 640;
 fFrameOut.height := 480;

//On getting sws_context I've tried srcFormat = AV_PIX_FMT_MMAL but the result was nil
 fScaler := sws_getContext(fCodecCtx.Width, fCodecCtx.Height, AV_PIX_FMT_NV12{fCodecCtx.pix_fmt},
 fOutputWidth, fOutputHeight, AV_PIX_FMT_BGRA, SWS_BILINEAR, nil, nil, nil);

 fPacket := av_packet_alloc;

 while (av_read_frame(fFormatCtx, fPacket) >= 0) do
 begin
 if fPacket.stream_index = fVideoStreamIndex then
 begin
 vDecPackResponse := DecodeVideoPacket;

 av_packet_unref(fPacket);

 if vDecPackResponse < 0 then
 Break;
 end
 end;

 Exit(0);
end; 

function TDecoder.DecodeVideoPacket: Integer;
var
 vResponse: Integer;
 vBmp: Vcl.Graphics.TBitmap;
 vScaleResult, vSize: Integer;
 vBuffer: PByte;
 vSWFrame, vTMPFrame: pAVFrame;
begin
 Result := 0;

 vResponse := avcodec_send_packet(fCodecCtx, fPacket);

 if vResponse < 0 then
 Exit(vResponse);

 while (vResponse >= 0) do
 begin
 vResponse := avcodec_receive_frame(fCodecCtx, fFrameIn);
 if (vResponse = AVERROR_EAGAIN) or (vResponse = AVERROR_EOF) then
 Break
 else if vResponse < 0 then
 Exit(vResponse);

 if vResponse >= 0 then
 begin
 vSWFrame := av_frame_alloc;

 if av_hwframe_transfer_data(vSWFrame, fFrameIn, 0) >= 0 then
 vTMPFrame := vSWFrame
 else
 vTMPFrame := fFrameIn;

 vSize := av_image_get_buffer_size(AVPixelFormat(vTMPFrame.format), vTMPFrame.width, vTMPFrame.height, 1);
 vBuffer := av_malloc(vSize);

 if Assigned(vBuffer) then
 av_image_copy_to_buffer(vBuffer, vSize, @vTMPFrame.data, @vTMPFrame.linesize, AVPixelFormat(vTMPFrame.format), vTMPFrame.width, vTMPFrame.height, 1);

 MoveMemory(vTMPFrame.data[0], vBuffer, vSize);

 vTMPFrame.data[0] := vTMPFrame.data[0] + vTMPFrame.linesize[0] * (fCodecCtx.height - 1);
 vTMPFrame.linesize[0] := vTMPFrame.linesize[0] * -1;
 vTMPFrame.data[1] := vTMPFrame.data[1] + vTMPFrame.linesize[1] * (fCodecCtx.height div 2 - 1);
 vTMPFrame.linesize[1] := vTMPFrame.linesize[1] * -1;
 vTMPFrame.data[2] := vTMPFrame.data[2] + vTMPFrame.linesize[2] * (fCodecCtx.height div 2 - 1);
 vTMPFrame.linesize[2] := vTMPFrame.linesize[2] * -1;

 vScaleResult := sws_scale(fScaler, @vTMPFrame.Data, @vTMPFrame.Linesize, 0,
 fCodecCtx.Height, @fFrameOut.data, @fFrameOut.Linesize);
 if vScaleResult <= 0 then
 begin
 Break;
 end;

 vBmp := Vcl.Graphics.TBitmap.Create;
 try
 vBmp.Height := fOutputHeight;
 vBmp.Width := fOutputWidth;
 vBmp.PixelFormat := TPixelFormat.pf32bit;

 MoveMemory(PByte(vBmp.ScanLine[vBmp.Height -1]),
 fFrameOut.data[0], fOutputHeight * fFrameOut.linesize[0]);

//Renders BMP on main thread
// if Assigned(fOnBitmap) then
// fOnBitmap(vBmp);
 finally
 av_frame_unref(vSWFrame);
 av_frame_free(vTMPFrame);
 av_freep(@vBuffer);
 FreeAndNil(vBmp);
 Result := 1;
 end;
 end;
 end;
end;

end.



I've tried using different pixelformats but none of them properly decoded the video.


-
iOS Build PJSIP with FFmpeg+libx264
22 février 2021, par MeonardoI have built the FFmpeg with libx264 into static libs, here is my directory tree.


./ffmpeg
├── include
│   ├── libavcodec
│   │   ├── ac3_parser.h
│   │   ├── adts_parser.h
│   │   ├── avcodec.h
│   │   ├── avdct.h
│   │   ├── avfft.h
│   │   ├── bsf.h
│   │   ├── codec.h
│   │   ├── codec_desc.h
│   │   ├── codec_id.h
│   │   ├── codec_par.h
│   │   ├── d3d11va.h
│   │   ├── dirac.h
│   │   ├── dv_profile.h
│   │   ├── dxva2.h
│   │   ├── jni.h
│   │   ├── mediacodec.h
│   │   ├── packet.h
│   │   ├── qsv.h
│   │   ├── vaapi.h
│   │   ├── vdpau.h
│   │   ├── version.h
│   │   ├── videotoolbox.h
│   │   ├── vorbis_parser.h
│   │   └── xvmc.h
│   ├── libavdevice
│   │   ├── avdevice.h
│   │   └── version.h
│   ├── libavfilter
│   │   ├── avfilter.h
│   │   ├── buffersink.h
│   │   ├── buffersrc.h
│   │   └── version.h
│   ├── libavformat
│   │   ├── avformat.h
│   │   ├── avio.h
│   │   └── version.h
│   ├── libavutil
│   │   ├── adler32.h
│   │   ├── aes.h
│   │   ├── aes_ctr.h
│   │   ├── attributes.h
│   │   ├── audio_fifo.h
│   │   ├── avassert.h
│   │   ├── avconfig.h
│   │   ├── avstring.h
│   │   ├── avutil.h
│   │   ├── base64.h
│   │   ├── blowfish.h
│   │   ├── bprint.h
│   │   ├── bswap.h
│   │   ├── buffer.h
│   │   ├── camellia.h
│   │   ├── cast5.h
│   │   ├── channel_layout.h
│   │   ├── common.h
│   │   ├── cpu.h
│   │   ├── crc.h
│   │   ├── des.h
│   │   ├── dict.h
│   │   ├── display.h
│   │   ├── dovi_meta.h
│   │   ├── downmix_info.h
│   │   ├── encryption_info.h
│   │   ├── error.h
│   │   ├── eval.h
│   │   ├── ffversion.h
│   │   ├── fifo.h
│   │   ├── file.h
│   │   ├── frame.h
│   │   ├── hash.h
│   │   ├── hdr_dynamic_metadata.h
│   │   ├── hmac.h
│   │   ├── hwcontext.h
│   │   ├── hwcontext_cuda.h
│   │   ├── hwcontext_d3d11va.h
│   │   ├── hwcontext_drm.h
│   │   ├── hwcontext_dxva2.h
│   │   ├── hwcontext_mediacodec.h
│   │   ├── hwcontext_opencl.h
│   │   ├── hwcontext_qsv.h
│   │   ├── hwcontext_vaapi.h
│   │   ├── hwcontext_vdpau.h
│   │   ├── hwcontext_videotoolbox.h
│   │   ├── hwcontext_vulkan.h
│   │   ├── imgutils.h
│   │   ├── intfloat.h
│   │   ├── intreadwrite.h
│   │   ├── lfg.h
│   │   ├── log.h
│   │   ├── lzo.h
│   │   ├── macros.h
│   │   ├── mastering_display_metadata.h
│   │   ├── mathematics.h
│   │   ├── md5.h
│   │   ├── mem.h
│   │   ├── motion_vector.h
│   │   ├── murmur3.h
│   │   ├── opt.h
│   │   ├── parseutils.h
│   │   ├── pixdesc.h
│   │   ├── pixelutils.h
│   │   ├── pixfmt.h
│   │   ├── random_seed.h
│   │   ├── rational.h
│   │   ├── rc4.h
│   │   ├── replaygain.h
│   │   ├── ripemd.h
│   │   ├── samplefmt.h
│   │   ├── sha.h
│   │   ├── sha512.h
│   │   ├── spherical.h
│   │   ├── stereo3d.h
│   │   ├── tea.h
│   │   ├── threadmessage.h
│   │   ├── time.h
│   │   ├── timecode.h
│   │   ├── timestamp.h
│   │   ├── tree.h
│   │   ├── twofish.h
│   │   ├── tx.h
│   │   ├── version.h
│   │   ├── video_enc_params.h
│   │   └── xtea.h
│   ├── libpostproc
│   │   ├── postprocess.h
│   │   └── version.h
│   ├── libswresample
│   │   ├── swresample.h
│   │   └── version.h
│   ├── libswscale
│   │   ├── swscale.h
│   │   └── version.h
│   └── libx264
│   ├── x264.h
│   └── x264_config.h
└── lib
 ├── libavcodec.a
 ├── libavdevice.a
 ├── libavfilter.a
 ├── libavformat.a
 ├── libavutil.a
 ├── libpostproc.a
 ├── libswresample.a
 ├── libswscale.a
 └── libx264.a



The final lib was created successfully, no error message in log file,
but when I import the lib to my Xcode Project,
the linker give me tons of errors(missing symbols like :
Undefined symbol: _pjsua_vid_codec_set_priority
).
I found thepjsua_vid.o
is very small(200Bytes) compare to my pjsip+openh264 build file(was 47KB), perhaps this is the reason cause the link error.

Here is my build log :
log_file


the build script I am using :


#!/bin/sh

# see http://stackoverflow.com/a/3915420/318790
function realpath { echo $(cd $(dirname "$1"); pwd)/$(basename "$1"); }
__FILE__=`realpath "$0"`
__DIR__=`dirname "${__FILE__}"`

# download
function download() {
 "${__DIR__}/download.sh" "$1" "$2" #--no-cache
}

BASE_DIR="$1"
PJSIP_URL="https://github.com/pjsip/pjproject/archive/2.10.zip"
#http://www.pjsip.org/release/2.8.0/pjproject-2.8.0.tar.bz2
PJSIP_DIR="$1/src"
LIB_PATHS=("pjlib/lib" \
 "pjlib-util/lib" \
 "pjmedia/lib" \
 "pjnath/lib" \
 "pjsip/lib" \
 "third_party/lib")

OPENSSL_PREFIX=
FFMPEG_PREFIX=
OPENH264_PREFIX=
OPUS_PREFIX=
while [ "$#" -gt 0 ]; do
 case $1 in
 --with-openssl)
 if [ "$#" -gt 1 ]; then
 OPENSSL_PREFIX=$(python -c "import os,sys; print os.path.realpath(sys.argv[1])" "$2")
 shift 2
 continue
 else
 echo 'ERROR: Must specify a non-empty "--with-openssl PREFIX" argument.' >&2
 exit 1
 fi
 ;;
 --with-openh264)
 if [ "$#" -gt 1 ]; then
 OPENH264_PREFIX=$(python -c "import os,sys; print os.path.realpath(sys.argv[1])" "$2")
 shift 2
 continue
 else
 echo 'ERROR: Must specify a non-empty "--with-openh264 PREFIX" argument.' >&2
 exit 1
 fi
 ;;
 --with-ffmpeg)
 if [ "$#" -gt 1 ]; then
 FFMPEG_PREFIX=$(python -c "import os,sys; print os.path.realpath(sys.argv[1])" "$2")
 shift 2
 continue
 else
 echo 'ERROR: Must specify a non-empty "--with-ffmpeg PREFIX" argument.' >&2
 exit 1
 fi
 ;;
 --with-opus)
 if [ "$#" -gt 1 ]; then
 OPUS_PREFIX=$(python -c "import os,sys; print os.path.realpath(sys.argv[1])" "$2")
 shift 2
 continue
 else
 echo 'ERROR: Must specify a non-empty "--with-opus PREFIX" argument.' >&2
 exit 1
 fi
 ;;
 esac

 shift
done

function config_site() {
 SOURCE_DIR=$1
 PJSIP_CONFIG_PATH="${SOURCE_DIR}/pjlib/include/pj/config_site.h"
 HAS_VIDEO=

 echo "Creating config_site.h ..."

 if [ -f "${PJSIP_CONFIG_PATH}" ]; then
 rm "${PJSIP_CONFIG_PATH}"
 fi

 echo "#define PJ_CONFIG_IPHONE 1" >> "${PJSIP_CONFIG_PATH}"
 echo "#define PJ_HAS_IPV6 1" >> "${PJSIP_CONFIG_PATH}" # Enable IPV6
 if [[ ${OPENH264_PREFIX} ]]; then
 # echo "#define PJMEDIA_HAS_VID_TOOLBOX_CODEC 1" >> "${PJSIP_CONFIG_PATH}"
 # echo "#define PJMEDIA_HAS_OPENH264_CODEC 1" >> "${PJSIP_CONFIG_PATH}"
 echo "#define PJMEDIA_HAS_FFMPEG_VID_CODEC 1" >> "${PJSIP_CONFIG_PATH}"
 HAS_VIDEO=1
 fi
 if [[ ${HAS_VIDEO} ]]; then
 echo "#define PJMEDIA_HAS_VIDEO 1" >> "${PJSIP_CONFIG_PATH}"
 echo "#define PJMEDIA_VIDEO_DEV_HAS_OPENGL 1" >> "${PJSIP_CONFIG_PATH}"
 echo "#define PJMEDIA_VIDEO_DEV_HAS_OPENGL_ES 1" >> "${PJSIP_CONFIG_PATH}"
 echo "#define PJMEDIA_VIDEO_DEV_HAS_IOS_OPENGL 1" >> "${PJSIP_CONFIG_PATH}"
 echo "#include <opengles></opengles>ES3/glext.h>" >> "${PJSIP_CONFIG_PATH}"
 fi
 echo "#include <pj></pj>config_site_sample.h>" >> "${PJSIP_CONFIG_PATH}"
}

function clean_libs () {
 ARCH=${1}
 for SRC_DIR in ${LIB_PATHS[*]}; do
 DIR="${PJSIP_DIR}/${SRC_DIR}"
 if [ -d "${DIR}" ]; then
 rm -rf "${DIR}"/*
 fi

 DIR="${PJSIP_DIR}/${SRC_DIR}-${ARCH}"
 if [ -d "${DIR}" ]; then
 rm -rf "${DIR}"
 fi
 done
}

function copy_libs () {
 ARCH=${1}

 for SRC_DIR in ${LIB_PATHS[*]}; do
 SRC_DIR="${PJSIP_DIR}/${SRC_DIR}"
 DST_DIR="${SRC_DIR}-${ARCH}"
 if [ -d "${DST_DIR}" ]; then
 rm -rf "${DST_DIR}"
 fi
 cp -R "${SRC_DIR}" "${DST_DIR}"
 rm -rf "${SRC_DIR}"/* # delete files because this directory will be used for the final lipo output
 done
}

function _build() {
 pushd . > /dev/null
 cd ${PJSIP_DIR}

 ARCH=$1
 LOG=${BASE_DIR}/${ARCH}.log

 # configure
 CONFIGURE="./configure-iphone"
 if [[ ${OPENSSL_PREFIX} ]]; then
 CONFIGURE="${CONFIGURE} --with-ssl=${OPENSSL_PREFIX}"
 fi
 # if [[ ${OPENH264_PREFIX} ]]; then
 # CONFIGURE="${CONFIGURE} --with-openh264=${OPENH264_PREFIX}"
 # fi
 if [[ ${FFMPEG_PREFIX} ]]; then
 CONFIGURE="${CONFIGURE} --with-ffmpeg=${FFMPEG_PREFIX}"
 fi
 if [[ ${OPUS_PREFIX} ]]; then
 CONFIGURE="${CONFIGURE} --with-opus=${OPUS_PREFIX}"
 fi

 # flags
 if [[ ! ${CFLAGS} ]]; then
 export CFLAGS=
 fi
 if [[ ! ${LDFLAGS} ]]; then
 export LDFLAGS=
 fi
 if [[ ${OPENSSL_PREFIX} ]]; then
 export CFLAGS="${CFLAGS} -I${OPENSSL_PREFIX}/include"
 export LDFLAGS="${LDFLAGS} -L${OPENSSL_PREFIX}/lib"
 fi
 # if [[ ${OPENH264_PREFIX} ]]; then
 # export CFLAGS="${CFLAGS} -I${OPENH264_PREFIX}/include"
 # export LDFLAGS="${LDFLAGS} -L${OPENH264_PREFIX}/lib"
 # fi
 if [[ ${FFMPEG_PREFIX} ]]; then
 export CFLAGS="${CFLAGS} -I${FFMPEG_PREFIX}/include"
 export LDFLAGS="${LDFLAGS} -L${FFMPEG_PREFIX}/lib"
 fi
 export LDFLAGS="${LDFLAGS} -lstdc++"

 echo "Building for ${ARCH}..."

 clean_libs ${ARCH}

 make distclean > ${LOG} 2>&1
 ARCH="-arch ${ARCH}" ${CONFIGURE} >> ${LOG} 2>&1
 make dep >> ${LOG} 2>&1
 make clean >> ${LOG}
 make lib >> ${LOG} 2>&1

 copy_libs ${ARCH}
}

# function armv7() {
# export DEVPATH="`xcrun -sdk iphoneos --show-sdk-platform-path`/Developer"
# export CFLAGS="-miphoneos-version-min=8.0"
# export LDFLAGS=
# _build "armv7"
# }
# function armv7s() {
# export DEVPATH="`xcrun -sdk iphoneos --show-sdk-platform-path`/Developer"
# export CFLAGS="-miphoneos-version-min=8.0"
# export LDFLAGS=
# _build "armv7s"
# }
function arm64() {
 export DEVPATH="`xcrun -sdk iphoneos --show-sdk-platform-path`/Developer"
 export CFLAGS="-miphoneos-version-min=8.0"
 export LDFLAGS=
 _build "arm64"
}
function i386() {
 export DEVPATH="`xcrun -sdk iphonesimulator --show-sdk-platform-path`/Developer"
 export CFLAGS="-O2 -m32 -mios-simulator-version-min=8.0"
 export LDFLAGS="-O2 -m32 -mios-simulator-version-min=8.0"
 _build "i386"
}
function x86_64() {
 export DEVPATH="`xcrun -sdk iphonesimulator --show-sdk-platform-path`/Developer"
 export CFLAGS="-O2 -m32 -mios-simulator-version-min=8.0"
 export LDFLAGS="-O2 -m32 -mios-simulator-version-min=8.0"
 _build "x86_64"
}

function lipo() {
 TMP=`mktemp -t lipo`
 echo "Lipo libs... (${TMP})"

 for LIB_DIR in ${LIB_PATHS[*]}; do # loop over libs
 DST_DIR="${PJSIP_DIR}/${LIB_DIR}"

 # use the first architecture to find all libraries
 PATTERN_DIR="${DST_DIR}-$1"
 for PATTERN_FILE in `ls -l1 "${PATTERN_DIR}"`; do
 OPTIONS=""

 # loop over all architectures and collect the current library
 for ARCH in "$@"; do
 FILE="${DST_DIR}-${ARCH}/${PATTERN_FILE/-$1-/-${ARCH}-}"
 if [ -e "${FILE}" ]; then
 OPTIONS="$OPTIONS -arch ${ARCH} ${FILE}"
 fi
 done

 if [ "$OPTIONS" != "" ]; then
 OUTPUT_PREFIX=$(dirname "${DST_DIR}")
 OUTPUT="${OUTPUT_PREFIX}/lib/${PATTERN_FILE/-$1-/-}"

 OPTIONS="${OPTIONS} -create -output ${OUTPUT}"
 echo "$OPTIONS" >> "${TMP}"
 fi
 done
 done

 while read LINE; do
 xcrun -sdk iphoneos lipo ${LINE}
 done < "${TMP}"
}

# download "${PJSIP_URL}" "${PJSIP_DIR}"
config_site "${PJSIP_DIR}"
arm64 && i386 && x86_64
lipo arm64 i386 x86_64



Thanks for any advice.