Skip to content

Commit

Permalink
ffmpeg API update (ch_layout)
Browse files Browse the repository at this point in the history
  • Loading branch information
ancientstraits committed Dec 23, 2022
1 parent d59e49a commit c3d6475
Show file tree
Hide file tree
Showing 6 changed files with 7,724 additions and 43 deletions.
45 changes: 45 additions & 0 deletions gltexture.c
@@ -0,0 +1,45 @@
#include <stdio.h>
#include <epoxy/gl.h>
#include <GLFW/glfw3.h>
#include "stb_image.h"

#define LOG(...) do { \
fprintf(stderr, "%s:%s():%d: ", __FILE__, __func__, __LINE__); \
fprintf(stderr, __VA_ARGS__); \
fputc('\n', stderr); \
} while(0)

#define FAIL(...) do { LOG("Error: " __VA_ARGS__); exit(1); } while(0)

#define ASSERT(cond, ...) if (!(cond)) FAIL(__VA_ARGS__)

#define GL() do { \
GLenum err = glGetError(); \
ASSERT(err == GL_NO_ERROR, "OpenGL error: %d", err); \
} while(0)


int main(int argc, char** argv) {
if (argc < 2) {
fprintf(stderr, "Usage: %s [image]", argv[0]);
return 1;
}
int img_w, img_h, img_ch;
uint8_t* img = stbi_load(argv[1], &img_w, &img_h, &img_ch, 4);

ASSERT(glfwInit() == GLFW_TRUE, "Failed to initialize GLFW");
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
#ifdef __APPLE__
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE);
#endif

GLFWwindow* win = glfwCreateWindow(img_w, img_h, "GL Texture", NULL, NULL);
ASSERT(win, "Failed to create GLFW window");
glfwMakeContextCurrent(win);

stbi_image_free(img);
return 0;
}
28 changes: 0 additions & 28 deletions gltri.c

This file was deleted.

Binary file modified out.mp4
Binary file not shown.
18 changes: 10 additions & 8 deletions src/main.c
Expand Up @@ -31,14 +31,16 @@ int main() {
return 1;
}


OutputContext* oc = output_create("out.mp4",
&(OutputAudioOpts) {
.sample_rate = 44100,
}, &(OutputVideoOpts) {
.fps = 24,
.width = 1920,
.height = 1080,
});
&(OutputAudioOpts) {
.sample_rate = 44100,
}, &(OutputVideoOpts) {
.fps = 24,
.width = 1920,
.height = 1080,
}
);

output_open(oc);

Expand All @@ -61,7 +63,7 @@ int main() {
int16_t *data = (int16_t *)oc->afd->data[0];
for (int i = 0; i < oc->afd->nb_samples; i++) {
int v = sin(at) * 10000;
for (int j = 0; j < oc->acc->channels; j++)
for (int j = 0; j < oc->acc->ch_layout.nb_channels; j++)
*data++ = v;
at += atincr;
atincr += atincr2;
Expand Down
20 changes: 13 additions & 7 deletions src/output.c
Expand Up @@ -54,10 +54,15 @@ OutputContext* output_create(
oc->fc, &oc->ac, &oc->ap, &oc->as, &oc->acc);

oc->acc->sample_fmt = AV_SAMPLE_FMT_FLTP;
oc->acc->sample_rate = ao->sample_rate;
oc->acc->channels = av_get_channel_layout_nb_channels(oc->acc->channel_layout);
oc->acc->channel_layout = AV_CH_LAYOUT_STEREO;
oc->as->time_base = (AVRational){1, oc->acc->sample_rate};
oc->acc->sample_rate = ao->sample_rate;

// !! KEY !!
//oc->acc->channels = av_get_channel_layout_nb_channels(oc->acc->channel_layout);
//oc->acc->channel_layout = AV_CH_LAYOUT_STEREO;
av_channel_layout_copy(&oc->acc->ch_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO);


oc->as->time_base = (AVRational){1, oc->acc->sample_rate};
}

if (oc->has_video) {
Expand All @@ -82,7 +87,8 @@ static AVFrame* create_audio_frame(AVCodecContext* acc,
if (!f) ODIE_ALLOCATE_ERR("AVFrame");

f->format = sample_fmt;
f->channel_layout = acc->channel_layout;
//f->channel_layout = acc->channel_layout;
av_channel_layout_copy(&f->ch_layout, &acc->ch_layout);
f->sample_rate = acc->sample_rate;
f->nb_samples = nb_samples;
int errnum = av_frame_get_buffer(f, 0);
Expand All @@ -97,10 +103,10 @@ static SwrContext* create_swr_context(AVCodecContext* acc) {
SwrContext* ret = swr_alloc();
if (!ret) ODIE_ALLOCATE_ERR("SwrContext");

av_opt_set_int(ret, "in_channel_count", acc->channels, 0);
av_opt_set_int(ret, "in_channel_count", acc->ch_layout.nb_channels, 0);
av_opt_set_int(ret, "in_sample_rate", acc->sample_rate, 0);
av_opt_set_sample_fmt(ret, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);
av_opt_set_int(ret, "out_channel_count", acc->channels, 0);
av_opt_set_int(ret, "out_channel_count", acc->ch_layout.nb_channels, 0);
av_opt_set_int(ret, "out_sample_rate", acc->sample_rate, 0);
av_opt_set_sample_fmt(ret, "out_sample_fmt", acc->sample_fmt, 0);
int errnum = swr_init(ret);
Expand Down

0 comments on commit c3d6475

Please sign in to comment.