Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upstream merge feb 2024 #3

Open
wants to merge 27 commits into
base: fancybits
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f443475
fix segv in audio code and other asan errors
tmm1 Jan 23, 2023
798cb2f
bump to ffmpeg 5.0.1
tmm1 Jan 23, 2023
6e66de5
Merge pull request #156 from erikkaashoek/crash-fixes
tmm1 Jan 23, 2023
708cb14
Fix delay_logo_search when using added_recording
Oct 3, 2023
3f940e6
Fix for deprecation of DECLARE_ALIGNED #164
bsperduto Dec 3, 2023
eae0b43
[PATCH] Update mpeg2dec.c
bsperduto Dec 10, 2023
c5d69ed
Add Intel Quick Sync Video acceleration (QSV) support
jmarcet Dec 30, 2023
cded331
ffmpeg build moved to github
erikkaashoek Dec 30, 2023
cea4f9a
Merge pull request #165 from CvH/ffmpeg6
erikkaashoek Dec 30, 2023
9c50c06
Merge pull request #166 from jmarcet/master
erikkaashoek Dec 30, 2023
109b5d1
Merge pull request #163 from skittlesvampir/fix_delay_logo_duration
erikkaashoek Dec 30, 2023
165cb9c
Fix close_data segfault when output_data is not set
kexis0 Mar 20, 2024
569f988
Fix VC1 CUDA encoding
rboy1 Jun 7, 2024
2ef8684
Merge pull request #169 from rboy1/patch-3
erikkaashoek Jun 7, 2024
c2d1e5f
Added support for AV1 CUVID and DXVA2 decoding
rboy1 Sep 10, 2024
0a8ce55
Add configure~ to .gitignore
phunkyfish Jan 23, 2025
d073c92
Enable building with ffmpeg 6 and 7
phunkyfish Jan 22, 2025
22a3aeb
Adding missing pthread header, needed for windows builds
phunkyfish Jan 23, 2025
102b2a4
Fixes needed for windows build with Msys2
phunkyfish Jan 23, 2025
cd5fce3
Github workflows for Linux, Mac and Windows
phunkyfish Jan 23, 2025
81a7efd
Merge pull request #174 from phunkyfish/ffmpeg7-changes
tmm1 Jan 24, 2025
76dc689
Update brew packages to canonical names
phunkyfish Jan 25, 2025
7c7cf48
Merge pull request #175 from phunkyfish/update-brew
erikkaashoek Jan 25, 2025
f76bde4
Merge pull request #171 from rboy1/patch-4
erikkaashoek Jan 25, 2025
55b0bcd
Merge pull request #168 from kexis0/fix_close_data_segfault
erikkaashoek Jan 25, 2025
f7a4368
Merge remote-tracking branch 'upstream/master' into upstream-merge-fe…
eric Feb 18, 2025
6522723
drop this
tmm1 Feb 26, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Build
on: [push, pull_request]

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
platform: linux
- os: macos-latest
platform: macos
ffmpeg_version: ffmpeg5
- os: macos-latest
platform: macos
ffmpeg_version: ffmpeg6
- os: macos-latest
platform: macos
ffmpeg_version: ffmpeg7
- os: windows-latest
platform: windows-mingw
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup
shell: bash
run: |
setupScript='ci/${{ matrix.platform }}/setup.sh'
[ ! -f "$setupScript" ] || "$setupScript"

- name: Configure Apt packages
if: ${{ matrix.platform == 'linux' }}
run: |
sudo apt-get install -y autoconf libtool git build-essential libargtable2-dev libavformat-dev libswscale-dev libsdl1.2-dev

- name: Configure Brew packages ffmpeg7
if: ${{ matrix.ffmpeg_version == 'ffmpeg7' }}
run: |
brew install autoconf automake libtool pkgconf argtable ffmpeg sdl12-compat

- name: Configure Brew packages ffmpeg6
if: ${{ matrix.ffmpeg_version == 'ffmpeg6' }}
run: |
brew install autoconf automake libtool pkgconf argtable ffmpeg@6 sdl12-compat
brew link ffmpeg@6

