Skip to content

Commit f7a4368

Browse files
committed
Merge remote-tracking branch 'upstream/master' into upstream-merge-feb-2024
2 parents 5bd92ea + 55b0bcd commit f7a4368

File tree

8 files changed

+173
-23
lines changed

8 files changed

+173
-23
lines changed

.github/workflows/build.yaml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Build
2+
on: [push, pull_request]
3+
4+
jobs:
5+
build:
6+
runs-on: ${{ matrix.os }}
7+
strategy:
8+
fail-fast: false
9+
matrix:
10+
include:
11+
- os: ubuntu-latest
12+
platform: linux
13+
- os: macos-latest
14+
platform: macos
15+
ffmpeg_version: ffmpeg5
16+
- os: macos-latest
17+
platform: macos
18+
ffmpeg_version: ffmpeg6
19+
- os: macos-latest
20+
platform: macos
21+
ffmpeg_version: ffmpeg7
22+
- os: windows-latest
23+
platform: windows-mingw
24+
steps:
25+
- name: Checkout
26+
uses: actions/checkout@v4
27+
28+
- name: Setup
29+
shell: bash
30+
run: |
31+
setupScript='ci/${{ matrix.platform }}/setup.sh'
32+
[ ! -f "$setupScript" ] || "$setupScript"
33+
34+
- name: Configure Apt packages
35+
if: ${{ matrix.platform == 'linux' }}
36+
run: |
37+
sudo apt-get install -y autoconf libtool git build-essential libargtable2-dev libavformat-dev libswscale-dev libsdl1.2-dev
38+
39+
- name: Configure Brew packages ffmpeg7
40+
if: ${{ matrix.ffmpeg_version == 'ffmpeg7' }}
41+
run: |
42+
brew install autoconf automake libtool pkgconf argtable ffmpeg sdl12-compat
43+
44+
- name: Configure Brew packages ffmpeg6
45+
if: ${{ matrix.ffmpeg_version == 'ffmpeg6' }}
46+
run: |
47+
brew install autoconf automake libtool pkgconf argtable ffmpeg@6 sdl12-compat
48+
brew link ffmpeg@6
49+
50+
- name: Configure Brew packages ffmpeg5
51+
if: ${{ matrix.ffmpeg_version == 'ffmpeg5' }}
52+
run: |
53+
brew install autoconf automake libtool pkgconf argtable ffmpeg@5 sdl12-compat
54+
brew link ffmpeg@5
55+
56+
- name: Setup msys2
57+
uses: msys2/setup-msys2@v2
58+
if: ${{ matrix.platform == 'windows-mingw' }}
59+
with:
60+
update: true
61+
install: >-
62+
mingw-w64-x86_64-gcc
63+
mingw-w64-x86_64-make
64+
mingw-w64-x86_64-autotools
65+
mingw-w64-x86_64-libtool
66+
mingw-w64-x86_64-pkg-config
67+
mingw-w64-x86_64-yasm
68+
mingw-w64-x86_64-argtable
69+
mingw-w64-x86_64-ffmpeg
70+
- name: Put MSYS2_MinGW64 on PATH
71+
if: ${{ matrix.platform == 'windows-mingw' }}
72+
run: |
73+
echo "${{ runner.temp }}/msys64/mingw64/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
74+
75+
- name: Configure and build Posix
76+
if: ${{ matrix.platform != 'windows-mingw' }}
77+
run: |
78+
./autogen.sh
79+
./configure
80+
make
81+
82+
- name: Configure and build Windows
83+
if: ${{ matrix.platform == 'windows-mingw' }}
84+
run: |
85+
msys2 -c './autogen.sh'
86+
msys2 -c './configure'
87+
msys2 -c 'make'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ autom4te.cache
2121
compile
2222
config.*
2323
configure
24+
configure~
2425
depcomp
2526
install-sh
2627
missing

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ First install Xcode (freely available from the Mac OS X App Store). After it's i
6767
The easiest way to install Comskip's dependencies is via Homebrew (http://brew.sh/):
6868

6969
```
70-
$ brew install autoconf automake libtool pkgconfig argtable ffmpeg sdl
70+
$ brew install autoconf automake libtool pkgconf argtable ffmpeg sdl12-compat
7171
```
7272

7373
[Macports](https://www.macports.org/install.php) natively compiles all libraries from source. The project [etv-comskip](https://github.com/essandess/etv-comskip) has an example [Makefile](https://github.com/essandess/etv-comskip/blob/master/Makefile) using Macports tools.

appveyor.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,20 @@ artifacts:
1212
before_build:
1313
- git log -1
1414
- cd C:\projects\comskip
15-
- appveyor DownloadFile https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.4.1-full_build-shared.7z
15+
- appveyor DownloadFile https://github.com/GyanD/codexffmpeg/releases/download/5.0.1/ffmpeg-5.0.1-full_build-shared.7z
1616
- appveyor DownloadFile https://downloads.sourceforge.net/project/argtable/argtable/argtable-2.13/argtable2-13.tar.gz
1717

1818
build_script:
19-
- 7z x ffmpeg-4.4.1-full_build-shared.7z
19+
- 7z x ffmpeg-5.0.1-full_build-shared.7z
2020
- C:\msys64\usr\bin\bash -lc "cd /c/projects/comskip && tar xf argtable2-13.tar.gz && cd argtable2-13 && ./configure --build=x86_64-w64-mingw32 && make"
21-
- C:\msys64\usr\bin\bash -lc "cd /c/projects/comskip && ./autogen.sh && argtable2_CFLAGS='-Iargtable2-13/src' argtable2_LIBS='-Largtable2-13/src/.libs -largtable2' ffmpeg_CFLAGS='-Iffmpeg-4.4.1-full_build-shared/include' ffmpeg_LIBS='-Lffmpeg-4.4.1-full_build-shared/lib -lavutil -lavformat -lavcodec -lswscale' ./configure && make"
21+
- C:\msys64\usr\bin\bash -lc "cd /c/projects/comskip && ./autogen.sh && argtable2_CFLAGS='-Iargtable2-13/src' argtable2_LIBS='-Largtable2-13/src/.libs -largtable2' ffmpeg_CFLAGS='-Iffmpeg-5.0.1-full_build-shared/include' ffmpeg_LIBS='-Lffmpeg-5.0.1-full_build-shared/lib -lavutil -lavformat -lavcodec -lswscale' ./configure && make"
2222

2323
before_test:
24-
- C:\msys64\usr\bin\bash -lc "cd /c/projects/comskip && export PATH=$(pwd)/ffmpeg-4.4.1-full_build-shared/bin/:$PATH && ls -alh comskip.exe && ldd comskip.exe"
24+
- C:\msys64\usr\bin\bash -lc "cd /c/projects/comskip && export PATH=$(pwd)/ffmpeg-5.0.1-full_build-shared/bin/:$PATH && ls -alh comskip.exe && ldd comskip.exe"
2525
- appveyor DownloadFile https://s3.amazonaws.com/tmm1/ten-copy.mkv
2626

2727
test_script:
28-
- SET PATH=C:\projects\comskip\ffmpeg-4.4.1-full_build-shared\bin;%PATH%
28+
- SET PATH=C:\projects\comskip\ffmpeg-5.0.1-full_build-shared\bin;%PATH%
2929
- comskip ten-copy.mkv
3030
- cat ten-copy.txt
3131
- grep "9361\s17922" ten-copy.txt

comskip.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "platform.h"
1717
#include "vo.h"
1818
#include <argtable2.h>
19+
#include <pthread.h>
1920

2021

2122
#include <libavformat/avformat.h>
@@ -476,6 +477,7 @@ int hardware_decode = 0;
476477
int use_cuvid = 0;
477478
int use_vdpau = 0;
478479
int use_dxva2 = 0;
480+
int use_qsv = 0;
479481
int skip_B_frames = 0;
480482
int lowres = 0;
481483
bool live_tv = false;
@@ -741,9 +743,9 @@ int sceneChangePercent;
741743
bool lastFrameWasBlack = false;
742744
bool lastFrameWasSceneChange = false;
743745

744-
#include <libavutil/avutil.h> // only for DECLARE_ALIGNED
745-
static DECLARE_ALIGNED(32, long, histogram)[256];
746-
static DECLARE_ALIGNED(32, long, lastHistogram)[256];
746+
747+
static long histogram[256];
748+
static long lastHistogram[256];
747749

748750
#define MAXCSLENGTH 400*300
749751
#define MAXCUTSCENES 8
@@ -3328,7 +3330,7 @@ int DetectCommercials(int f, double pts)
33283330
{
33293331
if (delay_logo_search == 0 ||
33303332
(delay_logo_search == 1 && F2T(frame_count) > added_recording * 60) ||
3331-
(F2T(frame_count) > delay_logo_search))
3333+
(delay_logo_search > 1 && F2T(frame_count) > delay_logo_search))
33323334
{
33333335
FillLogoBuffer();
33343336
if (logoBuffersFull)
@@ -8775,6 +8777,7 @@ FILE* LoadSettings(int argc, char ** argv)
87758777
struct arg_lit* cl_use_cuvid = arg_lit0(NULL, "cuvid", "Use NVIDIA Video Decoder (CUVID), if available");
87768778
struct arg_lit* cl_use_vdpau = arg_lit0(NULL, "vdpau", "Use NVIDIA Video Decode and Presentation API (VDPAU), if available");
87778779
struct arg_lit* cl_use_dxva2 = arg_lit0(NULL, "dxva2", "Use DXVA2 Video Decode and Presentation API (DXVA2), if available");
8780+
struct arg_lit* cl_use_qsv = arg_lit0(NULL, "qsv", "Use Intel Quick Sync Video acceleration (QSV), if available");
87788781
struct arg_lit* cl_list_decoders = arg_lit0(NULL, "decoders", "List all decoders and exit");
87798782
struct arg_int* cl_threads = arg_int0(NULL, "threads", "<int>", "The number of threads to use");
87808783
struct arg_int* cl_verbose = arg_intn("v", "verbose", NULL, 0, 1, "Verbose level");
@@ -8806,6 +8809,7 @@ FILE* LoadSettings(int argc, char ** argv)
88068809
cl_use_cuvid,
88078810
cl_use_vdpau,
88088811
cl_use_dxva2,
8812+
cl_use_qsv,
88098813
cl_list_decoders,
88108814
cl_threads,
88118815
cl_pid,
@@ -9269,6 +9273,12 @@ FILE* LoadSettings(int argc, char ** argv)
92699273
use_dxva2 = 1;
92709274
}
92719275

9276+
if (cl_use_qsv->count)
9277+
{
9278+
printf("Enabling use_qsv\n");
9279+
use_qsv = 1;
9280+
}
9281+
92729282
if (cl_threads->count)
92739283
{
92749284
thread_count = cl_threads->ival[0];
@@ -10114,7 +10124,7 @@ void LoadCutScene(const char *filename)
1011410124
#define OWN_HISTOGRAM_WIDTH 4
1011510125
#define OWN_HISTOGRAM_HEIGHT 256
1011610126

10117-
static DECLARE_ALIGNED(32, int, own_histogram)[OWN_HISTOGRAM_WIDTH][OWN_HISTOGRAM_HEIGHT];
10127+
static int own_histogram[OWN_HISTOGRAM_WIDTH][OWN_HISTOGRAM_HEIGHT];
1011810128
int scan_step;
1011910129

1012010130
#define SCAN_MULTI
@@ -16527,8 +16537,11 @@ void dump_data(char *start, int length)
1652716537

1652816538
void close_data()
1652916539
{
16530-
if (output_data && dump_data_file) {
16531-
fclose(dump_data_file);
16532-
dump_data_file = 0;
16533-
}
16540+
if (output_data)
16541+
{
16542+
if (dump_data_file) {
16543+
fclose(dump_data_file);
16544+
dump_data_file = 0;
16545+
}
16546+
}
1653416547
}

mpeg2dec.c

Lines changed: 50 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ const HWAccel hwaccels[] = {
5757
#endif
5858
#if CONFIG_VDA
5959
{ "vda", vda_init, HWACCEL_VDA, AV_PIX_FMT_VDA },
60+
#endif
61+
#if HAVE_QSV
62+
{ "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV },
6063
#endif
6164
{ 0 },
6265
};
@@ -70,6 +73,7 @@ extern int hardware_decode;
7073
extern int use_cuvid;
7174
extern int use_vdpau;
7275
extern int use_dxva2;
76+
extern int use_qsv;
7377
int av_log_level=AV_LOG_INFO;
7478

7579

@@ -351,7 +355,7 @@ static void signal_handler (int sig)
351355
#define AUDIOBUFFER 1600000
352356

353357
static double base_apts = 0.0, apts, top_apts = 0.0;
354-
static DECLARE_ALIGNED(16, short, audio_buffer[AUDIOBUFFER]);
358+
static short audio_buffer[AUDIOBUFFER];
355359
static short *audio_buffer_ptr = audio_buffer;
356360
static int audio_samples = 0;
357361
#define ISSAME(T1,T2) (fabs((T1) - (T2)) < 0.001)
@@ -573,8 +577,14 @@ void sound_to_frames(VideoState *is, short **b, int s, int c, int format)
573577
for (l=0;l < c;l++ ) volume += *((fb[l])++) * 64000;
574578
else
575579
for (l=0;l < c;l++ ) volume += *((fb[0])++) * 64000;
580+
#if LIBAVCODEC_BUILD >= AV_VERSION_INT(59, 37, 100) && \
581+
LIBAVUTIL_BUILD >= AV_VERSION_INT(57, 28, 100)
582+
*audio_buffer_ptr++ = volume / is->audio_st->codecpar->ch_layout.nb_channels;
583+
avg_volume += abs(volume / is->audio_st->codecpar->ch_layout.nb_channels);
584+
#else
576585
*audio_buffer_ptr++ = volume / is->audio_st->codecpar->channels;
577586
avg_volume += abs(volume / is->audio_st->codecpar->channels);
587+
#endif
578588
}
579589
}
580590
else
@@ -590,8 +600,14 @@ void sound_to_frames(VideoState *is, short **b, int s, int c, int format)
590600
for (l=0;l < c;l++ ) volume += *((sb[l])++);
591601
else
592602
for (l=0;l < c;l++ ) volume += *((sb[0])++);
603+
#if LIBAVCODEC_BUILD >= AV_VERSION_INT(59, 37, 100) && \
604+
LIBAVUTIL_BUILD >= AV_VERSION_INT(57, 28, 100)
605+
*audio_buffer_ptr++ = volume / is->audio_st->codecpar->ch_layout.nb_channels;
606+
avg_volume += abs(volume / is->audio_st->codecpar->ch_layout.nb_channels);
607+
#else
593608
*audio_buffer_ptr++ = volume / is->audio_st->codecpar->channels;
594609
avg_volume += abs(volume / is->audio_st->codecpar->channels);
610+
#endif
595611
}
596612
}
597613
}
@@ -767,7 +783,19 @@ void audio_packet_process(VideoState *is, AVPacket *pkt)
767783
}
768784

769785

770-
786+
#if LIBAVCODEC_BUILD >= AV_VERSION_INT(59, 37, 100) && \
787+
LIBAVUTIL_BUILD >= AV_VERSION_INT(57, 28, 100)
788+
data_size = av_samples_get_buffer_size(NULL, is->frame->ch_layout.nb_channels,
789+
is->frame->nb_samples,
790+
is->frame->format, 1);
791+
if (data_size > 0)
792+
{
793+
sound_to_frames(is, (short **)is->frame->data, is->frame->nb_samples ,is->frame->ch_layout.nb_channels, is->frame->format);
794+
}
795+
is->audio_clock += (double)data_size /
796+
(is->frame->ch_layout.nb_channels * is->frame->sample_rate * av_get_bytes_per_sample(is->frame->format));
797+
av_frame_unref(is->frame);
798+
#else
771799
data_size = av_samples_get_buffer_size(NULL, is->frame->channels,
772800
is->frame->nb_samples,
773801
is->frame->format, 1);
@@ -778,6 +806,7 @@ void audio_packet_process(VideoState *is, AVPacket *pkt)
778806
is->audio_clock += (double)data_size /
779807
(is->frame->channels * is->frame->sample_rate * av_get_bytes_per_sample(is->frame->format));
780808
av_frame_unref(is->frame);
809+
#endif
781810
}
782811

