#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
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;