- name: Configure Brew packages ffmpeg5
if: ${{ matrix.ffmpeg_version == 'ffmpeg5' }}
run: |
brew install autoconf automake libtool pkgconf argtable ffmpeg@5 sdl12-compat
brew link ffmpeg@5

- name: Setup msys2
uses: msys2/setup-msys2@v2
if: ${{ matrix.platform == 'windows-mingw' }}
with:
update: true
install: >-
mingw-w64-x86_64-gcc
mingw-w64-x86_64-make
mingw-w64-x86_64-autotools
mingw-w64-x86_64-libtool
mingw-w64-x86_64-pkg-config
mingw-w64-x86_64-yasm
mingw-w64-x86_64-argtable
mingw-w64-x86_64-ffmpeg
- name: Put MSYS2_MinGW64 on PATH
if: ${{ matrix.platform == 'windows-mingw' }}
run: |
echo "${{ runner.temp }}/msys64/mingw64/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append

- name: Configure and build Posix
if: ${{ matrix.platform != 'windows-mingw' }}
run: |
./autogen.sh
./configure
make

- name: Configure and build Windows
if: ${{ matrix.platform == 'windows-mingw' }}
run: |
msys2 -c './autogen.sh'
msys2 -c './configure'
msys2 -c 'make'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ autom4te.cache
compile
config.*
configure
configure~
depcomp
install-sh
missing
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ First install Xcode (freely available from the Mac OS X App Store). After it's i
The easiest way to install Comskip's dependencies is via Homebrew (http://brew.sh/):

```
$ brew install autoconf automake libtool pkgconfig argtable ffmpeg sdl
$ brew install autoconf automake libtool pkgconf argtable ffmpeg sdl12-compat
```

