saving video stream to a file

199 views
Skip to first unread message

cesar pachon

unread,
Mar 26, 2015, 5:32:37 PM3/26/15
to native-cli...@googlegroups.com
hi, I am working on capturing current tab as video from a chrome extension and need to store it as a video file to upload to a server.
right now I have the chrome extension with the capturing mechanism, passing the stream to a pnacl module based on the video_stream_demo (but without the OpenGL part).

what I need now is to pass the frames to something that creates the a video file, like ffmpeg or so. My question is: there is some chrome wrapper for doing that or my only option is to work directly with ffmpeg calls (naclport)?
do you know if there is some demo or tutorial that would guide me on this?

thank you

Bill Budge

unread,
Mar 27, 2015, 9:23:32 AM3/27/15
to native-cli...@googlegroups.com
A new API got added a few weeks ago, PPB_VideoEncoder, that might work for you.

Check out the video_decoder example in the NaCl SDK. It does most of what you're doing, except it posts the encoded stream back to the page instead of saving it to a file. I think you would have to do some additional work to mux the bitstream back into a playable file format.

cesar pachon

unread,
Mar 27, 2015, 10:49:50 AM3/27/15
to native-cli...@googlegroups.com
hi Bill thank you for your reply. The PPB_VIdeoEncoder class looks really nice, even what I need is quite the opposite: based on video_stream_demo I am already receiving frames from the browser, and I need to encode, no to decode, the stream.

In the other hand, your mention of the  PPB_VideoEncoder is quite interesting, but I had not been able to find it in the stable, beta nor dev NACL SDK documentation, nor I found the video_decoder example in my local nacl sdk (pepper_41, pepper_cannary). would you mind to explain me how to get that example?

thank you

cesar pachon

unread,
Mar 27, 2015, 10:50:40 AM3/27/15
to native-cli...@googlegroups.com
sorry I mean "video_encoder" example.. I got confussed :)

Bill Budge

unread,
Mar 28, 2015, 9:55:32 AM3/28/15
to native-cli...@googlegroups.com
I double checked, and the video_encoder example is not yet in the SDK. The patch is under review:

You could copy these files into your NaCl SDK folder, though you'll probably need the canary version of NaCl SDK to build this.

You can also find the example in the chromium repository (src/ppapi/examples/video_encoder) if you build chrome.

cesar pachon

unread,
Apr 8, 2015, 10:19:32 PM4/8/15
to native-cli...@googlegroups.com
hello,

Finally I am working using as reference the example located at:
nacl_sdk/pepper_41/toolchain/linux_pnacl/le32-nacl/usr/share/ffmpeg/examples/muxer.c

and I also had success using the nacl_io api to create,list and delete files in the sandboxed filesystem.

but I need to connect both things, it is: passing a file created with the nacl_io API as output for the ffmpeg muxer.

I am blocked here because the call to avformat_alloc_output_context2 receives a filename, not a file object, as argument, and I am not sure how to replace that call.

Also I wonder if there are multithreading issues, because the samples for nacl_io uses a separate thread, and I can't figure how it can be done with the muxer.

I highly appreciate any suggestion on this,

Sam Clegg

unread,
Apr 9, 2015, 7:15:51 PM4/9/15
to native-cli...@googlegroups.com
Hi Cesar,

Any code that does POSIX file I/O needs to run an a background thread.
However if you using ppapi_simple (which most code in naclports does)
then all your code is already running on a background thread so you
don't need to worry about this.

Presumably the ffmpeg will automatically create a new file using
open()? All you need to do is decide where you want to file to be
written. Normally /mnt/tmp/... corresponds to the html5 filesystem,
and / is a memfs by default so /foo we create a file called foo in
memory.

cheers,
sam
> --
> You received this message because you are subscribed to the Google Groups
> "Native-Client-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to native-client-di...@googlegroups.com.
> To post to this group, send email to native-cli...@googlegroups.com.
> Visit this group at http://groups.google.com/group/native-client-discuss.
> For more options, visit https://groups.google.com/d/optout.

cesar pachon

unread,
Apr 9, 2015, 10:15:48 PM4/9/15
to native-cli...@googlegroups.com
hello Sam, thank you for replying!

as in understand, ppapi_simple is the interface between js and native code, and it is by nature async.. so, yes, I am using it.

but, as you mention, in the native code, the file I/O operations seems to be required to be used in another (native) thread. I am using that too.

as you guess correctly, ffmpeg has methods that are supposed to create the output file based on a string (path), but when you try these methods inside NACL, they fail with a message that says something like "native operations are not implemented" or similar. my understanding is that all the standard fopen, fread, etc methods had been overrided to empty impliementations in NACL for security reasons, and you are forced to use the nacl_io versions, that are not directly consumible for the normal ffmpeg methods.

please let me know if all what I said is right, and correct me if I am doing wrong assumptions.

Today I had been playing with another approach: I am trying to encode the video file to a memory buffer, instead of a file. my expectation is after having the buffer completed, write it to filesystem using nacl_io. I will post if this approach works.

Sam Clegg

unread,
Apr 10, 2015, 12:15:51 PM4/10/15
to native-cli...@googlegroups.com
On Thu, Apr 9, 2015 at 7:15 PM, cesar pachon <cesar...@gmail.com> wrote:
> hello Sam, thank you for replying!
>
> as in understand, ppapi_simple is the interface between js and native code,
> and it is by nature async.. so, yes, I am using it.
>
> but, as you mention, in the native code, the file I/O operations seems to be
> required to be used in another (native) thread. I am using that too.

If you are using ppapi_simple then your main function is already
running on a background thread. You don't need to create another.

> as you guess correctly, ffmpeg has methods that are supposed to create the
> output file based on a string (path), but when you try these methods inside
> NACL, they fail with a message that says something like "native operations
> are not implemented" or similar. my understanding is that all the standard
> fopen, fread, etc methods had been overrided to empty impliementations in
> NACL for security reasons, and you are forced to use the nacl_io versions,
> that are not directly consumible for the normal ffmpeg methods.

nacl_io, allows applications to use standard POSIX file I/O APIs such
as fopen/open fread/read, etc. So if you are linking it in and
initializing it correctly ffmpeg should not be getting such error
messages. Also, ppapi_simple will initialize nacl_io on startup for
you. Are you sure you use linking the ppapi_simple library and
using it to run your main function?
>> > email to native-client-di...@googlegroups.com.
>> > To post to this group, send email to native-cli...@googlegroups.com.
>> > Visit this group at
>> > http://groups.google.com/group/native-client-discuss.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Native-Client-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to native-client-di...@googlegroups.com.

cesar pachon

unread,
Apr 10, 2015, 12:30:18 PM4/10/15
to native-cli...@googlegroups.com
hi Sam, you are right, I checked my makefile and I was linking against ppapi_cpp, not ppapi_simple. I really was not aware of that difference. I am going to check if ffmpeg code works  with this library.

thank you!


LDFLAGS := -L$(NACL_SDK_ROOT)/lib/pnacl/Debug -lppapi_cpp -lppapi $(FFMPEG_LIBS)
>> > To post to this group, send email to native-cli...@googlegroups.com.
>> > Visit this group at
>> > http://groups.google.com/group/native-client-discuss.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Native-Client-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Steve Farthing

unread,
Jun 2, 2015, 9:41:26 AM6/2/15
to native-cli...@googlegroups.com
Hello Cesar,

I am also working on capturing video from a chrome extension and storing it in a video file. Any chance you would share some of this code ?

Thanks,
Steve

cesar pachon

unread,
Jun 2, 2015, 6:14:40 PM6/2/15
to native-cli...@googlegroups.com
hi Steve, I am sorry but the code is owned by the company I work for. However I will try to answer as best as possible all your questions on this topic.

greetings,

Cesar

Cesar  Pachón
-------------------------------------------------------------
www.cesarpachon.com, just a digital hermit


Steve
>> > To post to this group, send email to native-cli...@googlegroups.com.
>> > Visit this group at
>> > http://groups.google.com/group/native-client-discuss.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Native-Client-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> To post to this group, send email to native-cli...@googlegroups.com.
> Visit this group at http://groups.google.com/group/native-client-discuss.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/native-client-discuss/Kci1pp6CWIg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to native-client-di...@googlegroups.com.

socialpsych...@gmail.com

unread,
Jun 5, 2015, 3:04:31 PM6/5/15
to native-cli...@googlegroups.com
Thanks Cesar,

The PPB_Encoder example (mentioned above) works for me and its a lot smaller than the ffmpeg port. Support for it is in the dev channel (Chrome 45) currently, but I expect support for it will be in the stable release by July.


Thanks,
Steve
Steve
>> > To post to this group, send email to native-cli...@googlegroups.com.
>> > Visit this group at
>> > http://groups.google.com/group/native-client-discuss.
>> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Native-Client-Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> To post to this group, send email to native-cli...@googlegroups.com.
> Visit this group at http://groups.google.com/group/native-client-discuss.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Native-Client-Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/native-client-discuss/Kci1pp6CWIg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to native-client-discuss+unsub...@googlegroups.com.

findearlya...@gmail.com

unread,
Jun 9, 2016, 7:43:42 PM6/9/16
to Native-Client-Discuss
Hi Steve,

I am trying to build something similar to what you described, if you can share the code that you have build will be great learning. I can not find anything after two days of search. 

Thanks,
Mohammad
Reply all
Reply to author
Forward
0 new messages