Commit d9521cb1 authored by Ronald S. Bultje's avatar Ronald S. Bultje

Fix FFM-based streaming from ffmpeg to ffserver. The basic problem is that

we'd memset() the codec context to zero, thereby setting audio input to U8
and video to YUV420P. For most video encoders, that actually works, but for
most audio codecs, it doesn't. This patch changes defaults to those set by
avcodec_context_get_defaults() and have ffmpeg figure out the optimal encoding
format itself if not set explicitely (as it does for the non-ffserver-cases
also).

Originally committed as revision 22751 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent d1032180
...@@ -515,6 +515,7 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename) ...@@ -515,6 +515,7 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename)
s->nb_streams = ic->nb_streams; s->nb_streams = ic->nb_streams;
for(i=0;i<ic->nb_streams;i++) { for(i=0;i<ic->nb_streams;i++) {
AVStream *st; AVStream *st;
AVCodec *codec;
// FIXME: a more elegant solution is needed // FIXME: a more elegant solution is needed
st = av_mallocz(sizeof(AVStream)); st = av_mallocz(sizeof(AVStream));
...@@ -524,13 +525,21 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename) ...@@ -524,13 +525,21 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename)
print_error(filename, AVERROR(ENOMEM)); print_error(filename, AVERROR(ENOMEM));
av_exit(1); av_exit(1);
} }
memcpy(st->codec, ic->streams[i]->codec, sizeof(AVCodecContext)); avcodec_copy_context(st->codec, ic->streams[i]->codec);
s->streams[i] = st; s->streams[i] = st;
if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && audio_stream_copy) codec = avcodec_find_encoder(st->codec->codec_id);
st->stream_copy = 1; if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && video_stream_copy) if (audio_stream_copy) {
st->stream_copy = 1; st->stream_copy = 1;
} else
choose_sample_fmt(st, codec);
} else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
if (video_stream_copy) {
st->stream_copy = 1;
} else
choose_pixel_fmt(st, codec);
}
if(!st->codec->thread_count) if(!st->codec->thread_count)
st->codec->thread_count = 1; st->codec->thread_count = 1;
......
...@@ -4039,7 +4039,6 @@ static int parse_ffconfig(const char *filename) ...@@ -4039,7 +4039,6 @@ static int parse_ffconfig(const char *filename)
filename, line_num); filename, line_num);
} else { } else {
FFStream *s; FFStream *s;
const AVClass *class;
stream = av_mallocz(sizeof(FFStream)); stream = av_mallocz(sizeof(FFStream));
get_arg(stream->filename, sizeof(stream->filename), &p); get_arg(stream->filename, sizeof(stream->filename), &p);
q = strrchr(stream->filename, '>'); q = strrchr(stream->filename, '>');
...@@ -4055,15 +4054,8 @@ static int parse_ffconfig(const char *filename) ...@@ -4055,15 +4054,8 @@ static int parse_ffconfig(const char *filename)
} }
stream->fmt = ffserver_guess_format(NULL, stream->filename, NULL); stream->fmt = ffserver_guess_format(NULL, stream->filename, NULL);
/* fetch avclass so AVOption works avcodec_get_context_defaults2(&video_enc, AVMEDIA_TYPE_VIDEO);
* FIXME try to use avcodec_get_context_defaults2 avcodec_get_context_defaults2(&audio_enc, AVMEDIA_TYPE_AUDIO);
* without changing defaults too much */
avcodec_get_context_defaults(&video_enc);
class = video_enc.av_class;
memset(&audio_enc, 0, sizeof(AVCodecContext));
memset(&video_enc, 0, sizeof(AVCodecContext));
audio_enc.av_class = class;
video_enc.av_class = class;
audio_id = CODEC_ID_NONE; audio_id = CODEC_ID_NONE;
video_id = CODEC_ID_NONE; video_id = CODEC_ID_NONE;
if (stream->fmt) { if (stream->fmt) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment