Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
in-league-with-satan committed Oct 27, 2020
2 parents c960997 + 410eaf5 commit ce84a9b
Show file tree
Hide file tree
Showing 36 changed files with 724 additions and 190 deletions.
12 changes: 12 additions & 0 deletions builder/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

ROOT_DIR=$(dirname $(readlink -f $0))

cd "$ROOT_DIR/linux"

bash build.sh


cd "$ROOT_DIR/win"

bash build.sh staticff
2 changes: 1 addition & 1 deletion builder/linux/build_docker_image.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

docker rmi capturer-builder-linux -f
docker build --no-cache -t capturer-builder-linux .
docker build -t capturer-builder-linux .
19 changes: 12 additions & 7 deletions builder/linux/worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ cd /temp


cd externals/3rdparty
bash http_server_update.sh
bash http_server_update.sh || { echo 'http_server_update err'; exit 1; }


cd ffmpeg
bash build.sh
bash build_linux.sh || { echo 'ffmpeg build err'; exit 1; }


cd tmp/ffmpeg
cd linux/tmp/ffmpeg
ffmpeg_version=`git log -1 --format=%cd-%h --date=format:'%Y%m%d'`


Expand All @@ -28,13 +27,20 @@ app_version=$app_last_tag.`git rev-list $app_last_tag.. --count`-`git log -1 --p
qt_version=`qmake --version | awk '{if ($1=="Using") print $4;}'`


qmake "DESTDIR=../$dest_dir" capturer.pro
qmake "DESTDIR=../$dest_dir" capturer.pro || exit 1
make clean
make -j`nproc`
make -j`nproc` || exit 1


cd /temp


echo -e '#!/bin/bash\n\n./capturer --setup\n\c' > $dest_dir/capturer.setup.sh
echo -e '#!/bin/bash\n\n./capturer --portable-mode\n\c' > $dest_dir/capturer.portable.sh
echo -e '#!/bin/bash\n\n./capturer --portable-mode --setup\n\c' > $dest_dir/capturer.portable.setup.sh
echo -e '#!/bin/bash\n\n./capturer --portable-mode --headless\n\c' > $dest_dir/capturer.portable.headless.sh
echo -e '#!/bin/bash\n\n./capturer --portable-mode --headless-curse\n\c' > $dest_dir/capturer.portable.headless-curse.sh

cp license $dest_dir/license


Expand All @@ -47,4 +53,3 @@ if [ -e $arcfilename.7z ]; then
fi

7z a -mx9 $arcfilename.7z *

17 changes: 10 additions & 7 deletions builder/win/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@ ENV TZ=Europe/Moscow
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

RUN apt-get update && apt-get upgrade -y \
&& apt-get install -y libtool build-essential cmake mc curl \
&& apt-get install -y libtool libtool-bin build-essential cmake mc curl \
autoconf automake autopoint bash bison bzip2 flex g++ g++-multilib gettext git gperf \
intltool libc6-dev-i386 libgdk-pixbuf2.0-dev libltdl-dev libssl-dev libtool-bin \
libxml-parser-perl lzip make openssl p7zip-full patch perl pkg-config python \
intltool libc6-dev-i386 libgdk-pixbuf2.0-dev libltdl-dev libssl-dev \
libxml-parser-perl lzip make openssl p7zip-full patch perl pkg-config python python-mako \
ruby sed unzip wget xz-utils \
&& git clone --depth 1 https://github.com/mxe/mxe.git && cd mxe && make -j`nproc` MXE_TARGETS='x86_64-w64-mingw32.static.posix' MXE_PLUGIN_DIRS='plugins/gcc10' qtbase qtmultimedia qtquickcontrols2 qtwinextras \
&& apt-get purge -y --allow-remove-essential libtool cmake pkg-config autoconf automake autopoint bison bzip2 flex g++ g++-multilib gettext gperf intltool libc6-dev-i386 libgdk-pixbuf2.0-dev \
libltdl-dev libssl-dev libtool-bin libxml-parser-perl lzip patch pkg-config ruby sed unzip wget xz-utils \
&& git clone --depth 1 https://github.com/mxe/mxe.git && cd mxe && make -j`nproc` MXE_TARGETS='x86_64-w64-mingw32.static.posix' MXE_PLUGIN_DIRS='plugins/gcc10' qtbase qtmultimedia qtquickcontrols2 qtwinextras dlfcn-win32 \
&& apt-get purge -y --allow-remove-essential autopoint bison bzip2 flex g++ g++-multilib gettext gperf intltool libc6-dev-i386 libgdk-pixbuf2.0-dev \
libltdl-dev libssl-dev libtool-bin libxml-parser-perl lzip patch ruby unzip wget xz-utils \
&& apt-get autoremove -y && apt-get autoclean -y \
&& rm -rfd /mxe/log /mxe/pkg /mxe/src /mxe/usr/x86_64-pc-linux-gnu /mxe/usr/x86_64-w64-mingw32.static.posix/bin \
&& rm -rfd /mxe/.ccache /mxe/.git /mxe/log /mxe/pkg /mxe/src /mxe/usr/x86_64-w64-mingw32.static.posix/bin \
/mxe/usr/x86_64-pc-linux-gnu/doc /mxe/usr/x86_64-pc-linux-gnu/icu4c /mxe/usr/x86_64-pc-linux-gnu/include /mxe/usr/x86_64-pc-linux-gnu/lib /mxe/usr/x86_64-pc-linux-gnu/share \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

RUN ln -s /mxe/usr/x86_64-w64-mingw32.static.posix/qt5/bin/qmake /mxe/usr/bin/qmake && \
ln -s /mxe/usr/bin/x86_64-w64-mingw32.static.posix-g++ /mxe/usr/bin/g++

RUN chmod -R a+w /mxe

ENV PATH /mxe/usr/bin:$PATH
CMD ["/bin/sh"]
4 changes: 3 additions & 1 deletion builder/win/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ PATH_HOST=$(pwd)
USER_ID=$(id -u)
GROUP_ID=$(id -g)

docker run --rm -v $PATH_HOST:/temp:z --user=$USER_ID:$GROUP_ID -i -t capturer-builder-windows /bin/bash -c "cd /temp/builder/win; bash worker.sh"
#

docker run --rm -v $PATH_HOST:/temp:z --user=$USER_ID:$GROUP_ID -i -t capturer-builder-windows /bin/bash -c "cd /temp/builder/win; bash worker.sh $1"
2 changes: 1 addition & 1 deletion builder/win/build_docker_image.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

docker rmi capturer-builder-windows -f
docker build --no-cache -t capturer-builder-windows .
docker build -t capturer-builder-windows .
64 changes: 33 additions & 31 deletions builder/win/worker.sh
Original file line number Diff line number Diff line change
@@ -1,73 +1,75 @@
#!/bin/bash


dest_dir=bin_win

ffmpeg_date=`curl -vs "https://ffmpeg.zeranoe.com/builds/win64/shared/" 2>&1 | grep -E 'ffmpeg-[0-9]{8}' | grep -oE '[0-9]{8}' | sort -r | head -1`
ffmpeg_version=`curl -vs "https://ffmpeg.zeranoe.com/builds/win64/shared/" 2>&1 | grep $ffmpeg_date | grep -Po '(?<=(ffmpeg-)).*(?=-win64-shared.zip)' | cut -c -16`
#

staticff=0

app_last_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
app_version=$app_last_tag.`git rev-list $app_last_tag.. --count`-`git log -1 --pretty=format:%h`
if [[ "$1" == "staticff" ]] ; then
staticff=1
fi


qt_version=`qmake --version | awk '{if ($1=="Using") print $4;}'`
cd /temp


cd /temp
cd externals/3rdparty
bash http_server_update.sh || { echo 'http_server_update err'; exit 1; }
bash curses_update.sh || { echo 'curses_update err'; exit 1; }

cd ffmpeg
bash build_win.sh $1 || { echo 'ffmpeg build err'; exit 1; }

mv externals/3rdparty/ffmpeg externals/3rdparty/ffmpeg_orig
mkdir externals/3rdparty/ffmpeg
cp externals/3rdparty/ffmpeg_orig/ffmpeg.pri externals/3rdparty/ffmpeg/ffmpeg.pri

curl -s "https://ffmpeg.zeranoe.com/builds/win64/shared/ffmpeg-$ffmpeg_version-win64-shared.zip" --output ffmpeg_bin.zip
curl -s "https://ffmpeg.zeranoe.com/builds/win64/dev/ffmpeg-$ffmpeg_version-win64-dev.zip" --output ffmpeg_dev.zip
cd win/tmp/ffmpeg
ffmpeg_version=`git log -1 --format=%cd-%h --date=format:'%Y%m%d'`


7z x ffmpeg_bin.zip
7z x ffmpeg_dev.zip
rm -rfd /temp/$dest_dir


mv -f ffmpeg-$ffmpeg_version-win64-dev/* externals/3rdparty/ffmpeg
cd /temp/capturer

app_last_tag=$(git describe --tags `git rev-list --tags --max-count=1`)
app_version=$app_last_tag.`git rev-list $app_last_tag.. --count`-`git log -1 --pretty=format:%h`

cd externals/3rdparty
bash http_server_update.sh
bash curses_update.sh
qt_version=`qmake --version | awk '{if ($1=="Using") print $4;}'`

rm -rfd /temp/$dest_dir

cd /temp/capturer
if [ $staticff -eq 1 ]; then
qmake "DEFINES+=STATIC_WIN_FF" "DESTDIR=../$dest_dir" capturer.pro || exit 1

else
qmake "DESTDIR=../$dest_dir" capturer.pro || exit 1
fi

qmake "DESTDIR=../$dest_dir" capturer.pro
make clean
make -j`nproc`
make -j`nproc` || exit 1


cd /temp


rm -rfd externals/3rdparty/ffmpeg
mv externals/3rdparty/ffmpeg_orig externals/3rdparty/ffmpeg
mv -f ffmpeg-$ffmpeg_version-win64-shared/bin/*.dll $dest_dir
rm ffmpeg_bin.zip
rm ffmpeg_dev.zip
rm -rfd ffmpeg-$ffmpeg_version-win64-shared
rm -rfd ffmpeg-$ffmpeg_version-win64-dev
if [ $staticff -eq 0 ]; then
cp -f externals/3rdparty/ffmpeg/win/bin/*.dll $dest_dir
fi

echo -e 'start capturer --setup\r\n\c' > $dest_dir/capturer.setup.cmd
echo -e 'start capturer --portable-mode\r\n\c' > $dest_dir/capturer.portable.cmd
echo -e 'start capturer --portable-mode --setup\r\n\c' > $dest_dir/capturer.portable.setup.cmd
echo -e 'start capturer --portable-mode --headless\r\n\c' > $dest_dir/capturer.portable.headless.cmd
echo -e 'start capturer --portable-mode --headless-curse\r\n\c' > $dest_dir/capturer.portable.headless-curse.cmd

cp license $dest_dir/license


cd $dest_dir


arcfilename="../builder/capturer-$app_version""_x86_64-win_qt-""$qt_version""_ffmpeg-$ffmpeg_version"

if [ -e $arcfilename.7z ]; then
arcfilename=$arcfilename.`date +%Y-%m-%d_%H-%M-%S`
fi

7z a -mx9 $arcfilename.7z *

38 changes: 26 additions & 12 deletions capturer/src/ffmpeg/ff_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ struct OutputStream
AVPacket *pkt=nullptr;

uint64_t size_total=0;

uint64_t avg_send_frame_time=0;
uint8_t send_frame_time_warning=0;
};

struct FFMpegContext
Expand Down Expand Up @@ -632,6 +635,8 @@ static QString add_stream_video(OutputStream *output_stream, AVFormatContext *fo
av_opt_set(output_stream->av_codec_context->priv_data, "preset", cfg.preset.toLatin1().constData(), 0);
}

output_stream->av_codec_context->thread_count=4;

} else if(cfg.video_encoder==FFEncoder::VideoEncoder::qsv_h264) {
if(cfg.video_bitrate==0) {
output_stream->av_codec_context->flags|=AV_CODEC_FLAG_QSCALE;
Expand Down Expand Up @@ -891,6 +896,9 @@ QString FFEncoder::write_video_frame(AVFormatContext *format_context, OutputStre
int ret;
QString err_string;

QElapsedTimer timer;
timer.restart();

if(output_stream->frame_hw) {
output_stream->frame_hw->pts=pts;

Expand All @@ -909,6 +917,16 @@ QString FFEncoder::write_video_frame(AVFormatContext *format_context, OutputStre
return QString("error encoding video frame: %1").arg(ffErrorString(ret));
}


output_stream->avg_send_frame_time=(output_stream->avg_send_frame_time + timer.nsecsElapsed())*.5;


if(++output_stream->send_frame_time_warning==0 && output_stream->avg_send_frame_time>10000000) {
qCritical() << "avcodec_send_frame time overload" << output_stream->avg_send_frame_time*.0000001;
// return "avcodec_send_frame time overload";
}


while(ret>=0) {
ret=avcodec_receive_packet(output_stream->av_codec_context, output_stream->pkt);

Expand Down Expand Up @@ -969,18 +987,7 @@ FFEncoder::FFEncoder(int enc_num, FFEncStartSync *start_sync, QObject *parent) :
{
context=new FFMpegContext();

int thread_count=QThread::idealThreadCount()/2;
// thread_count=QThread::idealThreadCount();

if(thread_count<1)
thread_count=2;

if(thread_count>4)
thread_count=4;

format_converter_ff=new FFFormatConverterMt(thread_count);
// format_converter_ff->useMultithreading(false);
format_converter_ff->useMultithreading(true);
format_converter_ff=new FFFormatConverterMt(this);

context->base_filename=nullptr;
context->enc_num=enc_num;
Expand Down Expand Up @@ -1600,6 +1607,8 @@ bool FFEncoder::setConfig(FFEncoder::Config cfg)
cfg.nvenc.aq_mode=0;
}

format_converter_ff->useMultithreading(cfg.format_converter_thread_size);

if(!cfg.direct_stream_copy && cfg.input_type_flags&SourceInterface::TypeFlag::video && !format_converter_ff->setup(
PixelFormat::normalizeFormat(cfg.pixel_format_src).toAVPixelFormat(), cfg.frame_resolution_src, cfg.pixel_format_dst.toAVPixelFormat(), cfg.frame_resolution_dst,
cfg.sws_color_space_src, cfg.sws_color_space_dst, cfg.sws_color_range_src, cfg.sws_color_range_dst,
Expand Down Expand Up @@ -1746,6 +1755,9 @@ bool FFEncoder::setConfig(FFEncoder::Config cfg)

context->out_stream_video.pts_stats=0;

context->out_stream_video.avg_send_frame_time=0;
context->out_stream_video.send_frame_time_warning=0xff;

context->out_stream_audio.pts_next=0;
context->out_stream_audio.size_total=0;

Expand Down Expand Up @@ -2082,6 +2094,8 @@ bool FFEncoder::stopCoder()
context->av_format_context=nullptr;
}

format_converter_ff->stop();

emit stateChanged(false);

return true;
Expand Down
2 changes: 2 additions & 0 deletions capturer/src/ffmpeg/ff_encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ class FFEncoder : public QObject

int aspect_ratio_4_3=0;

int format_converter_thread_size=0;

struct NVEnc {
int enabled=false;
int device=0;
Expand Down
9 changes: 6 additions & 3 deletions capturer/src/ffmpeg/ff_encoder_thread.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
Copyright © 2018-2019 Andrey Cheprasov <ae.cheprasov@gmail.com>
Copyright © 2018-2020 Andrey Cheprasov <ae.cheprasov@gmail.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
Expand All @@ -21,6 +21,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <qcoreapplication.h>

#include "decklink_thread.h"
#include "debug_helpers.h"

#include "ff_encoder_thread.h"

Expand All @@ -41,8 +42,8 @@ FFEncoderThread::FFEncoderThread(int enc_num, FFEncoderBaseFilename *base_filena
is_working=false;

// start(QThread::LowestPriority);
// start(QThread::NormalPriority);
start(QThread::HighPriority);
start(QThread::NormalPriority);
// start(QThread::HighPriority);
// start(QThread::HighestPriority);
// start(QThread::TimeCriticalPriority);
}
Expand Down Expand Up @@ -98,6 +99,8 @@ void FFEncoderThread::onStateChanged(bool state)

void FFEncoderThread::run()
{
printProcessId("FFEncoderThread");

FFEncoder *ffmpeg=new FFEncoder(enc_num, start_sync);

ffmpeg->moveToThread(this);
Expand Down
Loading

0 comments on commit ce84a9b

Please sign in to comment.