Hi all,

First, thanks for the libraries; they're an amazing feat. Unfortunately,
there seem to be few simple examples around. I don't want to be another
"look at my code, what am I doing wrong?", but I've literally spent 30+
hours at this. My ultimate goal is to encode to avi with mpeg4 advanced
simple and mp3 audio (but I'll deal with the audio later; I'm just using
CODEC_ID_NONE for the audio for now). Summary of the problem: avis are
unplayable, but "mpeg" or "m4v" containers work fine.

First, my configuration: using latest SVN (19214) on mingw32 compiled with
mingw gcc  4.3. I'm compiling to static libraries, and using the following
as my configuration options:
--enable-gpl --disable-debug --disable-ffmpeg --disable-ffplay
--disable-ffserver --disable-network --disable-ipv6
--enable-runtime-cpudetect --enable-memalign-hack
--extra-cflags="-fno-common"

I'm trying to get output_example.c (or something similar) working. It works
great if I specify the output as "mpeg" (or, since my eventual target is
MP4, if I specify "m4v"). However, if I specify an "avi" output, it works
fine (no error, etc.), but the resulting output is unplayable. This is true
whether I leave the video codec as avi's default or specify mpeg4 as the
output. The output from my player (Media Player classic) looks like this:

Media Type 0:
--------------------------
Unknown
AM_MEDIA_TYPE:
majortype: MEDIATYPE_Stream {E436EB83-524F-11CE-9F53-0020AF0BA770}
subtype: MEDIASUBTYPE_Avi {E436EB88-524F-11CE-9F53-0020AF0BA770}
formattype: TIME_FORMAT_NONE {00000000-0000-0000-0000-000000000000}
bFixedSizeSamples: 1
bTemporalCompression: 0
lSampleSize: 1
cbFormat: 0

The Media Type as "Unknown" is a bit worrying... I'm calling
av_write_header(), but I'm guessing AVIs need some other metadata about the
types of streams contained within...?

I'm configuring the format like thus (note -- D programming language...
works pretty much like C in this context except -> is replaced by . ):
    AVOutputFormat* fmt = guess_format("avi", null, null);
    assert(fmt !is null, "Could not find format");

    AVFormatContext* ctx = av_alloc_format_context();
    assert(ctx !is null, "Could not allocate format context");
    scope(exit) if(ctx) av_free(ctx);
    ctx.oformat = fmt;
    snprintf(ctx.filename.ptr, ctx.filename.sizeof, "%s", filename);
    //ctx.preload = cast(int) (0.5 * AV_TIME_BASE);
    ctx.max_delay = cast(int) (0.7 * AV_TIME_BASE);
    ctx.loop_output = AVFMT_NOOUTPUTLOOP;
    ctx.flags |= AVFMT_FLAG_NONBLOCK;

    AVFormatParameters params;
    params.prealloced_context = 1;
    params.video_codec_id = CODEC_ID_MPEG4;
    params.audio_codec_id = CODEC_ID_NONE;
    params.width = 352;
    params.height = 288;
    params.time_base.num = 1;
    params.time_base.den = STREAM_FRAME_RATE;
    params.pix_fmt = PIX_FMT_YUV420P;
    res = av_set_parameters(ctx, &params);
    assert(res >= 0, "Could not set parameters");
    dump_format(ctx, 0, filename, 1);

And as for the stream and codec:
    AVStream* stream = av_new_stream(ctx, 0);
    assert(stream !is null, "Could not allocate stream");
    scope(exit) if(stream) av_free(stream);
    ctx.streams[0] = stream;
    ctx.nb_streams = 1;

    AVCodec* codecName = avcodec_find_encoder(CODEC_ID_MPEG4);
    assert(codecName, "Could not find codec");
    AVCodecContext* codec = stream.codec;
    codec.codec_id = CODEC_ID_MPEG4;
    codec.codec_type = CODEC_TYPE_VIDEO;
    codec.bit_rate = 400000;
    codec.width = 352;
    codec.height = 288;
    codec.gop_size = 12;
    codec.time_base.den = STREAM_FRAME_RATE;
    codec.time_base.num = 1;
    codec.pix_fmt = PIX_FMT_YUV420P;
    codec.me_method = 1;
    codec.strict_std_compliance = 1;

I've attached the full source code of the program. Thanks in advance for any
help you can provide.

All the best,
Robert

Attachment: main.d
Description: Binary data

_______________________________________________
libav-user mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/libav-user

Reply via email to