summaryrefslogtreecommitdiffstats
path: root/mencoder.c
diff options
context:
space:
mode:
Diffstat (limited to 'mencoder.c')
-rw-r--r--mencoder.c1779
1 files changed, 0 insertions, 1779 deletions
diff --git a/mencoder.c b/mencoder.c
deleted file mode 100644
index 34053e3fce..0000000000
--- a/mencoder.c
+++ /dev/null
@@ -1,1779 +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.
- */
-
-#define VCODEC_COPY 0
-#define VCODEC_FRAMENO 1
-// real codecs:
-#define VCODEC_LIBAVCODEC 4
-#define VCODEC_VFW 7
-#define VCODEC_LIBDV 8
-#define VCODEC_XVID 9
-#define VCODEC_QTVIDEO 10
-#define VCODEC_NUV 11
-#define VCODEC_RAW 12
-#define VCODEC_X264 13
-
-#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
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include "config.h"
-
-#ifdef __MINGW32__
-#define SIGHUP 1
-#define SIGQUIT 3
-#define SIGPIPE 13
-#endif
-#if defined(__MINGW32__) || defined(__CYGWIN__)
-#include <windows.h>
-#endif
-
-#include <sys/time.h>
-
-#include "mp_msg.h"
-#include "av_log.h"
-
-#include "codec-cfg.h"
-#include "m_option.h"
-#include "m_config.h"
-#include "parser-mecmd.h"
-#include "parser-cfg.h"
-#include "mp_fifo.h"
-#include "path.h"
-
-#include "stream/stream.h"
-#include "libmpdemux/aviprint.h"
-#include "libmpdemux/demuxer.h"
-#include "libmpdemux/stheader.h"
-#include "libmpdemux/mp3_hdr.h"
-#include "libmpdemux/muxer.h"
-
-#include "input/input.h"
-#include "libvo/video_out.h"
-
-#include "libaf/af_format.h"
-
-#include "libmpcodecs/mp_image.h"
-#include "libmpcodecs/dec_audio.h"
-#include "libmpcodecs/dec_video.h"
-#include "libmpcodecs/vf.h"
-#include "libmpcodecs/vd.h"
-
-// for MPEGLAYER3WAVEFORMAT:
-#include "libmpdemux/ms_hdr.h"
-
-#include <inttypes.h>
-
-#include "libvo/fastmemcpy.h"
-
-#include "osdep/timer.h"
-
-#ifdef CONFIG_DVDREAD
-#include "stream/stream_dvd.h"
-#endif
-
-#include "stream/stream_dvdnav.h"
-#include "libavcodec/avcodec.h"
-
-#include "libmpcodecs/ae.h"
-#include "options.h"
-#include "defaultopts.h"
-
-MPOpts opts;
-struct osd_state *osd;
-
-const int under_mencoder = 1;
-int vo_doublebuffering=0;
-int vo_directrendering=0;
-int forced_subs_only=0;
-
-//--------------------------
-
-// cache2:
-int stream_cache_size=-1;
-#ifdef CONFIG_STREAM_CACHE
-float stream_cache_min_percent=20.0;
-float stream_cache_seek_min_percent=50.0;
-#endif
-
-int vobsub_id=-1;
-static char* spudec_ifo=NULL;
-
-static char** audio_codec_list=NULL; // override audio codec
-static char** video_codec_list=NULL; // override video codec
-static char** audio_fm_list=NULL; // override audio codec family
-static char** video_fm_list=NULL; // override video codec family
-extern char *demuxer_name; // override demuxer
-extern char *audio_demuxer_name; // override audio demuxer
-extern char *sub_demuxer_name; // override sub demuxer
-
-static int out_audio_codec=-1;
-static int out_video_codec=-1;
-
-int out_file_format=MUXER_TYPE_AVI; // default to AVI
-int quiet=0;
-double video_time_usage=0;
-double vout_time_usage=0;
-double max_video_time_usage=0;
-double max_vout_time_usage=0;
-double cur_video_time_usage=0;
-double cur_vout_time_usage=0;
-int benchmark=0;
-
-#include "osdep/priority.h"
-
-// A-V sync:
-int delay_corrected=1;
-static float default_max_pts_correction=-1;//0.01f;
-static float max_pts_correction=0;//default_max_pts_correction;
-static float c_total=0;
-
-static float audio_preload=0.5;
-static float audio_delay_fix=0.0;
-static float audio_delay=0.0;
-static int ignore_start=0;
-static int audio_density=2;
-
-double force_fps=0;
-static double force_ofps=0; // set to 24 for inverse telecine
-static int skip_limit=-1;
-
-static int force_srate=0;
-static int audio_output_format=0;
-
-char *vobsub_out=NULL;
-unsigned int vobsub_out_index=0;
-char *vobsub_out_id=NULL;
-
-char* out_filename=NULL;
-
-char *force_fourcc=NULL;
-int force_audiofmttag=-1;
-
-char* passtmpfile="divx2pass.log";
-
-static int play_n_frames=-1;
-static int play_n_frames_mf=-1;
-
-#include "libvo/font_load.h"
-#include "libvo/sub.h"
-
-// sub:
-char *font_name=NULL;
-char *sub_font_name=NULL;
-extern int font_fontconfig;
-float font_factor=0.75;
-char **sub_name=NULL;
-float sub_delay=0;
-float sub_fps=0;
-int sub_auto = 0;
-int subcc_enabled=0;
-int suboverlap_enabled = 1;
-
-int auto_expand=1;
-int encode_duplicates=1;
-
-// infos are empty by default
-char *info_name=NULL;
-char *info_artist=NULL;
-char *info_genre=NULL;
-char *info_subject=NULL;
-char *info_copyright=NULL;
-char *info_sourceform=NULL;
-char *info_comment=NULL;
-
-// Needed by libmpcodecs vf_vo.c
-int vo_config(struct vo *vo, uint32_t width, uint32_t height,
- uint32_t d_width, uint32_t d_height, uint32_t flags,
- char *title, uint32_t format) { abort(); }
-int vo_control(struct vo *vo, uint32_t request, void *data) { abort(); }
-void vo_seek_reset(struct vo *vo) { abort(); }
-int vo_draw_image(struct vo *vo, struct mp_image *mpi, double pts) { abort(); }
-int vo_draw_frame(struct vo *vo, uint8_t *src[]) { abort(); }
-int vo_draw_slice(struct vo *vo, uint8_t *src[], int stride[], int w, int h, int x, int y) { abort(); }
-void vo_draw_osd(struct vo *vo, struct osd_state *osd) { abort(); }
-void vo_flip_page(struct vo *vo, uint32_t pts_us, int duration) { abort(); }
-void vo_check_events(struct vo *vo) { abort(); }
-
-// Needed by getch2
-struct mp_fifo;
-void mplayer_put_key(struct mp_fifo *fifo, int code)
-{
-}
-
-#include "ass_mp.h"
-char *current_module;
-#include "mpcommon.h"
-
-// Needed by mpcommon.c
-void set_osd_subtitle(struct MPContext *mpctx, subtitle *subs) {
- vo_sub = subs;
- vo_osd_changed(OSDTYPE_SUBTITLE);
-}
-
-//-------------------------- config stuff:
-
-m_config_t* mconfig;
-
-static int cfg_inc_verbose(m_option_t *conf){ ++verbose; return 0;}
-
-static int cfg_include(m_option_t *conf, char *filename){
- return m_config_parse_config_file(mconfig, filename);
-}
-
-static double seek_to_sec;
-static off_t seek_to_byte=0;
-
-static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 };
-
-static char * frameno_filename=NULL;
-
-typedef struct {
- unsigned char* start;
- int in_size;
- float frame_time;
- int already_read;
-} s_frame_data;
-
-#include "edl.h"
-static edl_record_ptr edl_records = NULL; ///< EDL entries memory area
-static edl_record_ptr next_edl_record = NULL; ///< only for traversing edl_records
-static short edl_muted; ///< Stores whether EDL is currently in muted mode.
-static short edl_seeking; ///< When non-zero, stream is seekable.
-static short edl_seek_type; ///< When non-zero, frames are discarded instead of seeking.
-
-#include "cfg-mencoder.h"
-
-#include "spudec.h"
-#include "vobsub.h"
-
-#include "libao2/audio_out.h"
-/* FIXME */
-static void mencoder_exit(int level, const char *how)
-{
- if (how)
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "\nExiting... (%s)\n", how);
- else
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "\nExiting...\n");
-
- exit(level);
-}
-
-static void parse_cfgfiles( m_config_t* conf )
-{
- char *conffile;
- if (!disable_system_conf &&
- m_config_parse_config_file(conf, MPLAYER_CONFDIR "/mencoder.conf") < 0)
- mencoder_exit(1,_("config file error"));
-
- if (!disable_user_conf) {
- if ((conffile = get_path("mencoder.conf")) == NULL) {
- mp_tmsg(MSGT_CPLAYER,MSGL_ERR,"get_path(\"config\") problem\n");
- } else {
- if (m_config_parse_config_file(conf, conffile) < 0)
- mencoder_exit(1,_("config file error"));
- free(conffile);
- }
- }
-}
-
-
-//---------------------------------------------------------------------------
-
-static int dec_audio(sh_audio_t *sh_audio,unsigned char* buffer,int total){
- int size=0;
- int at_eof=0;
- while(size<total && !at_eof){
- int len=total-size;
- if (decode_audio(sh_audio, len) < 0) at_eof=1;
- if(len>sh_audio->a_out_buffer_len) len=sh_audio->a_out_buffer_len;
- fast_memcpy(buffer+size,sh_audio->a_out_buffer,len);
- sh_audio->a_out_buffer_len-=len; size+=len;
- if(sh_audio->a_out_buffer_len>0)
- fast_memcpy(sh_audio->a_out_buffer,&sh_audio->a_out_buffer[len],sh_audio->a_out_buffer_len);
- }
- return size;
-}
-
-//---------------------------------------------------------------------------
-
-static volatile int at_eof=0;
-static volatile int interrupted=0;
-
-static void exit_sighandler(int x){
- at_eof=1;
- interrupted=2; /* 1 means error */
-}
-
-static muxer_t* muxer=NULL;
-
-static void add_subtitles(char *filename, float fps, int silent)
-{
- sub_data *subd;
-#ifdef CONFIG_ASS
- ASS_Track *asst = 0;
-#endif
-
- if (!filename) return;
-
- subd = sub_read_file(filename, fps);
-#ifdef CONFIG_ASS
- if (opts.ass_enabled)
-#ifdef CONFIG_ICONV
- asst = ass_read_file(ass_library, filename, sub_cp);
-#else
- asst = ass_read_file(ass_library, filename, 0);
-#endif
- if (opts.ass_enabled && subd && !asst)
- asst = ass_read_subdata(ass_library, subd, fps);
-
- if (!asst && !subd && !silent)
-#else
- if (!subd && !silent)
-#endif
- mp_tmsg(MSGT_CPLAYER, MSGL_ERR, "Cannot load subtitles: %s\n",
- filename_recode(filename));
-
-#ifdef CONFIG_ASS
- if (!asst && !subd) return;
- ass_track = asst;
-#else
- if (!subd) return;
-#endif
- mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_FILE_SUB_FILENAME=%s\n",
- filename_recode(filename));
- subdata = subd;
-}
-
-/* This function returns the absolute time for which MEncoder will switch files
- * or move in the file so audio can be cut correctly. -1 if there is no limit. */
-static float stop_time(demuxer_t* demuxer, muxer_stream_t* mux_v)
-{
- float timeleft = -1;
- if (play_n_frames >= 0) timeleft = mux_v->timer + play_n_frames * (double)(mux_v->h.dwScale) / mux_v->h.dwRate;
- if (end_at.type == END_AT_TIME && (timeleft > end_at.pos || timeleft == -1)) timeleft = end_at.pos;
- if (next_edl_record && demuxer && demuxer->video) { // everything is OK to be checked
- float tmp = mux_v->timer + next_edl_record->start_sec - demuxer->video->pts;
- if (timeleft == -1 || timeleft > tmp) {
- // There's less time in EDL than what we already know
- if (next_edl_record->action == EDL_SKIP && edl_seeking) {
- timeleft = tmp;
- } else if (next_edl_record->action == EDL_MUTE) {
- //timeleft = next_edl_record->start_sec - demuxer->video->pts;
- // For the moment (and probably forever) EDL mute doesn't work in MEncoder
- }
- }
- }
- return timeleft;
-}
-
-/// Returns a_pts
-static float calc_a_pts(demux_stream_t *d_audio)
-{
- sh_audio_t * sh_audio = d_audio ? d_audio->sh : NULL;
- float a_pts = 0.;
- if (sh_audio)
- a_pts = d_audio->pts + (ds_tell_pts(d_audio) - sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps;
- return a_pts;
-}
-
-/** \brief Seeks audio forward to pts by dumping audio packets
- * \return The current audio pts. */
-static float forward_audio(float pts, demux_stream_t *d_audio, muxer_stream_t* mux_a)
-{
- sh_audio_t * sh_audio = d_audio ? d_audio->sh : NULL;
- int samplesize, avg;
- float a_pts = calc_a_pts(d_audio);
-
- if (!sh_audio) return a_pts;
-
- if (sh_audio->audio.dwScale) samplesize = sh_audio->audio.dwSampleSize;
- else samplesize = (sh_audio->wf ? sh_audio->wf->nBlockAlign : 1);
- avg = (sh_audio->wf ? sh_audio->wf->nAvgBytesPerSec : sh_audio->i_bps);
-
- // after a demux_seek, a_pts will be zero until you read some audio.
- // carefully checking if a_pts is truely correct by reading tiniest amount of data possible.
- if (pts > a_pts && a_pts == 0.0 && samplesize) {
- if (demux_read_data(sh_audio->ds,mux_a->buffer,samplesize) <= 0) return a_pts; // EOF
- a_pts = calc_a_pts(d_audio);
- }
-
- while (pts > a_pts) {
- int len;
- if (samplesize) {
- len = avg * (pts - a_pts > 0.5 ? 0.5 : pts - a_pts);
- len/= samplesize; if(len<1) len=1;
- len*= samplesize;
- len = demux_read_data(sh_audio->ds,mux_a->buffer,len);
- } else {
- unsigned char * crap;
- len = ds_get_packet(sh_audio->ds, &crap);
- }
- if (len <= 0) break; // EOF of audio.
- a_pts = calc_a_pts(d_audio);
- }
- return a_pts;
-}
-
-/** \brief Seeks slowly by dumping frames.
- * \return 1 for success, 2 for EOF. */
-static int slowseek(float end_pts, demux_stream_t *d_video,
- demux_stream_t *d_audio, muxer_stream_t *mux_a,
- s_frame_data *frame_data, int framecopy, int print_info)
-{
- sh_video_t * sh_video = d_video->sh;
- vf_instance_t * vfilter = sh_video ? sh_video->vfilter : NULL;
- int done = 0;
-
- while (!interrupted) {
- float a_pts = 0.;
-
- if (!frame_data->already_read) { // when called after fixdelay, a frame is already read
- frame_data->in_size = video_read_frame(sh_video, &frame_data->frame_time, &frame_data->start, force_fps);
- if(frame_data->in_size<0) return 2;
- sh_video->timer += frame_data->frame_time;
- }
- frame_data->already_read = 0;
-
- a_pts = forward_audio(sh_video->pts - frame_data->frame_time + audio_delay, d_audio, mux_a);
-
- if (done) {
- // wait for keyframe in case of -ovc copy
- if (!framecopy || (sh_video->ds->flags & 1)) {
- frame_data->already_read = 1;
- return 1;
- }
- }
- if (sh_video->pts >= end_pts) done = 1;
-
- if (vfilter) {
- sh_video->vfilter->control(sh_video->vfilter, VFCTRL_SET_OSD_OBJ,
- osd);
- int softskip = (vfilter->control(vfilter, VFCTRL_SKIP_NEXT_FRAME, 0) == CONTROL_TRUE);
- void *decoded_frame = decode_video(sh_video, frame_data->start, frame_data->in_size, !softskip, MP_NOPTS_VALUE);
- if (decoded_frame)
- if (filter_video(sh_video, decoded_frame, MP_NOPTS_VALUE)) {
- struct vf_instance *vf = sh_video->vfilter;
- vf->control(vf, VFCTRL_DRAW_EOSD, NULL);
- vf->control(vf, VFCTRL_DRAW_OSD, osd);
- }
- }
-
- if (print_info) mp_tmsg(MSGT_MENCODER, MSGL_STATUS,
- "EDL SKIP: Start: %.2f End: %.2f Current: V: %.2f A: %.2f \r",
- next_edl_record->start_sec, next_edl_record->stop_sec,
- sh_video->pts, a_pts);
- }
- if (interrupted) return 2;
- return 1;
-}
-
-/// Deletes audio or video as told by -delay to sync
-static void fixdelay(demux_stream_t *d_video, demux_stream_t *d_audio,
- muxer_stream_t *mux_a, s_frame_data *frame_data,
- int framecopy)
-{
- // TODO: Find a way to encode silence instead of deleting video
- sh_video_t * sh_video = d_video->sh;
- float a_pts;
-
- // demux_seek has a weirdness that sh_video->pts is meaningless,
- // until a single frame is read... Same for audio actually too.
- // Reading one frame, and keeping it.
- frame_data->in_size = video_read_frame(sh_video, &frame_data->frame_time, &frame_data->start, force_fps);
- if(frame_data->in_size<0) return;
- sh_video->timer += frame_data->frame_time;
- frame_data->already_read = 1;
-
- a_pts = forward_audio(sh_video->pts - frame_data->frame_time + audio_delay, d_audio, mux_a);
-
- if (audio_delay > 0) return;
- else if (sh_video->pts - frame_data->frame_time + audio_delay >= a_pts) return;
-
- slowseek(a_pts - audio_delay, d_video, d_audio, mux_a, frame_data, framecopy, 0);
-}
-
-/** \brief Seeks for EDL
- * \return 1 for success, 0 for failure, 2 for EOF. */
-static int edl_seek(edl_record_ptr next_edl_record, demuxer_t *demuxer,
- demux_stream_t *d_audio, muxer_stream_t *mux_a,
- s_frame_data *frame_data, int framecopy)
-{
- sh_video_t * sh_video = demuxer->video ? demuxer->video->sh : NULL;
-
- if (!sh_video) return 0;
- if (sh_video->pts >= next_edl_record->stop_sec) return 1; // nothing to do...
-
- if (!edl_seek_type) {
- if(demux_seek(demuxer, next_edl_record->stop_sec - sh_video->pts, audio_delay, 0)){
- sh_video->pts = demuxer->video->pts;
- //if (vo_vobsub) vobsub_seek(vo_vobsub,sh_video->pts);
- resync_video_stream(sh_video);
- //if(vo_spudec) spudec_reset(vo_spudec);
- if (audio_delay != 0.0) fixdelay(demuxer->video, d_audio, mux_a, frame_data, framecopy);
- return 1;
- }
- // non-seekable stream.
- return 0;
- }
-
- // slow seek, read every frame.
-
- return slowseek(next_edl_record->stop_sec, demuxer->video, d_audio, mux_a, frame_data, framecopy, 1);
-}
-
-
-int main(int argc,char* argv[]){
-
-stream_t* stream=NULL;
-stream_t* ostream=NULL;
-demuxer_t* demuxer=NULL;
-stream_t* stream2=NULL;
-demuxer_t* demuxer2=NULL;
-demux_stream_t *d_audio=NULL;
-demux_stream_t *d_video=NULL;
-demux_stream_t *d_dvdsub=NULL;
-sh_audio_t *sh_audio=NULL;
-sh_video_t *sh_video=NULL;
-int file_format=DEMUXER_TYPE_UNKNOWN;
-int i=DEMUXER_TYPE_UNKNOWN;
-void *vobsub_writer=NULL;
-s_frame_data frame_data = { .start = NULL, .in_size = 0, .frame_time = 0., .already_read = 0 };
-
-uint32_t ptimer_start;
-uint32_t audiorate=0;
-uint32_t videorate=0;
-uint32_t audiosamples=1;
-uint32_t videosamples=1;
-uint32_t skippedframes=0;
-uint32_t duplicatedframes=0;
-uint32_t badframes=0;
-
-muxer_stream_t* mux_a=NULL;
-muxer_stream_t* mux_v=NULL;
-off_t muxer_f_size=0;
-
-double v_pts_corr=0;
-double v_timer_corr=0;
-
-m_entry_t* filelist = NULL;
-char* filename=NULL;
-
-int decoded_frameno=0;
-int next_frameno=-1;
-int curfile=0;
-int new_srate=0;
-
-unsigned int timer_start=0;
-ao_data_t ao_data = {0,0,0,0,OUTBURST,-1,0};
-
-audio_encoding_params_t aparams;
-audio_encoder_t *aencoder = NULL;
-
- mp_msg_init();
- set_av_log_callback();
-
- // Create the config context and register the options
- set_default_mencoder_options(&opts);
- mconfig = m_config_new(&opts, cfg_include);
- m_config_register_options(mconfig,mencoder_opts);
- m_config_register_options(mconfig, common_opts);
-
- // Preparse the command line
- m_config_preparse_command_line(mconfig,argc,argv);
-
- print_version("MEncoder");
-
-#if (defined(__MINGW32__) || defined(__CYGWIN__)) && defined(CONFIG_WIN32DLL)
- set_path_env();
-#endif
-
- InitTimer();
-
-// check codec.conf
-if(!codecs_file || !parse_codec_cfg(codecs_file)){
- if(!parse_codec_cfg(get_path("codecs.conf"))){
- if(!parse_codec_cfg(MPLAYER_CONFDIR "/codecs.conf")){
- if(!parse_codec_cfg(NULL)){
- mencoder_exit(1,NULL);
- }
- mp_tmsg(MSGT_MENCODER,MSGL_V,"Using built-in default codecs.conf.\n");
- }
- }
-}
-
- parse_cfgfiles(mconfig);
- filelist = m_config_parse_me_command_line(mconfig, argc, argv);
- if(!filelist) mencoder_exit(1, _("error parsing command line"));
-
-{
- char *extension;
-
- if (!out_filename) mencoder_exit(1,_("No output file specified, please see the -o option."));
- extension=strrchr(out_filename,'.');
- if (extension != NULL && strlen(extension) > 3 && strlen(extension) < 6)
- {
- extension++;
-
- switch (out_file_format)
- {
- case MUXER_TYPE_AVI:
- if (strcasecmp(extension,"avi"))
- mp_tmsg(MSGT_MENCODER, MSGL_WARN, "\nWARNING: OUTPUT FILE FORMAT IS _AVI_. See -of help.\n");
- break;
-
- case MUXER_TYPE_MPEG:
- if (strcasecmp(extension,"mpg") &&
- strcasecmp(extension,"mpeg") &&
- strcasecmp(extension,"vob"))
- mp_tmsg(MSGT_MENCODER, MSGL_WARN, "\nWARNING: OUTPUT FILE FORMAT IS _MPEG_. See -of help.\n");
- break;
- }
- }
-}
- /* Display what configure line was used */
- mp_msg(MSGT_MENCODER, MSGL_V, "Configuration: " CONFIGURATION "\n");
-
-#define FormatNotRecognized _("============ Sorry, this file format is not recognized/supported =============\n"\
-"=== If this file is an AVI, ASF or MPEG stream, please contact the author! ===\n")
-
-
-if (frameno_filename) {
- stream2=open_stream(frameno_filename, NULL, NULL);
- if(stream2){
- demuxer2=demux_open(&opts, stream2,DEMUXER_TYPE_AVI,-1,-1,-2,NULL);
- if(demuxer2) mp_tmsg(MSGT_MENCODER, MSGL_INFO, "Using pass3 control file: %s\n", frameno_filename);
- else mp_tmsg(MSGT_DEMUXER,MSGL_ERR, FormatNotRecognized);
- }
-}
-
-#ifdef CONFIG_PRIORITY
- set_priority();
-#endif
-
- if (codec_path)
- set_codec_path(codec_path);
-
-// check font
-#ifdef CONFIG_FREETYPE
- init_freetype();
-#endif
-#ifdef CONFIG_FONTCONFIG
- if(font_fontconfig <= 0)
- {
-#endif
-#ifdef CONFIG_BITMAP_FONT
- if(font_name){
- vo_font=read_font_desc(font_name,font_factor,verbose>1);
- if(!vo_font) mp_tmsg(MSGT_CPLAYER,MSGL_ERR,"Cannot load bitmap font: %s\n",font_name);
- } else {
- // try default:
- vo_font=read_font_desc(get_path("font/font.desc"),font_factor,verbose>1);
- if(!vo_font)
- vo_font=read_font_desc(MPLAYER_DATADIR "/font/font.desc",font_factor,verbose>1);
- }
-#endif
-#ifdef CONFIG_FONTCONFIG
- }
-#endif
-
- osd = osd_create();
-
- /* HACK, for some weird reason, push() has to be called twice,
- otherwise options are not saved correctly */
- m_config_push(mconfig);
-play_next_file:
- m_config_push(mconfig);
- m_entry_set_options(mconfig,&filelist[curfile]);
- filename = filelist[curfile].name;
-
-#ifdef CONFIG_ASS
- ass_library = ass_init();
-#endif
-
- if(!filename){
- mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, "\nFilename missing.\n\n");
- mencoder_exit(1,NULL);
- }
- stream=open_stream(filename,0,&file_format);
-
- if(!stream){
- mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, "Cannot open file/device.\n");
- mencoder_exit(1,NULL);
- }
-
- mp_tmsg(MSGT_CPLAYER, MSGL_INFO, "success: format: %d data: 0x%X - 0x%x\n", file_format, (int)(stream->start_pos), (int)(stream->end_pos));
-
-#ifdef CONFIG_DVDREAD
-if(stream->type==STREAMTYPE_DVD){
- if(opts.audio_lang && opts.audio_id==-1) opts.audio_id=dvd_aid_from_lang(stream,opts.audio_lang);
- if(opts.sub_lang && opts.sub_id==-1) opts.sub_id=dvd_sid_from_lang(stream,opts.sub_lang);
-}
-#endif
-
-#ifdef CONFIG_DVDNAV
-if(stream->type==STREAMTYPE_DVDNAV){
- if(opts.audio_lang && opts.audio_id==-1) opts.audio_id=mp_dvdnav_aid_from_lang(stream,opts.audio_lang);
- if(opts.sub_lang && opts.sub_id==-1) opts.sub_id=mp_dvdnav_sid_from_lang(stream,opts.sub_lang);
-}
-#endif
-
- stream->start_pos+=seek_to_byte;
-
- if(stream_cache_size>0) stream_enable_cache(stream,stream_cache_size*1024,0,0);
-
- if(demuxer2) opts.audio_id=-2; /* do NOT read audio packets... */
-
- demuxer=demux_open(&opts, stream,file_format,opts.audio_id,opts.video_id,opts.sub_id,filename);
- if(!demuxer){
- mp_tmsg(MSGT_DEMUXER, MSGL_FATAL, FormatNotRecognized);
- mp_tmsg(MSGT_DEMUXER, MSGL_FATAL, "Cannot open demuxer.\n");
- mencoder_exit(1,NULL);
- }
-
- if (ts_prog) {
- demux_program_t prog = { .progid = ts_prog };
- if (demux_control(demuxer, DEMUXER_CTRL_IDENTIFY_PROGRAM, &prog) != DEMUXER_CTRL_NOTIMPL) {
- opts.audio_id = prog.aid; // switching is handled by select_audio below
- opts.video_id = prog.vid;
- demuxer_switch_video(demuxer, opts.video_id);
- }
- }
- select_audio(demuxer, opts.audio_id, opts.audio_lang);
-
- if (opts.sub_id < -1 && opts.sub_lang)
- opts.sub_id = demuxer_sub_track_by_lang(demuxer, opts.sub_lang);
-
- if (opts.sub_id < -1)
- opts.sub_id = demuxer_default_sub_track(demuxer);
-
- for (i = 0; i < MAX_S_STREAMS; i++) {
- sh_sub_t *sh = demuxer->s_streams[i];
- if (sh && sh->sid == opts.sub_id) {
- demuxer->sub->id = i;
- demuxer->sub->sh = sh;
- break;
- }
- }
-
- if(opts.chapterrange[0]>1) {
- double pts;
- if (demuxer_seek_chapter(demuxer, opts.chapterrange[0]-1, &pts, NULL) >= 0 && pts > -1.0)
- seek_to_sec = pts;
- }
-
-d_audio=demuxer2 ? demuxer2->audio : demuxer->audio;
-d_video=demuxer->video;
-d_dvdsub=demuxer->sub;
-sh_audio=d_audio->sh;
-sh_video=d_video->sh;
-
- if(!sh_video)
- {
- mp_tmsg(MSGT_CPLAYER,MSGL_FATAL,"Video stream is mandatory!\n");
- mencoder_exit(1,NULL);
- }
-
- if(!video_read_properties(sh_video)){
- mp_tmsg(MSGT_CPLAYER, MSGL_FATAL, "Video: Cannot read properties.\n");
- mencoder_exit(1,NULL);
- }
-
- mp_tmsg(MSGT_MENCODER,MSGL_INFO, "[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.3f ftime:=%6.4f\n",
- demuxer->file_format,sh_video->format, sh_video->disp_w,sh_video->disp_h,
- sh_video->fps,sh_video->frametime
- );
-
- if(force_fps){
- sh_video->fps=force_fps;
- sh_video->frametime=1.0f/sh_video->fps;
- mp_tmsg(MSGT_MENCODER,MSGL_INFO,"Input fps will be interpreted as %5.3f instead.\n", sh_video->fps);
- }
-
- if(sh_audio && out_audio_codec<0){
- if(opts.audio_id==-2)
- mp_tmsg(MSGT_MENCODER,MSGL_ERR,"This demuxer doesn't support -nosound yet.\n");
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"\nNo audio encoder (-oac) selected. Select one (see -oac help) or use -nosound.\n");
- mencoder_exit(1,NULL);
- }
- if(sh_video && out_video_codec<0){
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"\nNo video encoder (-ovc) selected. Select one (see -ovc help).\n");
- mencoder_exit(1,NULL);
- }
-
-if(sh_audio && (out_audio_codec || seek_to_sec || !sh_audio->wf || opts.playback_speed != 1.0)){
- // Go through the codec.conf and find the best codec...
- mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
- if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
- sh_audio=d_audio->sh=NULL; // failed to init :(
- }
- mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
-}
-
- if (sh_audio) {
- new_srate = sh_audio->samplerate;
- if (opts.playback_speed != 1.0) {
- new_srate *= opts.playback_speed;
- // limits are taken from libaf/af_resample.c
- if (new_srate < 8000) new_srate = 8000;
- if (new_srate > 192000) new_srate = 192000;
- opts.playback_speed = (float)new_srate / (float)sh_audio->samplerate;
- }
- }
-
-// set up video encoder:
-
-if (!curfile) { // curfile is non zero when a second file is opened
-if (vobsub_out) {
- unsigned int palette[16], width, height;
- unsigned char tmp[3] = { 0, 0, 0 };
- if (spudec_ifo && vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, opts.sub_id, tmp) >= 0)
- vobsub_writer = vobsub_out_open(vobsub_out, palette, sh_video->disp_w, sh_video->disp_h,
- vobsub_out_id?vobsub_out_id:(char *)tmp, vobsub_out_index);
-#ifdef CONFIG_DVDREAD
- if (vobsub_writer == NULL) {
- char tmp[3];
- if (vobsub_out_id == NULL && stream->type == STREAMTYPE_DVD) {
- int i;
- dvd_priv_t *dvd = (dvd_priv_t*)stream->priv;
- for (i = 0; i < dvd->nr_of_subtitles; ++i)
- if (dvd->subtitles[i].id == opts.sub_id) {
- tmp[0] = (dvd->subtitles[i].language >> 8) & 0xff;
- tmp[1] = dvd->subtitles[i].language & 0xff;
- tmp[2] = 0;
- vobsub_out_id = tmp;
- break;
- }
- }
- vobsub_writer=vobsub_out_open(vobsub_out, stream->type==STREAMTYPE_DVD?((dvd_priv_t *)(stream->priv))->cur_pgc->palette:NULL,
- sh_video->disp_w, sh_video->disp_h, vobsub_out_id, vobsub_out_index);
- }
-#endif
-}
-else {
-if (spudec_ifo) {
- unsigned int palette[16], width, height;
- if (vobsub_parse_ifo(NULL,spudec_ifo, palette, &width, &height, 1, -1, NULL) >= 0)
- vo_spudec=spudec_new_scaled(palette, sh_video->disp_w, sh_video->disp_h, NULL, 0);
-}
-#ifdef CONFIG_DVDREAD
-if (vo_spudec==NULL) {
-vo_spudec=spudec_new_scaled(stream->type==STREAMTYPE_DVD?((dvd_priv_t *)(stream->priv))->cur_pgc->palette:NULL,
- sh_video->disp_w, sh_video->disp_h, NULL, 0);
-}
-#endif
-if (vo_spudec)
- spudec_set_forced_subs_only(vo_spudec, forced_subs_only);
-}
-
-ostream = open_output_stream(out_filename, 0);
-if(!ostream) {
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "Cannot open output file '%s'.\n", out_filename);
- mencoder_exit(1,NULL);
-}
-
-muxer=muxer_new_muxer(out_file_format,ostream);
-if(!muxer) {
- mp_tmsg(MSGT_MENCODER, MSGL_FATAL, "Cannot initialize muxer.");
- mencoder_exit(1,NULL);
-}
-#if 0
-//disabled: it horrybly distorts filtered sound
-if(out_file_format == MUXER_TYPE_MPEG) audio_preload = 0;
-#endif
-
-muxer->audio_delay_fix = audio_delay_fix;
-
-// ============= VIDEO ===============
-
-mux_v=muxer_new_stream(muxer,MUXER_TYPE_VIDEO);
-
-mux_v->buffer_size=0x200000; // 2MB
-mux_v->buffer=malloc(mux_v->buffer_size);
-
-mux_v->source=sh_video;
-
-mux_v->h.dwSampleSize=0; // VBR
-#ifdef CONFIG_LIBAVCODEC
-{
- double fps = force_ofps?force_ofps:sh_video->fps*opts.playback_speed;
- AVRational q= av_d2q(fps, fps*1001+2);
- mux_v->h.dwScale= q.den;
- mux_v->h.dwRate = q.num;
-}
-#else
-mux_v->h.dwScale=10000;
-mux_v->h.dwRate=mux_v->h.dwScale*(force_ofps?force_ofps:sh_video->fps*opts.playback_speed);
-#endif
-
-mux_v->codec=out_video_codec;
-
-mux_v->bih=NULL;
-}
-sh_video->codec=NULL;
-sh_video->vfilter=NULL; // fixme!
-
-switch(mux_v->codec){
-case VCODEC_COPY:
- if (!curfile) {
- if (sh_video->bih) {
- mux_v->bih=malloc(sh_video->bih->biSize);
- memcpy(mux_v->bih, sh_video->bih, sh_video->bih->biSize);
- }
- else
- {
- mux_v->bih=calloc(1,sizeof(BITMAPINFOHEADER));
- mux_v->bih->biSize=sizeof(BITMAPINFOHEADER);
- mux_v->bih->biWidth=sh_video->disp_w;
- mux_v->bih->biHeight=sh_video->disp_h;
- mux_v->bih->biCompression=sh_video->format;
- mux_v->bih->biPlanes=1;
- mux_v->bih->biBitCount=24; // FIXME!!!
- mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
- }
- }
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "videocodec: framecopy (%dx%d %dbpp fourcc=%x)\n",
- mux_v->bih->biWidth, mux_v->bih->biHeight,
- mux_v->bih->biBitCount, mux_v->bih->biCompression);
-
- if (curfile) {
- if (sh_video->bih) {
- if ((mux_v->bih->biSize != sh_video->bih->biSize) ||
- memcmp(mux_v->bih, sh_video->bih, sh_video->bih->biSize))
- {
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "videocodec: framecopy (%dx%d %dbpp fourcc=%x)\n",
- sh_video->bih->biWidth, sh_video->bih->biHeight,
- sh_video->bih->biBitCount, sh_video->bih->biCompression);
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"\nAll video files must have identical fps, resolution, and codec for -ovc copy.\n");
- mencoder_exit(1,NULL);
- }
- }
- else {
- if ((mux_v->bih->biWidth != sh_video->disp_w) ||
- (mux_v->bih->biHeight != sh_video->disp_h) ||
- (mux_v->bih->biCompression != sh_video->format)) {
- mp_tmsg(MSGT_MENCODER, MSGL_INFO, "videocodec: framecopy (%dx%d %dbpp fourcc=%x)\n",
- sh_video->disp_w, sh_video->disp_w, 24, sh_video->format);
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"\nAll video files must have identical fps, resolution, and codec for -ovc copy.\n");
- mencoder_exit(1,NULL);
- }
- }
- }
- break;
-case VCODEC_FRAMENO:
- if (!curfile) {
- mux_v->bih=calloc(1,sizeof(BITMAPINFOHEADER));
- mux_v->bih->biSize=sizeof(BITMAPINFOHEADER);
- mux_v->bih->biWidth=sh_video->disp_w;
- mux_v->bih->biHeight=sh_video->disp_h;
- mux_v->bih->biPlanes=1;
- mux_v->bih->biBitCount=24;
- mux_v->bih->biCompression=mmioFOURCC('F','r','N','o');
- mux_v->bih->biSizeImage=mux_v->bih->biWidth*mux_v->bih->biHeight*(mux_v->bih->biBitCount/8);
- }
- break;
-default: {
- static vf_instance_t * ve = NULL;
- if (!ve) {
- switch(mux_v->codec){
- case VCODEC_LIBAVCODEC:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"lavc",(char *)mux_v); break;
- case VCODEC_RAW:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"raw",(char *)mux_v); break;
- case VCODEC_VFW:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"vfw",(char *)mux_v); break;
- case VCODEC_LIBDV:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"libdv",(char *)mux_v); break;
- case VCODEC_XVID:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"xvid",(char *)mux_v); break;
- case VCODEC_QTVIDEO:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"qtvideo",(char *)mux_v); break;
- case VCODEC_NUV:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"nuv",(char *)mux_v); break;
- case VCODEC_X264:
- sh_video->vfilter=vf_open_encoder(&opts, NULL,"x264",(char *)mux_v); break;
- }
- if(!mux_v->bih || !sh_video->vfilter){
- mp_tmsg(MSGT_MENCODER,MSGL_FATAL,"Failed to open the encoder.\n");
- mencoder_exit(1,NULL);
- }
- ve = sh_video->vfilter;
- } else sh_video->vfilter = ve;
- // append 'expand' filter, it fixes stride problems and renders osd:
-#ifdef CONFIG_ASS
- if (auto_expand && !opts.ass_enabled) { /* we do not want both */
-#else
- if (auto_expand) {
-#endif
- char* vf_args[] = { "osd", "1", NULL };
- sh_video->vfilter=vf_open_filter(&opts, sh_video->vfilter,"expand",vf_args);
- }
-
-#ifdef CONFIG_ASS
- if(opts.ass_enabled) {
- int i;
- int insert = 1;
- if (opts.vf_settings)
- for (i = 0; opts.vf_settings[i].name; ++i)
- if (strcmp(opts.vf_settings[i].name, "ass") == 0) {
- insert = 0;
- break;
- }
- if (insert) {
- extern vf_info_t vf_info_ass;
- vf_info_t* libass_vfs[] = {&vf_info_ass, NULL};
- char* vf_arg[] = {"auto", "1", NULL};
- vf_instance_t* vf_ass = vf_open_plugin(&opts,libass_vfs,sh_video->vfilter,"ass",vf_arg);
- if (vf_ass)
- sh_video->vfilter=(void*)vf_ass;
-