[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.
Expand Down
10 changes: 5 additions & 5 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ artifacts:
before_build:
- git log -1
- cd C:\projects\comskip
- appveyor DownloadFile https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-4.4.1-full_build-shared.7z
- appveyor DownloadFile https://github.com/GyanD/codexffmpeg/releases/download/5.0.1/ffmpeg-5.0.1-full_build-shared.7z
- appveyor DownloadFile https://downloads.sourceforge.net/project/argtable/argtable/argtable-2.13/argtable2-13.tar.gz

build_script:
- 7z x ffmpeg-4.4.1-full_build-shared.7z
- 7z x ffmpeg-5.0.1-full_build-shared.7z
- 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"
- 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"
- 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"

before_test:
- 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"
- 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"
- appveyor DownloadFile https://s3.amazonaws.com/tmm1/ten-copy.mkv

test_script:
- SET PATH=C:\projects\comskip\ffmpeg-4.4.1-full_build-shared\bin;%PATH%
- SET PATH=C:\projects\comskip\ffmpeg-5.0.1-full_build-shared\bin;%PATH%
- comskip ten-copy.mkv
- cat ten-copy.txt
- grep "9361\s17922" ten-copy.txt
31 changes: 22 additions & 9 deletions comskip.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "platform.h"
#include "vo.h"
#include <argtable2.h>
#include <pthread.h>


#include <libavformat/avformat.h>
Expand Down Expand Up @@ -476,6 +477,7 @@ int hardware_decode = 0;
int use_cuvid = 0;
int use_vdpau = 0;
int use_dxva2 = 0;
int use_qsv = 0;
int skip_B_frames = 0;
int lowres = 0;
bool live_tv = false;
Expand Down Expand Up @@ -741,9 +743,9 @@ int sceneChangePercent;
bool lastFrameWasBlack = false;
bool lastFrameWasSceneChange = false;

#include <libavutil/avutil.h> // only for DECLARE_ALIGNED
static DECLARE_ALIGNED(32, long, histogram)[256];
static DECLARE_ALIGNED(32, long, lastHistogram)[256];

static long histogram[256];
static long lastHistogram[256];

#define MAXCSLENGTH 400*300
#define MAXCUTSCENES 8
Expand Down Expand Up @@ -3328,7 +3330,7 @@ int DetectCommercials(int f, double pts)
{
if (delay_logo_search == 0 ||
(delay_logo_search == 1 && F2T(frame_count) > added_recording * 60) ||
(F2T(frame_count) > delay_logo_search))
(delay_logo_search > 1 && F2T(frame_count) > delay_logo_search))
{
FillLogoBuffer();
if (logoBuffersFull)
Expand Down Expand Up @@ -8775,6 +8777,7 @@ FILE* LoadSettings(int argc, char ** argv)
struct arg_lit* cl_use_cuvid = arg_lit0(NULL, "cuvid", "Use NVIDIA Video Decoder (CUVID), if available");
struct arg_lit* cl_use_vdpau = arg_lit0(NULL, "vdpau", "Use NVIDIA Video Decode and Presentation API (VDPAU), if available");
struct arg_lit* cl_use_dxva2 = arg_lit0(NULL, "dxva2", "Use DXVA2 Video Decode and Presentation API (DXVA2), if available");
struct arg_lit* cl_use_qsv = arg_lit0(NULL, "qsv", "Use Intel Quick Sync Video acceleration (QSV), if available");
struct arg_lit* cl_list_decoders = arg_lit0(NULL, "decoders", "List all decoders and exit");
struct arg_int* cl_threads = arg_int0(NULL, "threads", "<int>", "The number of threads to use");
struct arg_int* cl_verbose = arg_intn("v", "verbose", NULL, 0, 1, "Verbose level");
Expand Down Expand Up @@ -8806,6 +8809,7 @@ FILE* LoadSettings(int argc, char ** argv)
cl_use_cuvid,
cl_use_vdpau,
cl_use_dxva2,
cl_use_qsv,
cl_list_decoders,
cl_threads,
cl_pid,
Expand Down Expand Up @@ -9269,6 +9273,12 @@ FILE* LoadSettings(int argc, char ** argv)
use_dxva2 = 1;
}

if (cl_use_qsv->count)
{
printf("Enabling use_qsv\n");
use_qsv = 1;
}

if (cl_threads->count)
{
thread_count = cl_threads->ival[0];
Expand Down Expand Up @@ -10114,7 +10124,7 @@ void LoadCutScene(const char *filename)
#define OWN_HISTOGRAM_WIDTH 4
#define OWN_HISTOGRAM_HEIGHT 256

static DECLARE_ALIGNED(32, int, own_histogram)[OWN_HISTOGRAM_WIDTH][OWN_HISTOGRAM_HEIGHT];
static int own_histogram[OWN_HISTOGRAM_WIDTH][OWN_HISTOGRAM_HEIGHT];
int scan_step;

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

void close_data()
{
if (output_data && dump_data_file) {
fclose(dump_data_file);
dump_data_file = 0;
}
if (output_data)
{
if (dump_data_file) {
fclose(dump_data_file);
dump_data_file = 0;
}
}
}
53 changes: 50 additions & 3 deletions mpeg2dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ const HWAccel hwaccels[] = {
#endif
#if CONFIG_VDA
{ "vda", vda_init, HWACCEL_VDA, AV_PIX_FMT_VDA },
#endif
#if HAVE_QSV
{ "qsv", qsv_init, HWACCEL_QSV, AV_PIX_FMT_QSV },
#endif
{ 0 },
};
Expand All @@ -70,6 +73,7 @@ extern int hardware_decode;
extern int use_cuvid;
extern int use_vdpau;
extern int use_dxva2;
extern int use_qsv;
int av_log_level=AV_LOG_INFO;


Expand Down Expand Up @@ -351,7 +355,7 @@ static void signal_handler (int sig)
#define AUDIOBUFFER 1600000

static double base_apts = 0.0, apts, top_apts = 0.0;
static DECLARE_ALIGNED(16, short, audio_buffer[AUDIOBUFFER]);
static short audio_buffer[AUDIOBUFFER];
static short *audio_buffer_ptr = audio_buffer;
static int audio_samples = 0;
#define ISSAME(T1,T2) (fabs((T1) - (T2)) < 0.001)
Expand Down Expand Up @@ -573,8 +577,14 @@ void sound_to_frames(VideoState *is, short **b, int s, int c, int format)
for (l=0;l < c;l++ ) volume += *((fb[l])++) * 64000;
else
for (l=0;l < c;l++ ) volume += *((fb[0])++) * 64000;
#if LIBAVCODEC_BUILD >= AV_VERSION_INT(59, 37, 100) && \
LIBAVUTIL_BUILD >= AV_VERSION_INT(57, 28, 100)
*audio_buffer_ptr++ = volume / is->audio_st->codecpar->ch_layout.nb_channels;
avg_volume += abs(volume / is->audio_st->codecpar->ch_layout.nb_channels);
#else
*audio_buffer_ptr++ = volume / is->audio_st->codecpar->channels;
avg_volume += abs(volume / is->audio_st->codecpar->channels);
#endif
}
}
else
Expand All @@ -590,8 +600,14 @@ void sound_to_frames(VideoState *is, short **b, int s, int c, int format)
for (l=0;l < c;l++ ) volume += *((sb[l])++);
else
for (l=0;l < c;l++ ) volume += *((sb[0])++);
#if LIBAVCODEC_BUILD >= AV_VERSION_INT(59, 37, 100) && \
LIBAVUTIL_BUILD >= AV_VERSION_INT(57, 28, 100)
*audio_buffer_ptr++ = volume / is->audio_st->codecpar->ch_layout.nb_channels;
avg_volume += abs(volume / is->audio_st->codecpar->ch_layout.nb_channels);
#else
*audio_buffer_ptr++ = volume / is->audio_st->codecpar->channels;
avg_volume += abs(volume / is->audio_st->codecpar->channels);
#endif
}
}
}
Expand Down Expand Up @@ -767,7 +783,19 @@ void audio_packet_process(VideoState *is, AVPacket *pkt)
}



