Skip to content

Commit 5e85f57

Browse files
💎 Using h264 codec in video streams (elieserdejesus#1086, fix elieserdejesus#1043)
* Adding libx264 compilation details * Using raw h264 only, no more container data in video stream. The idea is use the container only when saving the video file in user machine. * Fixing and improving decoder to decode all frames * Improving resolution and bandwith * Updating ffmpeg compilation instructions
1 parent 835360e commit 5e85f57

File tree

17 files changed

+408
-422
lines changed

17 files changed

+408
-422
lines changed

Compiling ffmpeg.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@ Open a common prompt (not the power shell) and run the MSVC shell:
88

99
Compiling 64 bits
1010

11-
./configure --toolchain=msvc --enable-stripping --prefix="E:/ffmpeg-release-64bits" --enable-static --disable-shared --disable-everything --disable-programs --disable-doc --disable-avdevice --disable-postproc --disable-avfilter --disable-debug --enable-network --enable-decoder=flv,h264,mjpeg,mp3,mpeg4,ppm,vorbis,vp8,vp9 --enable-encoder=mpeg4,vorbis,flv,mjpeg --enable-parser=flac,h264,mjpeg,vorbis,vp8,vp9 --enable-demuxer=flv,mjpeg,mp3,h264,ogg,rtp,rtsp,avi --enable-muxer=mjpeg,rtp,rtsp,mp3,flv,ogg,webm,h264,avi --enable-protocol=httpproxy,rtmpt,https,rtmpts,rtp,tcp,file,pipe,rtmp,udp,rtmps,http --extra-cflags="-MD" --extra-cxxflags="-MD" --extra-ldflags="/NODEFAULTLIB:libcmt"
11+
Compiling libx264:
12+
13+
First install "nasm" and put the exe path in the system PATH
14+
15+
CC=cl ./configure --enable-static --prefix=. --extra-cflags="-DNO_PREFIX"
16+
17+
18+
Compiling FFmpeg
19+
20+
./configure --toolchain=msvc --enable-asm --enable-yasm --enable-stripping --prefix="E:/ffmpeg-release-64bits" --enable-static --disable-shared --disable-everything --disable-programs --disable-doc --disable-avdevice --disable-postproc --disable-avfilter --disable-debug --enable-network --enable-gpl --enable-libx264 --enable-decoder=h264,mp3,mpeg4 --enable-encoder=h264,mpeg4 --enable-parser=h264,mp4 --enable-demuxer=mp3,h264,rtp,rtsp,avi,mp4 --enable-muxer=rtp,rtsp,mp3,flv,h264,avi,mp4 --enable-protocol=httpproxy,rtmpt,https,rtmpts,rtp,tcp,file,rtmp,rtmps,http --enable-libx264 --enable-encoder=libx264 --enable-decoder=h264 --extra-cflags="-MD -DNO_PREFIX" --extra-cxxflags="-MD" --extra-ldflags="/NODEFAULTLIB:libcmt"
1221

1322
The generated libs (with .a extension) need be renamed to .lib
23+
1424
------------------------------------------------
1525

1626
Compilig 64 bits DEBUG version
@@ -21,11 +31,6 @@ use: --extra-cflags="-MDd"
2131

2232
Compiling 32 bits
2333

24-
./configure --toolchain=msvc --arch=i686 --enable-stripping --prefix="E:/ffmpeg-release-32bits" --enable-static --disable-shared --disable-everything --disable-programs --disable-doc --disable-avdevice --disable-postproc --disable-avfilter --disable-debug --enable-network --enable-decoder=flv,h264,mjpeg,mp3,mpeg4,ppm,vorbis,vp8,vp9 --enable-encoder=mpeg4,vorbis,flv,mjpeg --enable-parser=flac,h264,mjpeg,vorbis,vp8,vp9 --enable-demuxer=flv,mjpeg,mp3,h264,ogg,rtp,rtsp,avi--enable-muxer=mjpeg,rtp,rtsp,mp3,flv,ogg,webm,h264,avi --enable-protocol=httpproxy,rtmpt,https,rtmpts,rtp,tcp,file,pipe,rtmp,udp,rtmps,http --extra-cflags="-MD" --extra-cxxflags="-MD" --extra-ldflags="/NODEFAULTLIB:libcmt"
25-
26-
-------------------------------------------------
27-
28-
Compiling 32 bits DEBUG version
34+
add the --arch=i686 option
2935

30-
./configure --toolchain=msvc --arch=i686 --enable-stripping --prefix="E:/ffmpeg-release-32bits-debug" --enable-static --disable-shared --disable-everything --disable-programs --disable-doc --disable-avdevice --disable-postproc --disable-avfilter --disable-debug --enable-network --enable-decoder=flv,h264,mjpeg,mp3,mpeg4,ppm,vorbis,vp8,vp9 --enable-encoder=mpeg4,vorbis,flv,mjpeg --enable-parser=flac,h264,mjpeg,vorbis,vp8,vp9 --enable-demuxer=flv,mjpeg,mp3,h264,ogg,rtp,rtsp,avi--enable-muxer=mjpeg,rtp,rtsp,mp3,flv,ogg,webm,h264,avi --enable-protocol=httpproxy,rtmpt,https,rtmpts,rtp,tcp,file,pipe,rtmp,udp,rtmps,http --extra-cflags="-MDd" --extra-cxxflags="-MDd" --extra-ldflags="/NODEFAULTLIB:libcmt"
3136

PROJECTS/AUPlugin/JamTaba.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@
304304
2A1C7AAD1E0B5FBC00C7984D /* JamTaba_ViewFactory.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8BA4ADCF073EB19800A2709A /* JamTaba_ViewFactory.mm */; };
305305
2A1C7AAE1E0B5FBE00C7984D /* JamTaba_UIView.mm in Sources */ = {isa = PBXBuildFile; fileRef = 8BA4ADD1073EB19800A2709A /* JamTaba_UIView.mm */; };
306306
2A1C7AB41E0B66AC00C7984D /* JamTaba.h in Headers */ = {isa = PBXBuildFile; fileRef = 2A1C7AB21E0B66AC00C7984D /* JamTaba.h */; };
307+
2A2093B1207AB579001219DF /* libx264.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 2A2093B0207AB579001219DF /* libx264.a */; };
308+
2A2093B4207AB66A001219DF /* InstrumentsMenu.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2A2093B2207AB66A001219DF /* InstrumentsMenu.cpp */; };
309+
2A2093B5207AB66A001219DF /* InstrumentsMenu.h in Headers */ = {isa = PBXBuildFile; fileRef = 2A2093B3207AB66A001219DF /* InstrumentsMenu.h */; };
310+
2A2093B6207AB695001219DF /* InstrumentsMenu.h in Sources */ = {isa = PBXBuildFile; fileRef = 2A2093B3207AB66A001219DF /* InstrumentsMenu.h */; };
307311
2A2D725D1EABC04E00979920 /* Slider.h in Headers */ = {isa = PBXBuildFile; fileRef = 2A2D725B1EABC04E00979920 /* Slider.h */; };
308312
2A2D725E1EABC04E00979920 /* Slider.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2A2D725C1EABC04E00979920 /* Slider.cpp */; };
309313
2A2D725F1EABC06400979920 /* Slider.h in Sources */ = {isa = PBXBuildFile; fileRef = 2A2D725B1EABC04E00979920 /* Slider.h */; };
@@ -755,6 +759,9 @@
755759
2A14FF6E2007A6DA00ADAEB0 /* IconFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = IconFactory.cpp; sourceTree = "<group>"; };
756760
2A14FF6F2007A6DA00ADAEB0 /* IconFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IconFactory.h; sourceTree = "<group>"; };
757761
2A1C7AB21E0B66AC00C7984D /* JamTaba.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JamTaba.h; sourceTree = "<group>"; };
762+
2A2093B0207AB579001219DF /* libx264.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libx264.a; path = ../../libs/static/mac64/libx264.a; sourceTree = "<group>"; };
763+
2A2093B2207AB66A001219DF /* InstrumentsMenu.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InstrumentsMenu.cpp; sourceTree = "<group>"; };
764+
2A2093B3207AB66A001219DF /* InstrumentsMenu.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InstrumentsMenu.h; sourceTree = "<group>"; };
758765
2A2D725B1EABC04E00979920 /* Slider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Slider.h; sourceTree = "<group>"; };
759766
2A2D725C1EABC04E00979920 /* Slider.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Slider.cpp; sourceTree = "<group>"; };
760767
2A2F70051E08094500A4B6C2 /* libcups.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libcups.dylib; path = usr/lib/libcups.dylib; sourceTree = SDKROOT; };
@@ -962,6 +969,7 @@
962969
2A1C7AAA1E0B5F6600C7984D /* AudioToolbox.framework in Frameworks */,
963970
2A1362AF1F658D3E004953CF /* libqavfcamera.a in Frameworks */,
964971
2A13629E1F658714004953CF /* libavcodec.a in Frameworks */,
972+
2A2093B1207AB579001219DF /* libx264.a in Frameworks */,
965973
2A13629F1F658714004953CF /* libavformat.a in Frameworks */,
966974
2A1362A01F658714004953CF /* libavutil.a in Frameworks */,
967975
2A1362A11F658714004953CF /* libswresample.a in Frameworks */,
@@ -1020,6 +1028,7 @@
10201028
089C1671FE841209C02AAC07 /* External Frameworks and Libraries */ = {
10211029
isa = PBXGroup;
10221030
children = (
1031+
2A2093B0207AB579001219DF /* libx264.a */,
10231032
2AF5621A204719A700D809D7 /* libQt5WebSockets.a */,
10241033
2A1362B41F659642004953CF /* CoreVideo.framework */,
10251034
2A1362B21F6595D2004953CF /* AVFoundation.framework */,
@@ -1378,6 +1387,8 @@
13781387
2A0DBBE71E0AF46900BEF1FF /* widgets */ = {
13791388
isa = PBXGroup;
13801389
children = (
1390+
2A2093B2207AB66A001219DF /* InstrumentsMenu.cpp */,
1391+
2A2093B3207AB66A001219DF /* InstrumentsMenu.h */,
13811392
2A4E3FA71F99881700677E9C /* BoostSpinBox.cpp */,
13821393
2A4E3FA81F99881700677E9C /* BoostSpinBox.h */,
13831394
2A4E3FA31F9987E900677E9C /* ChatTabWidget.cpp */,
@@ -1893,6 +1904,7 @@
18931904
2A0DBE111E0AF46D00BEF1FF /* MidiDriver.h in Headers */,
18941905
2A0DBDF91E0AF46C00BEF1FF /* WavePeakPanel.h in Headers */,
18951906
2A0DBDFD1E0AF46C00BEF1FF /* Logging.h in Headers */,
1907+
2A2093B5207AB66A001219DF /* InstrumentsMenu.h in Headers */,
18961908
2AAAA7C22032462B0005C3F5 /* User.h in Headers */,
18971909
2A1362921F6586A4004953CF /* FFMpegDemuxer.h in Headers */,
18981910
2A67BDA91E410FE400A8FFF1 /* ScreensaverBlocker.h in Headers */,
@@ -2039,6 +2051,7 @@
20392051
2A3AE1E01E80863800D391C5 /* BlinkableButton.h in Sources */,
20402052
2A4E3FA11F99879800677E9C /* MetronomePanel.h in Sources */,
20412053
2A4E3FAF1F99885600677E9C /* InactivityDetector.h in Sources */,
2054+
2A2093B6207AB695001219DF /* InstrumentsMenu.h in Sources */,
20422055
2A4E3FB11F99889200677E9C /* BoostSpinBox.h in Sources */,
20432056
2A14FF722007A6FC00ADAEB0 /* EmojiWidget.h in Sources */,
20442057
2AAAA7A1203245AE0005C3F5 /* UPnPManager.h in Sources */,
@@ -2096,6 +2109,7 @@
20962109
2A120A771E0BF0F100E0E596 /* PeakMeter.h in Sources */,
20972110
2A120A781E0BF0F400E0E596 /* WavePeakPanel.h in Sources */,
20982111
2A120A6B1E0BEF8D00E0E596 /* UserNameDialog.h in Sources */,
2112+
2A2093B4207AB66A001219DF /* InstrumentsMenu.cpp in Sources */,
20992113
2A120A641E0BEF5C00E0E596 /* MainWindow.h in Sources */,
21002114
2A120A5E1E0BEF4800E0E596 /* Highligther.h in Sources */,
21012115
2A120A681E0BEF6400E0E596 /* NinjamTrackView.h in Sources */,

PROJECTS/Standalone/Standalone.pro

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ win32{
114114
LIBS_PATH = "static/win64-msvc"
115115
}
116116

117-
CONFIG(release, debug|release): LIBS += -L$$PWD/../../libs/$$LIBS_PATH -lportaudio -lminimp3 -lvorbisfile -lvorbis -logg -lavcodec -lavutil -lavformat -lswscale -lswresample -lstackwalker -lminiupnpc
118-
else:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../libs/$$LIBS_PATH/ -lportaudiod -lminimp3d -lvorbisfiled -lvorbisd -loggd -lavcodecd -lavutild -lavformatd -lswscaled -lswresampled -lstackwalkerd -lminiupnpcd
117+
CONFIG(release, debug|release): LIBS += -L$$PWD/../../libs/$$LIBS_PATH -lportaudio
118+
else:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../libs/$$LIBS_PATH/ -lportaudiod
119+
120+
LIBS += -L$$PWD/../../libs/$$LIBS_PATH -lminimp3 -lvorbisfile -lvorbis -logg -lx264 -lavcodec -lavutil -lavformat -lswscale -lswresample -lstackwalker -lminiupnpc
119121

120122
CONFIG(release, debug|release) {
121123
#ltcg - http://blogs.msdn.com/b/vcblog/archive/2009/02/24/quick-tips-on-using-whole-program-optimization.aspx
@@ -125,6 +127,7 @@ win32{
125127

126128
LIBS += -lwinmm -lole32 -lws2_32 -lAdvapi32 -lUser32 -lPsapi
127129
LIBS += -lIPHlpApi # used by miniupnp lib
130+
LIBS += -lSecur32 # used by libx264
128131

129132
#performance monitor lib
130133
QMAKE_CXXFLAGS += -DPSAPI_VERSION=1
@@ -138,7 +141,7 @@ macx{
138141
#message("Mac x86_64 build")
139142
LIBS_PATH = "static/mac64"
140143

141-
LIBS += -L$$PWD/../../libs/$$LIBS_PATH -lportaudio -lminimp3 -lvorbisfile -lvorbisenc -lvorbis -logg -lavcodec -lavutil -lavformat -lswscale -lswresample -liconv -lminiupnpc
144+
LIBS += -L$$PWD/../../libs/$$LIBS_PATH -lportaudio -lminimp3 -lvorbisfile -lvorbisenc -lvorbis -logg -lx264 -lavcodec -lavutil -lavformat -lswscale -lswresample -liconv -lminiupnpc
142145
LIBS += -framework IOKit
143146
LIBS += -framework CoreAudio
144147
LIBS += -framework CoreMidi
@@ -163,6 +166,6 @@ linux{
163166
DEFINES += __LINUX_ALSA__
164167

165168

166-
LIBS += -L$$PWD/../../libs/$$LIBS_PATH -lportaudio -lminimp3 -lvorbisfile -lvorbisenc -lvorbis -logg -lavformat -lavcodec -lswscale -lavutil -lswresample -lminiupnpc
169+
LIBS += -L$$PWD/../../libs/$$LIBS_PATH -lportaudio -lminimp3 -lvorbisfile -lvorbisenc -lvorbis -logg -lx264 -lavformat -lavcodec -lswscale -lavutil -lswresample -lminiupnpc
167170
LIBS += -lasound
168171
}

PROJECTS/VstPlugin/VstPlugin.pro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ win32 {
8585
CONFIG(debug, debug|release): LIBS += -L$(QTDIR)\plugins\mediaservice\ -ldsengined # necessary to use QCamera
8686
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
8787

88-
CONFIG(release, debug|release): LIBS += -L$$PWD/../../libs/$$LIBS_PATH -lminimp3 -lvorbisfile -lvorbis -logg -lavcodec -lavutil -lavformat -lswscale -lswresample -lstackwalker -lminiupnpc
89-
else:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../libs/$$LIBS_PATH/ -lminimp3d -lvorbisfiled -lvorbisd -loggd -lavcodecd -lavutild -lavformatd -lswscaled -lswresampled -lstackwalkerd -lminiupnpcd
88+
LIBS += -L$$PWD/../../libs/$$LIBS_PATH -lminimp3 -lvorbisfile -lvorbis -logg -lx264 -lavcodec -lavutil -lavformat -lswscale -lswresample -lstackwalker -lminiupnpc
9089

9190
LIBS += -lIPHlpApi # used by miniupnp lib
91+
LIBS += -lSecur32 # used by libx264
9292

9393
CONFIG(release, debug|release) {
9494
#ltcg - http://blogs.msdn.com/b/vcblog/archive/2009/02/24/quick-tips-on-using-whole-program-optimization.aspx

src/Common/MainController.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,8 +376,6 @@ void MainController::enqueueVideoDataToUpload(const QByteArray &encodedData, qui
376376
{
377377
if (isFirstPart) {
378378

379-
Q_ASSERT(encodedData.left(4) == "RIFF");
380-
381379
if (!videoIntervalToUpload.isEmpty()) {
382380

383381
// flush the end of previous interval
@@ -1110,6 +1108,8 @@ void MainController::stopNinjamController()
11101108
}
11111109

11121110
audioIntervalsToUpload.clear();
1111+
1112+
videoEncoder.finish(); // release memory used by video encoder
11131113
}
11141114

11151115
void MainController::setTranslationLanguage(const QString &languageCode)

src/Common/gui/MainWindow.cpp

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,13 @@ void MainWindow::initializeCamera(const QString &cameraDeviceName)
238238
QList<QSize> resolutions = camera->supportedViewfinderResolutions();
239239
if (!resolutions.isEmpty()) {
240240
QCameraViewfinderSettings settings;
241-
QSize lowResolution = resolutions.first();
242-
settings.setResolution(lowResolution);
241+
QSize bestResolution = getBestCameraResolution(resolutions);
242+
settings.setResolution(bestResolution);
243243
camera->setViewfinderSettings(settings);
244244

245245
//getBestSupportedFrameRate();
246246

247-
mainController->setVideoProperties(lowResolution);
247+
mainController->setVideoProperties(bestResolution);
248248
}
249249
else {
250250
qCritical() << "Camera resolutions list is empty!";
@@ -261,6 +261,31 @@ void MainWindow::initializeCamera(const QString &cameraDeviceName)
261261
}
262262
}
263263

264+
QSize MainWindow::getBestCameraResolution(const QList<QSize> resolutions) const
265+
{
266+
const static quint16 PREFERRED_WIDTH = 320;
267+
268+
auto bestResolution = QSize(PREFERRED_WIDTH, 240);
269+
270+
if (!resolutions.isEmpty()) {
271+
auto lowestResolution = resolutions.first();
272+
if (lowestResolution.width() > PREFERRED_WIDTH) { // using the lowest resolution in big resolution cams
273+
bestResolution = lowestResolution;
274+
}
275+
else { // pick the first resolution where width < 320
276+
for (int i = resolutions.size() - 1; i >= 0; --i) {
277+
if (resolutions.at(i).width() <= PREFERRED_WIDTH) {
278+
bestResolution = resolutions.at(i);
279+
break;
280+
}
281+
}
282+
//bestResolution = resolutions.first();
283+
}
284+
}
285+
286+
return bestResolution;
287+
}
288+
264289
void MainWindow::changeCameraStatus(bool activated)
265290
{
266291
if (camera) {

src/Common/gui/MainWindow.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ private slots:
415415
void initializeCameraWidget();
416416

417417
QCamera::FrameRateRange getBestSupportedFrameRate() const;
418+
QSize getBestCameraResolution(const QList<QSize> resolutions) const;
418419

419420
void updateUserNameLabel();
420421

src/Common/recorder/JamRecorder.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -207,16 +207,13 @@ void JamRecorder::appendLocalUserVideo(const QByteArray &encodedVideo, bool isFi
207207

208208
QByteArray encodedData(videoInterval.getEncodedData());
209209

210-
bool canSave = encodedData.left(4) == "RIFF";
211-
if (canSave) {
212-
QString videoFileName = buildVideoFileName(localUserName, videoInterval.getIntervalIndex(), "avi");
213-
QString videoFilePath = jamMetadataWritter->getVideoAbsolutePath(videoFileName);
210+
QString videoFileName = buildVideoFileName(localUserName, videoInterval.getIntervalIndex(), "mp4");
211+
QString videoFilePath = jamMetadataWritter->getVideoAbsolutePath(videoFileName);
214212

215-
if (!videoFilePath.isEmpty()) // some recorders (like ClipSort) can't save videos
216-
QtConcurrent::run(this, &JamRecorder::writeEncodedFile, encodedData, videoFilePath);
213+
if (!videoFilePath.isEmpty()) // some recorders (like ClipSort) can't save videos
214+
QtConcurrent::run(this, &JamRecorder::writeEncodedFile, encodedData, videoFilePath);
217215

218-
videoInterval.clear();
219-
}
216+
videoInterval.clear();
220217
}
221218

222219
videoInterval.appendEncodedData(encodedVideo);

0 commit comments

Comments
 (0)