]> git.sesse.net Git - nageru/commitdiff
Switch to uncompressed (32-bit) PCM. Saves a little CPU processing power. Also requir...
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 14 Nov 2015 00:50:55 +0000 (01:50 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sat, 14 Nov 2015 00:50:55 +0000 (01:50 +0100)
defs.h
h264encode.cpp

diff --git a/defs.h b/defs.h
index 3b48cddc6c1df9885efc0112faad7fa96a42b239..580ced7d71ba8a8c19a78a737bd4689e95475762 100644 (file)
--- a/defs.h
+++ b/defs.h
@@ -5,13 +5,13 @@
 #define OUTPUT_FREQUENCY 48000
 #define FPS 60
 
-#define AUDIO_OUTPUT_CODEC AV_CODEC_ID_MP3
-#define AUDIO_OUTPUT_SAMPLE_FMT AV_SAMPLE_FMT_FLTP
-#define AUDIO_OUTPUT_BIT_RATE 256000
+#define AUDIO_OUTPUT_CODEC AV_CODEC_ID_PCM_S32LE
+#define AUDIO_OUTPUT_SAMPLE_FMT AV_SAMPLE_FMT_S32
+#define AUDIO_OUTPUT_BIT_RATE 0
 
-#define LOCAL_DUMP_FILE_NAME "test.ts"
-#define STREAM_MUX_NAME "mpegts"
-#define MUX_OPTS {}
+#define LOCAL_DUMP_FILE_NAME "test.mov"
+#define STREAM_MUX_NAME "mov"
+#define MUX_OPTS {{ "movflags", "empty_moov+frag_keyframe+default_base_moof" }}
 
 // In bytes. Beware, if too small, stream clients will start dropping data.
 #define MUX_BUFFER_SIZE 10485760
index 6e946d961f54b7510dbd515976d2d224d1165a93..04ad66995955fa01b10ec0c4cc793794c6762d6f 100644 (file)
@@ -1698,14 +1698,19 @@ int H264Encoder::save_codeddata(storage_task task)
 
         AVFrame *frame = avcodec_alloc_frame();
         frame->nb_samples = audio.size() / 2;
-        frame->format = AV_SAMPLE_FMT_FLTP;
+        frame->format = AV_SAMPLE_FMT_S32;
         frame->channel_layout = AV_CH_LAYOUT_STEREO;
 
-        unique_ptr<float[]> planar_samples(new float[audio.size()]);
-        avcodec_fill_audio_frame(frame, 2, AV_SAMPLE_FMT_FLTP, (const uint8_t*)planar_samples.get(), audio.size() * sizeof(float), 0);
-        for (int i = 0; i < frame->nb_samples; ++i) {
-            planar_samples[i] = audio[i * 2 + 0];
-            planar_samples[i + frame->nb_samples] = audio[i * 2 + 1];
+        unique_ptr<int32_t[]> int_samples(new int32_t[audio.size()]);
+        avcodec_fill_audio_frame(frame, 2, AV_SAMPLE_FMT_S32, (const uint8_t*)int_samples.get(), audio.size() * sizeof(int32_t), 0);
+        for (int i = 0; i < frame->nb_samples * 2; ++i) {
+            if (audio[i] >= 1.0f) {
+                int_samples[i] = 2147483647;
+            } else if (audio[i] <= -1.0f) {
+                int_samples[i] = -2147483647;
+            } else {
+                int_samples[i] = lrintf(audio[i] * 2147483647.0f);
+            }
         }
 
         AVPacket pkt;