2
0
Эх сурвалжийг харах

Merge pull request #83 from tsoding/4

(#4) Render video on CI
Alexey Kutepov 5 жил өмнө
parent
commit
9ddaf72d73

+ 39 - 6
.github/workflows/ci.yml

@@ -2,8 +2,6 @@ name: CI
 on: [push, pull_request]
 
 jobs:
-# TODO(#4): Linux build doesn't render the video sample
-
   build-linux-gcc:
     runs-on: ubuntu-18.04
     steps:
@@ -11,13 +9,31 @@ jobs:
       - name: install dependencies
         run: |
           sudo apt-get update
-          sudo apt-get install -qq libfreetype6-dev libgif-dev libpng-dev libavutil-dev libavcodec-dev libcurl4-openssl-dev
-      - name: build the application
+          sudo apt-get install -qq nasm libfreetype6-dev libcurl4-openssl-dev
+      - uses: actions/cache@v2
+        with:
+          # TODO(#84): centralize third party versions in the build
+          path: |
+            ./third_party/ffmpeg-4.3-dist/
+            ./third_party/giflib-5.2.1-dist/
+          key: ${{ runner.os }}-ffmpeg-4.3-giflib-5.2.1
+      - name: build third-party things
+        run: |
+          cd third_party
+          ./build_third_party.sh
+          cd ..
+      - name: build vodus
         run: |
           make -B
+          ./emote_downloader
+          make render
         env:
           CC: gcc
           CXX: g++
+      - uses: actions/upload-artifact@v2
+        with:
+          name: output.mpeg
+          path: ./output.mpeg
 
   build-linux-clang:
     runs-on: ubuntu-18.04
@@ -26,13 +42,30 @@ jobs:
       - name: install dependencies
         run: |
           sudo apt-get update
-          sudo apt-get install -qq libfreetype6-dev libgif-dev libpng-dev libavutil-dev libavcodec-dev libcurl4-openssl-dev
-      - name: build the application
+          sudo apt-get install -qq nasm libfreetype6-dev libcurl4-openssl-dev
+      - uses: actions/cache@v2
+        with:
+          path: |
+            ./third_party/ffmpeg-4.3-dist/
+            ./third_party/giflib-5.2.1-dist/
+          key: ${{ runner.os }}-ffmpeg-4.3-giflib-5.2.1
+      - name: build third-party things
+        run: |
+          cd third_party
+          ./build_third_party.sh
+          cd ..
+      - name: build vodus
         run: |
           make -B
+          ./emote_downloader
+          make render
         env:
           CC: clang
           CXX: clang++
+      - uses: actions/upload-artifact@v2
+        with:
+          name: output.mpeg
+          path: ./output.mpeg
 
 # TODO(#5): no MacOS build
 # TODO(#8): no Windows build

+ 1 - 0
.gitignore

@@ -7,3 +7,4 @@ emote_downloader
 emotes/
 TAGS
 mapping.csv
+.vscode/

+ 4 - 4
Makefile

@@ -1,12 +1,12 @@
-VODUS_PKGS=freetype2 libavcodec libavutil
-VODUS_CXXFLAGS=-Wall -fno-exceptions -std=c++17 -ggdb `pkg-config --cflags $(VODUS_PKGS)`
-VODUS_LIBS=`pkg-config --libs $(VODUS_PKGS)` -lgif
+VODUS_PKGS=freetype2
+VODUS_CXXFLAGS=-Wall -fno-exceptions -std=c++17 -ggdb `pkg-config --cflags $(VODUS_PKGS)` -I./third_party/ffmpeg-4.3-dist/usr/local/include/ -I./third_party/giflib-5.2.1-dist/usr/local/include/
+VODUS_LIBS=`pkg-config --libs $(VODUS_PKGS)` -L./third_party/giflib-5.2.1-dist/usr/local/lib/ -l:libgif.a -L./third_party/ffmpeg-4.3-dist/usr/local/lib/ -lavcodec -lavutil -lswresample -pthread -lm -llzma -lz
 
 EMOTE_DOWNLOADER_PKGS=libcurl
 EMOTE_DOWNLOADER_CXXFLAGS=-Wall -fno-exceptions -std=c++17 -ggdb `pkg-config --cflags $(EMOTE_DOWNLOADER_PKGS)`
 EMOTE_DOWNLOADER_LIBS=`pkg-config --libs $(EMOTE_DOWNLOADER_PKGS)`
 
-RENDER_ARGS=--font assets/ComicNeue_Bold.otf --output output.mpeg --font-size 46 --fps 30 --width 600 --height 1080 --limit 20 sample.txt --bitrate 6000000
+RENDER_ARGS=--font assets/ComicNeue_Bold.otf --output output.mpeg --font-size 46 --fps 30 --width 704 --height 576 --limit 20 sample.txt --bitrate 6000000
 
 .PHONY: all
 all: vodus.release vodus.debug emote_downloader Makefile

+ 38 - 8
README.md

@@ -10,14 +10,44 @@ changed at any moment or stop working at all.**
 
 ## Quick Start
 
+### Install Dependencies
+
+#### Debian
+
+```console
+$ sudo apt-get install nasm libfreetype6-dev libcurl4-openssl-dev
+```
+
+#### NixOS
+
 ```console
-$ # Install Dependencies
-$ ## Debian
-$ sudo apt-get install libfreetype6-dev libgif-dev libavutil-dev libavcodec-dev libcurl4-openssl-dev
-$ ## NixOS
 $ nix-shell
-$ ## (add your distro here)
-$ # Build
-$ make            # build vodus executable
-$ make render     # test rendering (produces output.mpeg file)
+```
+
+### Build Third Party dependencies
+
+Needs to be done only once.
+
+``` console
+$ cd third_party/
+$ ./build_third_party.sh
+$ cd ..
+```
+
+### Build the Project
+
+```console
+$ make
+```
+
+### Download Emotes
+
+```console
+$ ./emote_downloader
+```
+
+### Render the Sample Video
+
+```console
+$ make render
 ```

+ 1 - 1
src/emote_downloader.cpp

@@ -34,7 +34,7 @@ struct Fixed_Array
     }
 };
 
-const size_t DEFAULT_STRING_BUFFER_CAPACITY = 20 * 1024;
+const size_t DEFAULT_STRING_BUFFER_CAPACITY = 20 * 1024 * 1024;
 
 template <size_t Capacity = DEFAULT_STRING_BUFFER_CAPACITY>
 struct String_Buffer

+ 11 - 6
src/vodus_emotes.cpp

@@ -1,5 +1,6 @@
 struct Gif_Animat
 {
+    String_View file_path;
     GifFileType *file;
     size_t index;
     GraphicsControlBlock gcb;
@@ -18,7 +19,10 @@ struct Gif_Animat
         while (delay_time <= 0.0f) {
             index = (index + 1) % file->ImageCount;
             int ok = DGifSavedExtensionToGCB(file, index, &gcb);
-            assert(ok);
+            if (!ok) {
+                println(stderr, "[ERROR] Could not retrieve Graphics Control Block from `", file_path, "`");
+                abort();
+            }
             delay_time = gcb.DelayTime + delay_time;
         }
     }
@@ -121,17 +125,18 @@ String_View file_extension(String_View filename)
     return ext;
 }
 
-Emote load_gif_emote(String_View filepath)
+Emote load_gif_emote(String_View file_path)
 {
     Emote emote = {Emote::Gif};
 
-    auto filepath_cstr = string_view_as_cstr(filepath);
-    defer(delete[] filepath_cstr);
+    auto file_path_cstr = string_view_as_cstr(file_path);
+    defer(delete[] file_path_cstr);
 
     int error = 0;
-    emote.gif.file = DGifOpenFileName(filepath_cstr, &error);
+    emote.gif.file_path = file_path;
+    emote.gif.file = DGifOpenFileName(file_path_cstr, &error);
     if (error) {
-        println(stderr, "Could not read gif file: ", filepath);
+        println(stderr, "Could not read gif file: ", file_path);
         exit(1);
     }
     assert(error == 0);

+ 14 - 1
src/vodus_main.cpp

@@ -458,6 +458,19 @@ Maybe<Pixel32> hexstr_as_pixel32(String_View hexstr)
     return {true, result};
 }
 
+int main_()
+{
+    void *iterator = NULL;
+    const AVCodec *codec = NULL;
+    println(stdout, "Probably available codecs:");
+    while ((codec = av_codec_iterate(&iterator))) {
+        if (avcodec_find_encoder_by_name(codec->name)) {
+            println(stdout, "  ", codec->name);
+        }
+    }
+    return 0;
+}
+
 int main(int argc, char *argv[])
 {
     const char *log_filepath = nullptr;
@@ -632,7 +645,7 @@ int main(int argc, char *argv[])
     context->time_base = (AVRational){1, (int) params.fps};
     context->framerate = (AVRational){(int) params.fps, 1};
     context->gop_size = 10;
-    context->max_b_frames = 1;
+    // context->max_b_frames = 1;
     context->pix_fmt = AV_PIX_FMT_YUV420P;
 
     AVPacket *packet = fail_if_null(

+ 5 - 0
third_party/.gitignore

@@ -0,0 +1,5 @@
+*.tar.xz
+*.tar.gz
+*-dist/
+ffmpeg-*/
+giflib-*/

+ 28 - 0
third_party/build_third_party.sh

@@ -0,0 +1,28 @@
+#!/bin/sh
+
+FFMPEG_VERSION=4.3
+GIFLIB_VERSION=5.2.1
+
+if [ ! -d "ffmpeg-${FFMPEG_VERSION}-dist" ]; then
+    wget "https://ffmpeg.org/releases/ffmpeg-${FFMPEG_VERSION}.tar.xz"
+    tar fvx "ffmpeg-${FFMPEG_VERSION}.tar.xz"
+    mkdir "ffmpeg-${FFMPEG_VERSION}-dist"
+    
+    cd "ffmpeg-${FFMPEG_VERSION}"
+      ./configure --disable-doc --disable-programs
+      make -j5
+      DESTDIR="../ffmpeg-${FFMPEG_VERSION}-dist" make install
+    cd ..
+fi
+
+if [ ! -d "giflib-${GIFLIB_VERSION}-dist" ]; then
+    wget "https://deac-riga.dl.sourceforge.net/project/giflib/giflib-${GIFLIB_VERSION}.tar.gz"
+    tar fvx "giflib-${GIFLIB_VERSION}.tar.gz"
+    mkdir "giflib-${GIFLIB_VERSION}-dist"
+
+    cd "giflib-${GIFLIB_VERSION}"
+      make -j5
+      DESTDIR="../giflib-${GIFLIB_VERSION}-dist" make install
+    cd ..
+fi
+