#if LIBAVCODEC_BUILD >= AV_VERSION_INT(59, 37, 100) && \
LIBAVUTIL_BUILD >= AV_VERSION_INT(57, 28, 100)
data_size = av_samples_get_buffer_size(NULL, is->frame->ch_layout.nb_channels,
is->frame->nb_samples,
is->frame->format, 1);
if (data_size > 0)
{
sound_to_frames(is, (short **)is->frame->data, is->frame->nb_samples ,is->frame->ch_layout.nb_channels, is->frame->format);
}
is->audio_clock += (double)data_size /
(is->frame->ch_layout.nb_channels * is->frame->sample_rate * av_get_bytes_per_sample(is->frame->format));
av_frame_unref(is->frame);
#else
data_size = av_samples_get_buffer_size(NULL, is->frame->channels,
is->frame->nb_samples,
is->frame->format, 1);
Expand All @@ -778,6 +806,7 @@ void audio_packet_process(VideoState *is, AVPacket *pkt)
is->audio_clock += (double)data_size /
(is->frame->channels * is->frame->sample_rate * av_get_bytes_per_sample(is->frame->format));
av_frame_unref(is->frame);
#endif
}

if (ALIGN_AC3_PACKETS && is->audio_st->codecpar->codec_id == AV_CODEC_ID_AC3) {
Expand Down Expand Up @@ -1036,6 +1065,10 @@ void DoSeekRequest(VideoState *is)
if(ret < 0)
{
char *error_text;
#if LIBAVCODEC_BUILD >= AV_VERSION_INT(59, 37, 100) && \
LIBAVUTIL_BUILD >= AV_VERSION_INT(57, 28, 100)
error_text = "Generic";
#else
if (is->pFormatCtx->iformat->read_seek)
{
error_text = "Format specific";
Expand All @@ -1048,6 +1081,7 @@ void DoSeekRequest(VideoState *is)
{
error_text = "Generic";
}
#endif

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

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

codec = avcodec_find_decoder(codecPar->codec_id);

if (use_qsv && !codec_hw) {
if (codecPar->codec_id == AV_CODEC_ID_MJPEG) codec_hw = avcodec_find_decoder_by_name("mjpeg_qsv");
if (codecPar->codec_id == AV_CODEC_ID_MPEG2VIDEO) codec_hw = avcodec_find_decoder_by_name("mpeg2_qsv");
if (codecPar->codec_id == AV_CODEC_ID_H264) codec_hw = avcodec_find_decoder_by_name("h264_qsv");
if (codecPar->codec_id == AV_CODEC_ID_VC1) codec_hw = avcodec_find_decoder_by_name("vc1_qsv");
if (codecPar->codec_id == AV_CODEC_ID_HEVC) codec_hw = avcodec_find_decoder_by_name("hevc_qsv");
if (codecPar->codec_id == AV_CODEC_ID_AV1) codec_hw = avcodec_find_decoder_by_name("av1_qsv");
if (codecPar->codec_id == AV_CODEC_ID_VP8) codec_hw = avcodec_find_decoder_by_name("vp8_qsv");
if (codecPar->codec_id == AV_CODEC_ID_VP9) codec_hw = avcodec_find_decoder_by_name("vp9_qsv");
}

if (use_dxva2 && !codec_hw) {
if (codecPar->codec_id == AV_CODEC_ID_MPEG2VIDEO) codec_hw = avcodec_find_decoder_by_name("mpeg2_dxva2");
if (codecPar->codec_id == AV_CODEC_ID_H264) codec_hw = avcodec_find_decoder_by_name("h264_dxva2");
if (codecPar->codec_id == AV_CODEC_ID_MPEG4) codec_hw = avcodec_find_decoder_by_name("mpeg4_dxva2");
if (codecPar->codec_id == AV_CODEC_ID_VC1) codec_hw = avcodec_find_decoder_by_name("vc1_dxva2");
if (codecPar->codec_id == AV_CODEC_ID_HEVC) codec_hw = avcodec_find_decoder_by_name("hevc_dxva2");
if (codecPar->codec_id == AV_CODEC_ID_AV1) codec_hw = avcodec_find_decoder_by_name("av1_dxva2");
}

if (use_vdpau && !codec_hw) {
Expand All @@ -1695,7 +1741,8 @@ int stream_component_open(VideoState *is, int stream_index)
if (codecPar->codec_id == AV_CODEC_ID_H264) codec_hw = avcodec_find_decoder_by_name("h264_cuvid");
if (codecPar->codec_id == AV_CODEC_ID_HEVC) codec_hw = avcodec_find_decoder_by_name("hevc_cuvid");
if (codecPar->codec_id == AV_CODEC_ID_MPEG4) codec_hw = avcodec_find_decoder_by_name("mpeg4_cuvid");
if (codecPar->codec_id == AV_CODEC_ID_VC1) codec_hw = avcodec_find_decoder_by_name("vc1_cuvidl");
if (codecPar->codec_id == AV_CODEC_ID_VC1) codec_hw = avcodec_find_decoder_by_name("vc1_cuvid");
if (codecPar->codec_id == AV_CODEC_ID_AV1) codec_hw = avcodec_find_decoder_by_name("av1_cuvid");
}

// If decoding in hardware try if running on a Raspberry Pi and then use it's decoder instead.
Expand Down
4 changes: 3 additions & 1 deletion platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ typedef unsigned char uint8_t;
typedef unsigned short uint16_t;
typedef unsigned int uint32_t;
typedef unsigned __int64 uint64_t;
#include "win32_pthread.h"
#if !defined(HARDWARE_DECODE) && !defined(__MINGW64__)
//#include <compat/w32pthreads.h> // Is already defined in ffmpeg
#endif

#include <time.h>
#else
Expand Down
8 changes: 4 additions & 4 deletions video_out_dx.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ static int create_window (dx_instance_t * instance)
/* store a directx_instance pointer into the window local storage
* (for later use in event_handler).
* We need to use SetWindowLongPtr when it is available in mingw */
SetWindowLongPtr (instance->window, GWLP_USERDATA, (LONG_PTR)instance);
SetWindowLongPtr (instance->window, GWLP_USERDATA, (LONG_PTR) instance);
SetWindowPos(instance->window, HWND_TOP, 100, 0, 0, 0, SWP_SHOWWINDOW|SWP_NOSIZE);

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

#ifdef RGB
instance = vo_dxrgb_open();
hWind = instance;
instance = (dx_instance_t *) vo_dxrgb_open();
hWind = (HWND) instance;
strcpy(instance->title, title);
dxrgb_setup( instance, width, height, width, height, &result);
// dx_setup_fbuf ( instance, buffer, &result);
#else
instance = vo_dx_open();
instance = (HWND) vo_dx_open();
strcpy(instance->title, title);
dx_setup( instance, width, height, width, height, &result);
#endif
Expand Down
Loading