#include <errno.h>
#include <signal.h>
#include <limits.h>
-#include "avformat.h"
-#include "avdevice.h"
-#include "swscale.h"
-#include "framehook.h"
-#include "opt.h"
-#include "fifo.h"
-#include "avstring.h"
-#include "os_support.h"
+#include "libavformat/avformat.h"
+#include "libavdevice/avdevice.h"
+#include "libswscale/swscale.h"
+#include "libavformat/framehook.h"
+#include "libavcodec/opt.h"
+#include "libavutil/fifo.h"
+#include "libavutil/avstring.h"
+#include "libavformat/os_support.h"
#ifdef HAVE_SYS_RESOURCE_H
+#include <sys/types.h>
#include <sys/resource.h>
#elif defined(HAVE_GETPROCESSTIMES)
#include <windows.h>
#undef exit
-static const char program_name[] = "FFmpeg";
+const char program_name[] = "FFmpeg";
static const int program_birth_year = 2000;
/* select an input stream for an output stream */
/* now encode as many frames as possible */
if (enc->frame_size > 1) {
/* output resampled raw samples */
- av_fifo_realloc(&ost->fifo, av_fifo_size(&ost->fifo) + size_out + 1);
- av_fifo_write(&ost->fifo, buftmp, size_out);
+ av_fifo_realloc(&ost->fifo, av_fifo_size(&ost->fifo) + size_out);
+ av_fifo_generic_write(&ost->fifo, buftmp, size_out, NULL);
frame_bytes = enc->frame_size * 2 * enc->channels;
- while (av_fifo_read(&ost->fifo, audio_buf, frame_bytes) == 0) {
+ while (av_fifo_size(&ost->fifo) >= frame_bytes) {
AVPacket pkt;
av_init_packet(&pkt);
+ av_fifo_read(&ost->fifo, audio_buf, frame_bytes);
+
//FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio()
ret = avcodec_encode_audio(enc, audio_out, audio_out_size,
bitrate = (double)(total_size * 8) / ti1 / 1000.0;
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
- "size=%8.0fkB time=%0.1f bitrate=%6.1fkbits/s",
+ "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s",
(double)total_size / 1024, ti1, bitrate);
if (verbose > 1)
if(fifo_bytes > 0 && enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) {
int fs_tmp = enc->frame_size;
enc->frame_size = fifo_bytes / (2 * enc->channels);
- if(av_fifo_read(&ost->fifo, (uint8_t *)samples, fifo_bytes) == 0) {
+ av_fifo_read(&ost->fifo, (uint8_t *)samples, fifo_bytes);
ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, samples);
- }
enc->frame_size = fs_tmp;
}
if(ret <= 0) {
codec->block_align= icodec->block_align;
if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3)
codec->block_align= 0;
+ if(codec->codec_id == CODEC_ID_AC3)
+ codec->block_align= 0;
break;
case CODEC_TYPE_VIDEO:
if(using_vhook) {
static int opt_verbose(const char *opt, const char *arg)
{
- verbose = parse_number_or_die(opt, arg, OPT_INT64, AV_LOG_QUIET, AV_LOG_DEBUG);
+ verbose = parse_number_or_die(opt, arg, OPT_INT64, -10, 10);
av_log_set_level(verbose);
return 0;
}
#endif
}
-static void opt_show_formats(void)
-{
- AVInputFormat *ifmt=NULL;
- AVOutputFormat *ofmt=NULL;
- URLProtocol *up=NULL;
- AVCodec *p=NULL, *p2;
- AVBitStreamFilter *bsf=NULL;
- const char *last_name;
-
- printf("File formats:\n");
- last_name= "000";
- for(;;){
- int decode=0;
- int encode=0;
- const char *name=NULL;
- const char *long_name=NULL;
-
- while((ofmt= av_oformat_next(ofmt))) {
- if((name == NULL || strcmp(ofmt->name, name)<0) &&
- strcmp(ofmt->name, last_name)>0){
- name= ofmt->name;
- long_name= ofmt->long_name;
- encode=1;
- }
- }
- while((ifmt= av_iformat_next(ifmt))) {
- if((name == NULL || strcmp(ifmt->name, name)<0) &&
- strcmp(ifmt->name, last_name)>0){
- name= ifmt->name;
- long_name= ifmt->long_name;
- encode=0;
- }
- if(name && strcmp(ifmt->name, name)==0)
- decode=1;
- }
- if(name==NULL)
- break;
- last_name= name;
-
- printf(
- " %s%s %-15s %s\n",
- decode ? "D":" ",
- encode ? "E":" ",
- name,
- long_name ? long_name:" ");
- }
- printf("\n");
-
- printf("Codecs:\n");
- last_name= "000";
- for(;;){
- int decode=0;
- int encode=0;
- int cap=0;
- const char *type_str;
-
- p2=NULL;
- while((p= av_codec_next(p))) {
- if((p2==NULL || strcmp(p->name, p2->name)<0) &&
- strcmp(p->name, last_name)>0){
- p2= p;
- decode= encode= cap=0;
- }
- if(p2 && strcmp(p->name, p2->name)==0){
- if(p->decode) decode=1;
- if(p->encode) encode=1;
- cap |= p->capabilities;
- }
- }
- if(p2==NULL)
- break;
- last_name= p2->name;
-
- switch(p2->type) {
- case CODEC_TYPE_VIDEO:
- type_str = "V";
- break;
- case CODEC_TYPE_AUDIO:
- type_str = "A";
- break;
- case CODEC_TYPE_SUBTITLE:
- type_str = "S";
- break;
- default:
- type_str = "?";
- break;
- }
- printf(
- " %s%s%s%s%s%s %s",
- decode ? "D": (/*p2->decoder ? "d":*/" "),
- encode ? "E":" ",
- type_str,
- cap & CODEC_CAP_DRAW_HORIZ_BAND ? "S":" ",
- cap & CODEC_CAP_DR1 ? "D":" ",
- cap & CODEC_CAP_TRUNCATED ? "T":" ",
- p2->name);
- /* if(p2->decoder && decode==0)
- printf(" use %s for decoding", p2->decoder->name);*/
- printf("\n");
- }
- printf("\n");
-
- printf("Bitstream filters:\n");
- while((bsf = av_bitstream_filter_next(bsf)))
- printf(" %s", bsf->name);
- printf("\n");
-
- printf("Supported file protocols:\n");
- while((up = av_protocol_next(up)))
- printf(" %s:", up->name);
- printf("\n");
-
- printf("Frame size, frame rate abbreviations:\n ntsc pal qntsc qpal sntsc spal film ntsc-film sqcif qcif cif 4cif\n");
- printf("\n");
- printf(
-"Note, the names of encoders and decoders do not always match, so there are\n"
-"several cases where the above table shows encoder only or decoder only entries\n"
-"even though both encoding and decoding are supported. For example, the h263\n"
-"decoder corresponds to the h263 and h263p encoders, for file formats it is even\n"
-"worse.\n");
- av_exit(0);
-}
-
static void parse_matrix_coeffs(uint16_t *dest, const char *str)
{
int i;
av_opt_show(sws_opts, NULL);
}
-static void opt_show_help(void)
-{
- show_help();
- av_exit(0);
-}
-
static void opt_target(const char *arg)
{
int norm = -1;
return 0;
}
-static void opt_show_license(void)
-{
- show_license();
- av_exit(0);
-}
-
-static void opt_show_version(void)
-{
- show_version(program_name);
- av_exit(0);
-}
-
static const OptionDef options[] = {
/* main options */
- { "L", 0, {(void*)opt_show_license}, "show license" },
- { "h", 0, {(void*)opt_show_help}, "show help" },
- { "version", 0, {(void*)opt_show_version}, "show version" },
- { "formats", 0, {(void*)opt_show_formats}, "show available formats, codecs, protocols, ..." },
+ { "L", OPT_EXIT, {(void*)show_license}, "show license" },
+ { "h", OPT_EXIT, {(void*)show_help}, "show help" },
+ { "version", OPT_EXIT, {(void*)show_version}, "show version" },
+ { "formats", OPT_EXIT, {(void*)show_formats}, "show available formats, codecs, protocols, ..." },
{ "f", HAS_ARG, {(void*)opt_format}, "force format", "fmt" },
{ "i", HAS_ARG, {(void*)opt_input_file}, "input file name", "filename" },
{ "y", OPT_BOOL, {(void*)&file_overwrite}, "overwrite output files" },