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
515515 s->nb_streams = ic->nb_streams;
516516 for(i=0;i<ic->nb_streams;i++) {
517517 AVStream *st;
518+ AVCodec *codec;
518519
519520 // FIXME: a more elegant solution is needed
520521 st = av_mallocz(sizeof(AVStream));
@@ -524,13 +525,21 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename) · 3 unmodified lines
524525 print_error(filename, AVERROR(ENOMEM));
525526 av_exit(1);
526527 }
527− memcpy(st->codec, ic->streams[i]->codec, sizeof(AVCodecContext));
528+ avcodec_copy_context(st->codec, ic->streams[i]->codec);
528529 s->streams[i] = st;
529530
530− if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && audio_stream_copy)
531− st->stream_copy = 1;
532− else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && video_stream_copy)
533− st->stream_copy = 1;
531+ codec = avcodec_find_encoder(st->codec->codec_id);
532+ if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) {
533+ if (audio_stream_copy) {
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+ }
534543
535544 if(!st->codec->thread_count)
536545 st->codec->thread_count = 1;
ffserver.c+2−10
@@ -4039,7 +4039,6 @@ static int parse_ffconfig(const char *filename) · 4038 unmodified lines
40394039 filename, line_num);
40404040 } else {
40414041 FFStream *s;
4042− const AVClass *class;
40434042 stream = av_mallocz(sizeof(FFStream));
40444043 get_arg(stream->filename, sizeof(stream->filename), &p);
40454044 q = strrchr(stream->filename, '>');
@@ -4055,15 +4054,8 @@ static int parse_ffconfig(const char *filename) · 9 unmodified lines
40554054 }
40564055
40574056 stream->fmt = ffserver_guess_format(NULL, stream->filename, NULL);
4058− /* fetch avclass so AVOption works
4059− * FIXME try to use avcodec_get_context_defaults2
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;
4057+ avcodec_get_context_defaults2(&video_enc, AVMEDIA_TYPE_VIDEO);
4058+ avcodec_get_context_defaults2(&audio_enc, AVMEDIA_TYPE_AUDIO);
40674059 audio_id = CODEC_ID_NONE;
40684060 video_id = CODEC_ID_NONE;
40694061 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