History

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

Ronald S. Bultje committed 16 years ago

Commit d9521cb1 parent d1032182 files · +16 −15Browse files

Unified · Split

2 files
  1. ffmpeg.c +14 −5
  2. ffserver.c +2 −10
ffmpeg.c+14−5
@@ -515,6 +515,7 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename) · 514 unmodified lines
515 s->nb_streams = ic->nb_streams;515 s->nb_streams = ic->nb_streams;
516 for(i=0;i<ic->nb_streams;i++) {516 for(i=0;i<ic->nb_streams;i++) {
517 AVStream *st;517 AVStream *st;
518 AVCodec *codec;
518 519
519 // FIXME: a more elegant solution is needed520 // FIXME: a more elegant solution is needed
520 st = av_mallocz(sizeof(AVStream));521 st = av_mallocz(sizeof(AVStream));
@@ -524,13 +525,21 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename) · 3 unmodified lines
524 print_error(filename, AVERROR(ENOMEM));525 print_error(filename, AVERROR(ENOMEM));
525 av_exit(1);526 av_exit(1);
526 }527 }
527 memcpy(st->codec, ic->streams[i]->codec, sizeof(AVCodecContext));528 avcodec_copy_context(st->codec, ic->streams[i]->codec);
528 s->streams[i] = st;529 s->streams[i] = st;
529 530
530 if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && audio_stream_copy)531 codec = avcodec_find_encoder(st->codec->codec_id);
531 st->stream_copy = 1;532 if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
532 else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && video_stream_copy)533 if (audio_stream_copy) {
533 st->stream_copy = 1;534 st->stream_copy = 1;
535 } else
536 choose_sample_fmt(st, codec);
537 } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
538 if (video_stream_copy) {
539 st->stream_copy = 1;
540 } else
541 choose_pixel_fmt(st, codec);
542 }
534 543
535 if(!st->codec->thread_count)544 if(!st->codec->thread_count)
536 st->codec->thread_count = 1;545 st->codec->thread_count = 1;
ffserver.c+2−10
@@ -4039,7 +4039,6 @@ static int parse_ffconfig(const char *filename) · 4038 unmodified lines
4039 filename, line_num);4039 filename, line_num);
4040 } else {4040 } else {
4041 FFStream *s;4041 FFStream *s;
4042 const AVClass *class;
4043 stream = av_mallocz(sizeof(FFStream));4042 stream = av_mallocz(sizeof(FFStream));
4044 get_arg(stream->filename, sizeof(stream->filename), &p);4043 get_arg(stream->filename, sizeof(stream->filename), &p);
4045 q = strrchr(stream->filename, '>');4044 q = strrchr(stream->filename, '>');
@@ -4055,15 +4054,8 @@ static int parse_ffconfig(const char *filename) · 9 unmodified lines
4055 }4054 }
4056 4055
4057 stream->fmt = ffserver_guess_format(NULL, stream->filename, NULL);4056 stream->fmt = ffserver_guess_format(NULL, stream->filename, NULL);
4058 /* fetch avclass so AVOption works4057 avcodec_get_context_defaults2(&video_enc, AVMEDIA_TYPE_VIDEO);
4059 * FIXME try to use avcodec_get_context_defaults24058 avcodec_get_context_defaults2(&audio_enc, AVMEDIA_TYPE_AUDIO);
4060 * without changing defaults too much */
4061 avcodec_get_context_defaults(&video_enc);
4062 class = video_enc.av_class;
4063 memset(&audio_enc, 0, sizeof(AVCodecContext));
4064 memset(&video_enc, 0, sizeof(AVCodecContext));
4065 audio_enc.av_class = class;
4066 video_enc.av_class = class;
4067 audio_id = CODEC_ID_NONE;4059 audio_id = CODEC_ID_NONE;
4068 video_id = CODEC_ID_NONE;4060 video_id = CODEC_ID_NONE;
4069 if (stream->fmt) {4061 if (stream->fmt) {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t