Nicolas Derouineau | 22 Aug 14:09 2014

Debug level


I'm currently playing with libavcodec as a static library, and I would like to get the debug message
(printed by the following)                

    av_log(h->avctx, AV_LOG_DEBUG,
                       "NAL_IDR Detected\n");

Only the message printed with 

    av_log(h->avctx, AV_LOG_ERROR,
                       "NAL_IDR Detected\n");

are currently displayed. Does anyone know how to activate this ? I see a DEBUGLEVEL option in the configure
script, but no further description is given.


Dmitry Adjiev | 22 Aug 04:49 2014

rtcp in multicasting

I have one question: should I send rtcp to multicast group?
Libav-user mailing list
Lyndon Hill | 22 Aug 00:53 2014

Reading packed BGR format

Hi, I'm trying to read a simple AVI file with raw BGR. This codec is the default and sometimes referred to as "DIB".

I can open the file and decode frames of format AV_PIX_FMT_BGR24 but the problem is that I'm getting
AVFrame.linesize[0] = -2160. I know this file is 720x480. Why the negative ?[0] certainly does not point to a frame of 2160 bytes.

If I use swscale() to convert to AV_PIX_FMT_RGB24 then it seems to handle the conversion fine.

None of this makes sense to me.
Lyndon Hill | 21 Aug 23:37 2014

Re: Writing Interlaced Video

Nils Jessen wrote:
> I would like to get some help writing interlaced video correctly flagged 
> as interlaced.

Your problem is that V210 is a raw format. There are no interlacing flags in V210. You also want to write using
the AVI container; AVI does not explicitly support interlacing. You can dump interlaced frames to AVI but
without prior knowledge or visual inspection there is no way for software to know.

On the other hand QuickTime mov format supports interlacing, this is the reason why you had success with it.

Lyndon Hill

freelance developer needed


I am trying to find a freelance developper for adding ffmpeg support to our software.

Best regards,

Libav-user mailing list
daytooner | 21 Aug 19:17 2014

Can't convert raw audio to mp3

I have a raw audio file (s16, 44100, 2 channels). FWIW, the file was
generated from a FLAC file, and I have tested it in audacity and it is fine.