783812
if (ALIGN_AC3_PACKETS && is->audio_st->codecpar->codec_id == AV_CODEC_ID_AC3) {
@@ -1036,6 +1065,10 @@ void DoSeekRequest(VideoState *is)
10361065
if(ret < 0)
10371066
{
10381067
char *error_text;
1068+
#if LIBAVCODEC_BUILD >= AV_VERSION_INT(59, 37, 100) && \
1069+
LIBAVUTIL_BUILD >= AV_VERSION_INT(57, 28, 100)
1070+
error_text = "Generic";
1071+
#else
10391072
if (is->pFormatCtx->iformat->read_seek)
10401073
{
10411074
error_text = "Format specific";
@@ -1048,6 +1081,7 @@ void DoSeekRequest(VideoState *is)
10481081
{
10491082
error_text = "Generic";
10501083
}
1084+
#endif
10511085

10521086
fprintf(stderr, "%s error while seeking. target=%6.3f, \"%s\"\n", error_text,is->seek_pts, is->pFormatCtx->url);
10531087

@@ -1674,12 +1708,24 @@ int stream_component_open(VideoState *is, int stream_index)
16741708

16751709
codec = avcodec_find_decoder(codecPar->codec_id);
16761710

1711+
if (use_qsv && !codec_hw) {
1712+
if (codecPar->codec_id == AV_CODEC_ID_MJPEG) codec_hw = avcodec_find_decoder_by_name("mjpeg_qsv");
1713+
if (codecPar->codec_id == AV_CODEC_ID_MPEG2VIDEO) codec_hw = avcodec_find_decoder_by_name("mpeg2_qsv");
1714+
if (codecPar->codec_id == AV_CODEC_ID_H264) codec_hw = avcodec_find_decoder_by_name("h264_qsv");
1715+
if (codecPar->codec_id == AV_CODEC_ID_VC1) codec_hw = avcodec_find_decoder_by_name("vc1_qsv");
1716+
if (codecPar->codec_id == AV_CODEC_ID_HEVC) codec_hw = avcodec_find_decoder_by_name("hevc_qsv");
1717+
if (codecPar->codec_id == AV_CODEC_ID_AV1) codec_hw = avcodec_find_decoder_by_name("av1_qsv");
1718+
if (codecPar->codec_id == AV_CODEC_ID_VP8) codec_hw = avcodec_find_decoder_by_name("vp8_qsv");
1719+
if (codecPar->codec_id == AV_CODEC_ID_VP9) codec_hw = avcodec_find_decoder_by_name("vp9_qsv");
1720+
}
1721+
16771722
if (use_dxva2 && !codec_hw) {
16781723
if (codecPar->codec_id == AV_CODEC_ID_MPEG2VIDEO) codec_hw = avcodec_find_decoder_by_name("mpeg2_dxva2");
16791724
if (codecPar->codec_id == AV_CODEC_ID_H264) codec_hw = avcodec_find_decoder_by_name("h264_dxva2");
16801725
if (codecPar->codec_id == AV_CODEC_ID_MPEG4) codec_hw = avcodec_find_decoder_by_name("mpeg4_dxva2");
16811726
if (codecPar->codec_id == AV_CODEC_ID_VC1) codec_hw = avcodec_find_decoder_by_name("vc1_dxva2");
16821727
if (codecPar->codec_id == AV_CODEC_ID_HEVC) codec_hw = avcodec_find_decoder_by_name("hevc_dxva2");
1728+
if (codecPar->codec_id == AV_CODEC_ID_AV1) codec_hw = avcodec_find_decoder_by_name("av1_dxva2");
16831729
}
16841730

16851731
if (use_vdpau && !codec_hw) {
@@ -1695,7 +1741,8 @@ int stream_component_open(VideoState *is, int stream_index)
16951741
if (codecPar->codec_id == AV_CODEC_ID_H264) codec_hw = avcodec_find_decoder_by_name("h264_cuvid");
16961742
if (codecPar->codec_id == AV_CODEC_ID_HEVC) codec_hw = avcodec_find_decoder_by_name("hevc_cuvid");
16971743
if (codecPar->codec_id == AV_CODEC_ID_MPEG4) codec_hw = avcodec_find_decoder_by_name("mpeg4_cuvid");
1698-
if (codecPar->codec_id == AV_CODEC_ID_VC1) codec_hw = avcodec_find_decoder_by_name("vc1_cuvidl");
1744+
if (codecPar->codec_id == AV_CODEC_ID_VC1) codec_hw = avcodec_find_decoder_by_name("vc1_cuvid");
1745+
if (codecPar->codec_id == AV_CODEC_ID_AV1) codec_hw = avcodec_find_decoder_by_name("av1_cuvid");
16991746
}
17001747

17011748
// If decoding in hardware try if running on a Raspberry Pi and then use it's decoder instead.

platform.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ typedef unsigned char uint8_t;
7474
typedef unsigned short uint16_t;
7575
typedef unsigned int uint32_t;
7676
typedef unsigned __int64 uint64_t;
77-
#include "win32_pthread.h"
77+
#if !defined(HARDWARE_DECODE) && !defined(__MINGW64__)
78+
#include <compat/w32pthreads.h> // Is already defined in ffmpeg
79+
#endif
7880

7981
#include <time.h>
8082
#else

video_out_dx.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ static int create_window (dx_instance_t * instance)
541541
/* store a directx_instance pointer into the window local storage
542542
* (for later use in event_handler).
543543
* We need to use SetWindowLongPtr when it is available in mingw */
544-
SetWindowLongPtr (instance->window, GWLP_USERDATA, (LONG_PTR)instance);
544+
SetWindowLongPtr (instance->window, GWLP_USERDATA, (LONG_PTR) instance);
545545
SetWindowPos(instance->window, HWND_TOP, 100, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);
546546

547547
ShowWindow (instance->window, SW_SHOW);
@@ -928,13 +928,13 @@ void vo_init(int width, int height, char *title)
928928
memset(buf2,128,width*height);
929929

930930
#ifdef RGB
931-
instance = vo_dxrgb_open();
932-
hWind = instance;
931+
instance = (dx_instance_t *) vo_dxrgb_open();
932+
hWind = (HWND) instance;
933933
strcpy(instance->title, title);
934934
dxrgb_setup( instance, width, height, width, height, &result);
935935
// dx_setup_fbuf ( instance, buffer, &result);
936936
#else
937-
instance = vo_dx_open();
937+
instance = (HWND) vo_dx_open();
938938
strcpy(instance->title, title);
939939
dx_setup( instance, width, height, width, height, &result);
940940
#endif

0 commit comments

Comments
 (0)