1
mirror of https://github.com/mpv-player/mpv synced 2024-09-28 17:52:52 +02:00

Remove MEncoder

Disable MEncoder compilation and remove files used by MEncoder
only. There's no attempt to remove all references to MEncoder from the
build system, documentation etc at this point.

Removed files: (muxers, audio/video encoders, misc)

mencoder.c
cfg-mencoder.h
parser-mecmd.[ch]
xvid_vbr.[ch]
libmpdemux/muxer*
libmpcodecs/ae*
libmpcodecs/ve*
libmpcodecs/native/rtjpegn.[ch]
libmpcodecs/native/mmx.h   // was used by rtjpegn only

Rationale:

MEncoder is still useful for some people, but there's not much
potential for further development; in the long run almost all use
cases can be handled better by solutions based on something else (for
example using FFmpeg or encoding MPlayer output). FFmpeg is already
getting video filtering support which should work for some common
MEncoder uses.

Keeping MEncoder working takes extra work that is away from player
development. While that amount of work is not huge (mostly MEncoder
can be just ignored), it's not completely insignificant either.

MEncoder is still maintained to some degree in the svn tree, so if
necessary it's possible to use it from there for now. This tree has
never had major improvements for the MEncoder side, so using svn
MEncoder instead should be no major loss.
This commit is contained in:
Uoti Urpala 2010-10-31 00:04:18 +03:00
parent 8939645dcf
commit 389c32b5c7
42 changed files with 6 additions and 16613 deletions

View File

@ -642,51 +642,18 @@ SRCS_MPLAYER = command.c \
libvo/vo_null.c \
$(SRCS_MPLAYER-yes)
SRCS_MENCODER-$(FAAC) += libmpcodecs/ae_faac.c
SRCS_MENCODER-$(LIBAVCODEC) += libmpcodecs/ae_lavc.c libmpcodecs/ve_lavc.c
SRCS_MENCODER-$(LIBAVFORMAT) += libmpdemux/muxer_lavf.c
SRCS_MENCODER-$(LIBDV) += libmpcodecs/ve_libdv.c
SRCS_MENCODER-$(LIBLZO) += libmpcodecs/ve_nuv.c \
libmpcodecs/native/rtjpegn.c
SRCS_MENCODER-$(MP3LAME) += libmpcodecs/ae_lame.c
SRCS_MENCODER-$(QTX_CODECS_WIN32) += libmpcodecs/ve_qtvideo.c
SRCS_MENCODER-$(TOOLAME) += libmpcodecs/ae_toolame.c
SRCS_MENCODER-$(TWOLAME) += libmpcodecs/ae_twolame.c
SRCS_MENCODER-$(WIN32DLL) += libmpcodecs/ve_vfw.c
SRCS_MENCODER-$(X264) += libmpcodecs/ve_x264.c
SRCS_MENCODER-$(XVID4) += libmpcodecs/ve_xvid4.c
SRCS_MENCODER = mencoder.c \
parser-mecmd.c \
xvid_vbr.c \
libmpcodecs/ae.c \
libmpcodecs/ae_pcm.c \
libmpcodecs/ve.c \
libmpcodecs/ve_raw.c \
libmpdemux/muxer.c \
libmpdemux/muxer_avi.c \
libmpdemux/muxer_mpeg.c \
libmpdemux/muxer_rawaudio.c \
libmpdemux/muxer_rawvideo.c \
$(SRCS_MENCODER-yes)
COMMON_LIBS += $(COMMON_LIBS-yes)
OBJS_COMMON += $(addsuffix .o, $(basename $(SRCS_COMMON)))
OBJS_MENCODER += $(addsuffix .o, $(basename $(SRCS_MENCODER)))
OBJS_MPLAYER += $(addsuffix .o, $(basename $(SRCS_MPLAYER)))
OBJS_MPLAYER-$(PE_EXECUTABLE) += osdep/mplayer-rc.o
OBJS_MPLAYER += $(OBJS_MPLAYER-yes)
MENCODER_DEPS = $(OBJS_MENCODER) $(OBJS_COMMON) $(COMMON_LIBS)
MPLAYER_DEPS = $(OBJS_MPLAYER) $(OBJS_COMMON) $(COMMON_LIBS)
DEPS = $(filter-out %.S,$(patsubst %.cpp,%.d,$(patsubst %.c,%.d,$(SRCS_COMMON) $(SRCS_MPLAYER:.m=.d) $(SRCS_MENCODER))))
DEPS = $(filter-out %.S,$(patsubst %.cpp,%.d,$(patsubst %.c,%.d,$(SRCS_COMMON) $(SRCS_MPLAYER:.m=.d))))
ALL_PRG-$(MPLAYER) += mplayer$(EXESUF)
ALL_PRG-$(MENCODER) += mencoder$(EXESUF)
INSTALL_TARGETS-$(MENCODER) += install-mencoder install-mencoder-man
INSTALL_TARGETS-$(MPLAYER) += install-mplayer \
install-mplayer-man \
install-mplayer-msg
@ -754,11 +721,9 @@ all: $(ALL_PRG-yes) locales
%-rc.o: %.rc
$(WINDRES) -I. $< $@
mencoder$(EXESUF): $(MENCODER_DEPS)
mencoder$(EXESUF): EXTRALIBS += $(EXTRALIBS_MENCODER)
mplayer$(EXESUF): $(MPLAYER_DEPS)
mplayer$(EXESUF): EXTRALIBS += $(EXTRALIBS_MPLAYER)
mencoder$(EXESUF) mplayer$(EXESUF):
mplayer$(EXESUF):
$(CC) -o $@ $^ $(EXTRALIBS)
codec-cfg$(EXESUF): codec-cfg.c codec-cfg.h
@ -848,29 +813,19 @@ install-dirs:
install-%: %$(EXESUF) install-dirs
$(INSTALL) -m 755 $(INSTALLSTRIP) $< $(BINDIR)
install-mencoder-man: $(foreach lang,$(MAN_LANGS),install-mencoder-man-$(lang))
install-mplayer-man: $(foreach lang,$(MAN_LANGS),install-mplayer-man-$(lang))
install-mplayer-msg: $(foreach lang,$(MSG_LANGS),install-mplayer-msg-$(lang))
install-mencoder-man-en: install-mplayer-man-en
cd $(MANDIR)/man1 && ln -sf mplayer.1 mencoder.1
install-mplayer-man-en:
if test ! -d $(MANDIR)/man1 ; then $(INSTALL) -d $(MANDIR)/man1 ; fi
$(INSTALL) -m 644 DOCS/man/en/mplayer.1 $(MANDIR)/man1/
define MENCODER_MAN_RULE
install-mencoder-man-$(lang): install-mplayer-man-$(lang)
cd $(MANDIR)/$(lang)/man1 && ln -sf mplayer.1 mencoder.1
endef
define MPLAYER_MAN_RULE
install-mplayer-man-$(lang):
if test ! -d $(MANDIR)/$(lang)/man1 ; then $(INSTALL) -d $(MANDIR)/$(lang)/man1 ; fi
$(INSTALL) -m 644 DOCS/man/$(lang)/mplayer.1 $(MANDIR)/$(lang)/man1/
endef
$(foreach lang,$(filter-out en,$(MAN_LANG_ALL)),$(eval $(MENCODER_MAN_RULE)))
$(foreach lang,$(filter-out en,$(MAN_LANG_ALL)),$(eval $(MPLAYER_MAN_RULE)))
define MPLAYER_MSG_RULE
@ -883,17 +838,15 @@ $(foreach lang,$(MSG_LANG_ALL),$(eval $(MPLAYER_MSG_RULE)))
uninstall:
rm -f $(BINDIR)/mplayer$(EXESUF) $(BINDIR)/gmplayer$(EXESUF)
rm -f $(BINDIR)/mencoder$(EXESUF)
rm -f $(MANDIR)/man1/mencoder.1 $(MANDIR)/man1/mplayer.1
rm -f $(prefix)/share/pixmaps/mplayer.xpm
rm -f $(prefix)/share/applications/mplayer.desktop
rm -f $(MANDIR)/man1/mplayer.1 $(MANDIR)/man1/mencoder.1
rm -f $(foreach lang,$(MAN_LANGS),$(foreach man,mplayer.1 mencoder.1,$(MANDIR)/$(lang)/man1/$(man)))
rm -f $(MANDIR)/man1/mplayer.1
rm -f $(foreach lang,$(MAN_LANGS),$(foreach man,mplayer.1,$(MANDIR)/$(lang)/man1/$(man)))
rm -f $(foreach lang,$(MSG_LANGS),$(LOCALEDIR)/$(lang)/LC_MESSAGES/mplayer.1)
clean:
-rm -f $(call ADD_ALL_DIRS,/*.o /*.a /*.ho /*~)
-rm -f $(call ADD_ALL_EXESUFS,mplayer mencoder)
-rm -f $(call ADD_ALL_EXESUFS,mplayer)
distclean: clean testsclean toolsclean driversclean dhahelperclean dhahelperwinclean
-rm -rf DOCS/tech/doxygen

View File

@ -1,278 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_CFG_MENCODER_H
#define MPLAYER_CFG_MENCODER_H
/*
* config for cfgparser
*/
#include "libmpcodecs/ve_x264.h"
#include "cfg-common.h"
extern const m_option_t faacopts_conf[];
extern const m_option_t lameopts_conf[];
extern const m_option_t lavcopts_conf[];
extern const m_option_t lavfopts_conf[];
extern const m_option_t mpegopts_conf[];
extern const m_option_t nuvopts_conf[];
extern const m_option_t toolameopts_conf[];
extern const m_option_t twolameopts_conf[];
extern const m_option_t vfwopts_conf[];
extern const m_option_t xvidencopts_conf[];
const m_option_t ovc_conf[]={
{"copy", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_COPY, NULL},
{"frameno", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_FRAMENO, NULL},
{"lavc", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_LIBAVCODEC, NULL},
// {"null", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_NULL, NULL},
{"raw", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_RAW, NULL},
{"vfw", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_VFW, NULL},
{"libdv", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_LIBDV, NULL},
{"xvid", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_XVID, NULL},
{"qtvideo", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_QTVIDEO, NULL},
{"nuv", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_NUV, NULL},
{"x264", &out_video_codec, CONF_TYPE_FLAG, 0, 0, VCODEC_X264, NULL},
{"help", "\nAvailable codecs:\n"
" copy - frame copy, without re-encoding. Doesn't work with filters.\n"
" frameno - special audio-only file for 3-pass encoding, see DOCS.\n"
" raw - uncompressed video. Use fourcc option to set format explicitly.\n"
#ifdef CONFIG_LIBLZO
" nuv - nuppel video\n"
#endif
#ifdef CONFIG_LIBAVCODEC
" lavc - libavcodec codecs - best quality!\n"
#endif
#ifdef CONFIG_WIN32DLL
" vfw - VfW DLLs, read DOCS/HTML/en/encoding-guide.html.\n"
" qtvideo - QuickTime DLLs, currently only SVQ1/3 are supported.\n"
#endif
#ifdef CONFIG_LIBDV095
" libdv - DV encoding with libdv v0.9.5\n"
#endif
#ifdef CONFIG_XVID4
" xvid - XviD encoding\n"
#endif
#ifdef CONFIG_X264
" x264 - H.264 encoding\n"
#endif
"\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
const m_option_t oac_conf[]={
{"copy", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_COPY, NULL},
{"pcm", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_PCM, NULL},
#ifdef CONFIG_MP3LAME
{"mp3lame", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_VBRMP3, NULL},
#else
{"mp3lame", "MPlayer was compiled without libmp3lame support.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif /* CONFIG_MP3LAME */
#ifdef CONFIG_LIBAVCODEC
{"lavc", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_LAVC, NULL},
#else
{"lavc", "MPlayer was compiled without libavcodec. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif /* CONFIG_LIBAVCODEC */
#ifdef CONFIG_TOOLAME
{"toolame", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_TOOLAME, NULL},
#else
{"toolame", "MPlayer was compiled without libtoolame. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif /* CONFIG_TOOLAME */
#ifdef CONFIG_TWOLAME
{"twolame", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_TWOLAME, NULL},
#else
{"twolame", "MPlayer was compiled without libtwolame. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif /* CONFIG_TWOLAME */
#ifdef CONFIG_FAAC
{"faac", &out_audio_codec, CONF_TYPE_FLAG, 0, 0, ACODEC_FAAC, NULL},
#else
{"faac", "MPlayer was compiled without libfaac. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif /* CONFIG_FAAC */
{"help", "\nAvailable codecs:\n"
" copy - frame copy, without re-encoding (useful for AC3)\n"
" pcm - uncompressed PCM audio\n"
#ifdef CONFIG_MP3LAME
" mp3lame - cbr/abr/vbr MP3 using libmp3lame\n"
#endif
#ifdef CONFIG_LIBAVCODEC
" lavc - FFmpeg audio encoder (MP2, AC3, ...)\n"
#endif
#ifdef CONFIG_TOOLAME
" toolame - Toolame MP2 audio encoder\n"
#endif
#ifdef CONFIG_TWOLAME
" twolame - Twolame MP2 audio encoder\n"
#endif
#ifdef CONFIG_FAAC
" faac - FAAC AAC audio encoder\n"
#endif
"\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
const m_option_t info_conf[]={
{"name", &info_name, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"artist", &info_artist, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"genre", &info_genre, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"subject", &info_subject, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"copyright", &info_copyright, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"srcform", &info_sourceform, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"comment", &info_comment, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"help", "\nAvailable INFO fields:\n"
" name - title of the work\n"
" artist - artist or author of the work\n"
" genre - original work category\n"
" subject - contents of the work\n"
" copyright - copyright information\n"
" srcform - original format of the digitzed material\n"
" comment - general comments about the work\n"
"\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
const m_option_t of_conf[]={
{"avi", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_AVI, NULL},
{"mpeg", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_MPEG, NULL},
#ifdef CONFIG_LIBAVFORMAT
{"lavf", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_LAVF, NULL},
#endif
{"rawvideo", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_RAWVIDEO, NULL},
{"rawaudio", &out_file_format, CONF_TYPE_FLAG, 0, 0, MUXER_TYPE_RAWAUDIO, NULL},
{"help", "\nAvailable output formats:\n"
" avi - Microsoft Audio/Video Interleaved\n"
" mpeg - MPEG-1/2 system stream format\n"
#ifdef CONFIG_LIBAVFORMAT
" lavf - FFmpeg libavformat muxers\n"
#endif
" rawvideo - (video only, one stream only) raw stream, no muxing\n"
" rawaudio - (audio only, one stream only) raw stream, no muxing\n"
"\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
extern float avi_aspect_override; /* defined in libmpdemux/muxer_avi.c */
extern int write_odml; /* defined in libmpdemux/muxer_avi.c */
const m_option_t mencoder_opts[]={
/* name, pointer, type, flags, min, max */
{"frameno-file", &frameno_filename, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
{"hr-edl-seek", &edl_seek_type, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{"nohr-edl-seek", &edl_seek_type, CONF_TYPE_FLAG, 0, 1, 0, NULL},
// set output framerate - recommended for variable-FPS (ASF etc) files
// and for 29.97FPS progressive MPEG2 streams
{"ofps", &force_ofps, CONF_TYPE_DOUBLE, CONF_MIN|CONF_GLOBAL, 0, 0, NULL},
{"o", &out_filename, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
// limit number of skippable frames after a non-skipped one
{"skiplimit", &skip_limit, CONF_TYPE_INT, 0, 0, 0, NULL},
{"noskiplimit", &skip_limit, CONF_TYPE_FLAG, 0, 0, -1, NULL},
{"noskip", &skip_limit, CONF_TYPE_FLAG, 0, 0, 0, NULL},
{"audio-density", &audio_density, CONF_TYPE_INT, CONF_RANGE|CONF_GLOBAL, 1, 50, NULL},
{"audio-preload", &audio_preload, CONF_TYPE_FLOAT, CONF_RANGE|CONF_GLOBAL, 0, 2, NULL},
{"audio-delay", &audio_delay_fix, CONF_TYPE_FLOAT, CONF_GLOBAL, 0, 0, NULL},
{"x", "-x has been removed, use -vf scale=w:h for scaling.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
{"xsize", "-xsize has been removed, use -vf crop=w:h:x:y for cropping.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
// output audio/video codec selection
{"oac", (void *) oac_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
{"ovc", (void *) ovc_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
// output file format
{"of", (void *) of_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
// override audio format tag in output file
{"fafmttag", &force_audiofmttag, CONF_TYPE_INT, CONF_GLOBAL, 0, 0, NULL},
// override FOURCC in output file
{"ffourcc", &force_fourcc, CONF_TYPE_STRING, CONF_GLOBAL, 4, 4, NULL},
// override avi aspect autodetection
{"force-avi-aspect", &avi_aspect_override, CONF_TYPE_FLOAT, CONF_RANGE|CONF_GLOBAL, 0.2, 3.0, NULL},
{"pass", "-pass has been removed, use -lavcopts vpass=n, -xvidencopts pass=n\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
{"passlogfile", &passtmpfile, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
{"vobsubout", &vobsub_out, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
{"vobsuboutindex", &vobsub_out_index, CONF_TYPE_INT, CONF_RANGE|CONF_GLOBAL, 0, 31, NULL},
{"vobsuboutid", &vobsub_out_id, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
{"autoexpand", &auto_expand, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{"noautoexpand", &auto_expand, CONF_TYPE_FLAG, 0, 1, 0, NULL},
{"encodedups", &encode_duplicates, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{"noencodedups", &encode_duplicates, CONF_TYPE_FLAG, 0, 1, 0, NULL},
{"odml", &write_odml, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
{"noodml", &write_odml, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL},
// info header strings
{"info", (void *) info_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
#ifdef CONFIG_MP3LAME
{"lameopts", lameopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
#endif
#ifdef CONFIG_LIBAVCODEC
{"lavcopts", lavcopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
#else
{"lavcopts", "MPlayer was compiled without libavcodec. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif /* CONFIG_LIBAVCODEC */
#ifdef CONFIG_TOOLAME
{"toolameopts", toolameopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
#else
{"toolameopts", "MPlayer was compiled without libtoolame. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif /* CONFIG_TOOLAME */
#ifdef CONFIG_TWOLAME
{"twolameopts", twolameopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
#else
{"twolameopts", "MPlayer was compiled without libtwolame. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif /* CONFIG_TWOLAME */
#ifdef CONFIG_FAAC
{"faacopts", faacopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
#else
{"faacopts", "MPlayer was compiled without libfaac. See README or DOCS.\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif /* CONFIG_FAAC */
#ifdef CONFIG_WIN32DLL
{"xvfwopts", vfwopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
#endif
#ifdef CONFIG_XVID4
{"xvidencopts", xvidencopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
#endif
#if defined(CONFIG_X264)
{"x264encopts", &x264enc_set_param, CONF_TYPE_FUNC_PARAM, CONF_GLOBAL, 0, 0, NULL},
#endif
#ifdef CONFIG_LIBLZO
{"nuvopts", nuvopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
#endif
{"mpegopts", mpegopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
#ifdef CONFIG_LIBAVFORMAT
{"lavfopts", lavfopts_conf, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
#endif
// {"-help", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
// {"help", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
// {"h", help_text, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
#endif /* MPLAYER_CFG_MENCODER_H */

9
configure vendored
View File

@ -264,7 +264,6 @@ Installation directories:
--codecsdir=DIR directory for binary codecs [LIBDIR/codecs]
Optional features:
--disable-mencoder disable MEncoder (A/V encoder) compilation [enable]
--disable-mplayer disable MPlayer compilation [enable]
--disable-largefiles disable support for files > 2GB [enable]
--enable-termcap use termcap database for key codes [autodetect]
@ -501,7 +500,6 @@ Use these options if autodetection fails:
--extra-ldflags=FLAGS extra LDFLAGS
--extra-libs=FLAGS extra linker flags
--extra-libs-mplayer=FLAGS extra linker flags for MPlayer
--extra-libs-mencoder=FLAGS extra linker flags for MEncoder
--with-xvmclib=NAME adapter-specific library name (e.g. XvMCNVIDIA)
--with-freetype-config=PATH path to freetype-config
@ -559,7 +557,7 @@ _libpostproc=auto
_libswscale=auto
_libavcodec_internals=no
_libswscale_internals=no
_mencoder=yes
_mencoder=no
_mplayer=yes
_x11=auto
_xshape=auto
@ -810,9 +808,6 @@ for ac_option do
--extra-libs-mplayer=*)
libs_mplayer=$(echo $ac_option | cut -d '=' -f 2)
;;
--extra-libs-mencoder=*)
libs_mencoder=$(echo $ac_option | cut -d '=' -f 2)
;;
--target=*)
_target=$(echo $ac_option | cut -d '=' -f 2)
@ -884,8 +879,6 @@ for ac_option do
--disable-runtime-cpudetection) _runtime_cpudetection=no ;;
--enable-cross-compile) _cross_compile=yes ;;
--disable-cross-compile) _cross_compile=no ;;
--enable-mencoder) _mencoder=yes ;;
--disable-mencoder) _mencoder=no ;;
--enable-mplayer) _mplayer=yes ;;
--disable-mplayer) _mplayer=no ;;
--enable-dynamic-plugins) _dynamic_plugins=yes ;;

View File

@ -1,116 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <sys/types.h>
#include <math.h>
#include "config.h"
#include "libmpdemux/aviheader.h"
#include "libmpdemux/ms_hdr.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include "ae.h"
#include "ae_pcm.h"
#ifdef CONFIG_TOOLAME
#include "ae_toolame.h"
#endif
#ifdef CONFIG_MP3LAME
#include "ae_lame.h"
#endif
#ifdef CONFIG_LIBAVCODEC
#include "ae_lavc.h"
#endif
#ifdef CONFIG_FAAC
#include "ae_faac.h"
#endif
#ifdef CONFIG_TWOLAME
#include "ae_twolame.h"
#endif
audio_encoder_t *new_audio_encoder(muxer_stream_t *stream, audio_encoding_params_t *params)
{
int ris;
audio_encoder_t *encoder;
if(! params)
return NULL;
encoder = calloc(1, sizeof(audio_encoder_t));
memcpy(&encoder->params, params, sizeof(audio_encoding_params_t));
encoder->stream = stream;
switch(stream->codec)
{
case ACODEC_PCM:
ris = mpae_init_pcm(encoder);
break;
#ifdef CONFIG_TOOLAME
case ACODEC_TOOLAME:
ris = mpae_init_toolame(encoder);
break;
#endif
#ifdef CONFIG_LIBAVCODEC
case ACODEC_LAVC:
ris = mpae_init_lavc(encoder);
break;
#endif
#ifdef CONFIG_MP3LAME
case ACODEC_VBRMP3:
ris = mpae_init_lame(encoder);
break;
#endif
#ifdef CONFIG_FAAC
case ACODEC_FAAC:
ris = mpae_init_faac(encoder);
break;
#endif
#ifdef CONFIG_TWOLAME
case ACODEC_TWOLAME:
ris = mpae_init_twolame(encoder);
break;
#endif
default:
ris = 0;
break;
}
if(! ris)
{
free(encoder);
return NULL;
}
encoder->bind(encoder, stream);
encoder->decode_buffer = malloc(encoder->decode_buffer_size);
if(! encoder->decode_buffer)
{
free(encoder);
return NULL;
}
encoder->codec = stream->codec;
return encoder;
}

View File

@ -1,65 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_AE_H
#define MPLAYER_AE_H
#include "libmpdemux/muxer.h"
#define ACODEC_COPY 0
#define ACODEC_PCM 1
#define ACODEC_VBRMP3 2
#define ACODEC_NULL 3
#define ACODEC_LAVC 4
#define ACODEC_TOOLAME 5
#define ACODEC_FAAC 6
#define ACODEC_TWOLAME 7
#define AE_NEEDS_COMPRESSED_INPUT 1
typedef struct {
int channels;
int sample_rate;
int bitrate;
int samples_per_frame;
int audio_preload;
} audio_encoding_params_t;
typedef struct audio_encoder_s {
int codec;
int flags;
muxer_stream_t *stream;
audio_encoding_params_t params;
int audio_preload; //in ms
int input_format;
int min_buffer_size, max_buffer_size; //for init_audio_filters
unsigned char *decode_buffer;
int decode_buffer_size;
int decode_buffer_len;
void *priv;
int (*bind)(struct audio_encoder_s*, muxer_stream_t*);
int (*get_frame_size)(struct audio_encoder_s*);
int (*set_decoded_len)(struct audio_encoder_s *encoder, int len);
int (*encode)(struct audio_encoder_s *encoder, uint8_t *dest, void *src, int nsamples, int max_size);
void (*fixup)(struct audio_encoder_s *encoder);
int (*close)(struct audio_encoder_s *encoder);
} audio_encoder_t;
audio_encoder_t *new_audio_encoder(muxer_stream_t *stream, audio_encoding_params_t *params);
#endif /* MPLAYER_AE_H */

View File

@ -1,215 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include "m_option.h"
#include "mp_msg.h"
#include "libmpdemux/aviheader.h"
#include "libaf/af_format.h"
#include "libaf/reorder_ch.h"
#include "libmpdemux/ms_hdr.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include <faac.h>
#include "ae.h"
static faacEncHandle faac;
static faacEncConfigurationPtr config = NULL;
static int
param_bitrate = 128,
param_quality = 0,
param_object_type = 1,
param_mpeg = 2,
param_tns = 0,
param_raw = 0,
param_cutoff = 0,
param_format = 16,
param_debug = 0;
static int enc_frame_size = 0, divisor;
static unsigned long samples_input, max_bytes_output;
static unsigned char *decoder_specific_buffer = NULL;
static unsigned long decoder_specific_len = 0;
const m_option_t faacopts_conf[] = {
{"br", &param_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
{"quality", &param_quality, CONF_TYPE_INT, CONF_RANGE, 0, 1000, NULL},
{"object", &param_object_type, CONF_TYPE_INT, CONF_RANGE, 1, 4, NULL},
{"mpeg", &param_mpeg, CONF_TYPE_INT, CONF_RANGE, 2, 4, NULL},
{"tns", &param_tns, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{"cutoff", &param_cutoff, CONF_TYPE_INT, 0, 0, 0, NULL},
{"format", &param_format, CONF_TYPE_INT, 0, 0, 0, NULL},
{"raw", &param_raw, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{"debug", &param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
static int bind_faac(audio_encoder_t *encoder, muxer_stream_t *mux_a)
{
mux_a->wf = calloc(1, sizeof(WAVEFORMATEX) + decoder_specific_len + 256);
mux_a->wf->wFormatTag = 0x706D;
mux_a->wf->nChannels = encoder->params.channels;
mux_a->h.dwSampleSize=0; // VBR
mux_a->h.dwRate=encoder->params.sample_rate;
mux_a->h.dwScale=encoder->params.samples_per_frame;
mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
mux_a->wf->nAvgBytesPerSec = encoder->params.bitrate / 8;
mux_a->wf->nBlockAlign = mux_a->h.dwScale;
mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
mux_a->wf->cbSize = decoder_specific_len;
mux_a->wf->wBitsPerSample = 0; /* does not apply */
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
// Fix allocation
mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize);
if(config->inputFormat == FAAC_INPUT_FLOAT)
encoder->input_format = AF_FORMAT_FLOAT_NE;
else if(config->inputFormat == FAAC_INPUT_32BIT)
encoder->input_format = AF_FORMAT_S32_NE;
else
encoder->input_format = AF_FORMAT_S16_NE;
encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
if(decoder_specific_buffer && decoder_specific_len)
memcpy(mux_a->wf + 1, decoder_specific_buffer, decoder_specific_len);
return 1;
}
static int get_frame_size(audio_encoder_t *encoder)
{
int sz = enc_frame_size;
enc_frame_size = 0;
return sz;
}
static int encode_faac(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
{
if (encoder->params.channels >= 5)
reorder_channel_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
AF_CHANNEL_LAYOUT_AAC_DEFAULT,
encoder->params.channels,
len / divisor, divisor);
// len is divided by the number of bytes per sample
enc_frame_size = faacEncEncode(faac, (int32_t*) src, len / divisor, dest, max_size);
return enc_frame_size;
}
int close_faac(audio_encoder_t *encoder)
{
return 1;
}
int mpae_init_faac(audio_encoder_t *encoder)
{
if(encoder->params.channels < 1 || encoder->params.channels > 6 || (param_mpeg != 2 && param_mpeg != 4))
{
mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, unsupported number of channels: %d, or mpeg version: %d, exit\n", encoder->params.channels, param_mpeg);
return 0;
}
faac = faacEncOpen(encoder->params.sample_rate, encoder->params.channels, &samples_input, &max_bytes_output);
if(!faac)
{
mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, couldn't init, exit\n");
return 0;
}
mp_msg(MSGT_MENCODER, MSGL_V, "AE_FAAC, sample_input: %lu, max_bytes_output: %lu\n", samples_input, max_bytes_output);
config = faacEncGetCurrentConfiguration(faac);
if(!config)
{
mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, couldn't get init configuration, exit\n");
return 0;
}
param_bitrate *= 1000;
if(param_quality)
config->quantqual = param_quality;
else
config->bitRate = param_bitrate / encoder->params.channels;
if(param_format==33)
{
config->inputFormat = FAAC_INPUT_FLOAT;
divisor = 4;
}
else if(param_format==32)
{
config->inputFormat = FAAC_INPUT_32BIT;
divisor = 4;
}
else
{
config->inputFormat = FAAC_INPUT_16BIT;
divisor = 2;
}
config->outputFormat = param_raw ? 0 : 1; // 1 is ADTS
config->aacObjectType = param_object_type;
if(MAIN==0) config->aacObjectType--;
config->mpegVersion = (param_mpeg == 4 ? MPEG4 : MPEG2);
config->useTns = param_tns;
config->allowMidside = 1;
config->shortctl = SHORTCTL_NORMAL;
param_cutoff = param_cutoff ? param_cutoff : encoder->params.sample_rate / 2;
if(param_cutoff > encoder->params.sample_rate / 2)
param_cutoff = encoder->params.sample_rate / 2;
config->bandWidth = param_cutoff;
if(encoder->params.channels == 6)
config->useLfe = 1;
if(!faacEncSetConfiguration(faac, config))
{
mp_msg(MSGT_MENCODER, MSGL_FATAL, "AE_FAAC, counldn't set specified parameters, exiting\n");
return 0;
}
if(param_raw)
faacEncGetDecoderSpecificInfo(faac, &decoder_specific_buffer, &decoder_specific_len);
else
decoder_specific_len = 0;
encoder->params.bitrate = param_bitrate;
encoder->params.samples_per_frame = 1024;
encoder->decode_buffer_size = divisor * samples_input; //samples * 16 bits_per_sample
encoder->bind = bind_faac;
encoder->get_frame_size = get_frame_size;
encoder->encode = encode_faac;
encoder->close = close_faac;
return 1;
}

View File

@ -1,27 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_AE_FAAC_H
#define MPLAYER_AE_FAAC_H
#include "ae.h"
#include "libmpdemux/muxer.h"
int mpae_init_faac(audio_encoder_t *encoder);
#endif /* MPLAYER_AE_FAAC_H */

View File

@ -1,493 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include "m_option.h"
#include "mp_msg.h"
#include "libmpdemux/aviheader.h"
#include "libmpdemux/ms_hdr.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include "ae_pcm.h"
#include "libaf/af_format.h"
#include "libmpdemux/mp3_hdr.h"
#undef CDECL
#include <lame/lame.h>
lame_global_flags *lame;
static int lame_param_quality=0; // best
static int lame_param_algqual=5; // same as old default
static int lame_param_vbr=vbr_default;
static int lame_param_mode=-1; // unset
static int lame_param_padding=-1; // unset
static int lame_param_br=-1; // unset
static int lame_param_ratio=-1; // unset
static float lame_param_scale=-1; // unset
static int lame_param_lowpassfreq = 0; //auto
static int lame_param_highpassfreq = 0; //auto
static int lame_param_free_format = 0; //disabled
static int lame_param_br_min = 0; //not specified
static int lame_param_br_max = 0; //not specified
#ifdef CONFIG_MP3LAME_PRESET
int lame_param_fast=0; // unset
static char* lame_param_preset=NULL; // unset
static int lame_presets_set( lame_t gfp, int fast, int cbr, const char* preset_name );
#endif
#define MEncoderMP3LameHelp _("\n\n"\
" vbr=<0-4> variable bitrate method\n"\
" 0: cbr (constant bitrate)\n"\
" 1: mt (Mark Taylor VBR algorithm)\n"\
" 2: rh (Robert Hegemann VBR algorithm - default)\n"\
" 3: abr (average bitrate)\n"\
" 4: mtrh (Mark Taylor Robert Hegemann VBR algorithm)\n"\
"\n"\
" abr average bitrate\n"\
"\n"\
" cbr constant bitrate\n"\
" Also forces CBR mode encoding on subsequent ABR presets modes.\n"\
"\n"\
" br=<0-1024> specify bitrate in kBit (CBR and ABR only)\n"\
"\n"\
" q=<0-9> quality (0-highest, 9-lowest) (only for VBR)\n"\
"\n"\
" aq=<0-9> algorithmic quality (0-best/slowest, 9-worst/fastest)\n"\
"\n"\
" ratio=<1-100> compression ratio\n"\
"\n"\
" vol=<0-10> set audio input gain\n"\
"\n"\
" mode=<0-3> (default: auto)\n"\
" 0: stereo\n"\
" 1: joint-stereo\n"\
" 2: dualchannel\n"\
" 3: mono\n"\
"\n"\
" padding=<0-2>\n"\
" 0: no\n"\
" 1: all\n"\
" 2: adjust\n"\
"\n"\
" fast Switch on faster encoding on subsequent VBR presets modes,\n"\
" slightly lower quality and higher bitrates.\n"\
"\n"\
" preset=<value> Provide the highest possible quality settings.\n"\
" medium: VBR encoding, good quality\n"\
" (150-180 kbps bitrate range)\n"\
" standard: VBR encoding, high quality\n"\
" (170-210 kbps bitrate range)\n"\
" extreme: VBR encoding, very high quality\n"\
" (200-240 kbps bitrate range)\n"\
" insane: CBR encoding, highest preset quality\n"\
" (320 kbps bitrate)\n"\
" <8-320>: ABR encoding at average given kbps bitrate.\n\n")
const m_option_t lameopts_conf[] = {
{"q", &lame_param_quality, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL},
{"aq", &lame_param_algqual, CONF_TYPE_INT, CONF_RANGE, 0, 9, NULL},
{"vbr", &lame_param_vbr, CONF_TYPE_INT, CONF_RANGE, 0, vbr_max_indicator, NULL},
{"cbr", &lame_param_vbr, CONF_TYPE_FLAG, 0, 0, 0, NULL},
{"abr", &lame_param_vbr, CONF_TYPE_FLAG, 0, 0, vbr_abr, NULL},
{"mode", &lame_param_mode, CONF_TYPE_INT, CONF_RANGE, 0, MAX_INDICATOR, NULL},
{"padding", &lame_param_padding, CONF_TYPE_INT, CONF_RANGE, 0, PAD_MAX_INDICATOR, NULL},
{"br", &lame_param_br, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
{"ratio", &lame_param_ratio, CONF_TYPE_INT, CONF_RANGE, 0, 100, NULL},
{"vol", &lame_param_scale, CONF_TYPE_FLOAT, CONF_RANGE, 0, 10, NULL},
{"lowpassfreq",&lame_param_lowpassfreq, CONF_TYPE_INT, CONF_RANGE, -1, 48000,0},
{"highpassfreq",&lame_param_highpassfreq, CONF_TYPE_INT, CONF_RANGE, -1, 48000,0},
{"nofree", &lame_param_free_format, CONF_TYPE_FLAG, 0, 0, 0, NULL},
{"free", &lame_param_free_format, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{"br_min", &lame_param_br_min, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
{"br_max", &lame_param_br_max, CONF_TYPE_INT, CONF_RANGE, 0, 1024, NULL},
#ifdef CONFIG_MP3LAME_PRESET
{"fast", &lame_param_fast, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{"preset", &lame_param_preset, CONF_TYPE_STRING, 0, 0, 0, NULL},
#else
{"fast", "MPlayer was built without -lameopts fast support (requires libmp3lame >=3.92).\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
{"preset", "MPlayer was built without -lameopts preset support (requires libmp3lame >=3.92).\n", CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
#endif
{"help", MEncoderMP3LameHelp, CONF_TYPE_PRINT, CONF_NOCFG, 0, 0, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
static int bind_lame(audio_encoder_t *encoder, muxer_stream_t *mux_a)
{
mp_tmsg(MSGT_MENCODER, MSGL_INFO, "MP3 audio selected.\n");
mux_a->h.dwSampleSize=0; // VBR
mux_a->h.dwRate=encoder->params.sample_rate;
mux_a->h.dwScale=encoder->params.samples_per_frame; // samples/frame
if(sizeof(MPEGLAYER3WAVEFORMAT)!=30) mp_tmsg(MSGT_MENCODER,MSGL_WARN,"sizeof(MPEGLAYER3WAVEFORMAT)==%d!=30, maybe broken C compiler?\n",sizeof(MPEGLAYER3WAVEFORMAT));
mux_a->wf=malloc(sizeof(MPEGLAYER3WAVEFORMAT)); // should be 30
mux_a->wf->wFormatTag=0x55; // MP3
mux_a->wf->nChannels= (lame_param_mode<0) ? encoder->params.channels : ((lame_param_mode==3) ? 1 : 2);
mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
if(! lame_param_vbr)
mux_a->wf->nAvgBytesPerSec=lame_param_br * 125;
else
mux_a->wf->nAvgBytesPerSec=192000/8; // FIXME!
mux_a->wf->nBlockAlign=encoder->params.samples_per_frame; // required for l3codeca.acm + WMP 6.4
mux_a->wf->wBitsPerSample=0; //16;
// from NaNdub: (requires for l3codeca.acm)
mux_a->wf->cbSize=12;
((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->wID=1;
((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->fdwFlags=2;
((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nBlockSize=encoder->params.samples_per_frame; // ???
((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nFramesPerBlock=1;
((MPEGLAYER3WAVEFORMAT*)(mux_a->wf))->nCodecDelay=0;
encoder->input_format = AF_FORMAT_S16_NE;
encoder->min_buffer_size = 4608;
encoder->max_buffer_size = mux_a->h.dwRate * mux_a->wf->nChannels * 2;
return 1;
}
#define min(a, b) ((a) <= (b) ? (a) : (b))
static int get_frame_size(audio_encoder_t *encoder)
{
int sz;
if(encoder->stream->buffer_len < 4)
return 0;
sz = mp_decode_mp3_header(encoder->stream->buffer);
if(sz <= 0)
return 0;
return sz;
}
static int encode_lame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
{
int n = 0;
if(encoder->params.channels == 1)
n = lame_encode_buffer(lame, (short *)src, (short *)src, len/2, dest, max_size);
else
n = lame_encode_buffer_interleaved(lame,(short *)src, len/4, dest, max_size);
return n < 0 ? 0 : n;
}
static int close_lame(audio_encoder_t *encoder)
{
return 1;
}
static void fixup(audio_encoder_t *encoder)
{
// fixup CBR mp3 audio header:
if(!lame_param_vbr) {
encoder->stream->h.dwSampleSize=1;
if (encoder->stream->h.dwLength)
((MPEGLAYER3WAVEFORMAT*)(encoder->stream->wf))->nBlockSize=
(encoder->stream->size+(encoder->stream->h.dwLength>>1))/encoder->stream->h.dwLength;
encoder->stream->h.dwLength=encoder->stream->size;
encoder->stream->h.dwRate=encoder->stream->wf->nAvgBytesPerSec;
encoder->stream->h.dwScale=1;
encoder->stream->wf->nBlockAlign=1;
mp_tmsg(MSGT_MENCODER, MSGL_V, "\n\nCBR audio: %d bytes/sec, %d bytes/block\n",
encoder->stream->h.dwRate,((MPEGLAYER3WAVEFORMAT*)(encoder->stream->wf))->nBlockSize);
}
}
int mpae_init_lame(audio_encoder_t *encoder)
{
encoder->params.bitrate = lame_param_br * 125;
encoder->params.samples_per_frame = encoder->params.sample_rate < 32000 ? 576 : 1152;
encoder->decode_buffer_size = 2304;
lame=lame_init();
lame_set_bWriteVbrTag(lame,0);
lame_set_in_samplerate(lame,encoder->params.sample_rate);
//lame_set_in_samplerate(lame,sh_audio->samplerate); // if resampling done by lame
lame_set_num_channels(lame,encoder->params.channels);
lame_set_out_samplerate(lame,encoder->params.sample_rate);
lame_set_quality(lame,lame_param_algqual); // 0 = best q
if(lame_param_free_format) lame_set_free_format(lame,1);
if(lame_param_vbr){ // VBR:
lame_set_VBR(lame,lame_param_vbr); // vbr mode
lame_set_VBR_q(lame,lame_param_quality); // 0 = best vbr q 5=~128k
if(lame_param_br>0) lame_set_VBR_mean_bitrate_kbps(lame,lame_param_br);
if(lame_param_br_min>0) lame_set_VBR_min_bitrate_kbps(lame,lame_param_br_min);
if(lame_param_br_max>0) lame_set_VBR_max_bitrate_kbps(lame,lame_param_br_max);
} else { // CBR:
if(lame_param_br>0) lame_set_brate(lame,lame_param_br);
}
if(lame_param_mode>=0) lame_set_mode(lame,lame_param_mode); // j-st
if(lame_param_ratio>0) lame_set_compression_ratio(lame,lame_param_ratio);
if(lame_param_scale>0) {
mp_tmsg(MSGT_MENCODER, MSGL_V, "Setting audio input gain to %f.\n", lame_param_scale);
lame_set_scale(lame,lame_param_scale);
}
if(lame_param_lowpassfreq>=-1) lame_set_lowpassfreq(lame,lame_param_lowpassfreq);
if(lame_param_highpassfreq>=-1) lame_set_highpassfreq(lame,lame_param_highpassfreq);
#ifdef CONFIG_MP3LAME_PRESET
if(lame_param_preset != NULL) {
mp_tmsg(MSGT_MENCODER, MSGL_V, "\npreset=%s\n\n",lame_param_preset);
if(lame_presets_set(lame,lame_param_fast, (lame_param_vbr==0), lame_param_preset) < 0)
return 0;
}
#endif
if(lame_init_params(lame) == -1) {
mp_tmsg(MSGT_MENCODER, MSGL_FATAL,
"Cannot set LAME options, check bitrate/samplerate, some very low bitrates\n"\
"(<32) need lower samplerates (i.e. -srate 8000).\n"\
"If everything else fails, try a preset.");
return 0;
}
if( mp_msg_test(MSGT_MENCODER,MSGL_V) ) {
lame_print_config(lame);
lame_print_internals(lame);
}
encoder->bind = bind_lame;
encoder->get_frame_size = get_frame_size;
encoder->encode = encode_lame;
encoder->fixup = fixup;
encoder->close = close_lame;
return 1;
}
#ifdef CONFIG_MP3LAME_PRESET
/* lame_presets_set
taken out of presets_set in lame-3.93.1/frontend/parse.c and modified */
static int lame_presets_set( lame_t gfp, int fast, int cbr, const char* preset_name )
{
int mono = 0;
if (strcmp(preset_name, "help") == 0) {
mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "LAME version %s (%s)\n\n", get_lame_version(), get_lame_url());
#define LamePresetsLongInfo _("\n"\
"The preset switches are designed to provide the highest possible quality.\n"\
"\n"\
"They have for the most part been subjected to and tuned via rigorous double\n"\
"blind listening tests to verify and achieve this objective.\n"\
"\n"\
"These are continually updated to coincide with the latest developments that\n"\
"occur and as a result should provide you with nearly the best quality\n"\
"currently possible from LAME.\n"\
"\n"\
"To activate these presets:\n"\
"\n"\
" For VBR modes (generally highest quality):\n"\
"\n"\
" \"preset=standard\" This preset should generally be transparent\n"\
" to most people on most music and is already\n"\
" quite high in quality.\n"\
"\n"\
" \"preset=extreme\" If you have extremely good hearing and similar\n"\
" equipment, this preset will generally provide\n"\
" slightly higher quality than the \"standard\"\n"\
" mode.\n"\
"\n"\
" For CBR 320kbps (highest quality possible from the preset switches):\n"\
"\n"\
" \"preset=insane\" This preset will usually be overkill for most\n"\
" people and most situations, but if you must\n"\
" have the absolute highest quality with no\n"\
" regard to filesize, this is the way to go.\n"\
"\n"\
" For ABR modes (high quality per given bitrate but not as high as VBR):\n"\
"\n"\
" \"preset=<kbps>\" Using this preset will usually give you good\n"\
" quality at a specified bitrate. Depending on the\n"\
" bitrate entered, this preset will determine the\n"\
" optimal settings for that particular situation.\n"\
" While this approach works, it is not nearly as\n"\
" flexible as VBR, and usually will not attain the\n"\
" same level of quality as VBR at higher bitrates.\n"\
"\n"\
"The following options are also available for the corresponding profiles:\n"\
"\n"\
" <fast> standard\n"\
" <fast> extreme\n"\
" insane\n"\
" <cbr> (ABR Mode) - The ABR Mode is implied. To use it,\n"\
" simply specify a bitrate. For example:\n"\
" \"preset=185\" activates this\n"\
" preset and uses 185 as an average kbps.\n"\
"\n"\
" \"fast\" - Enables the new fast VBR for a particular profile. The\n"\
" disadvantage to the speed switch is that often times the\n"\
" bitrate will be slightly higher than with the normal mode\n"\
" and quality may be slightly lower also.\n"\
" Warning: with the current version fast presets might result in too\n"\
" high bitrate compared to regular presets.\n"\
"\n"\
" \"cbr\" - If you use the ABR mode (read above) with a significant\n"\
" bitrate such as 80, 96, 112, 128, 160, 192, 224, 256, 320,\n"\
" you can use the \"cbr\" option to force CBR mode encoding\n"\
" instead of the standard abr mode. ABR does provide higher\n"\
" quality but CBR may be useful in situations such as when\n"\
" streaming an MP3 over the internet may be important.\n"\
"\n"\
" For example:\n"\
"\n"\
" \"-lameopts fast:preset=standard \"\n"\
" or \"-lameopts cbr:preset=192 \"\n"\
" or \"-lameopts preset=172 \"\n"\
" or \"-lameopts preset=extreme \"\n"\
"\n"\
"\n"\
"A few aliases are available for ABR mode:\n"\
"phone => 16kbps/mono phon+/lw/mw-eu/sw => 24kbps/mono\n"\
"mw-us => 40kbps/mono voice => 56kbps/mono\n"\
"fm/radio/tape => 112kbps hifi => 160kbps\n"\
"cd => 192kbps studio => 256kbps")
mp_tmsg(MSGT_MENCODER, MSGL_FATAL, LamePresetsLongInfo);
return -1;
}
//aliases for compatibility with old presets
if (strcmp(preset_name, "phone") == 0) {
preset_name = "16";
mono = 1;
}
if ( (strcmp(preset_name, "phon+") == 0) ||
(strcmp(preset_name, "lw") == 0) ||
(strcmp(preset_name, "mw-eu") == 0) ||
(strcmp(preset_name, "sw") == 0)) {
preset_name = "24";
mono = 1;
}
if (strcmp(preset_name, "mw-us") == 0) {
preset_name = "40";
mono = 1;
}
if (strcmp(preset_name, "voice") == 0) {
preset_name = "56";
mono = 1;
}
if (strcmp(preset_name, "fm") == 0) {
preset_name = "112";
}
if ( (strcmp(preset_name, "radio") == 0) ||
(strcmp(preset_name, "tape") == 0)) {
preset_name = "112";
}
if (strcmp(preset_name, "hifi") == 0) {
preset_name = "160";
}
if (strcmp(preset_name, "cd") == 0) {
preset_name = "192";
}
if (strcmp(preset_name, "studio") == 0) {
preset_name = "256";
}
#ifdef CONFIG_MP3LAME_PRESET_MEDIUM
if (strcmp(preset_name, "medium") == 0) {
if (fast > 0)
lame_set_preset(gfp, MEDIUM_FAST);
else
lame_set_preset(gfp, MEDIUM);
return 0;
}
#endif
if (strcmp(preset_name, "standard") == 0) {
if (fast > 0)
lame_set_preset(gfp, STANDARD_FAST);
else
lame_set_preset(gfp, STANDARD);
return 0;
}
else if (strcmp(preset_name, "extreme") == 0){
if (fast > 0)
lame_set_preset(gfp, EXTREME_FAST);
else
lame_set_preset(gfp, EXTREME);
return 0;
}
else if (((strcmp(preset_name, "insane") == 0) ||
(strcmp(preset_name, "320" ) == 0)) && (fast < 1)) {
lame_set_preset(gfp, INSANE);
return 0;
}
// Generic ABR Preset
if (((atoi(preset_name)) > 0) && (fast < 1)) {
if ((atoi(preset_name)) >= 8 && (atoi(preset_name)) <= 320){
lame_set_preset(gfp, atoi(preset_name));
if (cbr == 1 )
lame_set_VBR(gfp, vbr_off);
if (mono == 1 ) {
lame_set_mode(gfp, MONO);
}
return 0;
}
else {
mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "LAME version %s (%s)\n\n", get_lame_version(), get_lame_url());
mp_tmsg(MSGT_MENCODER, MSGL_FATAL,
"Error: The bitrate specified is out of the valid range for this preset.\n"\
"\n"\
"When using this mode you must enter a value between \"8\" and \"320\".\n"\
"\n"\
"For further information try: \"-lameopts preset=help\"\n");
return -1;
}
}
mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "LAME version %s (%s)\n\n", get_lame_version(), get_lame_url());
#define InvalidLamePresetOptions _("Error: You did not enter a valid profile and/or options with preset.\n"\
"\n"\
"Available profiles are:\n"\
"\n"\
" <fast> standard\n"\
" <fast> extreme\n"\
" insane\n"\
" <cbr> (ABR Mode) - The ABR Mode is implied. To use it,\n"\
" simply specify a bitrate. For example:\n"\
" \"preset=185\" activates this\n"\
" preset and uses 185 as an average kbps.\n"\
"\n"\
" Some examples:\n"\
"\n"\
" \"-lameopts fast:preset=standard \"\n"\
" or \"-lameopts cbr:preset=192 \"\n"\
" or \"-lameopts preset=172 \"\n"\
" or \"-lameopts preset=extreme \"\n"\
"\n"\
"For further information try: \"-lameopts preset=help\"\n")
mp_tmsg(MSGT_MENCODER, MSGL_FATAL, InvalidLamePresetOptions);
return -1;
}
#endif

View File

@ -1,26 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_AE_LAME_H
#define MPLAYER_AE_LAME_H
#include "ae.h"
int mpae_init_lame(audio_encoder_t *encoder);
#endif /* MPLAYER_AE_LAME_H */

View File

@ -1,244 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include "config.h"
#include "m_option.h"
#include "mp_msg.h"
#include "libmpdemux/aviheader.h"
#include "libmpdemux/ms_hdr.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include "ae_lavc.h"
#include "libaf/af_format.h"
#include "libaf/reorder_ch.h"
#include "libavcodec/avcodec.h"
#include "ffmpeg_files/intreadwrite.h"
static AVCodec *lavc_acodec;
static AVCodecContext *lavc_actx;
extern char *lavc_param_acodec;
extern int lavc_param_abitrate;
extern int lavc_param_atag;
extern int lavc_param_audio_global_header;
extern int avcodec_initialized;
static int compressed_frame_size = 0;
#include "libmpdemux/mp_taglists.h"
static int bind_lavc(audio_encoder_t *encoder, muxer_stream_t *mux_a)
{
mux_a->wf = malloc(sizeof(WAVEFORMATEX)+lavc_actx->extradata_size+256);
mux_a->wf->wFormatTag = lavc_param_atag;
mux_a->wf->nChannels = lavc_actx->channels;
mux_a->wf->nSamplesPerSec = lavc_actx->sample_rate;
mux_a->wf->nAvgBytesPerSec = (lavc_actx->bit_rate / 8);
mux_a->avg_rate= lavc_actx->bit_rate;
mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec;
if(lavc_actx->block_align)
mux_a->h.dwSampleSize = mux_a->h.dwScale = lavc_actx->block_align;
else
{
mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * lavc_actx->frame_size)/ mux_a->wf->nSamplesPerSec; /* for cbr */
if ((mux_a->wf->nAvgBytesPerSec *
lavc_actx->frame_size) % mux_a->wf->nSamplesPerSec)
{
mux_a->h.dwScale = lavc_actx->frame_size;
mux_a->h.dwRate = lavc_actx->sample_rate;
mux_a->h.dwSampleSize = 0; // Blocksize not constant
}
else
mux_a->h.dwSampleSize = 0;
}
if(mux_a->h.dwSampleSize)
mux_a->wf->nBlockAlign = mux_a->h.dwSampleSize;
else
mux_a->wf->nBlockAlign = 1;
mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
switch(lavc_param_atag)
{
case 0x11: /* imaadpcm */
mux_a->wf->wBitsPerSample = 4;
mux_a->wf->cbSize = 2;
AV_WL16(mux_a->wf+1, lavc_actx->frame_size);
break;
case 0x55: /* mp3 */
mux_a->wf->cbSize = 12;
mux_a->wf->wBitsPerSample = 0; /* does not apply */
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
break;
default:
mux_a->wf->wBitsPerSample = 0; /* Unknown */
if (lavc_actx->extradata && (lavc_actx->extradata_size > 0))
{
memcpy(mux_a->wf+1, lavc_actx->extradata, lavc_actx->extradata_size);
mux_a->wf->cbSize = lavc_actx->extradata_size;
}
else
mux_a->wf->cbSize = 0;
break;
}
// Fix allocation
mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize);
encoder->input_format = AF_FORMAT_S16_NE;
encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
return 1;
}
static int encode_lavc(audio_encoder_t *encoder, uint8_t *dest, void *src, int size, int max_size)
{
int n;
if ((encoder->params.channels == 6 || encoder->params.channels == 5) &&
(!strcmp(lavc_acodec->name,"ac3") ||
!strcmp(lavc_acodec->name,"libfaac"))) {
int isac3 = !strcmp(lavc_acodec->name,"ac3");
reorder_channel_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
isac3 ? AF_CHANNEL_LAYOUT_LAVC_DEFAULT
: AF_CHANNEL_LAYOUT_AAC_DEFAULT,
encoder->params.channels,
size / 2, 2);
}
n = avcodec_encode_audio(lavc_actx, dest, size, src);
compressed_frame_size = n;
return n;
}
static int close_lavc(audio_encoder_t *encoder)
{
compressed_frame_size = 0;
return 1;
}
static int get_frame_size(audio_encoder_t *encoder)
{
int sz = compressed_frame_size;
compressed_frame_size = 0;
return sz;
}
int mpae_init_lavc(audio_encoder_t *encoder)
{
encoder->params.samples_per_frame = encoder->params.sample_rate;
encoder->params.bitrate = encoder->params.sample_rate * encoder->params.channels * 2 * 8;
if(!lavc_param_acodec)
{
mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "Audio LAVC, Missing codec name!\n");
return 0;
}
if(!avcodec_initialized){
avcodec_init();
avcodec_register_all();
avcodec_initialized=1;
}
lavc_acodec = avcodec_find_encoder_by_name(lavc_param_acodec);
if (!lavc_acodec)
{
mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "Audio LAVC, couldn't find encoder for codec %s.\n", lavc_param_acodec);
return 0;
}
if(lavc_param_atag == 0)
{
lavc_param_atag = mp_av_codec_get_tag(mp_wav_taglists, lavc_acodec->id);
if(!lavc_param_atag)
{
mp_msg(MSGT_MENCODER, MSGL_FATAL, "Couldn't find wav tag for specified codec, exit\n");
return 0;
}
}
lavc_actx = avcodec_alloc_context();
if(lavc_actx == NULL)
{
mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "Audio LAVC, couldn't allocate context!\n");
return 0;
}
lavc_actx->codec_type = CODEC_TYPE_AUDIO;
lavc_actx->codec_id = lavc_acodec->id;
// put sample parameters
lavc_actx->channels = encoder->params.channels;
lavc_actx->sample_rate = encoder->params.sample_rate;
lavc_actx->time_base.num = 1;
lavc_actx->time_base.den = encoder->params.sample_rate;
if(lavc_param_abitrate<1000)
lavc_actx->bit_rate = encoder->params.bitrate = lavc_param_abitrate * 1000;
else
lavc_actx->bit_rate = encoder->params.bitrate = lavc_param_abitrate;
/*
* Special case for adpcm_ima_wav.
* The bitrate is only dependent on samplerate.
* We have to known frame_size and block_align in advance,
* so I just copied the code from libavcodec/adpcm.c
*
* However, ms adpcm_ima_wav uses a block_align of 2048,
* lavc defaults to 1024
*/
if(lavc_param_atag == 0x11) {
int blkalign = 2048;
int framesize = (blkalign - 4 * lavc_actx->channels) * 8 / (4 * lavc_actx->channels) + 1;
lavc_actx->bit_rate = lavc_actx->sample_rate*8*blkalign/framesize;
}
if((lavc_param_audio_global_header&1)
/*|| (video_global_header==0 && (oc->oformat->flags & AVFMT_GLOBALHEADER))*/){
lavc_actx->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
if(lavc_param_audio_global_header&2){
lavc_actx->flags2 |= CODEC_FLAG2_LOCAL_HEADER;
}
if(avcodec_open(lavc_actx, lavc_acodec) < 0)
{
mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "Couldn't open codec %s, br=%d.\n", lavc_param_acodec, lavc_param_abitrate);
return 0;
}
if(lavc_param_atag == 0x11) {
lavc_actx->block_align = 2048;
lavc_actx->frame_size = (lavc_actx->block_align - 4 * lavc_actx->channels) * 8 / (4 * lavc_actx->channels) + 1;
}
encoder->decode_buffer_size = lavc_actx->frame_size * 2 * encoder->params.channels;
while (encoder->decode_buffer_size < 1024) encoder->decode_buffer_size *= 2;
encoder->bind = bind_lavc;
encoder->get_frame_size = get_frame_size;
encoder->encode = encode_lavc;
encoder->close = close_lavc;
return 1;
}

View File

@ -1,26 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_AE_LAVC_H
#define MPLAYER_AE_LAVC_H
#include "ae.h"
int mpae_init_lavc(audio_encoder_t *encoder);
#endif /* MPLAYER_AE_LAVC_H */

View File

@ -1,101 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include "m_option.h"
#include "mp_msg.h"
#include "libmpdemux/aviheader.h"
#include "libaf/af_format.h"
#include "libaf/reorder_ch.h"
#include "libmpdemux/ms_hdr.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include "ae_pcm.h"
static int bind_pcm(audio_encoder_t *encoder, muxer_stream_t *mux_a)
{
mux_a->h.dwScale=1;
mux_a->h.dwRate=encoder->params.sample_rate;
mux_a->wf=malloc(sizeof(WAVEFORMATEX));
mux_a->wf->wFormatTag=0x1; // PCM
mux_a->wf->nChannels=encoder->params.channels;
mux_a->h.dwSampleSize=2*mux_a->wf->nChannels;
mux_a->wf->nBlockAlign=mux_a->h.dwSampleSize;
mux_a->wf->nSamplesPerSec=mux_a->h.dwRate;
mux_a->wf->nAvgBytesPerSec=mux_a->h.dwSampleSize*mux_a->wf->nSamplesPerSec;
mux_a->wf->wBitsPerSample=16;
mux_a->wf->cbSize=0; // FIXME for l3codeca.acm
encoder->input_format = (mux_a->wf->wBitsPerSample==8) ? AF_FORMAT_U8 : AF_FORMAT_S16_LE;
encoder->min_buffer_size = 16384;
encoder->max_buffer_size = mux_a->wf->nAvgBytesPerSec;
return 1;
}
static int encode_pcm(audio_encoder_t *encoder, uint8_t *dest, void *src, int nsamples, int max_size)
{
max_size = FFMIN(nsamples, max_size);
if (encoder->params.channels == 5 || encoder->params.channels == 6 ||
encoder->params.channels == 8) {
max_size -= max_size % (encoder->params.channels * 2);
reorder_channel_copy_nch(src, AF_CHANNEL_LAYOUT_MPLAYER_DEFAULT,
dest, AF_CHANNEL_LAYOUT_WAVEEX_DEFAULT,
encoder->params.channels,
max_size / 2, 2);
}
else
memcpy(dest, src, max_size);
return max_size;
}
static int set_decoded_len(audio_encoder_t *encoder, int len)
{
return len;
}
static int close_pcm(audio_encoder_t *encoder)
{
return 1;
}
static int get_frame_size(audio_encoder_t *encoder)
{
return 0;
}
int mpae_init_pcm(audio_encoder_t *encoder)
{
encoder->params.samples_per_frame = encoder->params.sample_rate;
encoder->params.bitrate = encoder->params.sample_rate * encoder->params.channels * 2 * 8;
encoder->decode_buffer_size = encoder->params.bitrate / 8;
encoder->bind = bind_pcm;
encoder->get_frame_size = get_frame_size;
encoder->set_decoded_len = set_decoded_len;
encoder->encode = encode_pcm;
encoder->close = close_pcm;
return 1;
}

View File

@ -1,26 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_AE_PCM_H
#define MPLAYER_AE_PCM_H
#include "ae.h"
int mpae_init_pcm(audio_encoder_t *encoder);
#endif /* MPLAYER_AE_PCM_H */

View File

@ -1,236 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include "m_option.h"
#include "mp_msg.h"
#include "libmpdemux/aviheader.h"
#include "libaf/af_format.h"
#include "libmpdemux/ms_hdr.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include "ae_toolame.h"
#include "libmpdemux/mp3_hdr.h"
static int
param_bitrate = 192,
param_psy = 3,
param_maxvbr = 0,
param_errprot = 0,
param_debug = 0;
static float param_vbr = 0;
static char *param_mode = "stereo";
const m_option_t toolameopts_conf[] = {
{"br", &param_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
{"mode", &param_mode, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"psy", &param_psy, CONF_TYPE_INT, CONF_RANGE, -1, 4, NULL},
{"vbr", &param_vbr, CONF_TYPE_FLOAT, CONF_RANGE, -50, 50, NULL},
{"maxvbr", &param_maxvbr, CONF_TYPE_INT, 0, 0, 0, NULL},
{"errprot", &param_errprot, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
{"debug", &param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
static int bind_toolame(audio_encoder_t *encoder, muxer_stream_t *mux_a)
{
mpae_toolame_ctx *ctx = (mpae_toolame_ctx *) encoder->priv;
mux_a->wf = malloc(sizeof(WAVEFORMATEX)+256);
mux_a->wf->wFormatTag = 0x50;
mux_a->wf->nChannels = encoder->params.channels;
mux_a->wf->nSamplesPerSec = encoder->params.sample_rate;
mux_a->wf->nAvgBytesPerSec = 125 * encoder->params.bitrate;
if(ctx->vbr || ((mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame) % mux_a->wf->nSamplesPerSec))
{
mux_a->h.dwScale = encoder->params.samples_per_frame;
mux_a->h.dwRate = encoder->params.sample_rate;
mux_a->h.dwSampleSize = 0; // Blocksize not constant
}
else
{
mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame)/ mux_a->wf->nSamplesPerSec; /* for cbr */
mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec;
mux_a->h.dwSampleSize = mux_a->h.dwScale;
}
mux_a->wf->nBlockAlign = mux_a->h.dwScale;
mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
mux_a->wf->cbSize = 0; //12;
mux_a->wf->wBitsPerSample = 0; /* does not apply */
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
// Fix allocation
mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize);
encoder->input_format = AF_FORMAT_S16_NE;
encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
return 1;
}
static int encode_toolame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
{
mpae_toolame_ctx *ctx = (mpae_toolame_ctx *)encoder->priv;
int ret_size = 0, r2, i, nsamples;
int16_t *buffer;
nsamples = len / (2*encoder->params.channels);
buffer = (uint16_t *) src;
for(i = 0; i < nsamples; i++)
{
ctx->left_pcm[i] = buffer[ctx->channels * i];
ctx->right_pcm[i] = buffer[(ctx->channels * i) + (ctx->channels - 1)];
}
toolame_encode_buffer(ctx->toolame_ctx, ctx->left_pcm, ctx->right_pcm, nsamples, dest, max_size, &ret_size);
r2 = mp_decode_mp3_header(dest);
mp_msg(MSGT_MENCODER, MSGL_DBG2, "\nSIZE: %d, max: %d, r2: %d\n", ret_size, max_size, r2);
if(r2 > 0)
ret_size = r2;
return ret_size;
}
static int close_toolame(audio_encoder_t *encoder)
{
free(encoder->priv);
return 1;
}
static int get_frame_size(audio_encoder_t *encoder)
{
int sz;
if(encoder->stream->buffer_len < 4)
return 0;
sz = mp_decode_mp3_header(encoder->stream->buffer);
if(sz <= 0)
return 0;
return sz;
}
int mpae_init_toolame(audio_encoder_t *encoder)
{
int mode;
mpae_toolame_ctx *ctx = NULL;
if(encoder->params.channels == 1)
{
mp_msg(MSGT_MENCODER, MSGL_INFO, "ae_toolame, 1 audio channel, forcing mono mode\n");
mode = MPG_MD_MONO;
}
else if(encoder->params.channels == 2)
{
if(! strcasecmp(param_mode, "dual"))
mode = MPG_MD_DUAL_CHANNEL;
else if(! strcasecmp(param_mode, "jstereo"))
mode = MPG_MD_JOINT_STEREO;
else if(! strcasecmp(param_mode, "stereo"))
mode = MPG_MD_STEREO;
else
{
mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, unknown mode %s, exiting\n", param_mode);
}
}
else
mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, Toolame can't encode > 2 channels, exiting\n");
ctx = calloc(1, sizeof(mpae_toolame_ctx));
if(ctx == NULL)
{
mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, couldn't alloc a %d bytes context, exiting\n", sizeof(mpae_toolame_ctx));
return 0;
}
ctx->toolame_ctx = toolame_init();
if(ctx->toolame_ctx == NULL)
{
mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_toolame, couldn't initial parameters from libtoolame, exiting\n");
free(ctx);
return 0;
}
ctx->vbr = 0;
ctx->channels = encoder->params.channels;
ctx->srate = encoder->params.sample_rate;
if(toolame_setMode(ctx->toolame_ctx, mode) != 0)
return 0;
if(toolame_setPsymodel(ctx->toolame_ctx, param_psy) != 0)
return 0;
if(toolame_setSampleFreq(ctx->toolame_ctx, encoder->params.sample_rate) != 0)
return 0;
if(toolame_setBitrate(ctx->toolame_ctx, param_bitrate) != 0)
return 0;
if(param_errprot)
if(toolame_setErrorProtection(ctx->toolame_ctx, TRUE) != 0)
return 0;
if(param_vbr != 0)
{
if(toolame_setVBR(ctx->toolame_ctx, TRUE) != 0)
return 0;
if(toolame_setVBRLevel(ctx->toolame_ctx, param_vbr) != 0)
return 0;
if(toolame_setPadding(ctx->toolame_ctx, FALSE) != 0)
return 0;
if(param_maxvbr)
{
if(toolame_setVBRUpperBitrate(ctx->toolame_ctx, param_maxvbr) != 0)
return 0;
}
ctx->vbr = 1;
}
if(toolame_setVerbosity(ctx->toolame_ctx, param_debug) != 0)
return 0;
if(toolame_init_params(ctx->toolame_ctx) != 0)
return 0;
ctx->bitrate = param_bitrate;
encoder->params.bitrate = ctx->bitrate;
encoder->params.samples_per_frame = 1152;
encoder->priv = ctx;
encoder->decode_buffer_size = 1152 * 2 * encoder->params.channels;
encoder->bind = bind_toolame;
encoder->get_frame_size = get_frame_size;
encoder->encode = encode_toolame;
encoder->close = close_toolame;
return 1;
}

View File

@ -1,34 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_AE_TOOLAME_H
#define MPLAYER_AE_TOOLAME_H
#include "ae.h"
#include <toolame.h>
typedef struct {
toolame_options *toolame_ctx;
int channels, srate, bitrate;
int vbr;
int16_t left_pcm[1152], right_pcm[1152];
} mpae_toolame_ctx;
int mpae_init_toolame(audio_encoder_t *encoder);
#endif /* MPLAYER_AE_TOOLAME_H */

View File

@ -1,235 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include "m_option.h"
#include "mp_msg.h"
#include "libmpdemux/aviheader.h"
#include "libaf/af_format.h"
#include "libmpdemux/ms_hdr.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include "ae_twolame.h"
#include "libmpdemux/mp3_hdr.h"
static int
param_bitrate = 192,
param_psy = 3,
param_maxvbr = 0,
param_errprot = 0,
param_debug = 0;
static float param_vbr = 0;
static char *param_mode = "stereo";
const m_option_t twolameopts_conf[] = {
{"br", &param_bitrate, CONF_TYPE_INT, 0, 0, 0, NULL},
{"mode", &param_mode, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"psy", &param_psy, CONF_TYPE_INT, CONF_RANGE, -1, 4, NULL},
{"vbr", &param_vbr, CONF_TYPE_FLOAT, CONF_RANGE, -50, 50, NULL},
{"maxvbr", &param_maxvbr, CONF_TYPE_INT, 0, 0, 0, NULL},
{"errprot", &param_errprot, CONF_TYPE_INT, CONF_RANGE, 0, 1, NULL},
{"debug", &param_debug, CONF_TYPE_INT, CONF_RANGE, 0, 100000000, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
static int bind_twolame(audio_encoder_t *encoder, muxer_stream_t *mux_a)
{
mpae_twolame_ctx *ctx = encoder->priv;
mux_a->wf = malloc(sizeof(WAVEFORMATEX)+256);
mux_a->wf->wFormatTag = 0x50;
mux_a->wf->nChannels = encoder->params.channels;
mux_a->wf->nSamplesPerSec = encoder->params.sample_rate;
mux_a->wf->nAvgBytesPerSec = encoder->params.bitrate / 8;
if(ctx->vbr || ((mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame) % mux_a->wf->nSamplesPerSec))
{
mux_a->h.dwScale = encoder->params.samples_per_frame;
mux_a->h.dwRate = encoder->params.sample_rate;
mux_a->h.dwSampleSize = 0; // Blocksize not constant
}
else
{
mux_a->h.dwScale = (mux_a->wf->nAvgBytesPerSec * encoder->params.samples_per_frame)/ mux_a->wf->nSamplesPerSec; /* for cbr */
mux_a->h.dwRate = mux_a->wf->nAvgBytesPerSec;
mux_a->h.dwSampleSize = mux_a->h.dwScale;
}
mux_a->wf->nBlockAlign = mux_a->h.dwScale;
mux_a->h.dwSuggestedBufferSize = (encoder->params.audio_preload*mux_a->wf->nAvgBytesPerSec)/1000;
mux_a->h.dwSuggestedBufferSize -= mux_a->h.dwSuggestedBufferSize % mux_a->wf->nBlockAlign;
mux_a->wf->cbSize = 0; //12;
mux_a->wf->wBitsPerSample = 0; /* does not apply */
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->wID = 1;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->fdwFlags = 2;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nBlockSize = mux_a->wf->nBlockAlign;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nFramesPerBlock = 1;
((MPEGLAYER3WAVEFORMAT *) (mux_a->wf))->nCodecDelay = 0;
// Fix allocation
mux_a->wf = realloc(mux_a->wf, sizeof(WAVEFORMATEX)+mux_a->wf->cbSize);
encoder->input_format = AF_FORMAT_S16_NE;
encoder->min_buffer_size = mux_a->h.dwSuggestedBufferSize;
encoder->max_buffer_size = mux_a->h.dwSuggestedBufferSize*2;
return 1;
}
static int encode_twolame(audio_encoder_t *encoder, uint8_t *dest, void *src, int len, int max_size)
{
mpae_twolame_ctx *ctx = encoder->priv;
int ret_size = 0, r2;
len /= (2*encoder->params.channels);
ret_size = twolame_encode_buffer_interleaved(ctx->twolame_ctx, src, len, dest, max_size);
r2 = mp_decode_mp3_header(dest);
mp_msg(MSGT_MENCODER, MSGL_DBG2, "\nSIZE: %d, max: %d, r2: %d\n", ret_size, max_size, r2);
if(r2 > 0)
ret_size = r2;
return ret_size;
}
static int close_twolame(audio_encoder_t *encoder)
{
free(encoder->priv);
return 1;
}
static int get_frame_size(audio_encoder_t *encoder)
{
int sz;
if(encoder->stream->buffer_len < 4)
return 0;
sz = mp_decode_mp3_header(encoder->stream->buffer);
if(sz <= 0)
return 0;
return sz;
}
int mpae_init_twolame(audio_encoder_t *encoder)
{
int mode;
mpae_twolame_ctx *ctx = NULL;
if(encoder->params.channels == 1)
{
mp_msg(MSGT_MENCODER, MSGL_INFO, "ae_twolame, 1 audio channel, forcing mono mode\n");
mode = TWOLAME_MONO;
}
else if(encoder->params.channels == 2)
{
if(! strcasecmp(param_mode, "dual"))
mode = TWOLAME_DUAL_CHANNEL;
else if(! strcasecmp(param_mode, "jstereo"))
mode = TWOLAME_JOINT_STEREO;
else if(! strcasecmp(param_mode, "stereo"))
mode = TWOLAME_STEREO;
else
{
mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, unknown mode %s, exiting\n", param_mode);
}
}
else
mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, Twolame can't encode > 2 channels, exiting\n");
ctx = calloc(1, sizeof(mpae_twolame_ctx));
if(ctx == NULL)
{
mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, couldn't alloc a %d bytes context, exiting\n", sizeof(mpae_twolame_ctx));
return 0;
}
ctx->twolame_ctx = twolame_init();
if(ctx->twolame_ctx == NULL)
{
mp_msg(MSGT_MENCODER, MSGL_ERR, "ae_twolame, couldn't initial parameters from libtwolame, exiting\n");
free(ctx);
return 0;
}
ctx->vbr = 0;
if(twolame_set_num_channels(ctx->twolame_ctx, encoder->params.channels) != 0)
return 0;
if(twolame_set_mode(ctx->twolame_ctx, mode) != 0)
return 0;
if(twolame_set_in_samplerate(ctx->twolame_ctx, encoder->params.sample_rate) != 0)
return 0;
if(twolame_set_out_samplerate(ctx->twolame_ctx, encoder->params.sample_rate) != 0)
return 0;
if(encoder->params.sample_rate < 32000)
twolame_set_version(ctx->twolame_ctx, TWOLAME_MPEG2);
else
twolame_set_version(ctx->twolame_ctx, TWOLAME_MPEG1);
if(twolame_set_psymodel(ctx->twolame_ctx, param_psy) != 0)
return 0;
if(twolame_set_bitrate(ctx->twolame_ctx, param_bitrate) != 0)
return 0;
if(param_errprot)
if(twolame_set_error_protection(ctx->twolame_ctx, TRUE) != 0)
return 0;
if(param_vbr != 0)
{
if(twolame_set_VBR(ctx->twolame_ctx, TRUE) != 0)
return 0;
if(twolame_set_VBR_q(ctx->twolame_ctx, param_vbr) != 0)
return 0;
if(twolame_set_padding(ctx->twolame_ctx, FALSE) != 0)
return 0;
if(param_maxvbr)
{
if(twolame_set_VBR_max_bitrate_kbps(ctx->twolame_ctx, param_maxvbr) != 0)
return 0;
}
ctx->vbr = 1;
}
if(twolame_set_verbosity(ctx->twolame_ctx, param_debug) != 0)
return 0;
if(twolame_init_params(ctx->twolame_ctx) != 0)
return 0;
encoder->params.bitrate = param_bitrate * 1000;
encoder->params.samples_per_frame = 1152;
encoder->priv = ctx;
encoder->decode_buffer_size = 1152 * 2 * encoder->params.channels;
encoder->bind = bind_twolame;
encoder->get_frame_size = get_frame_size;
encoder->encode = encode_twolame;
encoder->close = close_twolame;
return 1;
}

View File

@ -1,32 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_AE_TWOLAME_H
#define MPLAYER_AE_TWOLAME_H
#include "ae.h"
#include <twolame.h>
typedef struct {
twolame_options *twolame_ctx;
int vbr;
} mpae_twolame_ctx;
int mpae_init_twolame(audio_encoder_t *encoder);
#endif /* MPLAYER_AE_TWOLAME_H */

View File

@ -1,98 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_MMX_H
#define MPLAYER_MMX_H
typedef union {
long long q; /* Quadword (64-bit) value */
unsigned long long uq; /* Unsigned Quadword */
int d[2]; /* 2 Doubleword (32-bit) values */
unsigned int ud[2]; /* 2 Unsigned Doubleword */
short w[4]; /* 4 Word (16-bit) values */
unsigned short uw[4]; /* 4 Unsigned Word */
char b[8]; /* 8 Byte (8-bit) values */
unsigned char ub[8]; /* 8 Unsigned Byte */
float s[2]; /* Single-precision (32-bit) value */
} mmx_t; /* On an 8-byte (64-bit) boundary */
#define movq_m2r(var, reg) mmx_m2r(movq, var, reg)
#define movq_r2m(reg, var) mmx_r2m(movq, reg, var)
#define movq_r2r(regs, regd) mmx_r2r(movq, regs, regd)
#define punpcklwd_m2r(var, reg) mmx_m2r(punpcklwd, var, reg)
#define punpcklwd_r2r(regs, regd) mmx_r2r(punpcklwd, regs, regd)
#define punpckhwd_m2r(var, reg) mmx_m2r(punpckhwd, var, reg)
#define punpckhwd_r2r(regs, regd) mmx_r2r(punpckhwd, regs, regd)
#define punpcklbw_r2r(regs, regd) mmx_r2r(punpcklbw, regs, regd)
#define punpckhbw_r2r(regs, regd) mmx_r2r(punpckhbw, regs, regd)
#define punpckhdq_r2r(regs, regd) mmx_r2r(punpckhdq, regs, regd)
#define punpckldq_r2r(regs, regd) mmx_r2r(punpckldq, regs, regd)
#define psubw_m2r(var, reg) mmx_m2r(psubw, var, reg)
#define psubw_r2r(regs, regd) mmx_r2r(psubw, regs, regd)
#define psubsw_r2r(regs, regd) mmx_r2r(psubsw, regs, regd)
#define pmaddwd_r2r(regs, regd) mmx_r2r(pmaddwd, regs, regd)
#define paddw_m2r(var, reg) mmx_m2r(paddw, var, reg)
#define paddw_r2r(regs, regd) mmx_r2r(paddw, regs, regd)
#define psrad_i2r(imm, reg) mmx_i2r(psrad, imm, reg)
#define psllw_i2r(imm, reg) mmx_i2r(psllw, imm, reg)
#define pmulhw_r2r(regs, regd) mmx_r2r(pmulhw, regs, regd)
#define pmulhw_m2r(var, reg) mmx_m2r(pmulhw, var, reg)
#define psraw_i2r(imm, reg) mmx_i2r(psraw, imm, reg)
#define packssdw_r2r(regs, regd) mmx_r2r(packssdw, regs, regd)
#define packuswb_r2r(regs, regd) mmx_r2r(packuswb, regs, regd)
#define pxor_r2r(regs, regd) mmx_r2r(pxor, regs, regd)
#define pcmpgtw_r2r(regs, regd) mmx_r2r(pcmpgtw, regs, regd)
#define por_r2r(regs, regd) mmx_r2r(por, regs, regd)
#define mmx_i2r(op,imm,reg) \
__asm__ volatile (#op " %0, %%" #reg \
: /* nothing */ \
: "i" (imm) )
#define mmx_m2r(op, mem, reg) \
__asm__ volatile (#op " %0, %%" #reg \
: /* nothing */ \
: "m" (mem))
#define mmx_r2m(op, reg, mem) \
__asm__ volatile (#op " %%" #reg ", %0" \
: "=m" (mem) \
: /* nothing */ )
#define mmx_r2r(op, regs, regd) \
__asm__ volatile (#op " %" #regs ", %" #regd)
#define emms() __asm__ volatile ("emms")
#endif /* MPLAYER_MMX_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,44 +0,0 @@
/*
RTjpeg (C) Justin Schoeman 1998 (justin@suntiger.ee.up.ac.za)
With modifications by:
(c) 1998, 1999 by Joerg Walter <trouble@moes.pmnet.uni-oldenburg.de>
and
(c) 1999 by Wim Taymans <wim.taymans@tvd.be>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef MPLAYER_RTJPEGN_H
#define MPLAYER_RTJPEGN_H
#include <stdint.h>
#define __u8 uint8_t
#define __u16 uint16_t
#define __u32 uint32_t
#define __u64 uint64_t
#define __s8 int8_t
#define __s16 int16_t
#define __s32 int32_t
#define __s64 int64_t
void RTjpeg_init_compress(__u32 *buf, int width, int height, __u8 Q);
int RTjpeg_compressYUV420(__s8 *sp, unsigned char *bp);
void RTjpeg_init_mcompress(void);
int RTjpeg_mcompressYUV420(__s8 *sp, unsigned char *bp, __u16 lmask, __u16 cmask);
#endif /* MPLAYER_RTJPEGN_H */

View File

@ -1,75 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "mp_msg.h"
#include "img_format.h"
#include "mp_image.h"
#include "vf.h"
extern vf_info_t ve_info_lavc;
extern vf_info_t ve_info_vfw;
extern vf_info_t ve_info_raw;
extern vf_info_t ve_info_libdv;
extern vf_info_t ve_info_xvid;
extern vf_info_t ve_info_qtvideo;
extern vf_info_t ve_info_nuv;
extern vf_info_t ve_info_x264;
/* Please do not add any new encoders here. If you want to implement a new
* encoder, add it to libavcodec, except for wrappers around external
* libraries and encoders requiring binary support. */
static vf_info_t* encoder_list[]={
#ifdef CONFIG_LIBAVCODEC
&ve_info_lavc,
#endif
#ifdef CONFIG_WIN32DLL
&ve_info_vfw,
#ifdef CONFIG_QTX_CODECS_WIN32
&ve_info_qtvideo,
#endif
#endif
#ifdef CONFIG_LIBDV095
&ve_info_libdv,
#endif
&ve_info_raw,
#ifdef CONFIG_XVID4
&ve_info_xvid,
#endif
#ifdef CONFIG_LIBLZO
&ve_info_nuv,
#endif
#ifdef CONFIG_X264
&ve_info_x264,
#endif
/* Please do not add any new encoders here. If you want to implement a new
* encoder, add it to libavcodec, except for wrappers around external
* libraries and encoders requiring binary support. */
NULL
};
vf_instance_t* vf_open_encoder(struct MPOpts *opts, vf_instance_t* next, const char *name, char *args){
char* vf_args[] = { "_oldargs_", args, NULL };
return vf_open_plugin(opts, encoder_list,next,name,vf_args);
}

File diff suppressed because it is too large Load Diff

View File

@ -1,135 +0,0 @@
/*
* requires libdv-0.9.5 !!!
* (v0.9.0 is too old and has no encoding functionality exported!)
*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "mp_msg.h"
#include "codec-cfg.h"
#include "stream/stream.h"
#include "libmpdemux/demuxer.h"
#include "libmpdemux/stheader.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include "img_format.h"
#include "mp_image.h"
#include "vf.h"
#include <libdv/dv.h>
#ifndef DV_WIDTH
#define DV_WIDTH 720
#define DV_PAL_HEIGHT 576
#define DV_NTSC_HEIGHT 480
#endif
struct vf_priv_s {
muxer_stream_t* mux;
dv_encoder_t* enc;
};
#define mux_v (vf->priv->mux)
//===========================================================================//
static int config(struct vf_instance *vf,
int width, int height, int d_width, int d_height,
unsigned int flags, unsigned int outfmt){
if(width!=DV_WIDTH || (height!=DV_PAL_HEIGHT && height!=DV_NTSC_HEIGHT)){
mp_msg(MSGT_VFILTER,MSGL_ERR,"DV: only 720x480 (NTSC) and 720x576 (PAL) resolutions allowed! Try with -vf scale=720:480\n");
}
vf->priv->enc->isPAL=(height==DV_PAL_HEIGHT);
vf->priv->enc->is16x9=(d_width/(float)d_height > 1.7); // 16:9=1.777777
vf->priv->enc->vlc_encode_passes=3;
vf->priv->enc->static_qno=0;
vf->priv->enc->force_dct=0;
mux_v->bih->biWidth=width;
mux_v->bih->biHeight=height;
mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
mux_v->aspect = (float)d_width/d_height;
return 1;
}
static int control(struct vf_instance *vf, int request, void* data){
return CONTROL_UNKNOWN;
}
static int query_format(struct vf_instance *vf, unsigned int fmt){
if(fmt==IMGFMT_YUY2) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
if(fmt==IMGFMT_RGB24) return VFCAP_CSP_SUPPORTED;
return 0;
}
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
dv_encode_full_frame(vf->priv->enc, mpi->planes,
(mpi->flags&MP_IMGFLAG_YUV) ? e_dv_color_yuv : e_dv_color_rgb,
mux_v->buffer);
muxer_write_chunk(mux_v, 480 * (vf->priv->enc->isPAL ? 300 : 250) , 0x10, pts, pts);
return 1;
}
//===========================================================================//
static int vf_open(vf_instance_t *vf, char* args){
vf->config=config;
vf->default_caps=VFCAP_CONSTANT;
vf->control=control;
vf->query_format=query_format;
vf->put_image=put_image;
vf->priv=malloc(sizeof(struct vf_priv_s));
memset(vf->priv,0,sizeof(struct vf_priv_s));
vf->priv->mux=(muxer_stream_t*)args;
vf->priv->enc=dv_encoder_new(0,1,1); // FIXME, parse some options!
if(!vf->priv->enc) return 0;
mux_v->bih=calloc(1, sizeof(*mux_v->bih));
mux_v->bih->biSize=sizeof(*mux_v->bih);
mux_v->bih->biWidth=0;
mux_v->bih->biHeight=0;
mux_v->bih->biCompression=mmioFOURCC('d','v','s','d');
mux_v->bih->biPlanes=1;
mux_v->bih->biBitCount=24;
return 1;
}
vf_info_t ve_info_libdv = {
"DV encoder using libdv",
"libdv",
"A'rpi",
"for internal use by mencoder",
vf_open
};
//===========================================================================//

View File

@ -1,255 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "mp_msg.h"
#include "m_option.h"
#include "codec-cfg.h"
#include "stream/stream.h"
#include "libmpdemux/demuxer.h"
#include "libmpdemux/stheader.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include "img_format.h"
#include "mp_image.h"
#include "vf.h"
#include "ffmpeg_files/intreadwrite.h"
#include <lzo/lzo1x.h>
#include "native/rtjpegn.h"
#define LZO_AL(size) (((size) + (sizeof(long) - 1)) / sizeof(long))
#define LZO_OUT_LEN(in) ((in) + (in) / 64 + 16 + 3)
//===========================================================================//
struct vf_priv_s {
int raw; // Do not use RTjpeg
int lzo; // Use lzo
unsigned int l,c,q; // Mjpeg param
muxer_stream_t* mux;
uint8_t* buffer;
int buf_size;
int tbl_wrote;
lzo_byte *zbuffer;
long __LZO_MMODEL *zmem;
};
#define mux_v (vf->priv->mux)
struct vf_priv_s nuv_priv_dflt = {
0, // raw
1, // lzo
1,1, // l,c
255, // q
NULL,
NULL,
0,0,
NULL,NULL
};
const m_option_t nuvopts_conf[] = {
{"raw", &nuv_priv_dflt.raw, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{"rtjpeg", &nuv_priv_dflt.raw, CONF_TYPE_FLAG, 0, 1, 0, NULL},
{"lzo", &nuv_priv_dflt.lzo, CONF_TYPE_FLAG, 0, 0, 1, NULL},
{"nolzo", &nuv_priv_dflt.lzo, CONF_TYPE_FLAG, 0, 1, 0, NULL},
{"q", &nuv_priv_dflt.q, CONF_TYPE_INT, M_OPT_RANGE,3,255, NULL},
{"l", &nuv_priv_dflt.l, CONF_TYPE_INT, M_OPT_RANGE,0,20, NULL},
{"c", &nuv_priv_dflt.c, CONF_TYPE_INT, M_OPT_RANGE,0,20, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
//===========================================================================//
#define COMPDATASIZE (128*4)
#define FRAMEHEADERSIZE 12
static int config(struct vf_instance *vf,
int width, int height, int d_width, int d_height,
unsigned int flags, unsigned int outfmt){
// We need a buffer wich can holda header and a whole YV12 picture
// or a RTJpeg table
vf->priv->buf_size = width*height*3/2+FRAMEHEADERSIZE;
if(vf->priv->buf_size < COMPDATASIZE + FRAMEHEADERSIZE)
vf->priv->buf_size = COMPDATASIZE + FRAMEHEADERSIZE;
mux_v->bih->biWidth=width;
mux_v->bih->biHeight=height;
mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
mux_v->aspect = (float)d_width/d_height;
vf->priv->buffer = realloc(vf->priv->buffer,vf->priv->buf_size);
if (vf->priv->lzo)
vf->priv->zbuffer = realloc(vf->priv->zbuffer, FRAMEHEADERSIZE + LZO_OUT_LEN(vf->priv->buf_size));
vf->priv->tbl_wrote = 0;
return 1;
}
static int control(struct vf_instance *vf, int request, void* data){
return CONTROL_UNKNOWN;
}
static int query_format(struct vf_instance *vf, unsigned int fmt){
if(fmt==IMGFMT_I420) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
return 0;
}
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
uint8_t *header = vf->priv->buffer;
uint8_t* data = vf->priv->buffer + FRAMEHEADERSIZE;
uint8_t* zdata = vf->priv->zbuffer + FRAMEHEADERSIZE;
int len = 0, r;
size_t zlen = 0;
memset(header, 0, FRAMEHEADERSIZE); // Reset the header
if(vf->priv->lzo)
memset(vf->priv->zbuffer,0,FRAMEHEADERSIZE);
// This has to be don here otherwise tv with sound doesn't work
if(!vf->priv->tbl_wrote) {
RTjpeg_init_compress((uint32_t *)data,mpi->width,mpi->height,vf->priv->q);
RTjpeg_init_mcompress();
header[0] = 'D'; // frametype: compressor data
header[1] = 'R'; // comptype: compressor data for RTjpeg
AV_WL32(header + 8, COMPDATASIZE); // packetlength
mux_v->buffer=vf->priv->buffer;
muxer_write_chunk(mux_v,FRAMEHEADERSIZE + COMPDATASIZE, 0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
vf->priv->tbl_wrote = 1;
memset(header, 0, FRAMEHEADERSIZE); // Reset the header
}
// Raw picture
if(vf->priv->raw) {
len = mpi->width*mpi->height*3/2;
// Try lzo ???
if(vf->priv->lzo) {
r = lzo1x_1_compress(mpi->planes[0],len,
zdata,&zlen,vf->priv->zmem);
if(r != LZO_E_OK) {
mp_msg(MSGT_VFILTER,MSGL_ERR,"LZO compress error\n");
zlen = 0;
}
}
if(zlen <= 0 || zlen > len) {
memcpy(data,mpi->planes[0],len);
header[1] = '0'; // comptype: uncompressed
} else { // Use lzo only if it's littler
header = vf->priv->zbuffer;
header[1] = '3'; //comptype: lzo
len = zlen;
}
} else { // RTjpeg compression
len = RTjpeg_mcompressYUV420(data,mpi->planes[0],vf->priv->l,
vf->priv->c);
if(len <= 0) {
mp_msg(MSGT_VFILTER,MSGL_ERR,"RTjpeg_mcompressYUV420 error (%d)\n",len);
return 0;
}
if(vf->priv->lzo) {
r = lzo1x_1_compress(data,len,zdata,&zlen,vf->priv->zmem);
if(r != LZO_E_OK) {
mp_msg(MSGT_VFILTER,MSGL_ERR,"LZO compress error\n");
zlen = 0;
}
}
if(zlen <= 0 || zlen > len)
header[1] = '1'; // comptype: RTjpeg
else {
header = vf->priv->zbuffer;
header[1] = '2'; // comptype: RTjpeg + LZO
len = zlen;
}
}
header[0] = 'V'; // frametype: video frame
AV_WL32(header + 8, len); // packetlength
mux_v->buffer = header;
muxer_write_chunk(mux_v, len + FRAMEHEADERSIZE, 0x10, pts, pts);
return 1;
}
static void uninit(struct vf_instance *vf) {
if(vf->priv->buffer)
free(vf->priv->buffer);
if(vf->priv->zbuffer)
free(vf->priv->zbuffer);
if(vf->priv->zmem)
free(vf->priv->zmem);
}
//===========================================================================//
static int vf_open(vf_instance_t *vf, char* args){
vf->config=config;
vf->default_caps=VFCAP_CONSTANT;
vf->control=control;
vf->query_format=query_format;
vf->put_image=put_image;
vf->uninit = uninit;
vf->priv=malloc(sizeof(struct vf_priv_s));
memcpy(vf->priv, &nuv_priv_dflt,sizeof(struct vf_priv_s));
vf->priv->mux=(muxer_stream_t*)args;
mux_v->bih=calloc(1, sizeof(*mux_v->bih));
mux_v->bih->biSize=sizeof(*mux_v->bih);
mux_v->bih->biWidth=0;
mux_v->bih->biHeight=0;
mux_v->bih->biPlanes=1;
mux_v->bih->biBitCount=12;
mux_v->bih->biCompression = mmioFOURCC('N','U','V','1');
if(vf->priv->lzo) {
if(lzo_init() != LZO_E_OK) {
mp_msg(MSGT_VFILTER,MSGL_WARN,"LZO init failed: no lzo compression\n");
vf->priv->lzo = 0;
} else
vf->priv->zmem = malloc(sizeof(long)*LZO_AL(LZO1X_1_MEM_COMPRESS));
}
return 1;
}
vf_info_t ve_info_nuv = {
"nuv encoder",
"nuv",
"Albeu",
"for internal use by mencoder",
vf_open
};
//===========================================================================//

View File

@ -1,359 +0,0 @@
/*
* QT video encoder using Win32 libs
*
* Copyright (C) 2002 Sascha Sommer
*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#define MAX_IDSIZE 0x6F
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "mp_msg.h"
#include "mpbswap.h"
#ifdef WIN32_LOADER
#include "loader/ldt_keeper.h"
#endif
#include "loader/qtx/qtxsdk/components.h"
#include "loader/wine/winbase.h"
#include "loader/wine/windef.h"
#include "codec-cfg.h"
#include "stream/stream.h"
#include "libmpdemux/demuxer.h"
#include "libmpdemux/stheader.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include "img_format.h"
#include "mp_image.h"
#include "vf.h"
static HINSTANCE qtime_qts; //handle to preloaded quicktime.qts
static HMODULE handler;
static OSErr (*FindCodec)(CodecType cType,
CodecComponent specCodec,
CompressorComponent * compressor,
DecompressorComponent * decompressor);
static OSErr (*InitializeQTML)(long flags);
static PixMapHandle (*GetGWorldPixMap)(GWorldPtr offscreenGWorld);
static OSErr (*QTNewGWorldFromPtr)(GWorldPtr *gw,
OSType pixelFormat,
const Rect *boundsRect,
CTabHandle cTable,
/*GDHandle*/void* aGDevice, /*unused anyway*/
GWorldFlags flags,
void *baseAddr,
long rowBytes);
static Handle (*NewHandleClear)(Size byteCount);
static OSErr (*CompressSequenceBegin) (
ImageSequence *seqID,
PixMapHandle src,
PixMapHandle prev,
const Rect *srcRect,
const Rect *prevRect,
short colorDepth,
CodecType cType,
CompressorComponent codec,
CodecQ spatialQuality,
CodecQ temporalQuality,
long keyFrameRate,
CTabHandle ctable,
CodecFlags flags,
ImageDescriptionHandle desc );
static OSErr (*CompressSequenceFrame) (
ImageSequence seqID,
PixMapHandle src,
const Rect *srcRect,
CodecFlags flags,
Ptr data,
long *dataSize,
UInt8 *similarity,
ICMCompletionProcRecordPtr asyncCompletionProc );
static OSErr (*GetMaxCompressionSize)(PixMapHandle src,
const Rect *srcRect,
short colorDepth,
CodecQ quality,
CodecType cType,
CompressorComponent codec,
long *size );
static OSErr (*CDSequenceEnd)( ImageSequence seqID );
static Component (*FindNextComponent)(Component prev,ComponentDescription* desc);
static long (*CountComponents)(ComponentDescription* desc);
static OSErr (*GetComponentInfo)(Component prev,ComponentDescription* desc,Handle h1,Handle h2,Handle h3);
//static int format=mmioFOURCC('S','V','Q','1');
static int format=mmioFOURCC('S','V','Q','3');
//static void *frame_in; //input frame
static void *frame_prev; //previous frame
static void *frame_comp; //compressed frame
static GWorldPtr frame_GWorld_in = NULL;//a GWorld is some kind of description for a drawing environment
static GWorldPtr frame_GWorld_prev = NULL;
static Rect FrameRect;
static CompressorComponent compressor;
static ImageDescriptionHandle desc;
static ImageSequence seq;
struct vf_priv_s {
muxer_stream_t* mux;
//dv_encoder_t* enc;
};
#define mux_v (vf->priv->mux)
//===========================================================================//
static int config(struct vf_instance *vf,
int width, int height, int d_width, int d_height,
unsigned int flags, unsigned int outfmt){
// OSErr cres;
ComponentDescription cdesc;
mux_v->bih->biWidth=width;
mux_v->bih->biHeight=height;
mux_v->bih->biSizeImage=width*height*2;
mux_v->aspect = (float)d_width/d_height;
memset(&cdesc,0,sizeof(cdesc));
cdesc.componentType= (((unsigned char)'i')<<24)|
(((unsigned char)'m')<<16)|
(((unsigned char)'c')<<8)|
(((unsigned char)'o'));
cdesc.componentSubType=bswap_32(format);
cdesc.componentManufacturer=0;
cdesc.componentFlags=0;
cdesc.componentFlagsMask=0;
mp_msg(MSGT_MENCODER,MSGL_DBG2,"Count = %ld\n",CountComponents(&cdesc));
compressor=FindNextComponent(NULL,&cdesc);
if(!compressor){
mp_msg(MSGT_MENCODER,MSGL_ERR,"Cannot find requested component\n");
return 0;
}
mp_msg(MSGT_MENCODER,MSGL_DBG2,"Found it! ID = %p\n",compressor);
// cres= FindCodec (fourcc,anyCodec,&compressor,&decompressor );
// printf("FindCodec returned:%i compressor: 0x%X decompressor: 0x%X\n",cres&0xFFFF,compressor,decompressor);
return 1;
}
static int control(struct vf_instance *vf, int request, void* data){
return CONTROL_UNKNOWN;
}
static int query_format(struct vf_instance *vf, unsigned int fmt){
if(fmt==IMGFMT_YUY2) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
return 0;
}
static int codec_initialized = 0;
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
OSErr cres;
long framesizemax;
UInt8 similarity=0;
long compressedsize;
OSType in_format=kYUVSPixelFormat;
int width = mpi->width;
int height = mpi->height;
int stride = width*2;
if(!codec_initialized){
FrameRect.top=0;
FrameRect.left=0;
FrameRect.right=width;
FrameRect.bottom=height;
cres = QTNewGWorldFromPtr(
&frame_GWorld_in,
in_format,
&FrameRect,
0,
0,
0,
mpi->planes[0],
stride);
mp_msg(MSGT_MENCODER,MSGL_DBG2,"NewGWorldFromPtr returned:%i\n",cres&0xFFFF);
//dunno what todo about this
frame_prev = malloc(stride * height);
cres = QTNewGWorldFromPtr(
&frame_GWorld_prev,
in_format,
&FrameRect,
0,
0,
0,
frame_prev,
stride);
mp_msg(MSGT_MENCODER,MSGL_DBG2,"height:%i width:%i stride:%i\n",height,width,stride);
mp_msg(MSGT_MENCODER,MSGL_DBG2,"NewGWorldFromPtr returned:%i\n",cres&0xFFFF);
cres= GetMaxCompressionSize (
GetGWorldPixMap(frame_GWorld_in),
&FrameRect,
24,
codecNormalQuality,
bswap_32(format),
compressor,
&framesizemax );
mp_msg(MSGT_MENCODER,MSGL_DBG2,"GetMaxCompressionSize returned:%i : MaxSize:%li\n",cres&0xFFFF,framesizemax);
frame_comp=malloc(framesizemax);
desc = (ImageDescriptionHandle)NewHandleClear(MAX_IDSIZE); //memory where the desc will be stored
(*desc)->idSize=MAX_IDSIZE;
cres= CompressSequenceBegin (
&seq,
GetGWorldPixMap( frame_GWorld_in),
GetGWorldPixMap( frame_GWorld_prev),
&FrameRect,
&FrameRect,
24, // color depth
bswap_32(format), // fourcc
compressor, // codec component
codecNormalQuality, //codecNormalQuality,
codecMaxQuality, //codecNormalQuality,
10*30, // keyframe rate
0,
0,
desc);
mp_msg(MSGT_MENCODER,MSGL_DBG2,"CompressSequenceBegin returned:%i\n",cres&0xFFFF);
mp_msg(MSGT_MENCODER,MSGL_DBG2,"Sequence ID:%i\n",seq);
dump_ImageDescription(*desc);
codec_initialized++;
}
cres = CompressSequenceFrame (
seq,
GetGWorldPixMap(frame_GWorld_in),
&FrameRect,
0,
(char*)mux_v->buffer,
&compressedsize,
&similarity,
0);
if(cres&0xFFFF)mp_msg(MSGT_MENCODER,MSGL_DBG2,"CompressSequenceFrame returned:%i\n",cres&0xFFFF);
#if 0
printf("Size %i->%i \n",stride*height,compressedsize);
printf("Ratio: %i:1\n",(stride*height)/compressedsize);
#endif
muxer_write_chunk(mux_v, compressedsize , similarity?0:0x10, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
if(((*desc)->idSize)>MAX_IDSIZE){
mp_msg(MSGT_MENCODER,MSGL_ERR,"FATAL! idSize=%d too big, increase MAX_IDSIZE in ve_qtvideo.c!\n",((*desc)->idSize));
} else {
// according to QT docs, imagedescription may be changed while encoding
// a frame (even its size may (and does!) change!)
memcpy(mux_v->bih+1,*desc,(*desc)->idSize);
}
return 1;
}
//===========================================================================//
static int vf_open(vf_instance_t *vf, char* args){
OSErr cres = 1;
vf->config=config;
vf->default_caps=VFCAP_CONSTANT;
vf->control=control;
vf->query_format=query_format;
vf->put_image=put_image;
vf->priv=malloc(sizeof(struct vf_priv_s));
memset(vf->priv,0,sizeof(struct vf_priv_s));
vf->priv->mux=(muxer_stream_t*)args;
mux_v->bih=calloc(1, sizeof(BITMAPINFOHEADER)+MAX_IDSIZE);
mux_v->bih->biSize=sizeof(BITMAPINFOHEADER)+MAX_IDSIZE;
mux_v->bih->biWidth=0;
mux_v->bih->biHeight=0;
mux_v->bih->biCompression=format;
mux_v->bih->biPlanes=1;
mux_v->bih->biBitCount=24;
#ifdef WIN32_LOADER
Setup_LDT_Keeper();
#endif
//preload quicktime.qts to avoid the problems caused by the hardcoded path inside the dll
qtime_qts = LoadLibraryA("QuickTime.qts");
if(!qtime_qts){
mp_msg(MSGT_MENCODER,MSGL_ERR,"unable to load QuickTime.qts\n" );
return 0;
}
handler = LoadLibraryA("qtmlClient.dll");
if(!handler){
mp_msg(MSGT_MENCODER,MSGL_ERR,"unable to load qtmlClient.dll\n");
return 0;
}
InitializeQTML = (OSErr (*)(long))GetProcAddress(handler, "InitializeQTML");
GetGWorldPixMap = (PixMapHandle (*)(GWorldPtr))GetProcAddress(handler, "GetGWorldPixMap");
QTNewGWorldFromPtr = (OSErr(*)(GWorldPtr *,OSType,const Rect *,CTabHandle,void*,GWorldFlags,void *,long))GetProcAddress(handler, "QTNewGWorldFromPtr");
NewHandleClear = (OSErr(*)(Size))GetProcAddress(handler, "NewHandleClear");
FindCodec = (OSErr (*)(CodecType,CodecComponent,CompressorComponent *,DecompressorComponent *))GetProcAddress(handler,"FindCodec");
CompressSequenceBegin = (OSErr(*)(ImageSequence *,PixMapHandle,PixMapHandle,const Rect *,const Rect *,short,CodecType,CompressorComponent,CodecQ,CodecQ,long,CTabHandle,CodecFlags,ImageDescriptionHandle))GetProcAddress(handler,"CompressSequenceBegin");
CompressSequenceFrame = (OSErr(*)(ImageSequence,PixMapHandle,const Rect *,CodecFlags,Ptr,long *,UInt8 *,ICMCompletionProcRecordPtr))GetProcAddress(handler,"CompressSequenceFrame");
GetMaxCompressionSize = (OSErr(*)(PixMapHandle,const Rect *,short,CodecQ,CodecType,CompressorComponent,long *))GetProcAddress(handler,"GetMaxCompressionSize");
CDSequenceEnd = (OSErr (*)(ImageSequence))GetProcAddress(handler,"CDSequenceEnd");
FindNextComponent = (Component (*)(Component,ComponentDescription*))GetProcAddress(handler, "FindNextComponent");
CountComponents = (long (*)(ComponentDescription*))GetProcAddress(handler, "CountComponents");
GetComponentInfo = (OSErr (*)(Component,ComponentDescription*,Handle,Handle,Handle))GetProcAddress(handler, "GetComponentInfo");
if(!InitializeQTML ||!CompressSequenceBegin){
mp_msg(MSGT_MENCODER,MSGL_ERR,"invalid qt DLL!\n");
return 0;
}
//printf("%i,%i,%i\n",mmioFOURCC('S','V','Q','1'),'SVQ1',bswap_32(mmioFOURCC('S','V','Q','1')));
cres=InitializeQTML(6+16);
mp_msg(MSGT_MENCODER,MSGL_DBG2,"InitializeQTML returned %i\n",cres);
return 1;
}
vf_info_t ve_info_qtvideo = {
"Quicktime video encoder using win32 DLLs",
"qtvideo",
"Sascha Sommer",
"for internal use by mencoder",
vf_open
};
//===========================================================================//

View File

@ -1,177 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "config.h"
#include "mp_msg.h"
#include "codec-cfg.h"
#include "stream/stream.h"
#include "libmpdemux/demuxer.h"
#include "libmpdemux/stheader.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include "img_format.h"
#include "mp_image.h"
#include "vf.h"
//===========================================================================//
struct vf_priv_s {
muxer_stream_t* mux;
};
#define mux_v (vf->priv->mux)
static int set_format(struct vf_instance *vf, unsigned int fmt) {
if (!force_fourcc)
mux_v->bih->biCompression = fmt;
mux_v->bih->biPlanes = 1;
if (IMGFMT_IS_RGB(fmt)) {
if (IMGFMT_RGB_DEPTH(fmt) < 8 && !(fmt&128))
mux_v->bih->biBitCount = IMGFMT_RGB_DEPTH(fmt);
else
mux_v->bih->biBitCount = (IMGFMT_RGB_DEPTH(fmt)+7)&(~7);
return 1;
}
if (IMGFMT_IS_BGR(fmt)) {
if (IMGFMT_BGR_DEPTH(fmt) < 8 && !(fmt&128))
mux_v->bih->biBitCount = IMGFMT_BGR_DEPTH(fmt);
else
mux_v->bih->biBitCount = (IMGFMT_BGR_DEPTH(fmt)+7)&(~7);
return 1;
}
switch (fmt) {
case IMGFMT_I420:
case IMGFMT_IYUV:
case IMGFMT_YV12:
case IMGFMT_411P:
mux_v->bih->biPlanes = 3;
mux_v->bih->biBitCount = 12;
break;
case IMGFMT_444P:
mux_v->bih->biPlanes = 3;
mux_v->bih->biBitCount = 24;
break;
case IMGFMT_422P:
mux_v->bih->biPlanes = 3;
mux_v->bih->biBitCount = 16;
break;
case IMGFMT_IF09:
mux_v->bih->biPlanes = 4;
case IMGFMT_YVU9:
mux_v->bih->biBitCount = 9;
break;
case IMGFMT_UYVY:
case IMGFMT_YUY2:
mux_v->bih->biBitCount = 16;
break;
case IMGFMT_Y8:
mux_v->bih->biBitCount = 8;
break;
default:
mp_tmsg(MSGT_MENCODER, MSGL_INFO, "[VE_RAW] Raw output with FourCC [%x] not supported!\n", fmt);
mux_v->bih->biCompression = 0;
return 0;
}
return 1;
}
static int config(struct vf_instance *vf,
int width, int height, int d_width, int d_height,
unsigned int flags, unsigned int outfmt)
{
int ret;
mux_v->bih->biWidth = width;
mux_v->bih->biHeight = height;
mux_v->aspect = (float)d_width/d_height;
ret = set_format(vf, outfmt);
if (!ret) return 0;
mux_v->bih->biSizeImage = mux_v->bih->biWidth*mux_v->bih->biHeight*mux_v->bih->biBitCount/8;
return 1;
}
static int control(struct vf_instance *vf, int request, void *data) {
return CONTROL_UNKNOWN;
}
static int query_format(struct vf_instance *vf, unsigned int fmt) {
if (IMGFMT_IS_RGB(fmt) || IMGFMT_IS_BGR(fmt))
return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
switch (fmt) {
case IMGFMT_I420:
case IMGFMT_IYUV:
case IMGFMT_YV12:
case IMGFMT_411P:
case IMGFMT_444P:
case IMGFMT_422P:
case IMGFMT_UYVY:
case IMGFMT_YUY2:
case IMGFMT_YVU9:
case IMGFMT_IF09:
case IMGFMT_Y8:
return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
}
return 0;
}
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) {
mux_v->buffer = mpi->planes[0];
muxer_write_chunk(mux_v, mpi->width*mpi->height*mux_v->bih->biBitCount/8, 0x10, pts, pts);
return 1;
}
//===========================================================================//
static int vf_open(vf_instance_t *vf, char* args){
vf->config = config;
vf->default_caps = VFCAP_CONSTANT;
vf->control = control;
vf->query_format = query_format;
vf->put_image = put_image;
vf->default_caps = 0;
vf->priv = malloc(sizeof(struct vf_priv_s));
memset(vf->priv, 0, sizeof(struct vf_priv_s));
vf->priv->mux = (muxer_stream_t*)args;
mux_v->bih = calloc(1, sizeof(BITMAPINFOHEADER));
mux_v->bih->biSize = sizeof(BITMAPINFOHEADER);
mux_v->bih->biWidth = 0;
mux_v->bih->biHeight = 0;
return 1;
}
vf_info_t ve_info_raw = {
"raw encoder",
"raw",
"jwe21@cam.ac.uk",
"Based on rawrgb",
vf_open
};
//===========================================================================//

View File

@ -1,377 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <inttypes.h>
#include <sys/stat.h>
#include "config.h"
#include "mp_msg.h"
#include "codec-cfg.h"
//#include "stream/stream.h"
//#include "libmpdemux/demuxer.h"
//#include "libmpdemux/stheader.h"
#include "loader/loader.h"
//#include "loader/wine/mmreg.h"
#include "loader/wine/vfw.h"
#include "libmpdemux/aviheader.h"
#include "loader/wine/winerror.h"
#include "loader/wine/objbase.h"
#include "img_format.h"
#include "mp_image.h"
#include "vf.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
//===========================================================================//
static char *vfw_param_codec = NULL;
static char *vfw_param_compdata = NULL;
static HRESULT CoInitRes = -1;
#include "m_option.h"
const m_option_t vfwopts_conf[]={
{"codec", &vfw_param_codec, CONF_TYPE_STRING, 0, 0, 0, NULL},
{"compdata", &vfw_param_compdata, CONF_TYPE_STRING, 0, 0, 0, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
struct vf_priv_s {
muxer_stream_t* mux;
BITMAPINFOHEADER* bih;
};
static HIC encoder_hic;
static void* encoder_buf=NULL;
static int encoder_buf_size=0;
static int encoder_frameno=0;
//int init_vfw_encoder(char *dll_name, BITMAPINFOHEADER *input_bih, BITMAPINFOHEADER *output_bih)
static BITMAPINFOHEADER* vfw_open_encoder(char *dll_name, char *compdatafile, BITMAPINFOHEADER *input_bih,unsigned int out_fourcc)
{
HRESULT ret;
BITMAPINFOHEADER* output_bih=NULL;
int temp_len;
FILE *fd=NULL;
char *drvdata=NULL;
struct stat st;
//sh_video = malloc(sizeof(sh_video_t));
mp_msg(MSGT_WIN32,MSGL_V,"======= Win32 (VFW) VIDEO Encoder init =======\n");
CoInitRes = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
// memset(&sh_video->o_bih, 0, sizeof(BITMAPINFOHEADER));
// output_bih->biSize = sizeof(BITMAPINFOHEADER);
// encoder_hic = ICOpen( 0x63646976, out_fourcc, ICMODE_COMPRESS);
encoder_hic = ICOpen( (long) dll_name, out_fourcc, ICMODE_COMPRESS);
if(!encoder_hic){
mp_msg(MSGT_WIN32,MSGL_ERR,"ICOpen failed! unknown codec / wrong parameters?\n");
return NULL;
}
mp_msg(MSGT_WIN32,MSGL_INFO,"HIC: %x\n", encoder_hic);
{
ICINFO icinfo;
ret = ICGetInfo(encoder_hic, &icinfo, sizeof(ICINFO));
mp_msg(MSGT_WIN32,MSGL_INFO,"%ld - %ld - %d\n", ret, icinfo.dwSize, sizeof(ICINFO));
mp_tmsg(MSGT_WIN32,MSGL_INFO,"Compressor type: %.4lx\n", icinfo.fccType);
mp_tmsg(MSGT_WIN32,MSGL_INFO,"Compressor subtype: %.4lx\n", icinfo.fccHandler);
mp_tmsg(MSGT_WIN32,MSGL_INFO,"Compressor flags: %lu, version %lu, ICM version: %lu\n",
icinfo.dwFlags, icinfo.dwVersion, icinfo.dwVersionICM);
//printf("Compressor name: %s\n", icinfo.szName);
//printf("Compressor description: %s\n", icinfo.szDescription);
mp_tmsg(MSGT_WIN32,MSGL_INFO,"Flags:");
if (icinfo.dwFlags & VIDCF_QUALITY)
mp_tmsg(MSGT_WIN32,MSGL_INFO," quality");
if (icinfo.dwFlags & VIDCF_FASTTEMPORALD)
mp_msg(MSGT_WIN32,MSGL_INFO," fast-decompr");
if (icinfo.dwFlags & VIDCF_QUALITYTIME)
mp_msg(MSGT_WIN32,MSGL_INFO," temp-quality");
mp_msg(MSGT_WIN32,MSGL_INFO,"\n");
}
if(compdatafile){
if (!strncmp(compdatafile, "dialog", 6)){
if (ICSendMessage(encoder_hic, ICM_CONFIGURE, -1, 0) != ICERR_OK){
mp_msg(MSGT_WIN32,MSGL_ERR,"Compressor doesn't have a configure dialog!\n");
return NULL;
}
if (ICSendMessage(encoder_hic, ICM_CONFIGURE, 0, 0) != ICERR_OK){
mp_msg(MSGT_WIN32,MSGL_ERR,"Compressor configure dialog failed!\n");
return NULL;
}
}
else {
if (stat(compdatafile, &st) < 0){
mp_msg(MSGT_WIN32,MSGL_ERR,"Compressor data file not found!\n");
return NULL;
}
fd = fopen(compdatafile, "rb");
if (!fd){
mp_msg(MSGT_WIN32,MSGL_ERR,"Cannot open Compressor data file!\n");
return NULL;
}
drvdata = malloc(st.st_size);
if (fread(drvdata, st.st_size, 1, fd) != 1) {
mp_msg(MSGT_WIN32,MSGL_ERR,"Cannot read Compressor data file!\n");
fclose(fd);
free(drvdata);
return NULL;
}
fclose(fd);
mp_msg(MSGT_WIN32,MSGL_ERR,"Compressor data %d bytes\n", st.st_size);
if (!(temp_len = (unsigned int) ICSendMessage(encoder_hic, ICM_SETSTATE, (LPARAM) drvdata, (int) st.st_size))){
mp_msg(MSGT_WIN32,MSGL_ERR,"ICSetState failed!\n");
free(drvdata);
return NULL;
}
free(drvdata);
mp_msg(MSGT_WIN32,MSGL_INFO,"ICSetState ret: %d\n", temp_len);
}
}
temp_len = ICCompressGetFormatSize(encoder_hic, input_bih);
mp_msg(MSGT_WIN32,MSGL_INFO,"ICCompressGetFormatSize ret: %d\n", temp_len);
if (temp_len < sizeof(BITMAPINFOHEADER)) temp_len=sizeof(BITMAPINFOHEADER);
output_bih = malloc(temp_len+4);
memset(output_bih,0,temp_len);
output_bih->biSize = temp_len; //sizeof(BITMAPINFOHEADER);
return output_bih;
}
static int vfw_start_encoder(BITMAPINFOHEADER *input_bih, BITMAPINFOHEADER *output_bih){
HRESULT ret;
int temp_len=output_bih->biSize;
int i;
ret = ICCompressGetFormat(encoder_hic, input_bih, output_bih);
if(ret < 0){
unsigned char* temp=(unsigned char*)output_bih;
mp_msg(MSGT_WIN32,MSGL_ERR,"ICCompressGetFormat failed: Error %d (0x%X)\n", (int)ret, (int)ret);
for (i=0; i < temp_len; i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02x ", temp[i]);
return 0;
}
mp_msg(MSGT_WIN32,MSGL_V,"ICCompressGetFormat OK\n");
if (temp_len > sizeof(BITMAPINFOHEADER))
{
unsigned char* temp=(unsigned char*)output_bih;
mp_msg(MSGT_WIN32, MSGL_V, "Extra info in o_bih (%d bytes)!\n",
temp_len-sizeof(BITMAPINFOHEADER));
for(i=sizeof(output_bih);i<temp_len;i++) mp_msg(MSGT_WIN32, MSGL_DBG2, "%02X ",temp[i]);
}
// if( mp_msg_test(MSGT_WIN32,MSGL_V) ) {
printf("Starting compression:\n");
printf(" Input format:\n");
printf(" biSize %ld\n", input_bih->biSize);
printf(" biWidth %ld\n", input_bih->biWidth);
printf(" biHeight %ld\n", input_bih->biHeight);
printf(" biPlanes %d\n", input_bih->biPlanes);
printf(" biBitCount %d\n", input_bih->biBitCount);
printf(" biCompression 0x%lx ('%.4s')\n", input_bih->biCompression, (char *)&input_bih->biCompression);
printf(" biSizeImage %ld\n", input_bih->biSizeImage);
printf(" Output format:\n");
printf(" biSize %ld\n", output_bih->biSize);
printf(" biWidth %ld\n", output_bih->biWidth);
printf(" biHeight %ld\n", output_bih->biHeight);
printf(" biPlanes %d\n", output_bih->biPlanes);
printf(" biBitCount %d\n", output_bih->biBitCount);
printf(" biCompression 0x%lx ('%.4s')\n", output_bih->biCompression, (char *)&output_bih->biCompression);
printf(" biSizeImage %ld\n", output_bih->biSizeImage);
// }
output_bih->biWidth=input_bih->biWidth;
output_bih->biHeight=input_bih->biHeight;
ret = ICCompressQuery(encoder_hic, input_bih, output_bih);
if(ret){
mp_msg(MSGT_WIN32,MSGL_ERR,"ICCompressQuery failed: Error %d\n", (int)ret);
return 0;
} else
mp_msg(MSGT_WIN32,MSGL_V,"ICCompressQuery OK\n");
ret = ICCompressBegin(encoder_hic, input_bih, output_bih);
if(ret){
mp_msg(MSGT_WIN32,MSGL_ERR,"ICCompressBegin failed: Error %d\n", (int)ret);
// return 0;
} else
mp_msg(MSGT_WIN32,MSGL_V,"ICCompressBegin OK\n");
mp_msg(MSGT_WIN32,MSGL_INFO," Output format after query/begin:\n");
mp_msg(MSGT_WIN32,MSGL_INFO," biSize %ld\n", output_bih->biSize);
mp_msg(MSGT_WIN32,MSGL_INFO," biWidth %ld\n", output_bih->biWidth);
mp_msg(MSGT_WIN32,MSGL_INFO," biHeight %ld\n", output_bih->biHeight);
mp_msg(MSGT_WIN32,MSGL_INFO," biPlanes %d\n", output_bih->biPlanes);
mp_msg(MSGT_WIN32,MSGL_INFO," biBitCount %d\n", output_bih->biBitCount);
mp_msg(MSGT_WIN32,MSGL_INFO," biCompression 0x%lx ('%.4s')\n", output_bih->biCompression, (char *)&output_bih->biCompression);
mp_msg(MSGT_WIN32,MSGL_INFO," biSizeImage %ld\n", output_bih->biSizeImage);
encoder_buf_size=input_bih->biSizeImage;
encoder_buf=malloc(encoder_buf_size);
encoder_frameno=0;
mp_msg(MSGT_WIN32,MSGL_V,"VIDEO CODEC Init OK!!! ;-)\n");
return 1;
}
static int vfw_encode_frame(BITMAPINFOHEADER* biOutput,void* OutBuf,
BITMAPINFOHEADER* biInput,void* Image,
long* keyframe, int quality){
HRESULT ret;
//long VFWAPIV ICCompress(
// HIC hic,long dwFlags,LPBITMAPINFOHEADER lpbiOutput,void* lpOutputBuf,
// LPBITMAPINFOHEADER lpbiInput,void* lpImage,long* lpckid,
// long* lpdwFlags,long lFrameNum,long dwFrameSize,long dwQuality,
// LPBITMAPINFOHEADER lpbiInputPrev,void* lpImagePrev
//);
// printf("vfw_encode_frame(%p,%p, %p,%p, %p,%d)\n",biOutput,OutBuf,biInput,Image,keyframe,quality);
ret=ICCompress(encoder_hic, 0,
biOutput, OutBuf,
biInput, Image,
NULL, keyframe, encoder_frameno, 0, quality,
biInput, encoder_buf);
// printf("ok. size=%ld\n",biOutput->biSizeImage);
memcpy(encoder_buf,Image,encoder_buf_size);
++encoder_frameno;
return (int)ret;
}
#define mux_v (vf->priv->mux)
#define vfw_bih (vf->priv->bih)
static int config(struct vf_instance *vf,
int width, int height, int d_width, int d_height,
unsigned int flags, unsigned int outfmt){
vfw_bih->biWidth=width;
vfw_bih->biHeight=height;
vfw_bih->biSizeImage=width*height*((vfw_bih->biBitCount+7)/8);
mux_v->aspect = (float)d_width/d_height;
if(!vfw_start_encoder(vfw_bih, mux_v->bih)) return 0;
// mux_v->bih->biWidth=width;
// mux_v->bih->biHeight=height;
// mux_v->bih->biSizeImage=width*height*((mux_v->bih->biBitCount+7)/8);
return 1;
}
static int control(struct vf_instance *vf, int request, void* data){
return CONTROL_UNKNOWN;
}
static int query_format(struct vf_instance *vf, unsigned int fmt){
if(fmt==IMGFMT_BGR24) return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_FLIPPED;
return 0;
}
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
long flags=0;
int ret;
// flip_upside_down(vo_image_ptr,vo_image_ptr,3*vo_w,vo_h); // dirty hack
ret=vfw_encode_frame(mux_v->bih, mux_v->buffer, vfw_bih, mpi->planes[0], &flags, 10000);
// if (ret != ICERR_OK)
// return 0;
muxer_write_chunk(mux_v,mux_v->bih->biSizeImage,flags, pts, pts);
return 1;
}
static void uninit(struct vf_instance *vf)
{
HRESULT ret;
if(encoder_hic){
if(encoder_buf){
ret=ICCompressEnd(encoder_hic);
if(ret) mp_msg(MSGT_WIN32, MSGL_WARN, "ICCompressEnd failed: %ld\n", ret);
free(encoder_buf);
encoder_buf=NULL;
}
ret=ICClose(encoder_hic);
if(ret) mp_msg(MSGT_WIN32, MSGL_WARN, "ICClose failed: %ld\n", ret);
encoder_hic=0;
if ((CoInitRes == S_OK) || (CoInitRes == S_FALSE)) CoUninitialize();
}
}
//===========================================================================//
static int vf_open(vf_instance_t *vf, char* args){
vf->config=config;
vf->default_caps=VFCAP_CONSTANT;
vf->control=control;
vf->query_format=query_format;
vf->put_image=put_image;
vf->uninit=uninit;
vf->priv=malloc(sizeof(struct vf_priv_s));
memset(vf->priv,0,sizeof(struct vf_priv_s));
vf->priv->mux=(muxer_stream_t*)args;
vfw_bih=calloc(1, sizeof(BITMAPINFOHEADER));
vfw_bih->biSize=sizeof(BITMAPINFOHEADER);
vfw_bih->biWidth=0; // FIXME ?
vfw_bih->biHeight=0;
vfw_bih->biPlanes=1;
vfw_bih->biBitCount=24;
vfw_bih->biCompression=0;
// vfw_bih->biSizeImage=vo_w*vo_h*((vfw_bih->biBitCount+7)/8);
if (!vfw_param_codec)
{
mp_tmsg(MSGT_WIN32,MSGL_WARN, "[VE_RAW] Required VfW codec not specified!!\n");
return 0;
}
// mux_v->bih=vfw_open_encoder("divxc32.dll",vfw_bih,mmioFOURCC('D', 'I', 'V', '3'));
// mux_v->bih=vfw_open_encoder("AvidAVICodec.dll",vfw_bih, 0);
mux_v->bih = vfw_open_encoder(vfw_param_codec, vfw_param_compdata, vfw_bih, 0);
if(!mux_v->bih) return 0;
return 1;
}
vf_info_t ve_info_vfw = {
"Win32/VfW encoders",
"vfw",
"A'rpi",
"for internal use by mencoder",
vf_open
};
//===========================================================================//

View File

@ -1,308 +0,0 @@
/*****************************************************************************
*
* - H.264 encoder for mencoder using x264 -
*
* Copyright (C) 2004 LINUX4MEDIA GmbH
* Copyright (C) 2004 Ark Linux
*
* Written by Bernhard Rosenkraenzer <bero@arklinux.org>
*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*****************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "config.h"
#include "mp_msg.h"
#include "m_option.h"
#include "codec-cfg.h"
#include "stream/stream.h"
#include "libmpdemux/demuxer.h"
#include "libmpdemux/stheader.h"
#include "stream/stream.h"
#include "libmpdemux/muxer.h"
#include "img_format.h"
#include "mp_image.h"
#include "vf.h"
#include "ve_x264.h"
#include <x264.h>
typedef struct h264_module_t {
muxer_stream_t *mux;
x264_t * x264;
x264_picture_t pic;
} h264_module_t;
extern char* passtmpfile;
static int turbo = 0;
static x264_param_t param;
static int parse_error = 0;
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts);
static int encode_frame(struct vf_instance *vf, x264_picture_t *pic_in);
void x264enc_set_param(const m_option_t* opt, char* arg)
{
static int initted = 0;
if(!initted) {
x264_param_default(&param);
x264_param_parse(&param, "psnr", "no");
x264_param_parse(&param, "ssim", "no");
initted = 1;
}
if(!arg) {
parse_error = 1;
return;
}
while(*arg) {
char *name = arg;
char *value;
int ret;
arg += strcspn(arg, ":");
if(*arg) {
*arg = 0;
arg++;
}
value = strchr( name, '=' );
if(value) {
*value = 0;
value++;
}
if(!strcmp(name, "turbo")) {
turbo = value ? atoi(value) : 1;
continue;
}
ret = x264_param_parse(&param, name, value);
if(ret == X264_PARAM_BAD_NAME)
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option x264encopts: Unknown suboption %s\n", name);
if(ret == X264_PARAM_BAD_VALUE)
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option x264encopts: Bad argument %s=%s\n", name, value ? value : "(null)");
/* mark this option as done, so it's not reparsed if there's another -x264encopts */
*name = 0;
parse_error |= ret;
}
if(param.rc.b_stat_write && !param.rc.b_stat_read) {
/* Adjust or disable some flags to gain speed in the first pass */
if(turbo == 1)
{
param.i_frame_reference = ( param.i_frame_reference + 1 ) >> 1;
param.analyse.i_subpel_refine = FFMAX( FFMIN( 3, param.analyse.i_subpel_refine - 1 ), 1 );
param.analyse.inter &= ( ~X264_ANALYSE_PSUB8x8 );
param.analyse.inter &= ( ~X264_ANALYSE_BSUB16x16 );
param.analyse.i_trellis = 0;
}
else if(turbo >= 2)
{
param.i_frame_reference = 1;
param.analyse.i_subpel_refine = 1;
param.analyse.i_me_method = X264_ME_DIA;
param.analyse.inter = 0;
param.analyse.b_transform_8x8 = 0;
param.analyse.b_weighted_bipred = 0;
param.analyse.i_trellis = 0;
}
}
}
static int config(struct vf_instance *vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt) {
h264_module_t *mod=(h264_module_t*)vf->priv;
if(parse_error)
return 0;
mod->mux->bih->biWidth = width;
mod->mux->bih->biHeight = height;
mod->mux->bih->biSizeImage = width * height * 3;
mod->mux->aspect = (float)d_width/d_height;
// make sure param is initialized
x264enc_set_param(NULL, "");
param.i_width = width;
param.i_height = height;
param.i_fps_num = mod->mux->h.dwRate;
param.i_fps_den = mod->mux->h.dwScale;
param.b_vfr_input = 0;
param.vui.i_sar_width = d_width*height;
param.vui.i_sar_height = d_height*width;
x264_param_parse(&param, "stats", passtmpfile);
switch(outfmt) {
case IMGFMT_I420:
param.i_csp = X264_CSP_I420;
break;
case IMGFMT_YV12:
param.i_csp = X264_CSP_YV12;
break;
default:
mp_msg(MSGT_MENCODER, MSGL_ERR, "Wrong colorspace.\n");
return 0;
}
mod->x264 = x264_encoder_open(&param);
if(!mod->x264) {
mp_msg(MSGT_MENCODER, MSGL_ERR, "x264_encoder_open failed.\n");
return 0;
}
if(!param.b_repeat_headers){
x264_nal_t *nal;
int extradata_size, nnal;
extradata_size = x264_encoder_headers(mod->x264, &nal, &nnal);
mod->mux->bih= realloc(mod->mux->bih, sizeof(*mod->mux->bih) + extradata_size);
memcpy(mod->mux->bih + 1, nal->p_payload, extradata_size);
mod->mux->bih->biSize= sizeof(*mod->mux->bih) + extradata_size;
}
if (param.i_bframe > 1 && param.i_bframe_pyramid)
mod->mux->decoder_delay = 2;
else
mod->mux->decoder_delay = param.i_bframe ? 1 : 0;
return 1;
}
static int control(struct vf_instance *vf, int request, void *data)
{
h264_module_t *mod=(h264_module_t*)vf->priv;
switch(request){
case VFCTRL_FLUSH_FRAMES:
while (x264_encoder_delayed_frames(mod->x264) > 0)
encode_frame(vf, NULL);
return CONTROL_TRUE;
default:
return CONTROL_UNKNOWN;
}
}
static int query_format(struct vf_instance *vf, unsigned int fmt)
{
switch(fmt) {
case IMGFMT_I420:
return VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW;
case IMGFMT_YV12:
case IMGFMT_422P:
case IMGFMT_444P:
case IMGFMT_YVYU:
case IMGFMT_RGB:
case IMGFMT_BGR:
case IMGFMT_BGR32:
/* These colorspaces are supported, but they'll just have
* to be converted to I420 internally */
return 0; /* VFCAP_CSP_SUPPORTED */
}
return 0;
}
static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
{
h264_module_t *mod=(h264_module_t*)vf->priv;
int i;
memset(&mod->pic, 0, sizeof(x264_picture_t));
mod->pic.img.i_csp=param.i_csp;
mod->pic.img.i_plane=3;
for(i=0; i<4; i++) {
mod->pic.img.plane[i] = mpi->planes[i];
mod->pic.img.i_stride[i] = mpi->stride[i];
}
mod->pic.i_type = X264_TYPE_AUTO;
return encode_frame(vf, &mod->pic) >= 0;
}
static int encode_frame(struct vf_instance *vf, x264_picture_t *pic_in)
{
h264_module_t *mod=(h264_module_t*)vf->priv;
x264_picture_t pic_out;
x264_nal_t *nal;
int i_nal;
int i_size;
i_size = x264_encoder_encode(mod->x264, &nal, &i_nal, pic_in, &pic_out);
if(i_size<0) {
mp_msg(MSGT_MENCODER, MSGL_ERR, "x264_encoder_encode failed\n");
return -1;
}
if(i_size>0) {
int keyframe = pic_out.b_keyframe;
memcpy(mod->mux->buffer, nal->p_payload, i_size);
muxer_write_chunk(mod->mux, i_size, keyframe?AVIIF_KEYFRAME:0, MP_NOPTS_VALUE, MP_NOPTS_VALUE);
}
else
++mod->mux->encoder_delay;
return i_size;
}
static void uninit(struct vf_instance *vf)
{
h264_module_t *mod=(h264_module_t*)vf->priv;
if (mod->x264)
x264_encoder_close(mod->x264);
}
static int vf_open(vf_instance_t *vf, char *args) {
h264_module_t *mod;
vf->config = config;
vf->default_caps = VFCAP_CONSTANT;
vf->control = control;
vf->query_format = query_format;
vf->put_image = put_image;
vf->uninit = uninit;
vf->priv = malloc(sizeof(h264_module_t));
mod=(h264_module_t*)vf->priv;
mod->mux = (muxer_stream_t*)args;
mod->mux->bih = calloc(1, sizeof(*mod->mux->bih));
mod->mux->bih->biSize = sizeof(*mod->mux->bih);
mod->mux->bih->biPlanes = 1;
mod->mux->bih->biBitCount = 24;
mod->mux->bih->biCompression = mmioFOURCC('h', '2', '6', '4');
return 1;
}
vf_info_t ve_info_x264 = {
"H.264 encoder",
"x264",
"Bernhard Rosenkraenzer <bero@arklinux.org>",
"(C) 2004 LINUX4MEDIA GmbH; (C) 2004 Ark Linux",
vf_open
};

View File

@ -1,26 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_X264_H
#define MPLAYER_X264_H
#include "m_option.h"
void x264enc_set_param(const m_option_t* opt, char* arg);
#endif /* MPLAYER_X264_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,167 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <unistd.h>
#include "config.h"
#include "aviheader.h"
#include "ms_hdr.h"
#include "stream/stream.h"
#include "muxer.h"
#include "demuxer.h"
#include "mp_msg.h"
#include "stheader.h"
muxer_t *muxer_new_muxer(int type,stream_t *stream){
muxer_t* muxer=calloc(1,sizeof(muxer_t));
if(!muxer)
return NULL;
muxer->stream = stream;
switch (type) {
case MUXER_TYPE_MPEG:
if(! muxer_init_muxer_mpeg(muxer))
goto fail;
break;
case MUXER_TYPE_RAWVIDEO:
if(! muxer_init_muxer_rawvideo(muxer))
goto fail;
break;
case MUXER_TYPE_RAWAUDIO:
if(! muxer_init_muxer_rawaudio(muxer))
goto fail;
break;
#ifdef CONFIG_LIBAVFORMAT
case MUXER_TYPE_LAVF:
if(! muxer_init_muxer_lavf(muxer))
goto fail;
break;
#endif
case MUXER_TYPE_AVI:
default:
if(! muxer_init_muxer_avi(muxer))
goto fail;
}
return muxer;
fail:
free(muxer);
return NULL;
}
/* buffer frames until we either:
* (a) have at least one frame from each stream
* (b) run out of memory */
void muxer_write_chunk(muxer_stream_t *s, size_t len, unsigned int flags, double dts, double pts) {
if(dts == MP_NOPTS_VALUE) dts= s->timer;
if(pts == MP_NOPTS_VALUE) pts= s->timer; // this is wrong
if (s->muxer->muxbuf_skip_buffer) {
s->muxer->cont_write_chunk(s, len, flags, dts, pts);
}
else {
int num = s->muxer->muxbuf_num++;
muxbuf_t *buf, *tmp;
tmp = realloc_struct(s->muxer->muxbuf, (num+1), sizeof(muxbuf_t));
if(!tmp) {
mp_tmsg(MSGT_MUXER, MSGL_FATAL, "Muxer frame buffer cannot reallocate memory!\n");
return;
}
s->muxer->muxbuf = tmp;
buf = s->muxer->muxbuf + num;
/* buffer this frame */
buf->stream = s;
buf->dts= dts;
buf->pts= pts;
buf->len = len;
buf->flags = flags;
buf->buffer = malloc(len);
if (!buf->buffer) {
mp_tmsg(MSGT_MUXER, MSGL_FATAL, "Muxer frame buffer cannot allocate memory!\n");
return;
}
memcpy(buf->buffer, s->buffer, buf->len);
s->muxbuf_seen = 1;
/* see if we need to keep buffering */
s->muxer->muxbuf_skip_buffer = 1;
for (num = 0; s->muxer->streams[num]; ++num)
if (!s->muxer->streams[num]->muxbuf_seen)
s->muxer->muxbuf_skip_buffer = 0;
/* see if we can flush buffer now */
if (s->muxer->muxbuf_skip_buffer) {
mp_tmsg(MSGT_MUXER, MSGL_V, "Muxer frame buffer sending %d frame(s) to the muxer.\n", s->muxer->muxbuf_num);
/* fix parameters for all streams */
for (num = 0; s->muxer->streams[num]; ++num) {
muxer_stream_t *str = s->muxer->streams[num];
if(str->muxer->fix_stream_parameters)
muxer_stream_fix_parameters(str->muxer, str);
}
/* write header */
if (s->muxer->cont_write_header)
muxer_write_header(s->muxer);
/* send all buffered frames to muxer */
for (num = 0; num < s->muxer->muxbuf_num; ++num) {
muxbuf_t tmp_buf;
buf = s->muxer->muxbuf + num;
s = buf->stream;
/* 1. save timer and buffer (might have changed by now) */
tmp_buf.dts = s->timer;
tmp_buf.buffer = s->buffer;
/* 2. move stored timer and buffer into stream and mux it */
s->timer = buf->dts;
s->buffer = buf->buffer;
s->muxer->cont_write_chunk(s, buf->len, buf->flags, buf->dts, buf->pts);
/* 3. restore saved timer and buffer */
s->timer = tmp_buf.dts;
s->buffer = tmp_buf.buffer;
}
free(s->muxer->muxbuf);
s->muxer->muxbuf_num = 0;
}
}
/* this code moved directly from muxer_avi.c */
// alter counters:
if(s->h.dwSampleSize){
// CBR
s->h.dwLength+=len/s->h.dwSampleSize;
if(len%s->h.dwSampleSize) mp_tmsg(MSGT_MUXER, MSGL_WARN, "Warning, len isn't divisible by samplesize!\n");
} else {
// VBR
s->h.dwLength++;
}
s->timer=(double)s->h.dwLength*s->h.dwScale/s->h.dwRate;
s->size+=len;
return;
}

View File

@ -1,143 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_MUXER_H
#define MPLAYER_MUXER_H
#include <stdint.h>
#include <sys/types.h>
#include "aviheader.h"
#include "ms_hdr.h"
#include "stream/stream.h"
#define MUXER_MAX_STREAMS 16
#define MUXER_TYPE_VIDEO 0
#define MUXER_TYPE_AUDIO 1
#define MUXER_TYPE_AVI 0
#define MUXER_TYPE_MPEG 1
#define MUXER_TYPE_RAWVIDEO 2
#define MUXER_TYPE_LAVF 3
#define MUXER_TYPE_RAWAUDIO 4
typedef struct {
// muxer data:
int type; // audio or video
int id; // stream no
uint32_t ckid; // chunk id (00dc 01wb etc)
double timer;
off_t size;
float aspect; // aspect ratio of this stream (set by ve_*.c)
// buffering:
unsigned char *buffer;
unsigned int buffer_size;
unsigned int buffer_len;
// mpeg block buffer:
unsigned char *b_buffer;
unsigned int b_buffer_size; //size of b_buffer
unsigned int b_buffer_ptr; //index to next data to write
unsigned int b_buffer_len; //len of next data to write
// muxer frame buffer:
unsigned int muxbuf_seen;
// source stream:
void* source; // sh_audio or sh_video
int codec; // codec used for encoding. 0 means copy
// avi stream header:
AVIStreamHeader h; // Rate/Scale and SampleSize must be filled by caller!
// stream specific:
WAVEFORMATEX *wf;
BITMAPINFOHEADER *bih; // in format
int encoder_delay; // in number of frames
int decoder_delay; // in number of frames
int imgfmt;
// mpeg specific:
size_t ipb[3]; // sizes of I/P/B frames
// muxer of that stream
struct muxer_t *muxer;
void *priv; // private stream specific data stored by the muxer
int vbv_size;
int max_rate;
int avg_rate;
} muxer_stream_t;
typedef struct {
uint32_t id;
char *text;
} muxer_info_t;
typedef struct muxer_t{
// encoding:
MainAVIHeader avih;
off_t movi_start;
off_t movi_end;
off_t file_end; // for MPEG it's system timestamp in 1/90000 s
float audio_delay_fix;
// index:
AVIINDEXENTRY *idx;
int idx_pos;
int idx_size;
// streams:
int num_videos; // for MPEG recalculations
int num_audios;
unsigned int sysrate; // max rate in bytes/s
//int num_streams;
muxer_stream_t* def_v; // default video stream (for general headers)
muxer_stream_t* streams[MUXER_MAX_STREAMS];
// muxer frame buffer:
struct muxbuf_t * muxbuf;
int muxbuf_num;
int muxbuf_skip_buffer;
// functions:
stream_t *stream;
void (*fix_stream_parameters)(muxer_stream_t *);
void (*cont_write_chunk)(muxer_stream_t *,size_t,unsigned int, double dts, double pts);
void (*cont_write_header)(struct muxer_t *);
void (*cont_write_index)(struct muxer_t *);
muxer_stream_t* (*cont_new_stream)(struct muxer_t *,int);
void *priv;
} muxer_t;
/* muxer frame buffer */
typedef struct muxbuf_t {
muxer_stream_t *stream; /* pointer back to corresponding stream */
double dts; /* decode timestamp / time at which this packet should be feeded into the decoder */
double pts; /* presentation timestamp / time at which the data in this packet will be presented to the user */
unsigned char *buffer;
size_t len;
unsigned int flags;
} muxbuf_t;
extern char *force_fourcc;
muxer_t *muxer_new_muxer(int type,stream_t *stream);
#define muxer_new_stream(muxer,a) muxer->cont_new_stream(muxer,a)
#define muxer_stream_fix_parameters(muxer, a) muxer->fix_stream_parameters(a)
void muxer_write_chunk(muxer_stream_t *s, size_t len, unsigned int flags, double dts, double pts);
#define muxer_write_header(muxer) muxer->cont_write_header(muxer)
#define muxer_write_index(muxer) muxer->cont_write_index(muxer)
int muxer_init_muxer_avi(muxer_t *);
int muxer_init_muxer_mpeg(muxer_t *);
int muxer_init_muxer_rawvideo(muxer_t *);
int muxer_init_muxer_lavf(muxer_t *);
int muxer_init_muxer_rawaudio(muxer_t *);
#endif /* MPLAYER_MUXER_H */

View File

@ -1,694 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <unistd.h>
#include <limits.h>
#include "config.h"
#include "mpcommon.h"
#include "stream/stream.h"
#include "demuxer.h"
#include "stheader.h"
#include "muxer.h"
#include "aviheader.h"
#include "ms_hdr.h"
#include "mp_msg.h"
extern char *info_name;
extern char *info_artist;
extern char *info_genre;
extern char *info_subject;
extern char *info_copyright;
extern char *info_sourceform;
extern char *info_comment;
/* #define ODML_CHUNKLEN 0x02000000 */ /* for testing purposes */
#define ODML_CHUNKLEN 0x40000000
#define ODML_NOTKEYFRAME 0x80000000U
#define MOVIALIGN 0x00001000
float avi_aspect_override = -1.0;
int write_odml = 1;
struct avi_odmlidx_entry {
uint64_t ofs;
uint32_t len;
uint32_t flags;
};
struct avi_odmlsuperidx_entry {
uint64_t ofs;
uint32_t len;
uint32_t duration;
};
struct avi_stream_info {
int idxsize;
int idxpos;
int superidxpos;
int superidxsize;
int riffofspos;
int riffofssize;
off_t *riffofs;
struct avi_odmlidx_entry *idx;
struct avi_odmlsuperidx_entry *superidx;
};
static unsigned int avi_aspect(muxer_stream_t *vstream)
{
int x,y;
float aspect = vstream->aspect;
if (avi_aspect_override > 0.0) {
aspect = avi_aspect_override;
}
if (aspect <= 0.0) return 0;
if (aspect > 15.99/9.0 && aspect < 16.01/9.0) {
return MAKE_AVI_ASPECT(16, 9);
}
if (aspect > 3.99/3.0 && aspect < 4.01/3.0) {
return MAKE_AVI_ASPECT(4, 3);
}
if (aspect >= 1.0) {
x = 16384;
y = (float)x / aspect;
} else {
y = 16384;
x = (float)y * aspect;
}
return MAKE_AVI_ASPECT(x, y);
}
static muxer_stream_t* avifile_new_stream(muxer_t *muxer,int type){
struct avi_stream_info *si;
muxer_stream_t* s;
if (!muxer) return NULL;
if(muxer->avih.dwStreams>=MUXER_MAX_STREAMS){
mp_msg(MSGT_MUXER, MSGL_ERR, "Too many streams! increase MUXER_MAX_STREAMS !\n");
return NULL;
}
s=malloc(sizeof(muxer_stream_t));
memset(s,0,sizeof(muxer_stream_t));
if(!s) return NULL; // no mem!?
muxer->streams[muxer->avih.dwStreams]=s;
s->type=type;
s->id=muxer->avih.dwStreams;
s->timer=0.0;
s->size=0;
s->muxer=muxer;
s->priv=si=malloc(sizeof(struct avi_stream_info));
memset(si,0,sizeof(struct avi_stream_info));
si->idxsize=256;
si->idx=calloc(si->idxsize, sizeof(struct avi_odmlidx_entry));
si->riffofssize=16;
si->riffofs=calloc((si->riffofssize+1), sizeof(off_t));
memset(si->riffofs, 0, sizeof(off_t)*si->riffofssize);
switch(type){
case MUXER_TYPE_VIDEO:
s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
s->h.fccType=streamtypeVIDEO;
if(!muxer->def_v) muxer->def_v=s;
break;
case MUXER_TYPE_AUDIO:
s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'w','b');
s->h.fccType=streamtypeAUDIO;
break;
default:
mp_msg(MSGT_MUXER, MSGL_WARN, "Warning! unknown stream type: %d\n",type);
return NULL;
}
muxer->avih.dwStreams++;
return s;
}
static void write_avi_chunk(stream_t *stream,unsigned int id,int len,void* data){
int le_len = le2me_32(len);
int le_id = le2me_32(id);
stream_write_buffer(stream, &le_id, 4);
stream_write_buffer(stream, &le_len, 4);
if(len>0){
if(data){
// DATA
stream_write_buffer(stream, data, len);
if(len&1){ // padding
unsigned char zerobyte=0;
stream_write_buffer(stream, &zerobyte, 1);
}
} else {
// JUNK
char *avi_junk_data="[= MPlayer junk data! =]";
if(len&1) ++len; // padding
while(len>0){
int l=strlen(avi_junk_data);
if(l>len) l=len;
stream_write_buffer(stream, avi_junk_data, l);
len-=l;
}
}
}
}
static void write_avi_list(stream_t *s,unsigned int id,int len);
static void avifile_write_standard_index(muxer_t *muxer);
static void avifile_odml_new_riff(muxer_t *muxer)
{
struct avi_stream_info *vsi = muxer->def_v->priv;
uint32_t riff[3];
mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: Starting new RIFF chunk at %dMB.\n", (int)(muxer->file_end/1024/1024));
vsi->riffofspos++;
if (vsi->riffofspos>=vsi->riffofssize) {
vsi->riffofssize+=16;
vsi->riffofs=realloc_struct(vsi->riffofs,(vsi->riffofssize+1),sizeof(off_t));
}
vsi->riffofs[vsi->riffofspos] = stream_tell(muxer->stream);
/* RIFF/AVIX chunk */
riff[0]=le2me_32(mmioFOURCC('R','I','F','F'));
riff[1]=0;
riff[2]=le2me_32(mmioFOURCC('A','V','I','X'));
stream_write_buffer(muxer->stream, riff, 12);
write_avi_list(muxer->stream,listtypeAVIMOVIE,0);
muxer->file_end = stream_tell(muxer->stream);
}
static void avifile_write_header(muxer_t *muxer);
static void avifile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts, double pts){
off_t rifflen;
muxer_t *muxer=s->muxer;
struct avi_stream_info *si = s->priv;
struct avi_stream_info *vsi = muxer->def_v->priv;
int paddedlen = len + (len&1);
if (s->type == MUXER_TYPE_VIDEO && !s->h.dwSuggestedBufferSize) {
off_t pos=stream_tell(muxer->stream);
stream_seek(muxer->stream, 0);
avifile_write_header(muxer);
stream_seek(muxer->stream, pos);
}
if(index_mode){
rifflen = muxer->file_end - vsi->riffofs[vsi->riffofspos] - 8;
if (vsi->riffofspos == 0) {
rifflen += 8+muxer->idx_pos*sizeof(AVIINDEXENTRY);
}
if (rifflen + paddedlen > ODML_CHUNKLEN && write_odml == 1) {
if (vsi->riffofspos == 0) {
avifile_write_standard_index(muxer);
}
avifile_odml_new_riff(muxer);
}
if (vsi->riffofspos == 0) {
// add to the traditional index:
if(muxer->idx_pos>=muxer->idx_size){
muxer->idx_size+=256; // 4kB
muxer->idx=realloc_struct(muxer->idx,muxer->idx_size,16);
}
muxer->idx[muxer->idx_pos].ckid=s->ckid;
muxer->idx[muxer->idx_pos].dwFlags=flags; // keyframe?
muxer->idx[muxer->idx_pos].dwChunkOffset=muxer->file_end-(muxer->movi_start-4);
muxer->idx[muxer->idx_pos].dwChunkLength=len;
++muxer->idx_pos;
}
// add to odml index
if(si->idxpos>=si->idxsize){
si->idxsize+=256;
si->idx=realloc_struct(si->idx,si->idxsize,sizeof(*si->idx));
}
si->idx[si->idxpos].flags=(flags&AVIIF_KEYFRAME)?0:ODML_NOTKEYFRAME;
si->idx[si->idxpos].ofs=muxer->file_end;
si->idx[si->idxpos].len=len;
++si->idxpos;
}
// write out the chunk:
write_avi_chunk(muxer->stream,s->ckid,len,s->buffer); /* unsigned char */
if (len > s->h.dwSuggestedBufferSize){
s->h.dwSuggestedBufferSize = len;
}
if((unsigned int)len>s->h.dwSuggestedBufferSize) s->h.dwSuggestedBufferSize=len;
muxer->file_end += 8 + paddedlen;
}
static void write_avi_list(stream_t *stream,unsigned int id,int len){
unsigned int list_id=FOURCC_LIST;
int le_len;
int le_id;
len+=4; // list fix
list_id = le2me_32(list_id);
le_len = le2me_32(len);
le_id = le2me_32(id);
stream_write_buffer(stream, &list_id, 4);
stream_write_buffer(stream, &le_len, 4);
stream_write_buffer(stream, &le_id, 4);
}
#define WFSIZE(wf) (sizeof(*wf)+(wf)->cbSize)
static void avifile_write_header(muxer_t *muxer){
uint32_t riff[3];
unsigned int dmlh[1];
unsigned int i;
unsigned int hdrsize;
muxer_info_t info[16];
VideoPropHeader vprp;
uint32_t aspect = avi_aspect(muxer->def_v);
struct avi_stream_info *vsi = muxer->def_v->priv;
int isodml = vsi->riffofspos > 0;
mp_tmsg(MSGT_MUXER, MSGL_INFO, "Writing header...\n");
if (aspect == 0) {
mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: Aspect information not (yet?) available or unspecified, not writing vprp header.\n");
} else {
mp_msg(MSGT_MUXER, MSGL_INFO, "ODML: vprp aspect is %d:%d.\n", aspect >> 16, aspect & 0xffff);
}
/* deal with stream delays */
for (i = 0; muxer->streams[i] && i < MUXER_MAX_STREAMS; ++i) {
muxer_stream_t *s = muxer->streams[i];
if (s->type == MUXER_TYPE_AUDIO && muxer->audio_delay_fix > 0.0) {
s->h.dwStart = muxer->audio_delay_fix * s->h.dwRate/s->h.dwScale + 0.5;
mp_tmsg(MSGT_MUXER, MSGL_INFO, "Setting audio delay to %5.3fs.\n", (float)s->h.dwStart * s->h.dwScale/s->h.dwRate);
}
if (s->type == MUXER_TYPE_VIDEO && muxer->audio_delay_fix < 0.0) {
s->h.dwStart = -muxer->audio_delay_fix * s->h.dwRate/s->h.dwScale + 0.5;
mp_tmsg(MSGT_MUXER, MSGL_INFO, "Setting video delay to %5.3fs.\n", (float)s->h.dwStart * s->h.dwScale/s->h.dwRate);
}
}
if (isodml) {
unsigned int rifflen, movilen;
int i;
vsi->riffofs[vsi->riffofspos+1] = muxer->file_end;
/* fixup RIFF lengths */
for (i=0; i<=vsi->riffofspos; i++) {
rifflen = vsi->riffofs[i+1] - vsi->riffofs[i] - 8;
movilen = le2me_32(rifflen - 12);
rifflen = le2me_32(rifflen);
stream_seek(muxer->stream, vsi->riffofs[i]+4);
stream_write_buffer(muxer->stream,&rifflen,4);
/* fixup movi length */
if (i > 0) {
stream_seek(muxer->stream, vsi->riffofs[i]+16);
stream_write_buffer(muxer->stream,&movilen,4);
}
}
stream_seek(muxer->stream, 12);
} else {
// RIFF header:
riff[0]=mmioFOURCC('R','I','F','F');
riff[1]=muxer->file_end-2*sizeof(unsigned int); // filesize
riff[2]=formtypeAVI; // 'AVI '
riff[0]=le2me_32(riff[0]);
riff[1]=le2me_32(riff[1]);
riff[2]=le2me_32(riff[2]);
stream_write_buffer(muxer->stream,&riff,12);
}
// update AVI header:
if(muxer->def_v){
int i;
muxer->avih.dwMicroSecPerFrame=1000000.0*muxer->def_v->h.dwScale/muxer->def_v->h.dwRate;
// muxer->avih.dwMaxBytesPerSec=1000000; // dummy!!!!! FIXME
// muxer->avih.dwPaddingGranularity=2; // ???
muxer->avih.dwFlags|=AVIF_ISINTERLEAVED|AVIF_TRUSTCKTYPE;
muxer->avih.dwTotalFrames=0;
for (i=0; i<muxer->idx_pos; i++) {
if (muxer->idx[i].ckid == muxer->def_v->ckid)
muxer->avih.dwTotalFrames++;
}
// muxer->avih.dwSuggestedBufferSize=muxer->def_v->h.dwSuggestedBufferSize;
muxer->avih.dwWidth=muxer->def_v->bih->biWidth;
muxer->avih.dwHeight=muxer->def_v->bih->biHeight;
}
// AVI header:
hdrsize=sizeof(muxer->avih)+8;
if (isodml) hdrsize+=sizeof(dmlh)+20; // dmlh
// calc total header size:
for(i=0;i<muxer->avih.dwStreams;i++){
muxer_stream_t *s = muxer->streams[i];
struct avi_stream_info *si = s->priv;
hdrsize+=12; // LIST
hdrsize+=sizeof(muxer->streams[i]->h)+8; // strh
switch(muxer->streams[i]->type){
case MUXER_TYPE_VIDEO:
hdrsize+=muxer->streams[i]->bih->biSize+8; // strf
if (aspect != 0) {
hdrsize+=8+4*(9+8*1); // vprp
}
break;
case MUXER_TYPE_AUDIO:
hdrsize+=WFSIZE(muxer->streams[i]->wf)+8; // strf
break;
}
if (isodml && si && si->superidx && si->superidxsize) {
hdrsize += 32 + 16*si->superidxsize; //indx
}
}
write_avi_list(muxer->stream,listtypeAVIHEADER,hdrsize);
le2me_MainAVIHeader(&muxer->avih);
write_avi_chunk(muxer->stream,ckidAVIMAINHDR,sizeof(muxer->avih),&muxer->avih); /* MainAVIHeader */
le2me_MainAVIHeader(&muxer->avih);
// stream headers:
for(i=0;i<muxer->avih.dwStreams;i++){
muxer_stream_t *s = muxer->streams[i];
struct avi_stream_info *si = s->priv;
unsigned int idxhdr[8];
int j,n;
hdrsize=sizeof(s->h)+8; // strh
if (si && si->superidx && si->superidxsize) {
hdrsize += 32 + 16*si->superidxsize; //indx
}
switch(s->type){
case MUXER_TYPE_VIDEO:
hdrsize+=s->bih->biSize+8; // strf
s->h.fccHandler = s->bih->biCompression;
s->h.rcFrame.right = s->bih->biWidth;
s->h.rcFrame.bottom = s->bih->biHeight;
if (aspect != 0) {
// fill out vprp info
memset(&vprp, 0, sizeof(vprp));
vprp.dwVerticalRefreshRate = (s->h.dwRate+s->h.dwScale-1)/s->h.dwScale;
vprp.dwHTotalInT = muxer->avih.dwWidth;
vprp.dwVTotalInLines = muxer->avih.dwHeight;
vprp.dwFrameAspectRatio = aspect;
vprp.dwFrameWidthInPixels = muxer->avih.dwWidth;
vprp.dwFrameHeightInLines = muxer->avih.dwHeight;
vprp.nbFieldPerFrame = 1;
vprp.FieldInfo[0].CompressedBMHeight = muxer->avih.dwHeight;
vprp.FieldInfo[0].CompressedBMWidth = muxer->avih.dwWidth;
vprp.FieldInfo[0].ValidBMHeight = muxer->avih.dwHeight;
vprp.FieldInfo[0].ValidBMWidth = muxer->avih.dwWidth;
hdrsize+=8+4*(9+8*1); // vprp
}
break;
case MUXER_TYPE_AUDIO:
hdrsize+=WFSIZE(s->wf)+8; // strf
s->h.fccHandler = s->wf->wFormatTag;
break;
}
write_avi_list(muxer->stream,listtypeSTREAMHEADER,hdrsize);
le2me_AVIStreamHeader(&s->h);
write_avi_chunk(muxer->stream,ckidSTREAMHEADER,sizeof(s->h),&s->h); /* AVISTreamHeader */ // strh
le2me_AVIStreamHeader(&s->h);
switch(s->type){
case MUXER_TYPE_VIDEO:
{
int biSize=s->bih->biSize;
le2me_BITMAPINFOHEADER(s->bih);
write_avi_chunk(muxer->stream,ckidSTREAMFORMAT,biSize,s->bih); /* BITMAPINFOHEADER */
le2me_BITMAPINFOHEADER(s->bih);
if (aspect != 0) {
int fields = vprp.nbFieldPerFrame;
le2me_VideoPropHeader(&vprp);
le2me_VIDEO_FIELD_DESC(&vprp.FieldInfo[0]);
le2me_VIDEO_FIELD_DESC(&vprp.FieldInfo[1]);
write_avi_chunk(muxer->stream,mmioFOURCC('v','p','r','p'),
sizeof(VideoPropHeader) -
sizeof(VIDEO_FIELD_DESC)*(2-fields),
&vprp); /* Video Properties Header */
}
}
break;
case MUXER_TYPE_AUDIO:
{
int wfsize = WFSIZE(s->wf);
le2me_WAVEFORMATEX(s->wf);
write_avi_chunk(muxer->stream,ckidSTREAMFORMAT,wfsize,s->wf); /* WAVEFORMATEX */
le2me_WAVEFORMATEX(s->wf);
}
break;
}
if (isodml && si && si->superidx && si->superidxsize) {
n = si->superidxsize;
idxhdr[0] = le2me_32(mmioFOURCC('i', 'n', 'd', 'x'));
idxhdr[1] = le2me_32(24 + 16*n);
idxhdr[2] = le2me_32(0x00000004);
idxhdr[3] = le2me_32(si->superidxpos);
idxhdr[4] = le2me_32(s->ckid);
idxhdr[5] = 0;
idxhdr[6] = 0;
idxhdr[7] = 0;
stream_write_buffer(muxer->stream,idxhdr,sizeof(idxhdr));
for (j=0; j<n; j++) {
struct avi_odmlsuperidx_entry *entry = &si->superidx[j];
unsigned int data[4];
data[0] = le2me_32(entry->ofs);
data[1] = le2me_32(entry->ofs >> 32);
data[2] = le2me_32(entry->len);
data[3] = le2me_32(entry->duration);
stream_write_buffer(muxer->stream,data,sizeof(data));
}
}
}
// ODML
if (isodml) {
memset(dmlh, 0, sizeof(dmlh));
dmlh[0] = le2me_32(muxer->avih.dwTotalFrames);
write_avi_list(muxer->stream,mmioFOURCC('o','d','m','l'),sizeof(dmlh)+8);
write_avi_chunk(muxer->stream,mmioFOURCC('d','m','l','h'),sizeof(dmlh),dmlh);
}
// ============= INFO ===============
// always include software info
info[0].id=mmioFOURCC('I','S','F','T'); // Software:
info[0].text=mencoder_version;
// include any optional strings
i=1;
if(info_name!=NULL){
info[i].id=mmioFOURCC('I','N','A','M'); // Name:
info[i++].text=info_name;
}
if(info_artist!=NULL){
info[i].id=mmioFOURCC('I','A','R','T'); // Artist:
info[i++].text=info_artist;
}
if(info_genre!=NULL){
info[i].id=mmioFOURCC('I','G','N','R'); // Genre:
info[i++].text=info_genre;
}
if(info_subject!=NULL){
info[i].id=mmioFOURCC('I','S','B','J'); // Subject:
info[i++].text=info_subject;
}
if(info_copyright!=NULL){
info[i].id=mmioFOURCC('I','C','O','P'); // Copyright:
info[i++].text=info_copyright;
}
if(info_sourceform!=NULL){
info[i].id=mmioFOURCC('I','S','R','F'); // Source Form:
info[i++].text=info_sourceform;
}
if(info_comment!=NULL){
info[i].id=mmioFOURCC('I','C','M','T'); // Comment:
info[i++].text=info_comment;
}
info[i].id=0;
hdrsize=0;
// calc info size:
for(i=0;info[i].id!=0;i++) if(info[i].text){
size_t sz=strlen(info[i].text)+1;
hdrsize+=sz+8+sz%2;
}
// write infos:
if (hdrsize!=0){
write_avi_list(muxer->stream,mmioFOURCC('I','N','F','O'),hdrsize);
for(i=0;info[i].id!=0;i++) if(info[i].text){
write_avi_chunk(muxer->stream,info[i].id,strlen(info[i].text)+1,info[i].text);
}
}
// JUNK:
write_avi_chunk(muxer->stream,ckidAVIPADDING,MOVIALIGN-(stream_tell(muxer->stream)%MOVIALIGN)-8,NULL); /* junk */
if (!isodml) {
// 'movi' header:
write_avi_list(muxer->stream,listtypeAVIMOVIE,muxer->movi_end-stream_tell(muxer->stream)-12);
} else {
if (stream_tell(muxer->stream) != MOVIALIGN) {
mp_msg(MSGT_MUXER, MSGL_ERR, "Opendml superindex is too big for reserved space!\n");
mp_msg(MSGT_MUXER, MSGL_ERR, "Expected filepos %d, real filepos %ld, missing space %ld\n", MOVIALIGN, stream_tell(muxer->stream), stream_tell(muxer->stream)-MOVIALIGN);
mp_msg(MSGT_MUXER, MSGL_ERR, "Try increasing MOVIALIGN in libmpdemux/muxer_avi.c\n");
}
write_avi_list(muxer->stream,listtypeAVIMOVIE,muxer->movi_end-stream_tell(muxer->stream)-12);
}
muxer->movi_start=stream_tell(muxer->stream);
if (muxer->file_end == 0) muxer->file_end = stream_tell(muxer->stream);
}
static void avifile_odml_write_index(muxer_t *muxer){
muxer_stream_t* s;
struct avi_stream_info *si;
int i;
for (i=0; i<muxer->avih.dwStreams; i++) {
int j,k,n,idxpos,len,last,entries_per_subidx;
unsigned int idxhdr[8];
s = muxer->streams[i];
si = s->priv;
/*
* According to Avery Lee MSMP wants the subidx chunks to have the same size.
*
* So this code figures out how many entries we can put into
* an ix?? chunk, so that each ix?? chunk has the same size and the offsets
* don't overflow (Using ODML_CHUNKLEN for that is a bit more restrictive
* than it has to be though).
*/
len = 0;
n = 0;
entries_per_subidx = INT_MAX;
do {
off_t start = si->idx[0].ofs;
last = entries_per_subidx;
for (j=0; j<si->idxpos; j++) {
len = si->idx[j].ofs - start;
if(len >= ODML_CHUNKLEN || n >= entries_per_subidx) {
if (entries_per_subidx > n) {
entries_per_subidx = n;
}
start = si->idx[j].ofs;
len = 0;
n = 0;
}
n++;
}
} while (last != entries_per_subidx);
si->superidxpos = (si->idxpos+entries_per_subidx-1) / entries_per_subidx;
mp_msg(MSGT_MUXER, MSGL_V, "ODML: Stream %d: Using %d entries per subidx, %d entries in superidx\n",
i, entries_per_subidx, si->superidxpos);
si->superidxsize = si->superidxpos;
si->superidx = calloc(si->superidxsize, sizeof(*si->superidx));
memset(si->superidx, 0, sizeof(*si->superidx) * si->superidxsize);
idxpos = 0;
for (j=0; j<si->superidxpos; j++) {
off_t start = si->idx[idxpos].ofs;
int duration;
duration = 0;
for (k=0; k<entries_per_subidx && idxpos+k<si->idxpos; k++) {
duration += s->h.dwSampleSize ? si->idx[idxpos+k].len/s->h.dwSampleSize : 1;
}
idxhdr[0] = le2me_32((s->ckid << 16) | mmioFOURCC('i', 'x', 0, 0));
idxhdr[1] = le2me_32(24 + 8*k);
idxhdr[2] = le2me_32(0x01000002);
idxhdr[3] = le2me_32(k);
idxhdr[4] = le2me_32(s->ckid);
idxhdr[5] = le2me_32(start + 8);
idxhdr[6] = le2me_32((start + 8)>> 32);
idxhdr[7] = 0; /* unused */
si->superidx[j].len = 32 + 8*k;
si->superidx[j].ofs = stream_tell(muxer->stream);
si->superidx[j].duration = duration;
stream_write_buffer(muxer->stream, idxhdr,sizeof(idxhdr));
for (k=0; k<entries_per_subidx && idxpos<si->idxpos; k++) {
unsigned int entry[2];
entry[0] = le2me_32(si->idx[idxpos].ofs - start);
entry[1] = le2me_32(si->idx[idxpos].len | si->idx[idxpos].flags);
idxpos++;
stream_write_buffer(muxer->stream, entry, sizeof(entry));
}
}
}
muxer->file_end=stream_tell(muxer->stream);
}
static void avifile_write_standard_index(muxer_t *muxer){
muxer->movi_end=stream_tell(muxer->stream);
if(muxer->idx && muxer->idx_pos>0){
int i;
// fixup index entries:
// for(i=0;i<muxer->idx_pos;i++) muxer->idx[i].dwChunkOffset-=muxer->movi_start-4;
// write index chunk:
for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
write_avi_chunk(muxer->stream,ckidAVINEWINDEX,16*muxer->idx_pos,muxer->idx); /* AVIINDEXENTRY */
for (i=0; i<muxer->idx_pos; i++) le2me_AVIINDEXENTRY((&muxer->idx[i]));
muxer->avih.dwFlags|=AVIF_HASINDEX;
}
muxer->file_end=stream_tell(muxer->stream);
}
static void avifile_write_index(muxer_t *muxer){
struct avi_stream_info *vsi = muxer->def_v->priv;
mp_tmsg(MSGT_MUXER, MSGL_INFO, "Writing index...\n");
if (vsi->riffofspos > 0){
avifile_odml_write_index(muxer);
} else {
avifile_write_standard_index(muxer);
}
}
static void avifile_fix_parameters(muxer_stream_t *s){
/* adjust audio_delay_fix according to individual stream delay */
if (s->type == MUXER_TYPE_AUDIO)
s->muxer->audio_delay_fix -= (float)s->decoder_delay * s->h.dwScale/s->h.dwRate;
if (s->type == MUXER_TYPE_VIDEO)
s->muxer->audio_delay_fix += (float)s->decoder_delay * s->h.dwScale/s->h.dwRate;
}
int muxer_init_muxer_avi(muxer_t *muxer){
muxer->cont_new_stream = &avifile_new_stream;
muxer->cont_write_chunk = &avifile_write_chunk;
muxer->cont_write_header = &avifile_write_header;
muxer->cont_write_index = &avifile_write_index;
muxer->fix_stream_parameters = &avifile_fix_parameters;
return 1;
}

View File

@ -1,408 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <inttypes.h>
#include <limits.h>
#include "config.h"
#include "mp_msg.h"
#include "aviheader.h"
#include "ms_hdr.h"
#include "av_opts.h"
#include "stream/stream.h"
#include "muxer.h"
#include "demuxer.h"
#include "stheader.h"
#include "m_option.h"
#include "libavformat/avformat.h"
#include "libavutil/avstring.h"
#include "mp_taglists.h"
enum PixelFormat imgfmt2pixfmt(int fmt);
extern char *info_name;
extern char *info_artist;
extern char *info_genre;
extern char *info_subject;
extern char *info_copyright;
extern char *info_sourceform;
extern char *info_comment;
#define BIO_BUFFER_SIZE 32768
typedef struct {
//AVInputFormat *avif;
AVFormatContext *oc;
ByteIOContext *pb;
int audio_streams;
int video_streams;
int64_t last_pts;
uint8_t buffer[BIO_BUFFER_SIZE];
} muxer_priv_t;
typedef struct {
int64_t last_pts;
AVStream *avstream;
} muxer_stream_priv_t;
static char *conf_format = NULL;
static int mux_rate= 0;
static int mux_packet_size= 0;
static float mux_preload= 0.5;
static float mux_max_delay= 0.7;
static char *mux_avopt = NULL;
const m_option_t lavfopts_conf[] = {
{"format", &(conf_format), CONF_TYPE_STRING, 0, 0, 0, NULL},
{"muxrate", &mux_rate, CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL},
{"packetsize", &mux_packet_size, CONF_TYPE_INT, CONF_RANGE, 0, INT_MAX, NULL},
{"preload", &mux_preload, CONF_TYPE_FLOAT, CONF_RANGE, 0, INT_MAX, NULL},
{"delay", &mux_max_delay, CONF_TYPE_FLOAT, CONF_RANGE, 0, INT_MAX, NULL},
{"o", &mux_avopt, CONF_TYPE_STRING, 0, 0, 0, NULL},
{NULL, NULL, 0, 0, 0, 0, NULL}
};
static int mp_write(void *opaque, uint8_t *buf, int size)
{
muxer_t *muxer = opaque;
return stream_write_buffer(muxer->stream, buf, size);
}
static int64_t mp_seek(void *opaque, int64_t pos, int whence)
{
muxer_t *muxer = opaque;
if(whence == SEEK_CUR)
{
off_t cur = stream_tell(muxer->stream);
if(cur == -1)
return -1;
pos += cur;
}
else if(whence == SEEK_END)
{
off_t size=0;
if(stream_control(muxer->stream, STREAM_CTRL_GET_SIZE, &size) == STREAM_UNSUPPORTED || size < pos)
return -1;
pos = size - pos;
}
mp_msg(MSGT_MUXER, MSGL_DBG2, "SEEK %"PRIu64"\n", (int64_t)pos);
if(!stream_seek(muxer->stream, pos))
return -1;
return 0;
}
static muxer_stream_t* lavf_new_stream(muxer_t *muxer, int type)
{
muxer_priv_t *priv = muxer->priv;
muxer_stream_t *stream;
muxer_stream_priv_t *spriv;
AVCodecContext *ctx;
if(!muxer || (type != MUXER_TYPE_VIDEO && type != MUXER_TYPE_AUDIO))
{
mp_msg(MSGT_MUXER, MSGL_ERR, "UNKNOWN TYPE %d\n", type);
return NULL;
}
stream = calloc(1, sizeof(muxer_stream_t));
if(!stream)
{
mp_msg(MSGT_MUXER, MSGL_ERR, "Could not allocate muxer_stream, EXIT.\n");
return NULL;
}
muxer->streams[muxer->avih.dwStreams] = stream;
stream->b_buffer = malloc(2048);
if(!stream->b_buffer)
{
mp_msg(MSGT_MUXER, MSGL_ERR, "Could not allocate b_buffer, EXIT.\n");
free(stream);
return NULL;
}
stream->b_buffer_size = 2048;
stream->b_buffer_ptr = 0;
stream->b_buffer_len = 0;
spriv = calloc(1, sizeof(muxer_stream_priv_t));
if(!spriv)
{
free(stream);
return NULL;
}
stream->priv = spriv;
spriv->avstream = av_new_stream(priv->oc, 1);
if(!spriv->avstream)
{
mp_msg(MSGT_MUXER, MSGL_ERR, "Could not allocate avstream, EXIT.\n");
return NULL;
}
spriv->avstream->stream_copy = 1;
ctx = spriv->avstream->codec;
ctx->codec_id = muxer->avih.dwStreams;
switch(type)
{
case MUXER_TYPE_VIDEO:
ctx->codec_type = CODEC_TYPE_VIDEO;
break;
case MUXER_TYPE_AUDIO:
ctx->codec_type = CODEC_TYPE_AUDIO;
break;
}
muxer->avih.dwStreams++;
stream->muxer = muxer;
stream->type = type;
mp_msg(MSGT_MUXER, MSGL_V, "ALLOCATED STREAM N. %d, type=%d\n", muxer->avih.dwStreams, type);
return stream;
}
static void fix_parameters(muxer_stream_t *stream)
{
muxer_stream_priv_t *spriv = (muxer_stream_priv_t *) stream->priv;
AVCodecContext *ctx;
ctx = spriv->avstream->codec;
ctx->bit_rate= stream->avg_rate;
if(stream->wf && stream->wf->nAvgBytesPerSec && !ctx->bit_rate)
ctx->bit_rate = stream->wf->nAvgBytesPerSec * 8;
ctx->rc_buffer_size= stream->vbv_size;
ctx->rc_max_rate= stream->max_rate;
if(stream->type == MUXER_TYPE_AUDIO)
{
ctx->codec_id = mp_av_codec_get_id(mp_wav_taglists, stream->wf->wFormatTag);
#if 0 //breaks aac in mov at least
ctx->codec_tag = codec_get_wav_tag(ctx->codec_id);
#endif
mp_msg(MSGT_MUXER, MSGL_INFO, "AUDIO CODEC ID: %x, TAG: %x\n", ctx->codec_id, (uint32_t) ctx->codec_tag);
ctx->sample_rate = stream->wf->nSamplesPerSec;
// mp_msg(MSGT_MUXER, MSGL_INFO, "stream->h.dwSampleSize: %d\n", stream->h.dwSampleSize);
ctx->channels = stream->wf->nChannels;
if(stream->h.dwRate && (stream->h.dwScale * (int64_t)ctx->sample_rate) % stream->h.dwRate == 0)
ctx->frame_size= (stream->h.dwScale * (int64_t)ctx->sample_rate) / stream->h.dwRate;
mp_msg(MSGT_MUXER, MSGL_V, "MUXER_LAVF(audio stream) frame_size: %d, scale: %u, sps: %u, rate: %u, ctx->block_align = stream->wf->nBlockAlign; %d=%d stream->wf->nAvgBytesPerSec:%d\n",
ctx->frame_size, stream->h.dwScale, ctx->sample_rate, stream->h.dwRate,
ctx->block_align, stream->wf->nBlockAlign, stream->wf->nAvgBytesPerSec);
ctx->block_align = stream->h.dwSampleSize;
if(stream->wf+1 && stream->wf->cbSize)
{
ctx->extradata = av_malloc(stream->wf->cbSize);
if(ctx->extradata != NULL)
{
ctx->extradata_size = stream->wf->cbSize;
memcpy(ctx->extradata, stream->wf+1, ctx->extradata_size);
}
else
mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(audio stream) error! Could not allocate %d bytes for extradata.\n",
stream->wf->cbSize);
}
}
else if(stream->type == MUXER_TYPE_VIDEO)
{
ctx->codec_id = mp_av_codec_get_id(mp_bmp_taglists, stream->bih->biCompression);
if(ctx->codec_id <= 0 || force_fourcc)
ctx->codec_tag= stream->bih->biCompression;
mp_msg(MSGT_MUXER, MSGL_INFO, "VIDEO CODEC ID: %d\n", ctx->codec_id);
if (stream->imgfmt)
ctx->pix_fmt = imgfmt2pixfmt(stream->imgfmt);
ctx->width = stream->bih->biWidth;
ctx->height = stream->bih->biHeight;
ctx->bit_rate = 800000;
ctx->time_base.den = stream->h.dwRate;
ctx->time_base.num = stream->h.dwScale;
if(stream->bih+1 && (stream->bih->biSize > sizeof(BITMAPINFOHEADER)))
{
ctx->extradata_size = stream->bih->biSize - sizeof(BITMAPINFOHEADER);
ctx->extradata = av_malloc(ctx->extradata_size);
if(ctx->extradata != NULL)
memcpy(ctx->extradata, stream->bih+1, ctx->extradata_size);
else
{
mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(video stream) error! Could not allocate %d bytes for extradata.\n",
ctx->extradata_size);
ctx->extradata_size = 0;
}
}
}
}
static void write_chunk(muxer_stream_t *stream, size_t len, unsigned int flags, double dts, double pts)
{
muxer_t *muxer = (muxer_t*) stream->muxer;
muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
muxer_stream_priv_t *spriv = (muxer_stream_priv_t *) stream->priv;
AVPacket pkt;
if(len)
{
av_init_packet(&pkt);
pkt.size = len;
pkt.stream_index= spriv->avstream->index;
pkt.data = stream->buffer;
if(flags & AVIIF_KEYFRAME)
pkt.flags |= PKT_FLAG_KEY;
else
pkt.flags = 0;
pkt.dts = (dts / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5);
pkt.pts = (pts / av_q2d(priv->oc->streams[pkt.stream_index]->time_base) + 0.5);
//fprintf(stderr, "%Ld %Ld id:%d tb:%f %f\n", pkt.dts, pkt.pts, pkt.stream_index, av_q2d(priv->oc->streams[pkt.stream_index]->time_base), stream->timer);
if(av_interleaved_write_frame(priv->oc, &pkt) != 0) //av_write_frame(priv->oc, &pkt)
{
mp_msg(MSGT_MUXER, MSGL_ERR, "Error while writing frame.\n");
}
}
return;
}
static void write_header(muxer_t *muxer)
{
muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
mp_tmsg(MSGT_MUXER, MSGL_INFO, "Writing header...\n");
av_write_header(priv->oc);
muxer->cont_write_header = NULL;
}
static void write_trailer(muxer_t *muxer)
{
int i;
muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
mp_tmsg(MSGT_MUXER, MSGL_INFO, "Writing index...\n");
av_write_trailer(priv->oc);
for(i = 0; i < priv->oc->nb_streams; i++)
{
av_freep(&(priv->oc->streams[i]));
}
av_freep(&priv->oc->pb);
av_free(priv->oc);
}
static void list_formats(void) {
AVOutputFormat *fmt;
mp_msg(MSGT_DEMUX, MSGL_INFO, "Available lavf output formats:\n");
for (fmt = first_oformat; fmt; fmt = fmt->next)
mp_msg(MSGT_DEMUX, MSGL_INFO, "%15s : %s\n", fmt->name, fmt->long_name);
}
extern char *out_filename;
int muxer_init_muxer_lavf(muxer_t *muxer)
{
muxer_priv_t *priv;
AVOutputFormat *fmt = NULL;
av_register_all();
if (conf_format && strcmp(conf_format, "help") == 0) {
list_formats();
return 0;
}
mp_msg(MSGT_MUXER, MSGL_WARN, "** MUXER_LAVF *****************************************************************\n");
mp_msg(MSGT_MUXER, MSGL_WARN,
"REMEMBER: MEncoder's libavformat muxing is presently broken and can generate\n"
"INCORRECT files in the presence of B-frames. Moreover, due to bugs MPlayer\n"
"will play these INCORRECT files as if nothing were wrong!\n"
"*******************************************************************************\n");
priv = calloc(1, sizeof(muxer_priv_t));
if(priv == NULL)
return 0;
priv->oc = av_alloc_format_context();
if(!priv->oc)
{
mp_msg(MSGT_MUXER, MSGL_FATAL, "Could not get format context.\n");
goto fail;
}
if(conf_format)
fmt = guess_format(conf_format, NULL, NULL);
if(! fmt)
fmt = guess_format(NULL, out_filename, NULL);
if(! fmt)
{
mp_msg(MSGT_MUXER, MSGL_FATAL, "Cannot get specified format.\n");
goto fail;
}
priv->oc->oformat = fmt;
if(av_set_parameters(priv->oc, NULL) < 0)
{
mp_msg(MSGT_MUXER, MSGL_FATAL, "invalid output format parameters\n");
goto fail;
}
priv->oc->packet_size= mux_packet_size;
priv->oc->mux_rate= mux_rate;
priv->oc->preload= (int)(mux_preload*AV_TIME_BASE);
priv->oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
if (info_name)
av_strlcpy(priv->oc->title , info_name, sizeof(priv->oc->title ));
if (info_artist)
av_strlcpy(priv->oc->author , info_artist, sizeof(priv->oc->author ));
if (info_genre)
av_strlcpy(priv->oc->genre , info_genre, sizeof(priv->oc->genre ));
if (info_copyright)
av_strlcpy(priv->oc->copyright, info_copyright, sizeof(priv->oc->copyright));
if (info_comment)
av_strlcpy(priv->oc->comment , info_comment, sizeof(priv->oc->comment ));
if(mux_avopt){
if(parse_avopts(priv->oc, mux_avopt) < 0){
mp_msg(MSGT_MUXER,MSGL_ERR, "Your options /%s/ look like gibberish to me pal.\n", mux_avopt);
goto fail;
}
}
priv->oc->pb = av_alloc_put_byte(priv->buffer, BIO_BUFFER_SIZE, 1, muxer, NULL, mp_write, mp_seek);
if ((muxer->stream->flags & MP_STREAM_SEEK) != MP_STREAM_SEEK)
priv->oc->pb->is_streamed = 1;
muxer->priv = (void *) priv;
muxer->cont_new_stream = &lavf_new_stream;
muxer->cont_write_chunk = &write_chunk;
muxer->cont_write_header = &write_header;
muxer->cont_write_index = &write_trailer;
muxer->fix_stream_parameters = &fix_parameters;
mp_msg(MSGT_MUXER, MSGL_INFO, "OK, exit.\n");
return 1;
fail:
free(priv);
return 0;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,89 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include "mp_msg.h"
#include "aviheader.h"
#include "ms_hdr.h"
#include "stream/stream.h"
#include "muxer.h"
static muxer_stream_t* rawaudiofile_new_stream(muxer_t *muxer,int type){
muxer_stream_t* s;
if (!muxer) return NULL;
if(type==MUXER_TYPE_AUDIO && muxer->avih.dwStreams>=1){
mp_msg(MSGT_MUXER, MSGL_ERR, "%s %s", mp_gtext("Too many streams!"),
mp_gtext("Rawaudio muxer supports only one audio stream!\n"));
return NULL;
}
s=malloc(sizeof(muxer_stream_t));
memset(s,0,sizeof(muxer_stream_t));
if(!s) return NULL; // no mem!?
muxer->streams[muxer->avih.dwStreams]=s;
s->type=type;
s->id=muxer->avih.dwStreams;
s->timer=0.0;
s->size=0;
s->muxer=muxer;
switch(type){
case MUXER_TYPE_AUDIO:
s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
s->h.fccType=streamtypeAUDIO;
muxer->avih.dwStreams++;
break;
case MUXER_TYPE_VIDEO:
mp_tmsg(MSGT_MUXER,MSGL_WARN,"Ignoring video stream!\n");
s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
s->h.fccType=streamtypeAUDIO;
break;
default:
mp_tmsg(MSGT_MUXER,MSGL_ERR,"Warning, unknown stream type: %d\n",type);
return NULL;
}
return s;
}
static void rawaudiofile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts, double pts){
muxer_t *muxer=s->muxer;
// write out the chunk:
if (s->type==MUXER_TYPE_AUDIO)
stream_write_buffer(muxer->stream, s->buffer, len);
}
static void rawaudiofile_write_header(muxer_t *muxer){
return;
}
static void rawaudiofile_write_index(muxer_t *muxer){
return;
}
int muxer_init_muxer_rawaudio(muxer_t *muxer){
muxer->cont_new_stream = &rawaudiofile_new_stream;
muxer->cont_write_chunk = &rawaudiofile_write_chunk;
muxer->cont_write_header = &rawaudiofile_write_header;
muxer->cont_write_index = &rawaudiofile_write_index;
return 1;
}

View File

@ -1,92 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
#include <unistd.h>
#include "config.h"
//#include "stream/stream.h"
//#include "demuxer.h"
//#include "stheader.h"
#include "aviheader.h"
#include "ms_hdr.h"
#include "stream/stream.h"
#include "muxer.h"
static muxer_stream_t* rawvideofile_new_stream(muxer_t *muxer,int type){
muxer_stream_t* s;
if (!muxer) return NULL;
s=malloc(sizeof(muxer_stream_t));
memset(s,0,sizeof(muxer_stream_t));
if(!s) return NULL; // no mem!?
muxer->streams[muxer->avih.dwStreams]=s;
s->type=type;
s->id=muxer->avih.dwStreams;
s->timer=0.0;
s->size=0;
s->muxer=muxer;
switch(type){
case MUXER_TYPE_VIDEO:
s->ckid=mmioFOURCC(('0'+s->id/10),('0'+(s->id%10)),'d','c');
s->h.fccType=streamtypeVIDEO;
if(!muxer->def_v) muxer->def_v=s;
break;
}
muxer->avih.dwStreams++;
return s;
}
static void write_rawvideo_chunk(stream_t *stream,int len,void* data){
if(len>0){
if(data){
// DATA
stream_write_buffer(stream,data,len);
}
}
}
static void rawvideofile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts, double pts){
muxer_t *muxer=s->muxer;
// write out the chunk:
if (s->type == MUXER_TYPE_VIDEO)
write_rawvideo_chunk(muxer->stream,len,s->buffer); /* unsigned char */
// if((unsigned int)len>s->h.dwSuggestedBufferSize) s->h.dwSuggestedBufferSize=len;
}
static void rawvideofile_write_header(muxer_t *muxer){
return;
}
static void rawvideofile_write_index(muxer_t *muxer){
return;
}
int muxer_init_muxer_rawvideo(muxer_t *muxer){
muxer->cont_new_stream = &rawvideofile_new_stream;
muxer->cont_write_chunk = &rawvideofile_write_chunk;
muxer->cont_write_header = &rawvideofile_write_header;
muxer->cont_write_index = &rawvideofile_write_index;
return 1;
}

1779
mencoder.c

File diff suppressed because it is too large Load Diff

View File

@ -1,169 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/// \file
/// \ingroup ConfigParsers MEntry
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#ifdef MP_DEBUG
#include <assert.h>
#endif
#include "mp_msg.h"
#include "m_option.h"
#include "m_config.h"
#include "parser-mecmd.h"
void
m_entry_list_free(m_entry_t* lst) {
int i,j;
for(i = 0 ; lst[i].name != NULL ; i++){
free(lst[i].name);
for(j = 0 ; lst[i].opts[2*j] != NULL ; j++) {
free(lst[i].opts[2*j]);
free(lst[i].opts[2*j+1]);
}
free(lst[i].opts);
}
free(lst);
}
int
m_entry_set_options(m_config_t *config, m_entry_t* entry) {
int i,r;
for(i = 0 ; entry->opts[2*i] != NULL ; i++){
r = m_config_set_option(config,entry->opts[2*i],entry->opts[2*i+1]);
if(r < 0)
return 0;
}
return 1;
}
m_entry_t*
m_config_parse_me_command_line(m_config_t *config, int argc, char **argv)
{
int i,nf = 0,no = 0;
int tmp;
char *opt;
int no_more_opts = 0;
int opt_exit = 0;
m_entry_t *lst = NULL, *entry = NULL;
#ifdef MP_DEBUG
assert(config != NULL);
assert(argv != NULL);
assert(argc >= 1);
#endif
config->mode = M_COMMAND_LINE;
lst = calloc(1,sizeof(m_entry_t));
for (i = 1; i < argc; i++) {
//next:
opt = argv[i];
/* check for -- (no more options id.) except --help! */
if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) == 0))
{
no_more_opts = 1;
if (i+1 >= argc)
{
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, "'--' indicates no more options, but no filename was given on the command line.\n");
goto err_out;
}
continue;
}
if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */
{
const m_option_t* mp_opt = NULL;
/* remove trailing '-' */
opt++;
mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt);
mp_opt = m_config_get_option(config,opt);
if(!mp_opt) {
tmp = M_OPT_UNKNOWN;
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, "-%s is not an MEncoder option\n", opt);
goto err_out;
}
if(!entry || (mp_opt->flags & M_OPT_GLOBAL)){
tmp = m_config_set_option(config, opt, argv[i + 1]);
if (tmp <= M_OPT_EXIT) {
opt_exit = 1;
tmp = M_OPT_EXIT - tmp;
}
else
if(tmp < 0){
// mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
mp_tmsg(MSGT_CFGPARSER, MSGL_FATAL, "Error parsing option on the command line: -%s\n", opt);
goto err_out;
}
} else {
tmp = m_config_check_option(config, opt, argv[i + 1]);
if (tmp <= M_OPT_EXIT) {
opt_exit = 1;
tmp = M_OPT_EXIT - tmp;
}
if(tmp >= 0) {
entry->opts = realloc(entry->opts,(no+2)*2*sizeof(char*));
entry->opts[2*no] = strdup(opt);
entry->opts[2*no+1] = argv[i + 1] ? strdup(argv[i + 1]) : NULL;
entry->opts[2*no+2] = entry->opts[2*no+3] = NULL;
no++;
} else {
// mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
goto err_out;
}
}
i += tmp;
} else {/* filename */
mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]);
lst = realloc(lst,(nf+2)*sizeof(m_entry_t));
lst[nf].name = strdup(argv[i]);
lst[nf].opts = calloc(2,sizeof(char*));
entry = &lst[nf];
no = 0;
memset(&lst[nf+1],0,sizeof(m_entry_t));
nf++;
}
}
if (opt_exit)
exit(0);
if(nf == 0) {
m_entry_list_free(lst);
mp_tmsg(MSGT_CFGPARSER, MSGL_ERR, "No file given\n");
return NULL;
}
return lst;
err_out:
m_entry_list_free(lst);
return NULL;
}

View File

@ -1,55 +0,0 @@
/*
* This file is part of MPlayer.
*
* MPlayer is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* MPlayer is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPLAYER_PARSER_MECMD_H
#define MPLAYER_PARSER_MECMD_H
#include "m_config.h"
/// \file
/// \ingroup ConfigParsers MEntry
/// \brief A simple parser with per-entry settings.
/// \defgroup MEntry MEncoder's playlist
///@{
/// Playlist entry
typedef struct m_entry_st {
/// Filename, url or whatever.
char* name;
/// NULL terminated list of name,val pairs.
char** opts;
} m_entry_t;
/// Free a list returned by \ref m_config_parse_me_command_line.
void
m_entry_list_free(m_entry_t* lst);
/// Helper to set all config options from an entry.
int
m_entry_set_options(m_config_t *config, m_entry_t* entry);
/// Setup the \ref Config from command line arguments and build a playlist.
/** \ingroup ConfigParsers
*/
m_entry_t*
m_config_parse_me_command_line(m_config_t *config, int argc, char **argv);
///@}
#endif /* MPLAYER_PARSER_MECMD_H */

1648
xvid_vbr.c

File diff suppressed because it is too large Load Diff

View File

@ -1,231 +0,0 @@
/******************************************************************************
*
* XviD VBR Library
*
* Copyright (C) 2002 Edouard Gomez <ed.gomez@wanadoo.fr>
*
* The curve treatment algorithm is based on work done by Foxer <email?> and
* Dirk Knop <dknop@gwdg.de> for the XviD vfw dynamic library.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*****************************************************************************/
#ifndef MPLAYER_XVID_VBR_H
#define MPLAYER_XVID_VBR_H
#define VBR_VERSION 0
/******************************************************************************
* Function types used in the vbr controler
*****************************************************************************/
typedef int (vbr_init_function)(void *state);
typedef vbr_init_function *vbr_init_function_ptr;
typedef int (vbr_get_quant_function)(void *state);
typedef vbr_get_quant_function *vbr_get_quant_function_ptr;
typedef int (vbr_get_intra_function)(void *state);
typedef vbr_get_intra_function *vbr_get_intra_function_ptr;
typedef int (vbr_update_function)(void *state,
int quant,
int intra,
int header_bytes,
int total_bytes,
int kblocks,
int mblocks,
int ublocks);
typedef vbr_update_function *vbr_update_function_ptr;
typedef int (vbr_finish_function)(void *state);
typedef vbr_finish_function *vbr_finish_function_ptr;
/******************************************************************************
* The VBR CONTROLER structure - the spin of the library
*****************************************************************************/
typedef struct vbr_control_t
{
/* All modes - specifies what VBR algorithm has to be used */
int mode;
/* All modes - specifies what fps the movie uses */
float fps;
/* All modes */
int debug;
/*
* For VBR_MODE_2PASS_1/2 - specifies from/to what file the vbr
* controller has to write/read stats
*/
char *filename;
/* For VBR_MODE_2PASS_2 - Target size */
int desired_bitrate;
/* For VBR_MODE_2PASS_2 - Credits parameters */
int credits_mode;
int credits_start;
int credits_start_begin;
int credits_start_end;
int credits_end;
int credits_end_begin;
int credits_end_end;
int credits_quant_ratio;
int credits_fixed_quant;
int credits_quant_i;
int credits_quant_p;
int credits_start_size;
int credits_end_size;
/* For VBR_MODE_2PASS_2 - keyframe parameters */
int keyframe_boost;
int kftreshold;
int kfreduction;
int min_key_interval;
int max_key_interval;
/* For VBR_MODE_2PASS_2 - Normal curve */
int curve_compression_high;
int curve_compression_low;
/* For VBR_MODE_2PASS_2 - Alternate curve parameters */
int use_alt_curve;
int alt_curve_type;
int alt_curve_low_dist;
int alt_curve_high_dist;
int alt_curve_min_rel_qual;
int alt_curve_use_auto;
int alt_curve_auto_str;
int alt_curve_use_auto_bonus_bias;
int alt_curve_bonus_bias;
int bitrate_payback_method;
int bitrate_payback_delay;
int max_iquant;
int min_iquant;
int max_pquant;
int min_pquant;
int twopass_max_bitrate;
int twopass_max_overflow_improvement;
int twopass_max_overflow_degradation;
/*
* For VBR_MODE_FIXED_QUANT - the quantizer that has to be used for all
* frames
*/
int fixed_quant;
/* ----------- Internal data - Do not modify ----------- */
void *debug_file;
void *pass1_file;
long long desired_size;
int cur_frame;
int nb_frames;
int nb_keyframes;
int *keyframe_locations;
int last_keyframe;
double credits_start_curve;
double credits_end_curve;
double movie_curve;
double average_frame;
double alt_curve_low;
double alt_curve_low_diff;
double alt_curve_high;
double alt_curve_high_diff;
double alt_curve_mid_qual;
double alt_curve_qual_dev;
double curve_bias_bonus;
double curve_comp_scale;
double curve_comp_error;
int pass1_quant;
int pass1_intra;
int pass1_bytes;
int bytes1;
int bytes2;
int desired_bytes2;
int max_framesize;
int last_quant;
int quant_count[32];
double quant_error[32];
int overflow;
int KFoverflow;
int KFoverflow_partial;
int KF_idx;
int debug_quant_count[32];
/* ----------- Internal data - do not modify ----------- */
vbr_init_function_ptr init;
vbr_get_quant_function_ptr getquant;
vbr_get_intra_function_ptr getintra;
vbr_update_function_ptr update;
vbr_finish_function_ptr finish;
}vbr_control_t;
/******************************************************************************
* Constants
*****************************************************************************/
/* Constants for the mode member */
#define VBR_MODE_1PASS 0x01
#define VBR_MODE_2PASS_1 0x02
#define VBR_MODE_2PASS_2 0x04
#define VBR_MODE_FIXED_QUANT 0x08
/* Constants for the credits mode */
#define VBR_CREDITS_MODE_RATE 0x01
#define VBR_CREDITS_MODE_QUANT 0x02
#define VBR_CREDITS_MODE_SIZE 0x04
/* Alternate curve treatment types */
#define VBR_ALT_CURVE_SOFT 0x01
#define VBR_ALT_CURVE_LINEAR 0x02
#define VBR_ALT_CURVE_AGGRESIVE 0x04
/* Payback modes */
#define VBR_PAYBACK_BIAS 0x01
#define VBR_PAYBACK_PROPORTIONAL 0x02
/******************************************************************************
* VBR API
*****************************************************************************/
extern int vbrSetDefaults(vbr_control_t *state);
extern int vbrInit(vbr_control_t *state);
extern int vbrGetQuant(vbr_control_t *state);
extern int vbrGetIntra(vbr_control_t *state);
extern int vbrUpdate(vbr_control_t *state,
int quant,
int intra,
int header_bytes,
int total_bytes,
int kblocks,
int mblocks,
int ublocks);
extern int vbrFinish(vbr_control_t *state);
#endif /* MPLAYER_XVID_VBR_H */