Update libx264 build and main.cpp with more fields.

This commit is contained in:
Alf
2020-09-28 22:14:13 -07:00
parent 00d4b8fdba
commit 0d3ba47d8b
2 changed files with 54 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
FROM emscripten/emsdk as build
ARG FFMPEG_VERSION=4.3.1
ARG X264_VERSION=master
ARG X264_VERSION=20170226-2245-stable
ARG PREFIX=/opt/ffmpeg
ARG MAKEFLAGS="-j4"
@@ -9,11 +9,11 @@ ARG MAKEFLAGS="-j4"
RUN apt-get update && apt-get install -y autoconf libtool build-essential
# libx264
RUN cd /tmp/ && \
wget https://code.videolan.org/videolan/x264/-/archive/master/x264-master.tar.gz && \
tar zxf x264-${X264_VERSION}.tar.gz
RUN cd /tmp && \
wget https://download.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-${X264_VERSION}.tar.bz2 && \
tar xvfj x264-snapshot-${X264_VERSION}.tar.bz2
RUN cd /tmp/x264-${X264_VERSION} && \
RUN cd /tmp/x264-snapshot-${X264_VERSION} && \
emconfigure ./configure \
--prefix=${PREFIX} \
--host=i686-gnu \
@@ -22,8 +22,8 @@ RUN cd /tmp/x264-${X264_VERSION} && \
--disable-asm \
--extra-cflags="-s USE_PTHREADS=1"
RUN cd /tmp/x264-${X264_VERSION} && \
emmake make install-lib-static -j4
RUN cd /tmp/x264-snapshot-${X264_VERSION} && \
emmake make && emmake make install
# Get ffmpeg source.
RUN cd /tmp/ && \
@@ -72,6 +72,6 @@ RUN cd /tmp/ffmpeg-${FFMPEG_VERSION} && \
# -o ffmpeg-webtools.js
WORKDIR /build
COPY ./src/main.c /build/src/main.c
# COPY ./src/main.c /build/src/main.c
COPY ./Makefile /build/Makefile
# RUN make

View File

@@ -1,4 +1,6 @@
#include <vector>
#include <string>
#include <inttypes.h>
#include <emscripten.h>
#include <emscripten/bind.h>
@@ -8,21 +10,28 @@ extern "C" {
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#include <libavutil/imgutils.h>
};
const std::string c_avformat_version() {
return AV_STRINGIFY(LIBAVFORMAT_VERSION);
}
struct Stream {
typedef struct Stream {
int id;
int start_time;
int duration;
int codec_type;
};
typedef struct Stream Stream;
std::string codec_name;
std::string format;
int bit_rate;
std::string profile;
int level;
int width;
int height;
} Stream;
struct FileInfoResponse {
typedef struct FileInfoResponse {
std::string name;
int bit_rate;
int duration;
@@ -30,8 +39,7 @@ struct FileInfoResponse {
int nb_streams;
int flags;
std::vector<Stream> streams;
};
typedef struct FileInfoResponse FileInfoResponse;
} FileInfoResponse;
FileInfoResponse get_file_info() {
FILE *file = fopen("file", "rb");
@@ -52,6 +60,11 @@ FileInfoResponse get_file_info() {
printf("%s", av_err2str(ret));
}
// Get stream info from format.
if (avformat_find_stream_info(pFormatContext, NULL) < 0) {
printf("ERROR: could not get stream info\n");
}
// Initialize response struct with format data.
FileInfoResponse r = {
.name = pFormatContext->iformat->name,
@@ -71,13 +84,30 @@ FileInfoResponse get_file_info() {
for (int i = 0; i < pFormatContext->nb_streams; i++) {
AVCodecParameters *pLocalCodecParameters = NULL;
pLocalCodecParameters = pFormatContext->streams[i]->codecpar;
Stream s = {
// Convert to char byte array.
uint32_t n = pLocalCodecParameters->codec_tag;
char fourcc[5];
for (int j = 0; j < 4; ++j) {
fourcc[j] = (n >> (j * 8) & 0xFF);
}
fourcc[4] = 0x00; // NULL terminator.
Stream stream = {
.id = (int)pFormatContext->streams[i]->id,
.start_time = (int)pFormatContext->streams[i]->start_time,
.duration = (int)pFormatContext->streams[i]->duration,
.codec_type = (int)pLocalCodecParameters->codec_type
.codec_type = (int)pLocalCodecParameters->codec_type,
.codec_name = fourcc,
.format = av_get_pix_fmt_name((AVPixelFormat)pLocalCodecParameters->format),
.bit_rate = (int)pLocalCodecParameters->bit_rate,
.profile = avcodec_profile_name(pLocalCodecParameters->codec_id, pLocalCodecParameters->profile),
.level = (int)pLocalCodecParameters->level,
.width = (int)pLocalCodecParameters->width,
.height = (int)pLocalCodecParameters->height,
};
r.streams.push_back(s);
r.streams.push_back(stream);
free(fourcc);
}
return r;
}
@@ -93,6 +123,13 @@ EMSCRIPTEN_BINDINGS(FileInfoResponse_struct) {
.field("start_time", &Stream::start_time)
.field("duration", &Stream::duration)
.field("codec_type", &Stream::codec_type)
.field("codec_name", &Stream::codec_name)
.field("format", &Stream::format)
.field("bit_rate", &Stream::bit_rate)
.field("profile", &Stream::profile)
.field("level", &Stream::level)
.field("width", &Stream::width)
.field("height", &Stream::height)
;
register_vector<Stream>("Stream");
emscripten::value_object<FileInfoResponse>("FileInfoResponse")