Skip to content

Instantly share code, notes, and snippets.

@umjammer
Created March 27, 2014 04:20
Show Gist options
  • Save umjammer/9800142 to your computer and use it in GitHub Desktop.
Save umjammer/9800142 to your computer and use it in GitHub Desktop.
QCELP: patch for ffmpeg
Index: configure
===================================================================
--- configure (revision 9321)
+++ configure (working copy)
@@ -89,6 +89,7 @@
echo " --enable-libfaad enable FAAD support via libfaad [default=no]"
echo " --enable-libfaadbin build FAAD support with runtime linking [default=no]"
echo " --enable-libgsm enable GSM support via libgsm [default=no]"
+ echo " --enable-libqcelp enable 3GPP2 CELP support"
echo " --enable-libmp3lame enable MP3 encoding via libmp3lame [default=no]"
echo " --enable-libnut enable NUT (de)muxing via libnut,"
echo " native demuxer exists [default=no]"
@@ -586,6 +587,7 @@
libamr
libamr_nb
libamr_wb
+ libqcelp
libfaac
libfaad
libfaadbin
@@ -730,6 +732,7 @@
libamr_nb_encoder_deps="libamr_nb"
libamr_wb_decoder_deps="libamr_wb"
libamr_wb_encoder_deps="libamr_wb"
+libqcelp_encoder_deps="libqcelp"
libfaac_encoder_deps="libfaac"
libfaad_decoder_deps="libfaad"
libgsm_decoder_deps="libgsm"
@@ -850,6 +853,7 @@
liba52bin="no"
libamr_nb="no"
libamr_wb="no"
+libqcelp="no"
libfaac="no"
libfaad2="no"
libfaad="no"
@@ -1188,7 +1192,7 @@
VHOOKSHFLAGS='-shared -L$(BUILD_ROOT)/libavformat -L$(BUILD_ROOT)/libavcodec -L$(BUILD_ROOT)/libswscale -L$(BUILD_ROOT)/libavutil'
VHOOKLIBS='-lavformat$(BUILDSUF) -lavcodec$(BUILDSUF) -lswscale$(BUILDSUF) -lavutil$(BUILDSUF) $(EXTRALIBS)'
ffserver="no"
- network="no"
+ network="yes"
SLIBPREF=""
SLIBSUF=".dll"
EXESUF=".exe"
@@ -1648,13 +1652,14 @@
enabled liba52 && require liba52 a52dec/a52.h a52_init -la52
enabled libamr_nb && require libamrnb amrnb/interf_dec.h Speech_Decode_Frame_init -lamrnb -lm
enabled libamr_wb && require libamrwb amrwb/dec_if.h D_IF_init -lamrwb -lm
+enabled libqcelp && require libqcelp qcelp/celp.h initialize_decoder -lqcelp
enabled libgsm && require libgsm gsm.h gsm_create -lgsm
enabled libmp3lame && require LAME lame/lame.h lame_init -lmp3lame -lm
enabled libtheora && require libtheora theora/theora.h theora_info_init -ltheora -logg
enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbis -lvorbisenc -logg
enabled libogg && require libogg ogg/ogg.h ogg_sync_init -logg
enabled libnut && require libnut libnut.h nut_demuxer_init -lnut
-enabled libx264 && require x264 x264.h x264_encoder_open -lx264
+enabled libx264 && require x264 x264.h x264_encoder_open -lx264 -lpthread
enabled libxvid && require Xvid xvid.h xvid_global -lxvidcore
enabled dc1394 && require libdc1394 libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394
enabled mlib && require mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib
@@ -1861,6 +1866,7 @@
echo "C compiler $cc"
echo "make $make"
echo ".align is power-of-two $asmalign_pot"
+echo "target OS $targetos"
echo "ARCH $arch ($cpu)"
if test "$BUILDSUF" != ""; then
echo "build suffix $BUILDSUF"
@@ -1921,6 +1927,7 @@
echo "libtheora enabled $libtheora"
echo "libvorbis enabled $libvorbis"
echo "x264 enabled $libx264"
+echo "libqcelp enabled $libqcelp"
echo "XviD enabled $libxvid"
echo "zlib enabled $zlib"
if disabled gpl; then
Index: ffmpeg.c
===================================================================
--- ffmpeg.c (revision 9321)
+++ ffmpeg.c (working copy)
@@ -97,6 +97,8 @@
static int frame_width = 0;
static int frame_height = 0;
static float frame_aspect_ratio = 0;
+static float sample_aspect_ratio = 0; // MH
+static int fix_aspect_ratio = 0; // MH
static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE;
static int frame_padtop = 0;
static int frame_padbottom = 0;
@@ -278,7 +280,6 @@
} AVInputFile;
#ifndef __MINGW32__
-
/* init terminal so that we can grab keys */
static struct termios oldtty;
#endif
@@ -1175,7 +1176,7 @@
os = output_files[ost->file_index];
#if 0
- printf("%d: got pts=%0.3f %0.3f\n", i,
+ fprintf(stderr, "%d: got pts=%0.3f %0.3f\n", i,
(double)pkt->pts / AV_TIME_BASE,
((double)ist->pts / AV_TIME_BASE) -
((double)ost->st->pts.val * ost->st->time_base.num / ost->st->time_base.den));
@@ -1570,7 +1571,7 @@
ost->resample = audio_resample_init(codec->channels, icodec->channels,
codec->sample_rate, icodec->sample_rate);
if(!ost->resample){
- printf("Can't resample. Aborting.\n");
+ fprintf(stderr, "Can't resample. Aborting.\n");
av_abort();
}
}
@@ -2012,7 +2013,7 @@
int len, i;
if (url_open(&h, filename, O_RDONLY) < 0) {
- printf("could not open '%s'\n", filename);
+ fprintf(stderr, "could not open '%s'\n", filename);
return -1;
}
for(;;) {
@@ -2147,14 +2148,50 @@
static void opt_frame_size(const char *arg)
{
- if (parse_image_size(&frame_width, &frame_height, arg) < 0) {
+ int width,height,i; // MH
+ float sa;
+
+ if (parse_image_size(&width, &height, arg) < 0) { // MH
fprintf(stderr, "Incorrect frame size\n");
exit(1);
}
- if ((frame_width % 2) != 0 || (frame_height % 2) != 0) {
+ if ((width % 2) != 0 || (height % 2) != 0) { // MH
fprintf(stderr, "Frame size must be a multiple of 2\n");
exit(1);
}
+
+ // MH
+ sa = sample_aspect_ratio; if (sa == 0) { sa = 1; }
+ if ((frame_height != 0) && (height != 0)) {
+ i = (width * 1000 / height) - round(frame_width * sa * 1000 / frame_height);
+ if ((fix_aspect_ratio != 0) && (i != 0)) {
+ if (i<0) {
+ i = (int)((width * frame_height / (frame_width * sa)) / 2) * 2;
+ frame_width = width;
+ frame_height = i;
+ height = height - i;
+ frame_padtop = (int)((height / 2) / 2) * 2;
+ frame_padbottom = height - frame_padtop;
+ frame_padleft = 0;
+ frame_padright = 0;
+ } else {
+ i = (int)((height * frame_width * sa / frame_height) / 2) * 2;
+ frame_height = height;
+ frame_width = i;
+ width = width - i;
+ frame_padleft = (int)((width / 2) / 2) * 2;
+ frame_padright = width - frame_padleft;
+ frame_padtop = 0;
+ frame_padbottom = 0;
+ }
+ } else {
+ frame_width = width;
+ frame_height = height;
+ }
+ } else {
+ frame_width = width;
+ frame_height = height;
+ }
}
@@ -2249,7 +2286,7 @@
char pix_fmt_str[128];
for (i=-1; i < PIX_FMT_NB; i++) {
avcodec_pix_fmt_string (pix_fmt_str, sizeof(pix_fmt_str), i);
- fprintf(stdout, "%s\n", pix_fmt_str);
+ fprintf(stderr, "%s\n", pix_fmt_str);
}
}
@@ -2614,6 +2651,7 @@
frame_width = enc->width;
frame_aspect_ratio = av_q2d(enc->sample_aspect_ratio) * enc->width / enc->height;
frame_pix_fmt = enc->pix_fmt;
+ sample_aspect_ratio = av_q2d(enc->sample_aspect_ratio); // MH
rfps = ic->streams[i]->r_frame_rate.num;
rfps_base = ic->streams[i]->r_frame_rate.den;
if(enc->lowres) enc->flags |= CODEC_FLAG_EMU_EDGE;
@@ -3164,7 +3202,7 @@
AVCodec *p, *p2;
const char **pp, *last_name;
- printf("File formats:\n");
+ fprintf(stderr, "File formats:\n");
last_name= "000";
for(;;){
int decode=0;
@@ -3194,16 +3232,16 @@
break;
last_name= name;
- printf(
+ fprintf(stderr,
" %s%s %-15s %s\n",
decode ? "D":" ",
encode ? "E":" ",
name,
long_name ? long_name:" ");
}
- printf("\n");
+ fprintf(stderr, "\n");
- printf("Codecs:\n");
+ fprintf(stderr, "Codecs:\n");
last_name= "000";
for(;;){
int decode=0;
@@ -3242,7 +3280,7 @@
type_str = "?";
break;
}
- printf(
+ fprintf(stderr,
" %s%s%s%s%s%s %s",
decode ? "D": (/*p2->decoder ? "d":*/" "),
encode ? "E":" ",
@@ -3252,31 +3290,31 @@
cap & CODEC_CAP_TRUNCATED ? "T":" ",
p2->name);
/* if(p2->decoder && decode==0)
- printf(" use %s for decoding", p2->decoder->name);*/
- printf("\n");
+ fprintf(stderr, " use %s for decoding", p2->decoder->name);*/
+ fprintf(stderr, "\n");
}
- printf("\n");
+ fprintf(stderr, "\n");
- printf("Supported file protocols:\n");
+ fprintf(stderr, "Supported file protocols:\n");
for(up = first_protocol; up != NULL; up = up->next)
- printf(" %s:", up->name);
- printf("\n");
+ fprintf(stderr, " %s:", up->name);
+ fprintf(stderr, "\n");
- printf("Frame size, frame rate abbreviations:\n ntsc pal qntsc qpal sntsc spal film ntsc-film sqcif qcif cif 4cif\n");
- printf("Motion estimation methods:\n");
+ fprintf(stderr, "Frame size, frame rate abbreviations:\n ntsc pal qntsc qpal sntsc spal film ntsc-film sqcif qcif cif 4cif\n");
+ fprintf(stderr, "Motion estimation methods:\n");
pp = motion_str;
while (*pp) {
- printf(" %s", *pp);
+ fprintf(stderr, " %s", *pp);
if ((pp - motion_str + 1) == ME_ZERO)
- printf("(fastest)");
+ fprintf(stderr, "(fastest)");
else if ((pp - motion_str + 1) == ME_FULL)
- printf("(slowest)");
+ fprintf(stderr, "(slowest)");
else if ((pp - motion_str + 1) == ME_EPZS)
- printf("(default)");
+ fprintf(stderr, "(default)");
pp++;
}
- printf("\n\n");
- printf(
+ fprintf(stderr, "\n\n");
+ fprintf(stderr,
"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"
@@ -3610,6 +3648,7 @@
{ "r", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_rate}, "set frame rate (Hz value, fraction or abbreviation)", "rate" },
{ "s", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_size}, "set frame size (WxH or abbreviation)", "size" },
{ "aspect", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_aspect_ratio}, "set aspect ratio (4:3, 16:9 or 1.3333, 1.7777)", "aspect" },
+ { "fixaspect", OPT_BOOL | OPT_VIDEO, {(void*)&fix_aspect_ratio}, "fix aspect ratio" }, // MH
{ "pix_fmt", HAS_ARG | OPT_EXPERT | OPT_VIDEO, {(void*)opt_frame_pix_fmt}, "set pixel format, 'list' as argument shows all the pixel formats supported", "format" },
{ "croptop", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_top}, "set top crop band size (in pixels)", "size" },
{ "cropbottom", HAS_ARG | OPT_VIDEO, {(void*)opt_frame_crop_bottom}, "set bottom crop band size (in pixels)", "size" },
@@ -3702,7 +3741,7 @@
{
show_banner();
#ifdef CONFIG_GPL
- printf(
+ fprintf(stderr,
"FFmpeg is free software; you can redistribute it and/or modify\n"
"it under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation; either version 2 of the License, or\n"
@@ -3718,7 +3757,7 @@
"Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n"
);
#else
- printf(
+ fprintf(stderr,
"FFmpeg is free software; you can redistribute it and/or\n"
"modify it under the terms of the GNU Lesser General Public\n"
"License as published by the Free Software Foundation; either\n"
@@ -3743,16 +3782,16 @@
*/
static void log_callback_help(void* ptr, int level, const char* fmt, va_list vl)
{
- vfprintf(stdout, fmt, vl);
+ vfprintf(stderr, fmt, vl);
}
static void show_help(void)
{
av_log_set_callback(log_callback_help);
show_banner();
- printf("usage: ffmpeg [[infile options] -i infile]... {[outfile options] outfile}...\n"
+ fprintf(stderr, "usage: ffmpeg [[infile options] -i infile]... {[outfile options] outfile}...\n"
"Hyper fast Audio and Video encoder\n");
- printf("\n");
+ fprintf(stderr, "\n");
show_help_options(options, "Main options:\n",
OPT_EXPERT | OPT_AUDIO | OPT_VIDEO, 0);
show_help_options(options, "\nVideo options:\n",
@@ -3827,7 +3866,7 @@
stream_maps, nb_stream_maps);
ti = getutime() - ti;
if (do_benchmark) {
- printf("bench: utime=%0.3fs\n", ti / 1000000.0);
+ fprintf(stderr, "bench: utime=%0.3fs\n", ti / 1000000.0);
}
/* close files */
Index: libavcodec/libvorbis.c
===================================================================
--- libavcodec/libvorbis.c (revision 9321)
+++ libavcodec/libvorbis.c (working copy)
@@ -24,6 +24,9 @@
* @author Mark Hills <mark@pogo.org.uk>
*/
+#ifdef __MINGW32__
+#include <stdlib.h>
+#endif
#include <vorbis/vorbisenc.h>
#include "avcodec.h"
Index: libavcodec/Makefile
===================================================================
--- libavcodec/Makefile (revision 9321)
+++ libavcodec/Makefile (working copy)
@@ -279,6 +279,7 @@
# external codec libraries
OBJS-$(CONFIG_LIBA52) += liba52.o
OBJS-$(CONFIG_LIBAMR) += libamr.o
+OBJS-$(CONFIG_LIBQCELP) += libqcelp.o
OBJS-$(CONFIG_LIBFAAC) += libfaac.o
OBJS-$(CONFIG_LIBFAAD) += libfaad.o
OBJS-$(CONFIG_LIBGSM) += libgsm.o
Index: libavcodec/allcodecs.c
===================================================================
--- libavcodec/allcodecs.c (revision 9321)
+++ libavcodec/allcodecs.c (working copy)
@@ -175,6 +175,7 @@
REGISTER_DECODER(IMC, imc);
REGISTER_ENCDEC (LIBAMR_NB, libamr_nb);
REGISTER_ENCDEC (LIBAMR_WB, libamr_wb);
+ REGISTER_ENCDEC (LIBQCELP, libqcelp);
REGISTER_DECODER(LIBA52, liba52);
REGISTER_ENCODER(LIBFAAC, libfaac);
REGISTER_DECODER(LIBFAAD, libfaad);
Index: libavcodec/allcodecs.h
===================================================================
--- libavcodec/allcodecs.h (revision 9321)
+++ libavcodec/allcodecs.h (working copy)
@@ -276,6 +276,8 @@
extern AVCodec mpeg4aac_decoder;
extern AVCodec zlib_decoder;
extern AVCodec zlib_encoder;
+extern AVCodec libqcelp_decoder;
+extern AVCodec libqcelp_encoder;
/* subtitles */
extern AVCodec dvbsub_decoder;
Index: doc/ffmpeg-doc.texi
===================================================================
--- doc/ffmpeg-doc.texi (revision 9321)
+++ doc/ffmpeg-doc.texi (working copy)
@@ -1107,6 +1107,8 @@
@tab Real low bitrate AC3 codec, liba52 is used for decoding.
@item AMR-NB @tab X @tab X
@tab Supported through an external library.
+@item QCELP @tab X @tab X
+@tab Supported through an external library.
@item AMR-WB @tab X @tab X
@tab Supported through an external library.
@item DV audio @tab @tab X
Index: cmdutils.c
===================================================================
--- cmdutils.c (revision 9321)
+++ cmdutils.c (working copy)
@@ -34,7 +34,7 @@
char buf[64];
if ((po->flags & mask) == value) {
if (first) {
- printf("%s", msg);
+ fprintf(stderr, "%s", msg);
first = 0;
}
pstrcpy(buf, sizeof(buf), po->name);
@@ -42,7 +42,7 @@
pstrcat(buf, sizeof(buf), " ");
pstrcat(buf, sizeof(buf), po->argname);
}
- printf("-%-17s %s\n", buf, po->help);
+ fprintf(stderr, "-%-17s %s\n", buf, po->help);
}
}
}
Index: libavformat/mov.c
===================================================================
--- libavformat/mov.c (revision 9321)
+++ libavformat/mov.c (working copy)
@@ -841,6 +841,12 @@
st->codec->codec_type = CODEC_TYPE_AUDIO; /* force type after stsd for m1a hdlr */
st->need_parsing = AVSTREAM_PARSE_FULL;
break;
+#ifdef CONFIG_LIBQCELP
+ case CODEC_ID_QCELP:
+ st->codec->sample_rate = 8000;
+ st->codec->channels = 1;
+ break;
+#endif
default:
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment