Skip to content

Instantly share code, notes, and snippets.

@astoeckel
Created November 15, 2017 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astoeckel/6731bc846a2f70dd7f5e155e75683fae to your computer and use it in GitHub Desktop.
Save astoeckel/6731bc846a2f70dd7f5e155e75683fae to your computer and use it in GitHub Desktop.
libopusenc ope_continue_encoding_file
/*
Usage:
mkdir -p blocks
./opusenc_example test_libopusenc_ope_encoder_continue_new_file.raw
( for i in `find blocks -name '*.ogg' | sort -n`; do opusdec $i -; done ) | aplay -f dat
*/
#include <stdio.h>
#include "opusenc.h"
#define READ_SIZE 4096
int main(int argc, char **argv) {
FILE *fin;
OggOpusEnc *enc;
OggOpusComments *comments;
int error;
if (argc != 2) {
fprintf(stderr, "usage: %s <raw pcm input>\n", argv[0]);
return 1;
}
fin = fopen(argv[1], "rb");
if (!fin) {
fprintf(stderr, "cannot open input file: %s\n", argv[1]);
return 1;
}
comments = ope_comments_create();
ope_comments_add(comments, "ARTIST", "Someone");
ope_comments_add(comments, "TITLE", "Some track");
int idx = 0;
char fn[256];
sprintf(fn, "blocks/block_%05d.ogg", idx++);
enc = ope_encoder_create_file(fn, comments, 44100, 2, 0, &error);
if (!enc) {
fprintf(stderr, "cannout open output file: %s\n", argv[2]);
fclose(fin);
return 1;
}
while (1) {
short buf[2*READ_SIZE];
int ret = fread(buf, 2*sizeof(short), READ_SIZE, fin);
if (ret > 0) {
ope_encoder_write(enc, buf, ret);
} else break;
sprintf(fn, "blocks/block_%05d.ogg", idx++);
ope_encoder_continue_new_file(enc, fn, comments);
}
ope_encoder_drain(enc);
ope_encoder_destroy(enc);
ope_comments_destroy(comments);
fclose(fin);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment