[Libav-user] Does the image2 demuxer work with a custom AVIOContext?

2014-01-12 Thread Robert Krüger
Hi,

I am having problems programmatically extracting metadata like size
and pixel format from a dpx image using a custom AVIOContext. Should
that work or does the image2 demuxer only work with files even in the
single-file case? Or is there something I need to watch out for when
using it this way?

In my case the call to avformat_open_input fails already. The same
code generally works and has been used/tested with a lot of formats
for a long time. It just seems to fail on formats that the command
line tool opens with the image2 demuxer (I also tried jpg and png). Is
this related to not having a file name and if so, is there a way to
fix this?

Thanks in advance,

Robert
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


[Libav-user] Check an address to see if there is any video stream on it or not

2014-01-12 Thread Hadi
I want to read a video stream from a UDP address using libavcodec functions. To 
do so, I use the following code:

char *url = udp://127.0.0.1:1000;
AVFormatContext *oc = NULL;
avformat_open_input(oc, url, NULL , NULL);

If we run this code, then function avformat_open_input starts listening on 
the given UDP address, and it looks like the program is halted if there is no 
video stream at the given UDP address.

Now, I want to write a code to first check the given UDP address quickly to see 
whether there is any data on it or not, if there is no data then the program 
should neglect running avformat_open_input, otherwise it should run this 
function so that I can avoid the halting situation.

Any idea how I can do this? Thanks!   
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] Check an address to see if there is any video stream on it or not

2014-01-12 Thread Евгений Гарифуллин

12.01.2014, 22:23, Hadi hadi.hadiza...@hotmail.com:
 I want to read a video stream from a UDP address using libavcodec functions. 
 To do so, I use the following code:

 char *url = udp://127.0.0.1:1000;
 AVFormatContext *oc = NULL;
 avformat_open_input(oc, url, NULL , NULL);

 If we run this code, then function avformat_open_input starts listening on 
 the given UDP address, and it looks like the program is halted if there is no 
 video stream at the given UDP address.

 Now, I want to write a code to first check the given UDP address quickly to 
 see whether there is any data on it or not, if there is no data then the 
 program should neglect running avformat_open_input, otherwise it should run 
 this function so that I can avoid the halting situation.

 Any idea how I can do this? Thanks!
 ___
 Libav-user mailing list
 Libav-user@ffmpeg.org
 http://ffmpeg.org/mailman/listinfo/libav-user

use interrupt_callback function to unblock avformat_open_input(...);
concept:

time_t check_timestamp;

static int interrupt_cb(void* inputdata)
{
  time_t current_timestamp;
  current_timestamp = time(0)
  if (current_timestamp - check_timestamp = 10)
return true;  // interrupt blocked function
  else
return false; // NOT interrupt, wait more seconds...
}
...
oc = avformat_allocate_context();
oc-interrupt_callbacl = (AVIOInterruptCB){interrupt_cb, NULL};
checl_timestamp = time(0);
if (avformat_open_input(oc, url, NULL , NULL)  0)
{
   // error processing
}

something like that :) if avformat_open_input frezzes more than 10 seconds (in 
this example), interrupt_cb will break it execution.

--
С уважением, Евгений Гарифуллин.
e-mail: gri...@yandex.ru
jabber: joffad...@jabber.ufanet.ru
ICQ : 387906261
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] Does the image2 demuxer work with a custom AVIOContext?

2014-01-12 Thread Carl Eugen Hoyos
Robert Krüger krueger@... writes:

 I am having problems programmatically extracting metadata 
 like size and pixel format from a dpx image using a custom 
 AVIOContext. Should that work or does the image2 demuxer 
 only work with files even in the single-file case?

Contrary to all other demuxers, there is no auto-detection 
for image2, so (without looking at the actual code, sorry 
if it actually works differently) you have to either set 
demuxer and decoder or demuxer and a file name suffix.

Hope that helps, Carl Eugen

___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] Does the image2 demuxer work with a custom AVIOContext?

2014-01-12 Thread Hendrik Leppkes
On Sun, Jan 12, 2014 at 4:49 PM, Robert Krüger krue...@lesspain.de wrote:
 Hi,

 I am having problems programmatically extracting metadata like size
 and pixel format from a dpx image using a custom AVIOContext. Should
 that work or does the image2 demuxer only work with files even in the
 single-file case? Or is there something I need to watch out for when
 using it this way?

 In my case the call to avformat_open_input fails already. The same
 code generally works and has been used/tested with a lot of formats
 for a long time. It just seems to fail on formats that the command
 line tool opens with the image2 demuxer (I also tried jpg and png). Is
 this related to not having a file name and if so, is there a way to
 fix this?


