Read from a buffer instead of a file
Hi, is it possible to read video from a buffer instead of a file with libav(codec/format) ? I have MPEG2-TS video in a buffer, and cannot use "av_open_input_file" and the "av_read_frame" on a buffer, it only works from a file. Anyone has an idea how to do that ? Thanks in advance, --Raphael HUCK
Hi,
is it possible to read video from a buffer instead of a file with libav(codec/format) ?
I have MPEG2-TS video in a buffer, and cannot use "av_open_input_file" and the "av_read_frame" on a buffer, it only works from a file.
Anyone has an idea how to do that ?
You can add your own url protocol... For example I once made something with a bdataio protocol that would read from a BDataIO C++ object. Want the code ? Fran?ois.
What do you mean by url protocol ? Does adding my own url protocol implies modifying the source code of libav(codec/format) or is it possible to do without touching it (so people with the libavcodec library can use my program without altering their library) ? Btw, did you find some documentation to add your own url protocol ? There's not much documentation on libavcodec I could find... And finally, yes, I am very interested in your code, and I appreciate your help very much. Thanks. --Raphael
Hi,
is it possible to read video from a buffer instead of a file with libav(codec/format) ?
I have MPEG2-TS video in a buffer, and cannot use "av_open_input_file" and the "av_read_frame" on a buffer, it only works from a file.
Anyone has an idea how to do that ?
You can add your own url protocol... For example I once made something with a bdataio protocol that would read from a BDataIO C++ object.
Want the code ?
Fran?ois.
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu http://mplayerhq.hu/mailman/listinfo/ffmpeg-devel
What do you mean by url protocol ?
The pseudo class (a C struct with function pointers) handling input from different url types (pipe:, file:, http:...). url_open() selects one of them based on the url. See libavformat/avio.h
Does adding my own url protocol implies modifying the source code of libav(codec/format) or is it possible to do without touching it (so people with the libavcodec library can use my program without altering their library) ?
No you can avio.h:register_protocol(), or just fake an open (open "/dev/null") and override the url field in the cookie to your own protocol, as I did.
Btw, did you find some documentation to add your own url protocol ? There's not much documentation on libavcodec I could find...
And finally, yes, I am very interested in your code, and I appreciate your help very much.
See attached files, part of some unreleased dead project. Sent them on the list in case other ppl are interested, for archival. Fran?ois.
Hi, I have an MPEG2-TS video in a buffer, but I cannot read it using libavformat. Nevertheless, I've got no problems when I read/decode the same video from a file, so I guess there must be a way to get things working with a buffer instead. Anyone could help? Enrique.
Hi,
I have an MPEG2-TS video in a buffer, but I cannot read it using libavformat. Nevertheless, I've got no problems when I read/decode the same video from a file, so I guess there must be a way to get things working with a buffer instead.
Cf. a recent thread about this: http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/26784 Fran?ois.
Hi,
I have an MPEG2-TS video in a buffer, but I cannot read it using libavformat. Nevertheless, I've got no problems when I read/decode the same video from a file, so I guess there must be a way to get things working with a buffer instead.
Cf. a recent thread about this: http://thread.gmane.org/gmane.comp.video.ffmpeg.devel/26784
Actually it's the very thread you replied to when asking, what about you read before asking ?? Fran?ois.
Fran?ois Revol wrote:
Actually it's the very thread you replied to when asking, what about you read before asking ??
Fran?ois.
Yes, I had already read that thread, but as I wasn't able to achieve what I was looking for with the code you provided and as nobody else seemed to be contributing with it, I just wanted to ask for further help. Sincerely, sorry for the confussion. I didn't mean to bother. Enrique.
Hi, We have done this for a MPEG2-PS without changing anything in the libavformat code, but I guess that won't really matter. The following code is extracts which we use to parse the MPEG"-stream into MPEG2 packets which we then decode using avdecode. // --------------------------------------------- // First we declare a buffer read funtion (which reads directly from an mpeg2 compression card). // This can be replaced by reading from a buffer, make sure not to return 0 from this function, // since that will stop the parsing. int read_function(void * opaque, uint8_t *buf, int buf_size){ some_struct * data_struct = (some_struct * ) opaque; unsigned int data_to_copy = buf_size; int t = ReadFromCard(data_struct->board_handle, buf, &data_to_copy); return data_to_copy; } // --------------------------------------------- // init av format stuff input_format = av_find_input_format("mpeg"); input_format->flags |= AVFMT_NOFILE; av_packet.data = NULL; io = new ByteIOContext(); unsigned char * buffer = new unsigned char[ buffer_size ]; int ret = init_put_byte(io, buffer, buffer_size, 0, private_data, read_function, NULL, NULL); io->is_streamed = 1; // open the format context av_open_input_stream(&format_context, io, "", input_format, NULL); ---------------------------------------------- // then we loop, i.e. read one packet av_packet.pts = AV_NOPTS_VALUE; while(av_packet.pts == AV_NOPTS_VALUE){ int res = av_read_frame(format_context, &av_packet); if((res == 0)&& (av_packet.pts != AV_NOPTS_VALUE)){ break; } // Free packet if (av_packet.data != NULL){ av_free_packet(&av_packet); av_packet.data = NULL; } } ---------------------------------------------- regards Tomas Christiansson
-----Original Message----- From: ffmpeg-devel-bounces at mplayerhq.hu [mailto:ffmpeg-devel-bounces at mplayerhq.hu] On Behalf Of Enrique Estalayo Sent: den 9 januari 2006 16:44 To: FFMpeg development discussions and patches Subject: [Ffmpeg-devel] Reading video from a buffer
Hi,
I have an MPEG2-TS video in a buffer, but I cannot read it using libavformat. Nevertheless, I've got no problems when I read/decode the same video from a file, so I guess there must be a way to get things working with a buffer instead.
Anyone could help?
Enrique.
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel at mplayerhq.hu http://mplayerhq.hu/mailman/listinfo/ffmpeg-devel
Hi Francois, Do you still have the code for your bdataio protocol? I can't seems to download from it... - Bernard
Hi Francois,
Do you still have the code for your bdataio protocol? I can't seems to download from it...
My webspace got deleted long ago, didn't feel like putting everything back. Here it is for reference. It's not really clean, and the suggested method of passing a pointer through an url string is probably more robust against libavformat internal changes. Actually I'm not even sure that code still works :) Fran?ois.
participants (5)
-
eeg223@tid.es -
raphaelh@nist.gov -
revol@free.fr -
siahwb@artivision.com.sg -
tomas.christiansson@gasoptics.com