tmp
authoryu.dongliang <18588496441@163.com>
Fri, 14 Apr 2023 12:55:21 +0000 (20:55 +0800)
committeryu.dongliang <18588496441@163.com>
Fri, 14 Apr 2023 12:55:21 +0000 (20:55 +0800)
Makefile
main.c
simp.c
simp.h
simp_ffmpeg_alsa.c

index b7c494836f476d3d312538fc230e4a7e4b14a1c1..37b2e305d8fe7e95662dd1070b0d2b50fca53177 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -10,7 +10,7 @@ CFLAGS += -g -O3
 CFLAGS += -I./
 CFLAGS += `pkg-config --cflags gtk+-3.0`
 
-LDFLAGS += -lavformat -lavcodec -lavfilter -lavutil
+LDFLAGS += -lavdevice -lavformat -lavcodec -lavfilter -lavutil
 LDFLAGS += -lGL
 LDFLAGS += `pkg-config --libs gtk+-3.0`
 
diff --git a/main.c b/main.c
index 4dac9f1021cb077aabd3cb44de6d654b68b4ba63..7fb7d7317d9aadaa3e21eb669856ed0b18d55f02 100644 (file)
--- a/main.c
+++ b/main.c
@@ -12,9 +12,12 @@ int main(int argc, char* argv[])
                return -1;
        }
 
-       simp_filter_t* f   = NULL;
-       simp_avio_t*   in  = NULL;
-       simp_avio_t*   out = NULL;
+       avdevice_register_all();
+
+       simp_filter_t* f    = NULL;
+       simp_avio_t*   in   = NULL;
+       simp_avio_t*   out  = NULL;
+       simp_avio_t*   alsa = NULL;
 
        if (simp_avio_open(&in, "ffmpeg_input", argv[1], NULL) < 0) {
                scf_loge("\n");
@@ -26,6 +29,11 @@ int main(int argc, char* argv[])
                return -1;
        }
 
+       if (simp_avio_open(&alsa, "ffmpeg_alsa", NULL, "hw:0") < 0) {
+               scf_loge("\n");
+               return -1;
+       }
+
        if (simp_filter_open(&f) < 0) {
                scf_loge("\n");
                return -1;
@@ -33,8 +41,9 @@ int main(int argc, char* argv[])
 
        simp_filter_add_input (f, in);
        simp_filter_add_output(f, out);
+       simp_filter_add_output(f, alsa);
 
-       f->speed.num = 200;
+       f->speed.num = 1;
        f->speed.den = 1;
 
        if (simp_filter_run(f) < 0) {
@@ -42,6 +51,11 @@ int main(int argc, char* argv[])
                return -1;
        }
 
+       if (simp_avio_run(alsa) < 0) {
+               scf_loge("\n");
+               return -1;
+       }
+
        if (simp_avio_run(out) < 0) {
                scf_loge("\n");
                return -1;
diff --git a/simp.c b/simp.c
index 2b8acda60ecc1742af1b2449def05c2f6b0cfb34..5fa4a6d32a33256541938fd451a5c5e0e933b351 100644 (file)
--- a/simp.c
+++ b/simp.c
@@ -2,11 +2,13 @@
 
 extern simp_avio_ops_t   simp_avio_ffmpeg_input;
 extern simp_avio_ops_t   simp_avio_ffmpeg_output;
+extern simp_avio_ops_t   simp_avio_ffmpeg_alsa;
 
 static simp_avio_ops_t*  avio_array[] =
 {
        &simp_avio_ffmpeg_input,
        &simp_avio_ffmpeg_output,
+       &simp_avio_ffmpeg_alsa,
        NULL,
 };
 
diff --git a/simp.h b/simp.h
index 3cab8e7b2e3a8e313d61b78671da9e9cd101de25..cf706c6357fc8faa8a72ef20dc1be93d9e6e071e 100644 (file)
--- a/simp.h
+++ b/simp.h
@@ -6,6 +6,7 @@
 
 #include "libavformat/avformat.h"
 #include "libavcodec/avcodec.h"
+#include "libavdevice/avdevice.h"
 #include "libavutil/avutil.h"
 #include "libavutil/opt.h"
 #include "libavfilter/avfilter.h"
index eb51552dee2ff8fa8ed8c95cd7935dfc1f0336f4..91bca41bb7a8d3b28e222183e28d9bed65723a3a 100644 (file)
@@ -70,9 +70,13 @@ static int _audio_output_init(simp_audio_t* priv, const char* path)
        AVStream*       s   = NULL;
        AVCodec*        c;
 
+       scf_loge("out: %p\n", out);
+
        avformat_alloc_output_context2(&priv->ctx_out, out, NULL, path);
-       if (!priv->ctx_out)
+       if (!priv->ctx_out) {
+               scf_loge("\n");
                return -ENOMEM;
+       }
 
        c = avcodec_find_encoder(priv->codec_in->codec_id);
        if (!c)
@@ -185,12 +189,14 @@ static int _ffmpeg_alsa_open(simp_avio_t* io, const char* in, const char* out)
        priv->idx_out = -1;
 
        if (in) {
+               scf_loge("in: %s\n", in);
                ret = _audio_input_init(priv, in);
                if (ret < 0)
                        goto error;
        }
 
        if (out) {
+               scf_loge("out: %s\n", out);
                ret = _audio_output_init(priv, out);
                if (ret < 0)
                        goto error;