image2 requires to directly access the files itself.
There is also a image2pipe, which can read the data from a avio
context, but in my experience it also didn't work properly because its
designed for a pipe scenario where it doesn't know the file size,
and therefor reads kinda blindly.

Now for custom IO that knows the size, but just wants to deliver the
data through its own IO functions, neither seem to work properly as of
today.

- Hendrik
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] Check an address to see if there is any video stream on it or not

2014-01-12 Thread Hadi
Thanks for the response, it works! :) I was thinking to put such a code within 
a thread. Whenever avformat_open_input finds a stream at the given address, 
then the thread can be terminated. In the meantime, the program can do other 
stuffs. But do you know how I can make a thread with libavcodec functions?


 From: gri...@yandex.ru
 To: libav-user@ffmpeg.org
 Date: Sun, 12 Jan 2014 22:38:51 +0600
 Subject: Re: [Libav-user] Check an address to see if there is any video 
 stream on it or not


 12.01.2014, 22:23, Hadi hadi.hadiza...@hotmail.com:
 I want to read a video stream from a UDP address using libavcodec functions. 
 To do so, I use the following code:

 char *url = udp://127.0.0.1:1000;
 AVFormatContext *oc = NULL;
 avformat_open_input(oc, url, NULL , NULL);

 If we run this code, then function avformat_open_input starts listening on 
 the given UDP address, and it looks like the program is halted if there is 
 no video stream at the given UDP address.

 Now, I want to write a code to first check the given UDP address quickly to 
 see whether there is any data on it or not, if there is no data then the 
 program should neglect running avformat_open_input, otherwise it should 
 run this function so that I can avoid the halting situation.

 Any idea how I can do this? Thanks!
 ___
 Libav-user mailing list
 Libav-user@ffmpeg.org
 http://ffmpeg.org/mailman/listinfo/libav-user

 use interrupt_callback function to unblock avformat_open_input(...);
 concept:

 time_t check_timestamp;

 static int interrupt_cb(void* inputdata)
 {
 time_t current_timestamp;
 current_timestamp = time(0)
 if (current_timestamp - check_timestamp= 10)
 return true; // interrupt blocked function
 else
 return false; // NOT interrupt, wait more seconds...
 }
 ...
 oc = avformat_allocate_context();
 oc-interrupt_callbacl = (AVIOInterruptCB){interrupt_cb, NULL};
 checl_timestamp = time(0);
 if (avformat_open_input(oc, url, NULL , NULL)  0)
 {
 // error processing
 }

 something like that :) if avformat_open_input frezzes more than 10 seconds 
 (in this example), interrupt_cb will break it execution.

 --
 С уважением, Евгений Гарифуллин.
 e-mail: gri...@yandex.ru
 jabber: joffad...@jabber.ufanet.ru
 ICQ : 387906261
 ___
 Libav-user mailing list
 Libav-user@ffmpeg.org
 http://ffmpeg.org/mailman/listinfo/libav-user 
   
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] Check an address to see if there is any video stream on it or not

2014-01-12 Thread redhat_doom
Thanks for the response, it works! :) I was thinking to put such a code
within a thread. Whenever avformat_open_input finds a stream at the given
address, then the thread can be terminated. In the meantime, the program can
do other stuffs. But do you know how I can make a thread with libavcodec
functions?



--
View this message in context: 
http://libav-users.943685.n4.nabble.com/Libav-user-Check-an-address-to-see-if-there-is-any-video-stream-on-it-or-not-tp4659115p4659119.html
Sent from the libav-users mailing list archive at Nabble.com.
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


[Libav-user] ffmpeg on android

2014-01-12 Thread Marcelo Paes Rech
Hi guys,

I am trying to do a stream player in android but I need to read a array of
bytes and then decode every packet of array of bytes. In the end started to
make my AAC decoder work with the ffmpeg example of decoder. But I ran into
the same problem of this guy:

http://stackoverflow.com/questions/13499480/decode-aac-to-pcm-with-ffmpeg-on-android

But the decoder does not work. I am receiving a error as follows:

TNS filter order %d is greater than maximum %d.
Error while decoding: -1

If I use the ffmpeg to decode it works fine.

ffmpeg -i audio.mp4 audio.wav

Environment:
ffmpeg 1.2
Android ndkr9b

Follows my source code:

AVCodec *codec;

AVCodecContext *c= NULL;

int len;

FILE *f, *outfile;

uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];

AVPacket avpkt;

AVFrame *decoded_frame = NULL;

av_log_set_callback(my_ffmpeg_log);

av_init_packet(avpkt);


printf(Decode audio file %s to %s\n, filename, outfilename);


/* find the mpeg audio decoder */

codec = avcodec_find_decoder(AV_CODEC_ID_AAC);

if (!codec) {

LOGV(Codec not found\n);

return;

}


c = avcodec_alloc_context3(codec);

c-channels = 2;

c-sample_rate = 48000;


if (!c) {

LOGV(Could not  allocate audio codec context\n);

return;

}


/* open it */

if (avcodec_open2(c, codec, NULL)  0) {

LOGV(Could not open codec\n);

return;

}


f = fopen(filename, rb);

if (!f) {

LOGV(Could not open %s\n, filename);

return;

}

outfile = fopen(outfilename, wb);

if (!outfile) {

av_free(c);

return;

}


/* decode until eof */

avpkt.data = inbuf;

avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);


while (avpkt.size  0) {

int got_frame = 0;


if (!decoded_frame) {

if (!(decoded_frame = avcodec_alloc_frame())) {

LOGV(Could not allocate audio frame\n);

return;

}

} else

avcodec_get_frame_defaults(decoded_frame);


len = avcodec_decode_audio4(c, decoded_frame, got_frame, avpkt);

if (len  0) {

LOGV(Error while decoding: %d\n, len);

return;

}

if (got_frame) {

/* if a frame has been decoded, output it */

int data_size = av_samples_get_buffer_size(NULL, c-channels,


decoded_frame-nb_samples,

   c-sample_fmt, 1);

fwrite(decoded_frame-data[0], 1, data_size, outfile);

}

avpkt.size -= len;

avpkt.data += len;

avpkt.dts =

avpkt.pts = AV_NOPTS_VALUE;

if (avpkt.size  AUDIO_REFILL_THRESH) {

/* Refill the input buffer, to avoid trying to decode

 * incomplete frames. Instead of this, one could also use

 * a parser, or use a proper container format through

 * libavformat. */

memmove(inbuf, avpkt.data, avpkt.size);

avpkt.data = inbuf;

len = fread(avpkt.data + avpkt.size, 1,

AUDIO_INBUF_SIZE - avpkt.size, f);

if (len  0)

avpkt.size += len;

}

}


fclose(outfile);

fclose(f);


avcodec_close(c);

av_free(c);

avcodec_free_frame(decoded_frame);

-- 
*Atenciosamente, Marcelo Paes Rech.*
E-mail: marcelopaesr...@gmail.com
Blog: http://marcelopaesrech.blogspot.com
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] Does the image2 demuxer work with a custom AVIOContext?

2014-01-12 Thread Carl Eugen Hoyos
Hendrik Leppkes h.leppkes@... writes:

 image2 requires to directly access the files itself.

Thank you for correcting me!

 There is also a image2pipe, which can read the data from a avio
 context, but in my experience it also didn't work properly because its
 designed for a pipe scenario where it doesn't know the file size,
 and therefor reads kinda blindly.

Could you elaborate a little on the shortcomings of image2pipe?
I seem to remember that it is used often.
Or do you just mean that too many parsers are missing?

Carl Eugen

___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] Does the image2 demuxer work with a custom AVIOContext?

2014-01-12 Thread Hendrik Leppkes
On Sun, Jan 12, 2014 at 8:02 PM, Carl Eugen Hoyos ceho...@ag.or.at wrote:
 Hendrik Leppkes h.leppkes@... writes:

 image2 requires to directly access the files itself.

 Thank you for correcting me!

 There is also a image2pipe, which can read the data from a avio
 context, but in my experience it also didn't work properly because its
 designed for a pipe scenario where it doesn't know the file size,
 and therefor reads kinda blindly.

 Could you elaborate a little on the shortcomings of image2pipe?
 I seem to remember that it is used often.
 Or do you just mean that too many parsers are missing?

Yeah it only works on img formats which have a parser to re-assemble
full images, so its use is a bit limited.
On the other hand, you can actually use it to pipe several images in
one command into it (if you have a parser), so both use-cases can be
useful i suppose.

- Hendrik
___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] Does the image2 demuxer work with a custom AVIOContext?

2014-01-12 Thread Carl Eugen Hoyos
Hendrik Leppkes h.leppkes@... writes:

 Yeah it only works on img formats which have a 
 parser to re-assemble full images, so its use is 
 a bit limited.

Note that I (?) implemented -frame_size for image 
formats with constant frame size.

Carl Eugen

___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user


Re: [Libav-user] ffmpeg on android

2014-01-12 Thread Sylvio José Alves Neto
Marcelo, have you initialized the ffmpeg using av_register_all()?

Also, when building the ffmpeg, have you included encoding/decoding/
parsing support for aac?

Sylvio
 Em 12/01/2014 16:18, Marcelo Paes Rech marcelopaesr...@gmail.com
escreveu:

 Hi guys,

 I am trying to do a stream player in android but I need to read a array of
 bytes and then decode every packet of array of bytes. In the end started to
 make my AAC decoder work with the ffmpeg example of decoder. But I ran into
 the same problem of this guy:


 http://stackoverflow.com/questions/13499480/decode-aac-to-pcm-with-ffmpeg-on-android

 But the decoder does not work. I am receiving a error as follows:

 TNS filter order %d is greater than maximum %d.
 Error while decoding: -1

 If I use the ffmpeg to decode it works fine.

 ffmpeg -i audio.mp4 audio.wav

 Environment:
 ffmpeg 1.2
 Android ndkr9b

 Follows my source code:

 AVCodec *codec;

 AVCodecContext *c= NULL;

 int len;

 FILE *f, *outfile;

 uint8_t inbuf[AUDIO_INBUF_SIZE + FF_INPUT_BUFFER_PADDING_SIZE];

 AVPacket avpkt;

 AVFrame *decoded_frame = NULL;

 av_log_set_callback(my_ffmpeg_log);

 av_init_packet(avpkt);


 printf(Decode audio file %s to %s\n, filename, outfilename);


 /* find the mpeg audio decoder */

 codec = avcodec_find_decoder(AV_CODEC_ID_AAC);

 if (!codec) {

 LOGV(Codec not found\n);

 return;

 }


 c = avcodec_alloc_context3(codec);

 c-channels = 2;

 c-sample_rate = 48000;


 if (!c) {

 LOGV(Could not  allocate audio codec context\n);

 return;

 }


 /* open it */

 if (avcodec_open2(c, codec, NULL)  0) {

 LOGV(Could not open codec\n);

 return;

 }


 f = fopen(filename, rb);

 if (!f) {

 LOGV(Could not open %s\n, filename);

 return;

 }

 outfile = fopen(outfilename, wb);

 if (!outfile) {

 av_free(c);

 return;

 }


 /* decode until eof */

 avpkt.data = inbuf;

 avpkt.size = fread(inbuf, 1, AUDIO_INBUF_SIZE, f);


 while (avpkt.size  0) {

 int got_frame = 0;


 if (!decoded_frame) {

 if (!(decoded_frame = avcodec_alloc_frame())) {

 LOGV(Could not allocate audio frame\n);

 return;

 }

 } else

 avcodec_get_frame_defaults(decoded_frame);


 len = avcodec_decode_audio4(c, decoded_frame, got_frame, avpkt);

 if (len  0) {

 LOGV(Error while decoding: %d\n, len);

 return;

 }

 if (got_frame) {

 /* if a frame has been decoded, output it */

 int data_size = av_samples_get_buffer_size(NULL, c-channels,


 decoded_frame-nb_samples,

c-sample_fmt, 1);

 fwrite(decoded_frame-data[0], 1, data_size, outfile);

 }

 avpkt.size -= len;

 avpkt.data += len;

 avpkt.dts =

 avpkt.pts = AV_NOPTS_VALUE;

 if (avpkt.size  AUDIO_REFILL_THRESH) {

 /* Refill the input buffer, to avoid trying to decode

  * incomplete frames. Instead of this, one could also use

  * a parser, or use a proper container format through

  * libavformat. */

 memmove(inbuf, avpkt.data, avpkt.size);

 avpkt.data = inbuf;

 len = fread(avpkt.data + avpkt.size, 1,

 AUDIO_INBUF_SIZE - avpkt.size, f);

 if (len  0)

 avpkt.size += len;

 }

 }


 fclose(outfile);

 fclose(f);


 avcodec_close(c);

 av_free(c);

 avcodec_free_frame(decoded_frame);

 --
 *Atenciosamente, Marcelo Paes Rech.*
 E-mail: marcelopaesr...@gmail.com
 Blog: http://marcelopaesrech.blogspot.com


 ___
 Libav-user mailing list
 Libav-user@ffmpeg.org
 http://ffmpeg.org/mailman/listinfo/libav-user


___
Libav-user mailing list
Libav-user@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/libav-user