Skip to content

Instantly share code, notes, and snippets.

@blachniet
Created February 15, 2020 12:57
Show Gist options
  • Save blachniet/8c19cfdfbaa8774f2dca44a18627591b to your computer and use it in GitHub Desktop.
Save blachniet/8c19cfdfbaa8774f2dca44a18627591b to your computer and use it in GitHub Desktop.
Build libogg and liboggz in Docker containers
FROM golang:buster AS oggzit-build
WORKDIR /go/src/oggzit
COPY . .
RUN go install -v ./...
FROM debian:buster AS oggz-install
WORKDIR /root
RUN apt-get update && apt-get install -y \
automake \
build-essential \
curl \
git \
libtool \
pkg-config \
&& rm -rf /var/lib/apt/lists/* \
&& git clone https://github.com/xiph/ogg.git \
&& git clone git://git.xiph.org/liboggz.git
WORKDIR /root/ogg
RUN ./autogen.sh \
&& ./configure \
&& make install
WORKDIR /root/liboggz
RUN ./autogen.sh \
&& ./configure \
&& make install
WORKDIR /root/samples
RUN curl -L https://people.xiph.org/~giles/2012/opus/ehren-paper_lights-96.opus --output ehren-paper_lights-96.opus \
&& curl -L https://www.w3schools.com/html/mov_bbb.ogg --output mov_bbb.ogg \
&& curl -L https://www.w3schools.com/html/horse.ogg --output horse.ogg
FROM debian:buster as oggz
COPY --from=oggzit-build /go/bin/oggzit /usr/local/bin/oggzit
COPY --from=oggz-install /usr/local/bin/oggz* /usr/local/bin/
COPY --from=oggz-install /usr/local/lib/libogg* /usr/local/lib/
COPY --from=oggz-install /root/samples/* /tmp/samples/
ENV LD_LIBRARY_PATH=/usr/local/lib/
ENV PORT=3000
CMD ["oggzit"]
FROM centos:7.7.1908
ENV LD_LIBRARY_PATH=/usr/local/lib
WORKDIR /root
RUN yum install -y \
automake \
curl \
gcc \
git \
libtool \
make \
&& git clone https://github.com/xiph/ogg.git \
&& git clone git://git.xiph.org/liboggz.git
WORKDIR /root/ogg
RUN ./autogen.sh \
&& ./configure \
&& make install
WORKDIR /root/liboggz
RUN ./autogen.sh \
&& ./configure \
&& make install
WORKDIR /root/samples
RUN curl -L https://people.xiph.org/~giles/2012/opus/ehren-paper_lights-96.opus --output ehren-paper_lights-96.opus \
&& curl -L https://www.w3schools.com/html/mov_bbb.ogg --output mov_bbb.ogg \
&& curl -L https://www.w3schools.com/html/horse.ogg --output horse.ogg
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "oggz/oggz.h"
int main() {
OggzStreamContent content;
const char * content_types[OGGZ_CONTENT_UNKNOWN];
printf("Hello World!\n");
/* Collect the content type names, filtering out deprecated and
duplicates ones */
for (content = 0; content < OGGZ_CONTENT_UNKNOWN; content++) {
switch (content) {
case OGGZ_CONTENT_FLAC0:
case OGGZ_CONTENT_ANXDATA:
content_types[content] = NULL;
break;
default:
content_types[content] = oggz_content_type(content);
break;
}
}
/* Sort them */
// qsort (content_types, OGGZ_CONTENT_UNKNOWN, sizeof (char *),
// (qsort_func) cmpstringp);
/* Print them */
for (content = 0; content < OGGZ_CONTENT_UNKNOWN; content++) {
if (content_types[content])
puts (content_types[content]);
}
return 0;
}
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"os/exec"
"github.com/gorilla/mux"
)
func main() {
port := os.Getenv("PORT")
if port == "" {
port = "3000"
}
r := mux.NewRouter()
r.HandleFunc("/", oggzGet("help")).Methods("GET")
s := r.PathPrefix("/help").Subrouter()
s.HandleFunc("/", oggzGet("help")).Methods("GET")
s.HandleFunc("/codecs", oggzGet("help", "codecs")).Methods("GET")
s.HandleFunc("/dump", oggzGet("help", "dump")).Methods("GET")
s.HandleFunc("/info", oggzGet("help", "info")).Methods("GET")
s.HandleFunc("/scan", oggzGet("help", "scan")).Methods("GET")
s.HandleFunc("/known-codecs", oggzGet("help", "known-codecs")).Methods("GET")
r.HandleFunc("/codecs", oggzPut("codecs", "-1")).Methods("POST", "PUT")
r.HandleFunc("/dump", oggzPut("dump")).Methods("POST", "PUT")
r.HandleFunc("/info", oggzPut("info")).Methods("POST", "PUT")
r.HandleFunc("/scan", oggzPut("scan")).Methods("POST", "PUT")
r.HandleFunc("/known-codecs", oggzGet("known-codecs")).Methods("GET")
http.Handle("/", r)
log.Printf("Listening on %v", port)
http.ListenAndServe(fmt.Sprintf(":%v", port), r)
}
func oggzGet(args ...string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cmd := exec.Command("oggz", args...)
cmd.Stdout = w
err := cmd.Run()
if err != nil {
fmt.Fprint(w, "error running commnand")
return
}
}
}
func oggzPut(args ...string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
tempFile, err := ioutil.TempFile("", "oggzit-upload-*.ogg")
if err != nil {
fmt.Fprintf(w, "error creating temp file")
log.Printf("error creating temp file: %v", err)
return
}
defer tempFile.Close()
defer os.Remove(tempFile.Name())
_, err = io.Copy(tempFile, r.Body)
if err != nil {
fmt.Fprintf(w, "error writing to temp file")
log.Printf("error creating temp file: %v", err)
return
}
args := append(args, tempFile.Name())
cmd := exec.Command("oggz", args...)
cmd.Stdout = w
err = cmd.Run()
if err != nil {
fmt.Fprintf(w, "error running command")
log.Printf("error running command: %v", err)
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment