3

I am currently doing:

source_path = 'file:///home/raj/videos/sample.mpg'
descr = 'uridecodebin uri=%s ! videoconvert ! gdkpixbufsink name=sink' % (source_path)
pipeline = Gst.parse_launch(descr)

But instead of using uri, how can I use a raw file source, such as from source_file = request.POST['file'].file. (Perhaps that would be loading a video file from a string?)

My research thus far has led me to appsrc ( http://ingo.fargonauten.de/node/447 ), but I am not sure how to use it with GStreamer 1.0, as I cannot figure out how to load the file into the buffer:

raw_src = request.POST['files[]'].file
descr = 'appsrc name=vidsrc ! videoconvert ! gdkpixbufsink name=sink'
pipeline = Gst.parse_launch(descr)
appsrc = pipeline.get_by_name('vidsrc')
appsrc.emit('push-buffer', Gst.Buffer(raw_src.read()) ##I am not creating the buffer correctly for GStreamer 1.0
Raj
  • 1,479
  • 3
  • 15
  • 29
  • I don't quite understand your goal. Are you hoping to call GStreamer from within a web script? – Multimedia Mike Mar 24 '13 at 00:47
  • @MultimediaMike, Yes I am. The end-user is uploading a video to the website, and I want to pass that file object to appsrc (or any appropriate element) to utilize the file. The file is not yet saved to the harddrive, so I have no path for it. – Raj Mar 24 '13 at 00:52
  • So the file will be held in memory for this entire process? Video files can get pretty big. Are you sure you wouldn't rather store this in a temporary file? It should be possible to encode from memory, but I'm wondering about the overall architecture. Is there a file upload size limit? – Multimedia Mike Mar 24 '13 at 03:55
  • @MultimediaMike There is no file upload size limit. I am making 10 thumbnails from any video that is uploaded. Is that a time intensive process? – Raj Mar 24 '13 at 03:57

2 Answers2

1

There are a couple of options you can use:

  1. Pipe, create a set of pipes, write the file content to the write pipe and pass in the read pipe to fdsrc using the fd property.

  2. Create a temporary file using the tempfile module, write the content and pass in the file to to filesink using the filename property.

  3. Appsrc, but you need to connect to the push-buffer and end-of-stream signals, create buffers from the data. It's better to avoid this option as you have to do the reading in python, it's more efficient to use fdsrc/filesink as parts of the processing is done in C.

Johan Dahlin
  • 25,300
  • 6
  • 40
  • 55
  • My (MVC-style) webframework has a transaction manager which automatically puts the uploaded file into a temporary directory (I have no access to the temporary file's name/path). So therefore I'm left with a file I can `.read()` – Raj Mar 24 '13 at 17:55
  • I would like to see an example of the code to do your first suggestion and 3rd suggestions please. Preferably, I would like to stick with the `descr` and `Gst.parse_lauch(descr)` format, since that is the way I already have all the code setup. And redoing method of pipeline creation may cause a host of other issues – Raj Mar 24 '13 at 18:00
0

If you have a real file object rather than just file-like, you can use fdsrc directly instead of using pipes in between.

To adapt from the code in the question, something like this should work:

descr = 'fdsrc name=vidsrc ! decodebin ! videoconvert ! gdkpixbufsink name=sink'
pipeline = Gst.parse_launch(descr)

src = pipeline.get_by_name('vidsrc')
src.props.fd = source_file.fileno()

You want to add decodebin since you're switching from uridecodebin, fd source will not likely provide the kind of input that videoconvert/pixbufsink needs.

Juhaz
  • 26
  • 2