Skip to content

Commit

Permalink
Merge pull request #2 from spicyjpeg/colorspace-fix
Browse files Browse the repository at this point in the history
.STR black video fix, Windows and Linux CI
  • Loading branch information
asiekierka authored Jun 20, 2023
2 parents 4419132 + 13d8afd commit d524746
Show file tree
Hide file tree
Showing 6 changed files with 164 additions and 7 deletions.
92 changes: 92 additions & 0 deletions .github/scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
#!/bin/bash

ROOT_DIR="$(pwd)"
FFMPEG_VERSION="6.0"
NUM_JOBS="4"

if [ $# -eq 1 ]; then
PACKAGE_NAME="$1"
FFMPEG_OPTIONS=""
PSXAVENC_OPTIONS=""
elif [ $# -eq 3 ]; then
PACKAGE_NAME="$1"
FFMPEG_OPTIONS="--arch=x86 --target-os=mingw32 --cross-prefix=$2-"
PSXAVENC_OPTIONS="--cross-file $3"
else
echo "Usage: $0 <package name> [cross prefix] [cross file]"
exit 0
fi

## Download FFmpeg

if [ ! -d ffmpeg-$FFMPEG_VERSION ]; then
wget "https://ffmpeg.org/releases/ffmpeg-$FFMPEG_VERSION.tar.xz" \
|| exit 1
tar Jxf ffmpeg-$FFMPEG_VERSION.tar.xz \
|| exit 1

rm -f ffmpeg-$FFMPEG_VERSION.tar.xz
fi

## Build FFmpeg

mkdir -p ffmpeg-build
cd ffmpeg-build

../ffmpeg-$FFMPEG_VERSION/configure \
--prefix="$ROOT_DIR/ffmpeg-dist" \
$FFMPEG_OPTIONS \
--enable-gpl \
--enable-version3 \
--enable-static \
--disable-shared \
--enable-small \
--disable-programs \
--disable-doc \
--disable-avdevice \
--disable-postproc \
--disable-avfilter \
--disable-network \
--disable-encoders \
--disable-hwaccels \
--disable-muxers \
--disable-bsfs \
--disable-devices \
--disable-filters \
--disable-mmx \
|| exit 2
make -j $NUM_JOBS \
|| exit 2
make install \
|| exit 2

cd ..
rm -rf ffmpeg-build

## Build psxavenc

meson setup \
--buildtype release \
--strip \
--prefix $ROOT_DIR/psxavenc-dist \
--pkg-config-path $ROOT_DIR/ffmpeg-dist/lib/pkgconfig \
$PSXAVENC_OPTIONS \
psxavenc-build \
psxavenc \
|| exit 3
meson compile -C psxavenc-build \
|| exit 3
meson install -C psxavenc-build \
|| exit 3

rm -rf ffmpeg-dist psxavenc-build

## Package psxavenc

cd psxavenc-dist

zip -9 -r ../$PACKAGE_NAME.zip . \
|| exit 4

cd ..
rm -rf psxavenc-dist
12 changes: 12 additions & 0 deletions .github/scripts/mingw-cross.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[binaries]
c = 'x86_64-w64-mingw32-gcc'
cpp = 'x86_64-w64-mingw32-g++'
ar = 'x86_64-w64-mingw32-ar'
strip = 'x86_64-w64-mingw32-strip'
pkgconfig = 'pkg-config'

[host_machine]
system = 'windows'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'
48 changes: 48 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

name: Build psxavenc
on: [ push, pull_request ]

jobs:
build:
name: Build and create release
runs-on: ubuntu-latest

steps:
- name: Install prerequisites
run: |
sudo apt-get update -y
sudo apt-get install -y --no-install-recommends meson ninja-build gcc-mingw-w64-x86-64
- name: Fetch repo contents
uses: actions/checkout@v3
with:
path: psxavenc

- name: Build psxavenc for Windows
run: |
psxavenc/.github/scripts/build.sh psxavenc-windows x86_64-w64-mingw32 psxavenc/.github/scripts/mingw-cross.txt
- name: Upload Windows build artifacts
uses: actions/upload-artifact@v3
with:
name: psxavenc-windows
path: psxavenc-windows.zip

- name: Build psxavenc for Linux
run: |
psxavenc/.github/scripts/build.sh psxavenc-linux
- name: Upload Linux build artifacts
uses: actions/upload-artifact@v3
with:
name: psxavenc-linux
path: psxavenc-linux.zip

- name: Publish release
if: ${{ github.ref_type == 'tag' }}
uses: softprops/action-gh-release@v1
with:
#fail_on_unmatched_files: true
files: |
psxavenc-windows.zip
psxavenc-linux.zip
1 change: 0 additions & 1 deletion psxavenc/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ typedef struct {
} vid_encoder_state_t;

typedef struct {
int video_frame_src_size;
int video_frame_dst_size;
int audio_stream_index;
int video_stream_index;
Expand Down
16 changes: 11 additions & 5 deletions psxavenc/decoding.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ bool open_av_data(const char *filename, settings_t *settings, bool use_audio, bo
av_decoder_state_t* av = &(settings->decoder_state_av);
av->video_next_pts = 0.0;
av->frame = NULL;
av->video_frame_src_size = 0;
av->video_frame_dst_size = 0;
av->audio_stream_index = -1;
av->video_stream_index = -1;
Expand Down Expand Up @@ -202,8 +201,13 @@ bool open_av_data(const char *filename, settings_t *settings, bool use_audio, bo
NULL,
NULL
);
// Is this even necessary? -- spicyjpeg
sws_setColorspaceDetails(
if (av->scaler == NULL) {
return false;
}
#if 0
// FIXME: if this is uncommented libswscale may produce completely black
// frames for whatever reason...
if (sws_setColorspaceDetails(
av->scaler,
sws_getCoefficients(av->video_codec_context->colorspace),
(av->video_codec_context->color_range == AVCOL_RANGE_JPEG),
Expand All @@ -212,14 +216,16 @@ bool open_av_data(const char *filename, settings_t *settings, bool use_audio, bo
0,
0,
0
);
) < 0) {
return false;
}
#endif
if (settings->swscale_options) {
if (av_opt_set_from_string(av->scaler, settings->swscale_options, NULL, "=", ":,") < 0) {
return false;
}
}

av->video_frame_src_size = 4*av->video_codec_context->width*av->video_codec_context->height;
av->video_frame_dst_size = 3*settings->video_width*settings->video_height/2;
}

Expand Down
2 changes: 1 addition & 1 deletion psxavenc/filefmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ void encode_file_sbs(settings_t *settings, FILE *output) {
settings->state_vid.frame_max_size = settings->alignment;
settings->state_vid.quant_scale_sum = 0;

for (int j = 0; ensure_av_data(settings, 0, 1); j++) {
for (int j = 0; ensure_av_data(settings, 0, 2); j++) {
encode_frame_bs(settings->video_frames, settings);
fwrite(settings->state_vid.frame_output, settings->alignment, 1, output);

Expand Down

0 comments on commit d524746

Please sign in to comment.