Log in

View Full Version : [libavcodec] writing to a virtual file in memory


coordz
6th October 2008, 16:25
Continuing on my quest for lossless HD video capture to a rather slow disk.... I'm now using libavcodec with FFVHUFF lossless which works well capturing SD video to disk but sadly the harddrive in the computer is simply not fast enough to manage HD. My idea now is to capture segments of video into memory and then dump these non-realtime to the disk.

I'm currently using url_fopen() to open the output file. Is it possible to create this output file in memory? I'm thinking that I can create this whole file in a memory buffer and then simply dump it out when the capture is done. I could do this manually by buffering up all the packets before sending them to av_write_frame() but I was hoping it may be already implemented in the ffmpeg libraries.

TIA

akupenguin
7th October 2008, 11:09
If you're on linux, then it's trivial: use normal file output on a tmpfs partition, and the file will be held in memory.
If not, carry on with the URLContext.

Dark Shikari
7th October 2008, 11:11
Are you using adaptive huffman tables and median prediction with FFVHUFF? That should increase compression a bit, and could help you towards your goal.

coordz
7th October 2008, 16:39
I'm using adaptive Huff tables, plane/gradient prediction (because my source is RGB so no median prediction..... why? dunno ;)) and FFVHUFF. I tried FFV1 but it was too slow compressing. I don't want to convert to YUV b/c of the subsampling introduced.

@akupenguin What do you mean by carrying on using URLContext? I can't see how to use it to open a file in memory? Any pointers would be much appreciated.

akupenguin
7th October 2008, 22:55
RGB so no median prediction..... why? dunno
RGB median is of course not impossible, but if you want to know why it wasn't implemented in huffyuv: because losslessly decorrelated RGB takes 9bits if you store the whole value (needed for median), but can be done mod256 if you use only linear transforms (gradient).
I don't want to convert to YUV b/c of the subsampling introduced.
So just don't subsample.

coordz
8th October 2008, 05:47
So just don't subsample.

I believe FFVHUFF only supports PIX_FMT_YUV420P and PIX_FMT_YUV422P which are both subsampled formats...... Thanks for the insight into the median prediction for RGB. Very interesting.