2005-02-21 23:18:31 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <inttypes.h>
|
2006-01-25 20:55:47 +00:00
|
|
|
#include <limits.h>
|
2005-02-21 23:18:31 +00:00
|
|
|
#include "config.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "version.h"
|
|
|
|
#include "mp_msg.h"
|
2005-11-29 22:04:57 +00:00
|
|
|
#include "help_mp.h"
|
2005-02-21 23:18:31 +00:00
|
|
|
|
|
|
|
#include "aviheader.h"
|
|
|
|
#include "ms_hdr.h"
|
|
|
|
|
2007-03-15 18:36:36 +00:00
|
|
|
#include "stream/stream.h"
|
2006-12-18 21:03:59 +00:00
|
|
|
#include "muxer.h"
|
2005-02-21 23:18:31 +00:00
|
|
|
#include "demuxer.h"
|
|
|
|
#include "stheader.h"
|
2005-11-18 14:39:25 +00:00
|
|
|
#include "m_option.h"
|
2006-01-09 19:35:44 +00:00
|
|
|
#ifdef USE_LIBAVFORMAT_SO
|
|
|
|
#include <ffmpeg/avformat.h>
|
|
|
|
#else
|
2005-02-21 23:18:31 +00:00
|
|
|
#include "avformat.h"
|
2006-01-09 19:35:44 +00:00
|
|
|
#endif
|
2007-06-24 08:39:40 +00:00
|
|
|
#include "libavutil/avstring.h"
|
2005-02-21 23:18:31 +00:00
|
|
|
|
2007-01-21 15:44:58 +00:00
|
|
|
extern const struct AVCodecTag *mp_wav_taglists[];
|
|
|
|
extern const struct AVCodecTag *mp_bmp_taglists[];
|
2005-04-06 11:57:10 +00:00
|
|
|
|
2006-05-30 23:23:28 +00:00
|
|
|
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;
|
|
|
|
|
2005-02-21 23:18:31 +00:00
|
|
|
typedef struct {
|
|
|
|
//AVInputFormat *avif;
|
|
|
|
AVFormatContext *oc;
|
|
|
|
ByteIOContext pb;
|
|
|
|
int audio_streams;
|
|
|
|
int video_streams;
|
|
|
|
int64_t last_pts;
|
|
|
|
} muxer_priv_t;
|
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
int64_t last_pts;
|
|
|
|
AVStream *avstream;
|
|
|
|
} muxer_stream_priv_t;
|
|
|
|
|
|
|
|
static char *conf_format = NULL;
|
2006-01-25 01:17:57 +00:00
|
|
|
static int mux_rate= 0;
|
|
|
|
static int mux_packet_size= 0;
|
|
|
|
static float mux_preload= 0.5;
|
|
|
|
static float mux_max_delay= 0.7;
|
2005-02-21 23:18:31 +00:00
|
|
|
|
|
|
|
m_option_t lavfopts_conf[] = {
|
|
|
|
{"format", &(conf_format), CONF_TYPE_STRING, 0, 0, 0, NULL},
|
2006-01-25 01:17:57 +00:00
|
|
|
{"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},
|
|
|
|
|
2005-02-21 23:18:31 +00:00
|
|
|
{NULL, NULL, 0, 0, 0, 0, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static int mp_open(URLContext *h, const char *filename, int flags)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mp_close(URLContext *h)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int mp_read(URLContext *h, unsigned char *buf, int size)
|
|
|
|
{
|
2006-11-07 19:05:38 +00:00
|
|
|
mp_msg(MSGT_MUXER, MSGL_WARN, "READ %d\n", size);
|
2005-02-21 23:18:31 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mp_write(URLContext *h, unsigned char *buf, int size)
|
|
|
|
{
|
|
|
|
muxer_t *muxer = (muxer_t*)h->priv_data;
|
2006-12-18 21:03:59 +00:00
|
|
|
return stream_write_buffer(muxer->stream, buf, size);
|
2005-02-21 23:18:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static offset_t mp_seek(URLContext *h, offset_t pos, int whence)
|
|
|
|
{
|
|
|
|
muxer_t *muxer = (muxer_t*)h->priv_data;
|
2006-12-18 21:03:59 +00:00
|
|
|
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_UNSUPORTED || size < pos)
|
|
|
|
return -1;
|
|
|
|
pos = size - pos;
|
|
|
|
}
|
2006-11-07 19:05:38 +00:00
|
|
|
mp_msg(MSGT_MUXER, MSGL_DBG2, "SEEK %"PRIu64"\n", (int64_t)pos);
|
2006-12-18 21:03:59 +00:00
|
|
|
if(!stream_seek(muxer->stream, pos))
|
|
|
|
return -1;
|
|
|
|
return 0;
|
2005-02-21 23:18:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static URLProtocol mp_protocol = {
|
|
|
|
"menc",
|
|
|
|
mp_open,
|
|
|
|
mp_read,
|
|
|
|
mp_write,
|
|
|
|
mp_seek,
|
|
|
|
mp_close,
|
2005-04-17 09:13:48 +00:00
|
|
|
NULL
|
2005-02-21 23:18:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static muxer_stream_t* lavf_new_stream(muxer_t *muxer, int type)
|
|
|
|
{
|
2006-03-13 07:08:01 +00:00
|
|
|
muxer_priv_t *priv = muxer->priv;
|
2005-02-21 23:18:31 +00:00
|
|
|
muxer_stream_t *stream;
|
|
|
|
muxer_stream_priv_t *spriv;
|
|
|
|
AVCodecContext *ctx;
|
|
|
|
|
2006-03-12 18:06:46 +00:00
|
|
|
if(!muxer || (type != MUXER_TYPE_VIDEO && type != MUXER_TYPE_AUDIO))
|
2005-02-21 23:18:31 +00:00
|
|
|
{
|
2006-03-13 07:08:01 +00:00
|
|
|
mp_msg(MSGT_MUXER, MSGL_ERR, "UNKNOW TYPE %d\n", type);
|
2005-02-21 23:18:31 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-03-12 18:11:32 +00:00
|
|
|
stream = calloc(1, sizeof(muxer_stream_t));
|
2005-02-21 23:18:31 +00:00
|
|
|
if(!stream)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_MUXER, MSGL_ERR, "Could not alloc muxer_stream, EXIT\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-11-21 22:53:14 +00:00
|
|
|
muxer->streams[muxer->avih.dwStreams] = stream;
|
2006-03-12 18:11:32 +00:00
|
|
|
stream->b_buffer = malloc(2048);
|
2005-02-21 23:18:31 +00:00
|
|
|
if(!stream->b_buffer)
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_MUXER, MSGL_ERR, "Could not alloc b_buffer, EXIT\n");
|
|
|
|
free(stream);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
stream->b_buffer_size = 2048;
|
|
|
|
stream->b_buffer_ptr = 0;
|
|
|
|
stream->b_buffer_len = 0;
|
|
|
|
|
2006-03-12 18:11:32 +00:00
|
|
|
spriv = calloc(1, sizeof(muxer_stream_priv_t));
|
2005-02-21 23:18:31 +00:00
|
|
|
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 alloc avstream, EXIT\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
spriv->avstream->stream_copy = 1;
|
|
|
|
|
2005-07-18 00:10:09 +00:00
|
|
|
ctx = spriv->avstream->codec;
|
2005-02-21 23:18:31 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-06 11:57:10 +00:00
|
|
|
static void fix_parameters(muxer_stream_t *stream)
|
2005-02-21 23:18:31 +00:00
|
|
|
{
|
|
|
|
muxer_stream_priv_t *spriv = (muxer_stream_priv_t *) stream->priv;
|
|
|
|
AVCodecContext *ctx;
|
|
|
|
|
2005-07-18 00:10:09 +00:00
|
|
|
ctx = spriv->avstream->codec;
|
2006-07-13 23:02:03 +00:00
|
|
|
|
2006-08-10 21:48:41 +00:00
|
|
|
ctx->bit_rate= stream->avg_rate;
|
|
|
|
if(stream->wf && stream->wf->nAvgBytesPerSec && !ctx->bit_rate)
|
2006-03-13 07:08:01 +00:00
|
|
|
ctx->bit_rate = stream->wf->nAvgBytesPerSec * 8;
|
2006-01-25 01:17:57 +00:00
|
|
|
ctx->rc_buffer_size= stream->vbv_size;
|
|
|
|
ctx->rc_max_rate= stream->max_rate;
|
|
|
|
|
2005-02-21 23:18:31 +00:00
|
|
|
if(stream->type == MUXER_TYPE_AUDIO)
|
|
|
|
{
|
2007-01-21 15:44:58 +00:00
|
|
|
ctx->codec_id = av_codec_get_id(mp_wav_taglists, stream->wf->wFormatTag);
|
2006-01-25 15:49:31 +00:00
|
|
|
#if 0 //breaks aac in mov at least
|
2005-02-21 23:18:31 +00:00
|
|
|
ctx->codec_tag = codec_get_wav_tag(ctx->codec_id);
|
2006-01-25 15:49:31 +00:00
|
|
|
#endif
|
2005-02-21 23:18:31 +00:00
|
|
|
mp_msg(MSGT_MUXER, MSGL_INFO, "AUDIO CODEC ID: %x, TAG: %x\n", ctx->codec_id, (uint32_t) ctx->codec_tag);
|
2005-03-25 02:41:08 +00:00
|
|
|
ctx->sample_rate = stream->wf->nSamplesPerSec;
|
|
|
|
// mp_msg(MSGT_MUXER, MSGL_INFO, "stream->h.dwSampleSize: %d\n", stream->h.dwSampleSize);
|
2005-02-21 23:18:31 +00:00
|
|
|
ctx->channels = stream->wf->nChannels;
|
2005-03-25 22:47:09 +00:00
|
|
|
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;
|
2005-04-17 09:13:48 +00:00
|
|
|
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);
|
2006-01-25 19:30:01 +00:00
|
|
|
ctx->block_align = stream->h.dwSampleSize;
|
2005-05-17 21:44:28 +00:00
|
|
|
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! couldn't allocate %d bytes for extradata\n",
|
|
|
|
stream->wf->cbSize);
|
|
|
|
}
|
2005-02-21 23:18:31 +00:00
|
|
|
}
|
|
|
|
else if(stream->type == MUXER_TYPE_VIDEO)
|
|
|
|
{
|
2007-01-21 15:44:58 +00:00
|
|
|
ctx->codec_id = av_codec_get_id(mp_bmp_taglists, stream->bih->biCompression);
|
2007-01-21 10:10:07 +00:00
|
|
|
if(ctx->codec_id <= 0 || force_fourcc)
|
2006-01-25 15:49:31 +00:00
|
|
|
ctx->codec_tag= stream->bih->biCompression;
|
2005-02-21 23:18:31 +00:00
|
|
|
mp_msg(MSGT_MUXER, MSGL_INFO, "VIDEO CODEC ID: %d\n", ctx->codec_id);
|
2007-05-18 02:09:26 +00:00
|
|
|
if (stream->imgfmt)
|
2007-05-18 02:10:41 +00:00
|
|
|
ctx->pix_fmt = imgfmt2pixfmt(stream->imgfmt);
|
2005-02-21 23:18:31 +00:00
|
|
|
ctx->width = stream->bih->biWidth;
|
|
|
|
ctx->height = stream->bih->biHeight;
|
|
|
|
ctx->bit_rate = 800000;
|
2005-05-01 05:11:02 +00:00
|
|
|
ctx->time_base.den = stream->h.dwRate;
|
|
|
|
ctx->time_base.num = stream->h.dwScale;
|
2005-05-17 21:44:28 +00:00
|
|
|
if(stream->bih+1 && (stream->bih->biSize > sizeof(BITMAPINFOHEADER)))
|
|
|
|
{
|
2007-01-05 15:41:00 +00:00
|
|
|
ctx->extradata_size = stream->bih->biSize - sizeof(BITMAPINFOHEADER);
|
|
|
|
ctx->extradata = av_malloc(ctx->extradata_size);
|
2005-05-17 21:44:28 +00:00
|
|
|
if(ctx->extradata != NULL)
|
|
|
|
memcpy(ctx->extradata, stream->bih+1, ctx->extradata_size);
|
|
|
|
else
|
2007-01-05 15:41:00 +00:00
|
|
|
{
|
2005-05-17 21:44:28 +00:00
|
|
|
mp_msg(MSGT_MUXER, MSGL_ERR, "MUXER_LAVF(video stream) error! couldn't allocate %d bytes for extradata\n",
|
2007-01-05 15:41:00 +00:00
|
|
|
ctx->extradata_size);
|
|
|
|
ctx->extradata_size = 0;
|
|
|
|
}
|
2005-05-17 21:44:28 +00:00
|
|
|
}
|
2005-02-21 23:18:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-26 19:32:07 +00:00
|
|
|
static void write_chunk(muxer_stream_t *stream, size_t len, unsigned int flags, double dts, double pts)
|
2005-02-21 23:18:31 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2005-04-17 09:13:48 +00:00
|
|
|
if(len)
|
|
|
|
{
|
2005-02-21 23:18:31 +00:00
|
|
|
av_init_packet(&pkt);
|
|
|
|
pkt.size = len;
|
|
|
|
pkt.stream_index= spriv->avstream->index;
|
|
|
|
pkt.data = stream->buffer;
|
|
|
|
|
2005-04-17 09:13:48 +00:00
|
|
|
if(flags & AVIIF_KEYFRAME)
|
2005-02-21 23:18:31 +00:00
|
|
|
pkt.flags |= PKT_FLAG_KEY;
|
|
|
|
else
|
|
|
|
pkt.flags = 0;
|
2007-07-31 17:24:53 +00:00
|
|
|
|
|
|
|
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);
|
2005-05-01 11:13:14 +00:00
|
|
|
//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);
|
2005-02-21 23:18:31 +00:00
|
|
|
|
|
|
|
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");
|
|
|
|
}
|
2005-04-17 09:13:48 +00:00
|
|
|
}
|
|
|
|
|
2005-02-21 23:18:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void write_header(muxer_t *muxer)
|
|
|
|
{
|
|
|
|
muxer_priv_t *priv = (muxer_priv_t *) muxer->priv;
|
|
|
|
|
2005-11-29 22:04:57 +00:00
|
|
|
mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_WritingHeader);
|
2005-02-21 23:18:31 +00:00
|
|
|
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;
|
|
|
|
|
2005-11-29 22:04:57 +00:00
|
|
|
mp_msg(MSGT_MUXER, MSGL_INFO, MSGTR_WritingTrailer);
|
2005-02-21 23:18:31 +00:00
|
|
|
av_write_trailer(priv->oc);
|
|
|
|
for(i = 0; i < priv->oc->nb_streams; i++)
|
|
|
|
{
|
|
|
|
av_freep(&(priv->oc->streams[i]));
|
|
|
|
}
|
|
|
|
|
|
|
|
url_fclose(&(priv->oc->pb));
|
|
|
|
|
|
|
|
av_free(priv->oc);
|
|
|
|
}
|
|
|
|
|
2007-02-14 11:06:59 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2005-02-21 23:18:31 +00:00
|
|
|
extern char *out_filename;
|
|
|
|
int muxer_init_muxer_lavf(muxer_t *muxer)
|
|
|
|
{
|
|
|
|
muxer_priv_t *priv;
|
|
|
|
AVOutputFormat *fmt = NULL;
|
|
|
|
char mp_filename[256] = "menc://stream.dummy";
|
2005-12-02 19:43:36 +00:00
|
|
|
|
2007-02-14 11:06:59 +00:00
|
|
|
av_register_all();
|
|
|
|
|
2007-02-16 23:09:13 +00:00
|
|
|
if (conf_format && strcmp(conf_format, "help") == 0) {
|
2007-02-14 11:06:59 +00:00
|
|
|
list_formats();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-12-02 19:43:36 +00:00
|
|
|
mp_msg(MSGT_MUXER, MSGL_WARN, "** MUXER_LAVF *****************************************************************\n");
|
|
|
|
mp_msg(MSGT_MUXER, MSGL_WARN,
|
2007-07-31 17:28:47 +00:00
|
|
|
"REMEMBER: MEncoder's libavformat muxing is presently broken and can generate\n"
|
2005-12-02 19:43:36 +00:00
|
|
|
"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");
|
2005-02-21 23:18:31 +00:00
|
|
|
|
|
|
|
priv = (muxer_priv_t *) 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, "Couldn't 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, "CAN'T 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;
|
|
|
|
}
|
2006-01-25 01:17:57 +00:00
|
|
|
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);
|
2006-05-30 23:23:28 +00:00
|
|
|
if (info_name)
|
2007-06-24 08:39:40 +00:00
|
|
|
av_strlcpy(priv->oc->title , info_name, sizeof(priv->oc->title ));
|
2006-05-30 23:23:28 +00:00
|
|
|
if (info_artist)
|
2007-06-24 08:39:40 +00:00
|
|
|
av_strlcpy(priv->oc->author , info_artist, sizeof(priv->oc->author ));
|
2006-05-30 23:23:28 +00:00
|
|
|
if (info_genre)
|
2007-06-24 08:39:40 +00:00
|
|
|
av_strlcpy(priv->oc->genre , info_genre, sizeof(priv->oc->genre ));
|
2006-05-30 23:23:28 +00:00
|
|
|
if (info_copyright)
|
2007-06-24 08:39:40 +00:00
|
|
|
av_strlcpy(priv->oc->copyright, info_copyright, sizeof(priv->oc->copyright));
|
2006-05-30 23:23:28 +00:00
|
|
|
if (info_comment)
|
2007-06-24 08:39:40 +00:00
|
|
|
av_strlcpy(priv->oc->comment , info_comment, sizeof(priv->oc->comment ));
|
2005-02-21 23:18:31 +00:00
|
|
|
register_protocol(&mp_protocol);
|
|
|
|
|
|
|
|
if(url_fopen(&priv->oc->pb, mp_filename, URL_WRONLY))
|
|
|
|
{
|
|
|
|
mp_msg(MSGT_MUXER, MSGL_FATAL, "Coulnd't open outfile\n");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
((URLContext*)(priv->oc->pb.opaque))->priv_data= muxer;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|