I am now trying to convert that to an mp3 file. The code I am using follows.
(Note that I have removed a lot of insignificant lines, such as #includes). 

/************************* begin code ********************************
# many includes/macros #

typedef unsigned char	BYTE;

static AVFormatContext *encfmt_ctx = NULL;
static AVCodecContext *audio_enc_ctx;
static AVStream *audio_encstream = NULL;
static int audio_frame_deccount = 0, audio_frame_enccount = 0;
static SwrContext *swr;

#define	MP3_BITRATE		256000
#define	MP3_SAMPLE_RATE 	44100

#define	FLAC_BITRATE		256000
#define	FLAC_SAMPLE_RATE	  44100

#define SAMPLES_TO_CB(stc, cs)
(av_get_bytes_per_sample(stc->codec->sample_fmt) * stc->codec->channels *
#define SAMPLES_FROM_CB(stc, cb)
cb/(av_get_bytes_per_sample(stc->codec->sample_fmt) * stc->codec->channels)

#define	BYTES_TO_READ   	4594

void flush_audio()
	int ret;
	int	got_frame;
	AVPacket	epkt = {0};

	ret = avcodec_encode_audio2(audio_enc_ctx, &epkt, NULL, &got_frame);
	av_assert0(ret >= 0);

 * encode a buffer of cbdec bytes of raw audio
bool encode_buffer(BYTE* buff, int cbdec)
	int ret;
	int	got_frame;
	int	line_size;
	BYTE*	ob[2];
	const BYTE*	ib[2];
	AVPacket	epkt = {0};
	AVFrame *eframe = avcodec_alloc_frame();

	 * convert audio
	long int c_insamples = cbdec/(4);
//	long int delay = swr_get_delay(swr,(long int) 44100);
	long int delay = 0;
	int c_outsamples = av_rescale_rnd(delay + c_insamples,
			(long int) MP3_SAMPLE_RATE,
	ret = av_samples_alloc(ob, &line_size, 2,
					c_outsamples,MP3_SAMPLE_FMT, 0);
	av_assert0(ret >= 0);
	ib[0] = buff;
	ret = swr_convert(swr, ob, c_outsamples, ib, c_insamples);
	av_assert0(ret >= 0);

	 * encode
	eframe->nb_samples = cbdec/(4);
	eframe->pts = (audio_frame_deccount * ( av_rescale_q(1,
audio_encstream->codec->time_base, audio_encstream->time_base)));
	avcodec_fill_audio_frame(eframe, 2, MP3_SAMPLE_FMT, ob[0], cbdec, 1);

	epkt.stream_index = audio_encstream->index;
	eframe->nb_samples = audio_enc_ctx->frame_size;

	ret = avcodec_encode_audio2(audio_enc_ctx, &epkt, eframe, &got_frame);
	av_assert0(ret >= 0);
	audio_frame_deccount +=(cbdec/4);
	printf("cbdec=%d, decoded=%d pts=%ld\n", cbdec, audio_frame_deccount,
	if (!got_frame)
		return false;
	epkt.stream_index = audio_encstream->index;
	audio_frame_enccount ++ ;
	/* Write the compressed frame to the media file. */
	ret = av_interleaved_write_frame(encfmt_ctx, &epkt);

	return true;


int open_encodec_context(AVFormatContext *fmt_ctx, enum AVMediaType type)
	int ret;
	AVStream *st;
	AVCodec *enc = NULL;
	enc = avcodec_find_encoder(fmt_ctx->oformat->audio_codec);
	av_assert0(enc != NULL);
	st = avformat_new_stream(fmt_ctx, enc);
	/* find encoder for the stream */
	st->codec->sample_fmt = MP3_SAMPLE_FMT;
	st->codec->bit_rate = MP3_BITRATE;
	st->codec->sample_rate = MP3_SAMPLE_RATE;
	st->codec->channels = 2;
	st->codec->channel_layout = 3;
	ret = avcodec_open2(st->codec, enc, NULL);
	av_assert0(ret >= 0);

	return 1;

int main(int argc, char **argv)

	const char *fn_out = argv[1];
	int ret;

	ret = avformat_alloc_output_context2(&encfmt_ctx, NULL, NULL, fn_out);
	av_assert0(ret >= 0);
	if (open_encodec_context(encfmt_ctx, AVMEDIA_TYPE_AUDIO) >= 0)

		audio_encstream = encfmt_ctx->streams[0];
		audio_enc_ctx = audio_encstream->codec;
		av_dump_format(encfmt_ctx, 0, fn_out, 1);

	swr = swr_alloc();

	/* set options */
	av_opt_set_int(swr, "in_channel_layout", 3, 0);
	av_opt_set_int(swr, "in_channel_count", 2, 0);
	av_opt_set_int(swr, "in_sample_rate", FLAC_SAMPLE_RATE,0);
	av_opt_set_sample_fmt(swr, "in_sample_fmt", FLAC_SAMPLE_FMT, 0);
	av_opt_set_int(swr, "out_channel_layout",3, 0);
	av_opt_set_int(swr, "out_sample_rate", MP3_SAMPLE_RATE, 0);
	av_opt_set_sample_fmt(swr, "out_sample_fmt",MP3_SAMPLE_FMT, 0);
	ret = swr_init(swr);
	av_assert0(ret >= 0);

	if (!(encfmt_ctx->oformat->flags & AVFMT_NOFILE))
		ret = avio_open(&encfmt_ctx->pb, fn_out, AVIO_FLAG_WRITE);
                av_assert0(ret >= 0);
	ret = avformat_write_header(encfmt_ctx, NULL);
	av_assert0(ret >= 0);

	int cbread = 0;
	int	fd = open("/nas/temp/flac.raw", O_RDONLY);
	assert(fd > 0);
	int cb2read = BYTES_TO_READ;
	BYTE	b[cb2read];
	int c_reads = 0;
	while ((cbread = read(fd, b, cb2read)) > 0)
		encode_buffer(b, cbread);
	ret = av_interleaved_write_frame(encfmt_ctx, NULL);
	av_assert0(ret >= 0);


/**************** end code *************************/

I have discovered that if I change the number of bytes read in and encoded
(BYTES_TO_READ), that the output changes. I experimented with different
values, and the value 4594 seems to get the closest to the original audio -
although it it about 0.5 seconds longer and the audio is choppy. Also, with
some values of BYTES_TO_READ, the avcodec_encode_audio2  call fails, with an
error of "not enough bytes".

I would like to transcode directly from the flac file to mp3, as the ffmpeg
command line does, as well as take raw audio and encode it to mp3 and other

So, the basic question is: what is wrong with the above code? I have pieced
this together from the various libav samples on the ffmpeg website.

Also, in the future, I will need to do the same thing with video - encode
raw video in various pixel formats. So, any help here is greatly



PS: sorry for the long message, but I did feel the code was important.

View this message in context:
Sent from the libav-users mailing list archive at
Mike Charikov | 20 Aug 16:16 2014

Question about avdevice_list_devices() using.



I try to use avdevice_list_devices() for getting list of video devices, but don’t clearly understand, how to do that properly. How should I properly init AVFormatContext for calling avdevice_list_devices()?


Tried something like that:


int main() {





                AVFormatContext* format_context = avformat_alloc_context();

                AVInputFormat *fmt = av_find_input_format("dshow");

                AVDeviceInfoList *device_list=NULL;


                int err = avformat_open_input(&format_context, NULL, fmt, NULL);

                if (err != 0) {

                               fprintf(stderr, "ffmpeg: Unable to open input: %d\n", err);



                int i = avdevice_list_devices(format_context, &device_list);


                return 0;



But avformat_open_input() returns error (code -1414092869), and so does avdevice_list_devices() (code -40)


Libav-user mailing list
Swapnil Bhoite | 20 Aug 14:38 2014

ffmpeg with Android


I am working on Android (Compiled ffmpeg-2.3.3 for Android on Ubuntu 12.04).
The basic purpose of my project is open and play HLS.
I've been searching on internet for doing so, but I'm unable to find useful guidance.
Looking forward for further guidance.

From examples, I have created one to get metadata of file. It is working fine for local file but avformat_open_input(...) returning -5(I/O error) if online URL is passed as input file name.

Thank you,
Libav-user mailing list
Hector Alonso | 19 Aug 11:25 2014

HW Accelerator in Windows: DXVA2 with new API

I'm developing a H264 decoder in Windows and I want to use the hardware acceleration capabilities: DXVA2
I've already built FFMPEG from git (lastest version: N-65404-gd34ec64; libavcodec 55.73.101 ...) using Mingw64 for 32bits this way:

echo 'export PATH=.:/local/bin:/bin:/mingw64/bin' > .profile source .profile
git config --global core.autocrlf false
  git clone git:// x264 cd x264 ./configure --host=x86_64-w64-mingw32 --enable-static --enable-shared && make && make install cd ..   git clone git:// fdk-aac cd fdk-aac ./ ./configure --host=x86_64-w64-mingw32 --enable-static --enable-shared && make && make install cd ..

git clone git:// ffmpeg cd ffmpeg
./configure --enable-gpl --enable-nonfree --enable-libx264 --enable-libfdk_aac --enable-memalign-hack --enable-runtime-cpudetect --enable-dxva2 --enable-decoder?h264_dxva2 --disable-hwaccels --enable-hwaccel=h264_dxva2 --enable-static --enable-shared --extra-cflags=-I/local/include --extra-ldflags='-L/local/lib -static' && make && make install

I've adapted the newest version of ffmpeg_dxva2.c to C++ (with a header file including InputStream, HWAccelID and dxva2_init declarations), now it builds with VisualStudio 2012 and everything is running correctly with my current decoder (not HW accelerated).

I found an old post of this list ( describing the steps for running it, but now te API has changed...
I've also studied the VLC method, but it is also working with the older API (get_buffer instead of get_buffer2, and so).
In the newest ffmpeg.c they actually use the hwaccel including DXVA2, but in quite a complicated way... could you please give an example or a piece of advice  on how to do it? 

1.- Create a InputStream instance, populate it and address it to AVCodecContext->opaque. Which are the needed attributes? It requires width and height of the input before opening it!

2.- call dxva_init() with the decoder AVCodecContext allocated using avcodec_alloc_context3 from CODEC_ID_H264 codec before calling avcodec_open2 ?

3.- Call dxva2_retrieve_data() with the decoder AVCodecContext  and a AV_PIX_FMT_NV12 frame when avcodec_decode_video2 returns a complete frame (got_output) ?

4.- Copy (convert) the resulting frame to a YUV420P OpenGL texture, apply a pixelformat conversion shader and show it! <- This step is working fine (I did it for a separated decoder using Intel Media SDK last week).

(Future step. - use directly the DX surface using OpenGL extensions.)

Now I'm stuck in the first and second steps, when avcodec_decode_video2  is called it crashes. I've debugged step by step the dxva initialization and the DX surfaces are being created correctly. What am I missing?

Libav-user mailing list
Sunil Morya | 14 Aug 11:32 2014

can libavcodec notify sli/pli/rpli

Hi All,


   To support AVPF (RFC 4585) in RTCP layer.  I need support for indication of slice loss, picture loss and reference picture loss from decoder using libavcodec to upper layer RTCP/RTP.


   Please provide your suggestions , if it is possible using libavcodec.     




Libav-user mailing list
Prashanth Bhat | 11 Aug 13:10 2014

H.264 decoding on Haswell CPU/Xubuntu 14.04

I'm using libavcodec to perform decoding of H.264 frames.  I'm on a Linux environment (14.04 Xubuntu), and Intel Haswell (Pentium grade) CPU. My program decodes the frames, without rendering them on the screen. With 4 simultaneous decodes of 1080p resolution and 15 fps, the CPU utilization is around 90% (not bad), but the load average shown by 'top' is 20+ This looks excessive. I don't think I'm using the hardware decoding ability of the Haswell CPU. Could someone please advise how to find out if I'm effectively using the decoder? The API calls I'm making are pretty standard -  avcodec_register_all(); avcodec_alloc_context3(NULL); avcodec_find_decoder(AV_CODEC_ID_H264); av_parser_init(AV_CODEC_ID_H264); avcodec_open2(); The above calls are made during initialization. The below calls are made on each frame - av_parser_parse2 avcodec_decode_video2 The following points are probably relevant -  a) The default context allocated by avcodec_alloc_context3() does not have any hw_accel associated with it. I allocated a h264_vaapi accelerator, but this doesn't lead to any improvement. b) The codec capabilities does not have the HW_ACCEL bit set.c) The same code worked better when used with Ubuntu 11.10 on a Sandybridge Pentium grade CPU and FFMPEG 0.9
Any help would be appreciated.  Thanks, Prashanth
Libav-user mailing list