Workaround for older systems

This commit is contained in:
ArsenArsen 2017-06-29 19:50:06 +02:00
parent e2cbdcb57c
commit 4ba500e378
3 changed files with 102 additions and 4 deletions

View File

@ -137,7 +137,8 @@ FORMS += mainwindow.ui \
DISTFILES += \
README.md \
LICENSE
LICENSE \
OlderSystemFix.patch
RESOURCES += \
icon.qrc

94
OlderSystemFix.patch Normal file
View File

@ -0,0 +1,94 @@
diff --git a/recording/encoders/encoder.cpp b/recording/encoders/encoder.cpp
index 481ba40..c04d32b 100644
--- a/recording/encoders/encoder.cpp
+++ b/recording/encoders/encoder.cpp
@@ -64,8 +64,8 @@ Encoder::Encoder(QString &targetFile, QSize res, CodecSettings *settings) {
if (ret < 0) throwAVErr(ret, "codec open");
if (codec->capabilities & AV_CODEC_CAP_DR1) avcodec_align_dimensions(out->enc, &out->enc->width, &out->enc->height);
- ret = avcodec_parameters_from_context(out->st->codecpar, out->enc);
- if (ret < 0) throwAVErr(ret, "stream opt copy");
+ // ret = avcodec_parameters_from_context(out->st->codecpar, out->enc);
+ // if (ret < 0) throwAVErr(ret, "stream opt copy");
// Frames
out->frame = av_frame_alloc();
@@ -111,25 +111,28 @@ bool Encoder::addFrame(QImage frm) {
pkt.size = 0;
pkt.data = NULL;
av_init_packet(&pkt);
- int ret = avcodec_send_frame(out->enc, out->frame);
- if (ret == AVERROR(EAGAIN)) {
- do {
- ret = avcodec_receive_packet(out->enc, &pkt);
- if (ret < 0) {
- if (ret != AVERROR(EAGAIN))
- throwAVErr(ret, "receive packet");
- else
- break;
- }
- av_packet_rescale_ts(&pkt, out->enc->time_base, out->st->time_base);
- pkt.stream_index = out->st->index;
- ret = av_interleaved_write_frame(fc, &pkt);
- } while (ret >= 0);
- if (ret < 0 && ret != AVERROR(EAGAIN)) {
- av_packet_unref(&pkt);
- throwAVErr(ret, "send frame");
- }
- }
+ int gotPack;
+ int ret = avcodec_encode_video2(out->enc, &pkt, NULL, &gotPack);
+ if (gotPack) av_interleaved_write_frame(fc, &pkt);
+ // int ret = avcodec_send_frame(out->enc, out->frame);
+ // if (ret == AVERROR(EAGAIN)) {
+ // do {
+ // ret = avcodec_receive_packet(out->enc, &pkt);
+ // if (ret < 0) {
+ // if (ret != AVERROR(EAGAIN))
+ // throwAVErr(ret, "receive packet");
+ // else
+ // break;
+ // }
+ // av_packet_rescale_ts(&pkt, out->enc->time_base, out->st->time_base);
+ // pkt.stream_index = out->st->index;
+ // ret = av_interleaved_write_frame(fc, &pkt);
+ // } while (ret >= 0);
+ // if (ret < 0 && ret != AVERROR(EAGAIN)) {
+ // av_packet_unref(&pkt);
+ // throwAVErr(ret, "send frame");
+ // }
+ // }
av_packet_unref(&pkt);
if (ret < 0 && ret != AVERROR(EAGAIN)) throwAVErr(ret, "send frame");
return true;
@@ -145,19 +148,21 @@ bool Encoder::end() {
if (!success) {
goto cleanup;
}
- avcodec_send_frame(out->enc, NULL);
- int ret;
+ // avcodec_send_frame(out->enc, NULL);
AVPacket pkt;
pkt.size = 0;
pkt.data = NULL;
av_init_packet(&pkt);
- do {
- ret = avcodec_receive_packet(out->enc, &pkt);
- if (ret < 0) break;
- av_packet_rescale_ts(&pkt, out->enc->time_base, out->st->time_base);
- pkt.stream_index = out->st->index;
- av_interleaved_write_frame(fc, &pkt);
- } while (ret >= 0);
+ int gotPack;
+ avcodec_encode_video2(out->enc, &pkt, NULL, &gotPack);
+ if (gotPack) av_interleaved_write_frame(fc, &pkt);
+ // do {
+ // ret = avcodec_receive_packet(out->enc, &pkt);
+ // if (ret < 0) break;
+ // av_packet_rescale_ts(&pkt, out->enc->time_base, out->st->time_base);
+ // pkt.stream_index = out->st->index;
+ // av_interleaved_write_frame(fc, &pkt);
+ // } while (ret >= 0);
av_write_trailer(fc);
cleanup:
avcodec_free_context(&out->enc);

View File

@ -5,7 +5,7 @@ A [ShareX](https://getsharex.com/) inspired cross platform utility written with
|:---:|:-----:|:--:|
|[![Build Status](https://nativeci.arsenarsen.com/job/KShare/badge/icon)](https://nativeci.arsenarsen.com/job/KShare)| [![Build Status](https://nativeci.arsenarsen.com/job/KShare%20Windows%20x86_64/badge/icon)](https://nativeci.arsenarsen.com/job/KShare%20Windows%20x86_64/)| Soon |
## Screenshot
Made with KShare itself, of course :)
Made with KShare itself, of course :)
![](http://i.imgur.com/ffWvCun.png)
## Usage
@ -15,7 +15,7 @@ See the [wiki](https://github.com/ArsenArsen/KShare/wiki).
* Qt 5 Widgets
* Qt 5 GUI
* Qt 5 Network
* Qt 5 X11Extras | Winextras
* Qt 5 X11Extras | Winextras
* [QHotkey](https://github.com/Skycoder42/QHotkey)
* libavformat
* libavcodec
@ -35,7 +35,7 @@ See the [projects](https://github.com/ArsenArsen/KShare/projects)
|Arch Linux |[kshare](https://aur.archlinux.org/packages/kshare-git/)|
|Ubuntu |[Ubuntu .deb](https://nativeci.arsenarsen.com/job/KShare%20Stable/lastSuccessfulBuild/artifact/packages/simpleName.deb )|
I do plan to make a Debian ~~and Ubuntu (see below)~~ packages.
I do plan to make a Debian packages.
For other UNIX-like platforms, and MSYS2 (for Windows):
@ -47,4 +47,7 @@ qmake // Might be qmake-qt5 on your system
make
```
On systems with FFMpeg pre-3.1 you need to apply `OlderSystemFix.patch` to `recording/encoders/encoder.cpp`.
On systems with Qt pre-5.7 you need to install the Qt version from their website.
###### Started on 19th of April 2017 to bring some attention and improvement to Linux screenshotting.