Skip to content

Add docker container and build script with sample #3

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
56 changes: 56 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Project specific
*.mp4
ffmpeg/*
libs/*

# Checkpoints and archives
**/.ipynb_checkpoints
*.pth
*.pth.*
*.tar
*.tar.*
*.zip
*.mp4
*.avi
*.out
*.npy
*.log

# DCN RFCN parameters
Deformable-ConvNets-py3/

# Generated logs
screenlog.*
*.log

# From torchvision
build/
dist/
docs/build
*.egg-info/

.coverage

# Python
*/**/__pycache__
*/__pycache__
*/*.pyc
*/**/*.pyc
*/**/**/*.pyc
*/**/*~
*~

# System
*.so*
*.dylib*
*/*.so*
*/*.dylib*

# VIM
*.swp
*.swo
.*.swp

# VSCode
*.code-workspace
.vscode/
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@ This is an incremental H.264 video codec based on x264 and FFmpeg that supports
- Multi-frame RoI encoding
- Macroblock-level error bound control

## Docker build
```sh
# build and run docker container
cd docker
make build
make run
# build and run modified x264 on sample images in assets/
cd myh264
./build.sh
```

## Build (MacOS and Linux)
X264 and FFmpeg need to be rebuilt each time a modification is made in any of the two directories. For now, it is required that you have access to sudo on linux command line. To build, simply run
```
Expand Down
Binary file added assets/frame-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/frame-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 26 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
#!/bin/bash

set -x

cd x264
./configure --enable-shared --disable-asm
make
sudo make install
cd ../ffmpeg
./configure --enable-libx264 --enable-gpl --enable-shared
make
sudo make install
cd ..
make clean
./configure --enable-shared --disable-asm --enable-pic
make -j8
make install
cd ..

git clone https://github.com/FFmpeg/FFmpeg.git ffmpeg
cd ffmpeg
git checkout n4.3
./configure --enable-libx264 --enable-gpl --enable-shared --disable-doc
make -j8 && make install
cd ..

mkdir -p libs
rm -rf libs/*
LIB_PATH=`realpath libs`

# copy libs to single dir
find "x264/" -name "*.so.*" -exec cp {} libs/ \;
find "ffmpeg/" -name "*.so.*" -exec cp {} libs/ \;

LD_LIBRARY_PATH=$LIB_PATH ./ffmpeg/ffmpeg -y -loglevel debug -pix_fmt yuv420p -i assets/frame-%d.png -start_number 0 video.mp4
8 changes: 8 additions & 0 deletions conda/build_conda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

set -eou pipefail

docker run -it --rm \
-v `pwd`/..:/home/myh264 \
"pytorch/conda-cuda:latest" \
/bin/bash
29 changes: 29 additions & 0 deletions conda/recipe_ffmpeg/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# unset the SUBDIR variable since it changes the behavior of make here
unset SUBDIR

if [[ "$(uname)" == Darwin ]]; then
export CONDA_BUILD_SYSROOT=$(xcode-select -p)/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk
fi

./configure \
--prefix="${PREFIX}" \
--cc=${CC} \
--disable-doc \
--enable-avresample \
--enable-gnutls \
--enable-hardcoded-tables \
--enable-libfreetype \
--enable-libx264 \
--enable-gpl \
--enable-pic \
--enable-pthreads \
--enable-shared \
--disable-static \
--enable-version3 \
--enable-zlib \
--enable-libmp3lame

make -j${CPU_COUNT}
make install -j${CPU_COUNT}
76 changes: 76 additions & 0 deletions conda/recipe_ffmpeg/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{% set version = "n4.3" %}

package:
name: ffmpeg_custom
version: {{ version }}

source:
git_rev: {{ version }}
git_url: https://github.com/FFmpeg/FFmpeg.git

build:
number: 0

requirements:
build:
- {{ compiler("c") }}
- {{ compiler("cxx") }}
- pkg-config # [not win]
- libtool # [not win]
- nasm # [not win]
- lame # [not win]
- make # [not win]
host:
- bzip2
- libpng
- freetype
- gnutls # [not win]
- libiconv
- zlib
- necla-ml::x264=0.1
- lame # [not win]
- gmp # [unix]
- nettle # [not win]
run:
- bzip2
- libpng
- freetype
- gnutls # [not win]
- libiconv
- zlib
- necla-ml::x264=0.1 # [not win]
- lame # [not win]
- gmp # [unix]
- nettle # [not win]

test:
commands:
- ffmpeg --help
- ffmpeg -loglevel panic -protocols | grep "https" # [not win]
- ffmpeg -loglevel panic -codecs | grep "libmp3lame" # [not win]
- ffmpeg -loglevel panic -codecs | grep "DEVI.S zlib" # [unix]
- ffmpeg -loglevel panic -codecs | grep "DEV.LS h264" # [unix]
- ffmpeg -loglevel panic -codecs | grep "x264" # [unix]
# Verify dynamic libraries on all systems
{% set ffmpeg_libs = [
"avcodec",
"avdevice",
"swresample",
"avfilter",
"swresample",
"avcodec",
"avformat",
"swscale",
"avresample"
] %}
{% for each_ffmpeg_lib in ffmpeg_libs %}
- test -f $PREFIX/lib/lib{{ each_ffmpeg_lib }}.dylib # [osx]
- test -f $PREFIX/lib/lib{{ each_ffmpeg_lib }}.so # [linux]
{% endfor %}
- conda inspect linkages -p $PREFIX $PKG_NAME # [not win]
- conda inspect objects -p $PREFIX $PKG_NAME # [osx]

about:
home: http://www.ffmpeg.org/
license: LGPL
summary: Custom ffmpeg for incremental x264
28 changes: 28 additions & 0 deletions conda/recipe_x264/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
# Get an updated config.sub and config.guess
cp $BUILD_PREFIX/share/gnuconfig/config.* .
set -xe
mkdir -vp ${PREFIX}/bin

# Set the assembler to `nasm`
if [[ ${target_platform} == "linux-64" || ${target_platform} == osx-64 ]]; then
export AS="${BUILD_PREFIX}/bin/nasm"
fi

if [[ "${target_platform}" == *-aarch64 || "${target_platform}" == *-arm64 ]]; then
unset AS
fi

cd /home/myh264/x264

chmod +x configure
# Using --system-libx264 links the executable to the shared lib not the static library
./configure \
--host=$HOST \
--enable-pic \
--enable-shared \
--system-libx264 \
--prefix=${PREFIX}

make -j${CPU_COUNT}
make install -j${CPU_COUNT}
29 changes: 29 additions & 0 deletions conda/recipe_x264/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% set version = '0.1' %}
package:
name: x264
version: {{ version }}

build:
number: 1

requirements:
build:
- gnuconfig # [unix]
- {{ compiler("c") }}
- perl
- nasm
- make
- {{ posix }}bash # [win]
- {{ posix }}coreutils # [win]
- {{ posix }}grep # [win]
- {{ posix }}sed # [win]

test:
commands:
- x264 --help

about:
home: https://github.com/Alex-q-z/myh264
license: GPL-2.0-or-later
summary: Incremental x264 for macroblock level error bound control
dev_url: https://github.com/Alex-q-z/myh264
42 changes: 42 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
ARG OS_VERSION=18.04
FROM ubuntu:${OS_VERSION}

# Set home dir
WORKDIR /home
ENV HOME="/home"

SHELL ["/bin/bash", "-c"]

# [X] Install min essentials
# [X] Install miniconda
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
ca-certificates \
software-properties-common \
autoconf \
automake \
build-essential \
cmake \
git-core \
libass-dev \
libfreetype6-dev \
libgnutls28-dev \
libmp3lame-dev \
libsdl2-dev \
libtool \
libva-dev \
libvdpau-dev \
libvorbis-dev \
libxcb1-dev \
libxcb-shm0-dev \
libxcb-xfixes0-dev \
meson \
ninja-build \
pkg-config \
texinfo \
wget \
yasm \
zlib1g-dev

SHELL ["/bin/bash", "-c"]
14 changes: 14 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
TAG=ffmpeg:env

# Build
build:
docker build --tag=$(TAG) .

build-no_cache:
docker build --no-cache --tag=$(TAG) .

run:
docker run -it --rm \
--ipc=host \
-v $$(pwd)/..:/home/myh264 \
$(TAG)
Binary file removed ffmpeg/.DS_Store
Binary file not shown.
25 changes: 0 additions & 25 deletions ffmpeg/.mailmap

This file was deleted.

Loading