[Product-Developers] Re: Capture still image from video/automatically assign P4A file image

Espen Moe-Nilssen espen at medialog.no
Thu Sep 24 07:52:27 UTC 2009


If I understand this right and you got this to work:

1) Add a "p4video-file" to plone
2) The first frame of the image shows as the video/image.

I am pretty sure the people behind p4artists would like that code....


Espen



Den 23. sep. 2009 kl. 18.19 skrev Brayton Osgood:

> Between this and IRC I've got the image capture working. Still have  
> to write the captured image back into Plone, but I think I have  
> that under control. Thanks for all the help,
>
> Brayton
>
> Here is the code I used (for future Googlers):
>
>   context = aq_inner(file)
>   movie_data = context.get_data()
>
>   movie_id, movie_name = tempfile.mkstemp('.mov',text=False)
>   image_id, image_name = tempfile.mkstemp('jpg', text=False)
>   output_id, output_name = tempfile.mkstemp()
>   wfile = open(movie_name, 'wb')
>   wfile.write(movie_data)
>   wfile.close()
>
>   args = "ffmpeg -i %s -ss 1 -an -vframes 1 -f image2 %s" %  
> (movie_name, image_name)
>   p = sub.Popen(args, shell=True, stdin=sub.PIPE,  
> stdout=output_name, stderr=sub.STDOUT)
>
>
> On Sep 23, 2009, at 1:38 AM, Jean-Michel FRANCOIS wrote:
>
>> Tom Gross a écrit :
>>>
>>> Hi Brayton,
>>>
>>>   p4a-video uses the File-content-type, which again uses OFS.File as
>>> content-class. If you want to access the raw-data use:
>>>
>>> atfileobject.getFile().data
>>>
>>> or
>>>
>>> str(atfileobject.getFile())
>>>
>>> If you need a file-like object, you have to do:
>>>
>>> stream = StringIO(str(atfileobject.getFile()))
>>>
>>> HTH
>>> -Tom
>>>
>>>
>>> Brayton Osgood wrote:
>>>
>>>> I'm trying to extend P4A Video to automatically generate the  
>>>> file images
>>>> that can be added to each video via the edit panel of any  
>>>> IVideoEnhanced
>>>> content. Ideally, the result will be an adapter (I think) that  
>>>> responds
>>>> to the IVideoEnhanced interface.
>>>>
>>>> Right now I'm running into trouble capturing an image from a  
>>>> video file
>>>> once it's stored in Plone. I've tried calling ffmpeg as a  
>>>> subprocess,
>>>> but I get an I/O error (see below):
>>>>
>>>>
>>>>>>> image = subprocess.Popen('ffmpeg -i moviefile -ss 1 -an - 
>>>>>>> vframes 1
>>>>>>>
>>>> -f image2 thumb%2d.jpg', shell=True, stdin=subprocess.PIPE,
>>>> stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
>>>>
>>>>>>> print image.stdout.read()
>>>>>>>
>>>> FFmpeg version SVN-rUNKNOWN, Copyright (c) 2000-2007 Fabrice  
>>>> Bellard, et
>>>> al.
>>>>   configuration: --enable-gpl --enable-pp --enable-swscaler
>>>> --enable-pthreads --enable-libvorbis --enable-libtheora --enable- 
>>>> libogg
>>>> --     enable-libgsm --enable-dc1394 --disable-debug --enable- 
>>>> shared
>>>> --prefix=/usr
>>>>   libavutil version: 1d.49.3.0
>>>>   libavcodec version: 1d.51.38.0
>>>>   libavformat version: 1d.51.10.0
>>>>   built on Mar 16 2009 21:19:49, gcc: 4.2.4 (Ubuntu 4.2.4-1ubuntu3)
>>>> moviefile: I/O error occured
>>>> Usually that means that input file is truncated and/or corrupted.
>>>>
>>>> I've tried doing this where 'moviefile' is an <ATFile at
>>>> /Plone/Members/brayt/jumping2.mov> object, a <p4a.video  
>>>> _ATCTFileVideo>
>>>> object (applying the IVideo interface to the ATFile), and even the
>>>> binary data (passed by moviefile.getData()). Each case gives me  
>>>> the same
>>>> error.
>>>>
>>>> I suspect this is because ffmpeg expects to receive certain file  
>>>> types,
>>>> and Plone files are somehow wrapped so they aren't recognized. I  
>>>> guess
>>>> my question may boil down to how do I access (and do something  
>>>> useful
>>>> with) the data in a file that's not normally read by Plone? I  
>>>> suspect
>>>> that the indexing of PDFs behaves similarly to what I'm hoping  
>>>> to do,
>>>> but I haven't quite figured out how that works.
>>>>
>>>> Any help would be greatly appreciated!
>>>>
>>>> Thanks much,
>>>>
>>>> Brayton
>>>>
>>>
>>>
>>> _______________________________________________
>>> Product-Developers mailing list
>>> Product-Developers at lists.plone.org
>>> http://lists.plone.org/mailman/listinfo/product-developers
>>>
>> To call it with subprocess :
>> - use mkstemp python module to create a temp file
>> - write the raw data inside it
>> - do the subprocess on that new tempfile
>> - don't forget to delete the temp file
>> - write the image inside your image field.
>>
>> -- 
>> Cordialement,
>> Jean-Michel FRANCOIS
>> Makina-Corpus
>
> _______________________________________________
> Product-Developers mailing list
> Product-Developers at lists.plone.org
> http://lists.plone.org/mailman/listinfo/product-developers

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.plone.org/pipermail/plone-product-developers/attachments/20090924/c1deb6e4/attachment.html>


More information about the Product-Developers mailing list