From a760e66cfed5caa0ef8dce1afa438ce515b6f66c Mon Sep 17 00:00:00 2001 From: Anatole Date: Mon, 28 Nov 2022 18:11:35 +0100 Subject: [PATCH 1/2] Revert "fix image resize (#74)" This reverts commit cf7edc8446e594d2ec16eaf403767f353eea413f. --- .github/workflows/ci.yaml | 117 ++++++++++++++++++++++++-- go/internal/image_processor/worker.go | 41 +++------ 2 files changed, 124 insertions(+), 34 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index f4884d11..ee1e1c4d 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -40,11 +40,118 @@ jobs: cancel-in-progress: true steps: + - name: Set up Go + uses: actions/setup-go@v3 + with: + go-version: 1.18.3 + + - uses: actions/setup-node@v3 + with: + node-version: "18" + + - name: Install Yarn + run: npm install -g yarn + - name: Checkout code uses: actions/checkout@v3 with: submodules: recursive + - id: cache-paths + run: | + echo "::set-output name=go-build::$(go env GOCACHE)" + echo "::set-output name=go-mod::$(go env GOMODCACHE)" + echo "::set-output name=pwd::$(pwd)" + + - name: Results Cache + uses: actions/cache@v3 + with: + path: ${{ steps.cache-paths.outputs.pwd }}/cpp/out + key: ${{ runner.os }}-results-${{ hashFiles('cpp/third-party/Makefile') }} + + - name: External Build Cache + uses: actions/cache@v3 + with: + path: ${{ steps.cache-paths.outputs.pwd }}/cpp/third-party/build + key: ${{ runner.os }}-external-build-${{ hashFiles('cpp/third-party/Makefile') }} + + - name: Go Build Cache + uses: actions/cache@v3 + with: + path: ${{ steps.cache-paths.outputs.go-build }} + key: ${{ runner.os }}-go-build-${{ hashFiles('go.sum') }} + + - name: Go Mod Cache + uses: actions/cache@v3 + with: + path: ${{ steps.cache-paths.outputs.go-mod }} + key: ${{ runner.os }}-go-mod-${{ hashFiles('go.sum') }} + + - name: GoLint Cache + uses: actions/cache@v3 + with: + path: ${{ env.GOLANGCI_LINT_CACHE }} + key: ${{ runner.os }}-go-lint-ci + + - name: Node Modules Cache + uses: actions/cache@v3 + with: + path: node_modules + key: ${{ runner.os }}-node_modules-${{ hashFiles('yarn.lock') }} + + - name: Setup | Rust + uses: ATiltedTree/setup-rust@v1 + with: + rust-version: stable + + - name: Install Development Dependencies + run: make dev_deps + + - name: Run Linter + run: make lint + + - name: Install Dependencies + run: | + sudo apt-get update + sudo apt-get install -y \ + ca-certificates \ + build-essential \ + curl \ + ninja-build \ + meson \ + git \ + nasm \ + openssl \ + pkg-config \ + cmake \ + libssl-dev \ + libpng-dev \ + zlib1g-dev \ + libx264-dev \ + libx265-dev \ + libvpx-dev \ + libopenjp2-7-dev \ + libssl-dev \ + gifsicle \ + optipng + + - name: Compile External Dependencies + run: make -C cpp external + + - name: Build CPP Applications + run: make -C cpp build + + - name: Move built files to /usr/local + run: | + sudo cp -r cpp/out/* /usr/local + sudo ldconfig + + - name: Run Tests + run: make test + + - name: Build App + run: make build + - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 if: ${{ env.DEPLOY_PROD == 'true' || env.DEPLOY_STAGE == 'true' }} @@ -75,11 +182,11 @@ jobs: if: ${{ env.DEPLOY_PROD == 'true' || env.DEPLOY_STAGE == 'true' }} with: context: . - file: docker/full.Dockerfile - cache-from: | - type=gha - cache-to: | - type=gha,mode=max + file: docker/partial.Dockerfile + # cache-from: | + # type=registry,ref=gha + # cache-to: | + # type=registry,ref=gha,mode=max tags: | ${{ steps.login-ecr.outputs.registry }}/${{ (env.DEPLOY_PROD == 'true' && '7tv') || '7tv-stage' }}/image-processor:latest ${{ steps.login-ecr.outputs.registry }}/${{ (env.DEPLOY_PROD == 'true' && '7tv') || '7tv-stage' }}/image-processor:${{ github.sha }} diff --git a/go/internal/image_processor/worker.go b/go/internal/image_processor/worker.go index e9e0a79c..b81191f8 100644 --- a/go/internal/image_processor/worker.go +++ b/go/internal/image_processor/worker.go @@ -730,40 +730,23 @@ func (Worker) resizeFrames(ctx global.Context, inputDir string, tmpDir string, t } if tsk.ResizeRatio == task.ResizeRatioNothing { - // Get the largest scale factor - scale := 1 - for _, s := range tsk.Scales { - if s > scale { - scale = s - } - } - - // Divide the width and height by the scale factor - // This is integer division, so it will round down - width /= scale - height /= scale + smwf := float64(tsk.SmallestMaxWidth) + wf := float64(width) + smhf := float64(tsk.SmallestMaxHeight) + hf := float64(height) - // If the height is bigger than the max height, then scale it down - if height > tsk.SmallestMaxHeight { - width = int(float64(width) * (float64(tsk.SmallestMaxHeight) / float64(height))) - height = tsk.SmallestMaxHeight + if smwf < wf { + hf *= smwf / wf + wf = smwf } - // If the width is bigger than the max width, then scale it down - if width > tsk.SmallestMaxWidth { - height = int(float64(height) * (float64(tsk.SmallestMaxWidth) / float64(width))) - width = tsk.SmallestMaxWidth + if smhf < hf { + wf *= smhf / hf + hf = smhf } - // If the width is 0, then set it to 1 - if width == 0 { - width = 1 - } - - // If the height is 0, then set it to 1 - if height == 0 { - height = 1 - } + width = int(math.Round(wf)) + height = int(math.Round(hf)) tsk.ResizeRatio = task.ResizeRatioStretch } else { From fe1a19d92ff7cf909af4f8f3db834f342030f57a Mon Sep 17 00:00:00 2001 From: Anatole Date: Mon, 28 Nov 2022 18:14:03 +0100 Subject: [PATCH 2/2] keep ci changes --- .github/workflows/ci.yaml | 117 ++------------------------------------ 1 file changed, 5 insertions(+), 112 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ee1e1c4d..f4884d11 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -40,118 +40,11 @@ jobs: cancel-in-progress: true steps: - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: 1.18.3 - - - uses: actions/setup-node@v3 - with: - node-version: "18" - - - name: Install Yarn - run: npm install -g yarn - - name: Checkout code uses: actions/checkout@v3 with: submodules: recursive - - id: cache-paths - run: | - echo "::set-output name=go-build::$(go env GOCACHE)" - echo "::set-output name=go-mod::$(go env GOMODCACHE)" - echo "::set-output name=pwd::$(pwd)" - - - name: Results Cache - uses: actions/cache@v3 - with: - path: ${{ steps.cache-paths.outputs.pwd }}/cpp/out - key: ${{ runner.os }}-results-${{ hashFiles('cpp/third-party/Makefile') }} - - - name: External Build Cache - uses: actions/cache@v3 - with: - path: ${{ steps.cache-paths.outputs.pwd }}/cpp/third-party/build - key: ${{ runner.os }}-external-build-${{ hashFiles('cpp/third-party/Makefile') }} - - - name: Go Build Cache - uses: actions/cache@v3 - with: - path: ${{ steps.cache-paths.outputs.go-build }} - key: ${{ runner.os }}-go-build-${{ hashFiles('go.sum') }} - - - name: Go Mod Cache - uses: actions/cache@v3 - with: - path: ${{ steps.cache-paths.outputs.go-mod }} - key: ${{ runner.os }}-go-mod-${{ hashFiles('go.sum') }} - - - name: GoLint Cache - uses: actions/cache@v3 - with: - path: ${{ env.GOLANGCI_LINT_CACHE }} - key: ${{ runner.os }}-go-lint-ci - - - name: Node Modules Cache - uses: actions/cache@v3 - with: - path: node_modules - key: ${{ runner.os }}-node_modules-${{ hashFiles('yarn.lock') }} - - - name: Setup | Rust - uses: ATiltedTree/setup-rust@v1 - with: - rust-version: stable - - - name: Install Development Dependencies - run: make dev_deps - - - name: Run Linter - run: make lint - - - name: Install Dependencies - run: | - sudo apt-get update - sudo apt-get install -y \ - ca-certificates \ - build-essential \ - curl \ - ninja-build \ - meson \ - git \ - nasm \ - openssl \ - pkg-config \ - cmake \ - libssl-dev \ - libpng-dev \ - zlib1g-dev \ - libx264-dev \ - libx265-dev \ - libvpx-dev \ - libopenjp2-7-dev \ - libssl-dev \ - gifsicle \ - optipng - - - name: Compile External Dependencies - run: make -C cpp external - - - name: Build CPP Applications - run: make -C cpp build - - - name: Move built files to /usr/local - run: | - sudo cp -r cpp/out/* /usr/local - sudo ldconfig - - - name: Run Tests - run: make test - - - name: Build App - run: make build - - name: Configure AWS credentials uses: aws-actions/configure-aws-credentials@v1 if: ${{ env.DEPLOY_PROD == 'true' || env.DEPLOY_STAGE == 'true' }} @@ -182,11 +75,11 @@ jobs: if: ${{ env.DEPLOY_PROD == 'true' || env.DEPLOY_STAGE == 'true' }} with: context: . - file: docker/partial.Dockerfile - # cache-from: | - # type=registry,ref=gha - # cache-to: | - # type=registry,ref=gha,mode=max + file: docker/full.Dockerfile + cache-from: | + type=gha + cache-to: | + type=gha,mode=max tags: | ${{ steps.login-ecr.outputs.registry }}/${{ (env.DEPLOY_PROD == 'true' && '7tv') || '7tv-stage' }}/image-processor:latest ${{ steps.login-ecr.outputs.registry }}/${{ (env.DEPLOY_PROD == 'true' && '7tv') || '7tv-stage' }}/image-processor:${{ github.sha }}