35 #ifdef HAVE_AV_CONFIG_H
36 #undef HAVE_AV_CONFIG_H
46 #define INBUF_SIZE 4096
47 #define AUDIO_INBUF_SIZE 20480
48 #define AUDIO_REFILL_THRESH 4096
67 int best_samplerate = 0;
74 best_samplerate =
FFMAX(*p, best_samplerate);
77 return best_samplerate;
84 uint64_t best_ch_layout = 0;
85 int best_nb_channells = 0;
94 if (nb_channels > best_nb_channells) {
100 return best_ch_layout;
112 int i, j, k, ret, got_output;
118 printf(
"Audio encoding\n");
123 fprintf(stderr,
"codec not found\n");
135 fprintf(stderr,
"encoder does not support %s",
147 fprintf(stderr,
"could not open codec\n");
151 f = fopen(filename,
"wb");
153 fprintf(stderr,
"could not open %s\n", filename);
160 fprintf(stderr,
"could not allocate audio frame\n");
174 fprintf(stderr,
"could not allocate %d bytes for samples buffer\n",
180 (
const uint8_t*)samples, buffer_size, 0);
182 fprintf(stderr,
"could not setup audio frame\n");
195 samples[2*j] = (int)(sin(t) * 10000);
198 samples[2*j + k] = samples[2*j];
204 fprintf(stderr,
"error encoding audio frame\n");
235 printf(
"Audio decoding\n");
240 fprintf(stderr,
"codec not found\n");
248 fprintf(stderr,
"could not open codec\n");
252 f = fopen(filename,
"rb");
254 fprintf(stderr,
"could not open %s\n", filename);
257 outfile = fopen(outfilename,
"wb");
267 while (avpkt.
size > 0) {
270 if (!decoded_frame) {
272 fprintf(stderr,
"out of memory\n");
280 fprintf(stderr,
"Error while decoding\n");
288 fwrite(decoded_frame->
data[0], 1, data_size, outfile);
297 memmove(inbuf, avpkt.
data, avpkt.
size);
299 len = fread(avpkt.
data + avpkt.
size, 1,
321 int i, ret, x, y, got_output;
325 uint8_t endcode[] = { 0, 0, 1, 0xb7 };
327 printf(
"Video encoding\n");
332 fprintf(stderr,
"codec not found\n");
352 fprintf(stderr,
"could not open codec\n");
356 f = fopen(filename,
"wb");
358 fprintf(stderr,
"could not open %s\n", filename);
365 fprintf(stderr,
"could not alloc raw picture buffer\n");
381 for(y=0;y<c->
height;y++) {
382 for(x=0;x<c->
width;x++) {
383 picture->
data[0][y * picture->
linesize[0] + x] = x + y + i * 3;
388 for(y=0;y<c->
height/2;y++) {
389 for(x=0;x<c->
width/2;x++) {
390 picture->
data[1][y * picture->
linesize[1] + x] = 128 + y + i * 2;
391 picture->
data[2][y * picture->
linesize[2] + x] = 64 + x + i * 5;
400 fprintf(stderr,
"error encoding frame\n");
405 printf(
"encoding frame %3d (size=%5d)\n", i, pkt.
size);
412 for (got_output = 1; got_output; i++) {
417 fprintf(stderr,
"error encoding frame\n");
422 printf(
"encoding frame %3d (size=%5d)\n", i, pkt.
size);
429 fwrite(endcode, 1,
sizeof(endcode), f);
443 static void pgm_save(
unsigned char *buf,
int wrap,
int xsize,
int ysize,
449 f=fopen(filename,
"w");
450 fprintf(f,
"P5\n%d %d\n%d\n",xsize,ysize,255);
452 fwrite(buf + i * wrap,1,xsize,f);
460 int frame, got_picture,
len;
472 printf(
"Video decoding\n");
477 fprintf(stderr,
"codec not found\n");
493 fprintf(stderr,
"could not open codec\n");
499 f = fopen(filename,
"rb");
501 fprintf(stderr,
"could not open %s\n", filename);
527 while (avpkt.
size > 0) {
530 fprintf(stderr,
"Error while decoding frame %d\n", frame);
534 printf(
"saving frame %3d\n", frame);
539 snprintf(buf,
sizeof(buf), outfilename, frame);
556 printf(
"saving last frame %3d\n", frame);
561 snprintf(buf,
sizeof(buf), outfilename, frame);
575 int main(
int argc,
char **argv)
577 const char *filename;
587 filename =
"/tmp/test.mpg";