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_channels = 0;
94 if (nb_channels > best_nb_channels) {
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");
279 fprintf(stderr,
"Error while decoding\n");
287 fwrite(decoded_frame->
data[0], 1, data_size, outfile);
296 memmove(inbuf, avpkt.
data, avpkt.
size);
298 len = fread(avpkt.
data + avpkt.
size, 1,
320 int i, ret, x, y, got_output;
324 uint8_t endcode[] = { 0, 0, 1, 0xb7 };
326 printf(
"Video encoding\n");
331 fprintf(stderr,
"codec not found\n");
351 fprintf(stderr,
"could not open codec\n");
355 f = fopen(filename,
"wb");
357 fprintf(stderr,
"could not open %s\n", filename);
364 fprintf(stderr,
"could not alloc raw picture buffer\n");
380 for(y=0;y<c->
height;y++) {
381 for(x=0;x<c->
width;x++) {
382 picture->
data[0][y * picture->
linesize[0] + x] = x + y + i * 3;
387 for(y=0;y<c->
height/2;y++) {
388 for(x=0;x<c->
width/2;x++) {
389 picture->
data[1][y * picture->
linesize[1] + x] = 128 + y + i * 2;
390 picture->
data[2][y * picture->
linesize[2] + x] = 64 + x + i * 5;
399 fprintf(stderr,
"error encoding frame\n");
404 printf(
"encoding frame %3d (size=%5d)\n", i, pkt.
size);
411 for (got_output = 1; got_output; i++) {
416 fprintf(stderr,
"error encoding frame\n");
421 printf(
"encoding frame %3d (size=%5d)\n", i, pkt.
size);
428 fwrite(endcode, 1,
sizeof(endcode), f);
442 static void pgm_save(
unsigned char *buf,
int wrap,
int xsize,
int ysize,
448 f=fopen(filename,
"w");
449 fprintf(f,
"P5\n%d %d\n%d\n",xsize,ysize,255);
451 fwrite(buf + i * wrap,1,xsize,f);
459 int frame, got_picture,
len;
471 printf(
"Video decoding\n");
476 fprintf(stderr,
"codec not found\n");
492 fprintf(stderr,
"could not open codec\n");
498 f = fopen(filename,
"rb");
500 fprintf(stderr,
"could not open %s\n", filename);
526 while (avpkt.
size > 0) {
529 fprintf(stderr,
"Error while decoding frame %d\n", frame);
533 printf(
"saving frame %3d\n", frame);
538 snprintf(buf,
sizeof(buf), outfilename, frame);
555 printf(
"saving last frame %3d\n", frame);
560 snprintf(buf,
sizeof(buf), outfilename, frame);
574 int main(
int argc,
char **argv)
576 const char *filename;
586 filename =
"/tmp/test.mpg";