# Using python scripts in GNURadio blocks?

**URL:** <https://www.ruby-forum.com/t/using-python-scripts-in-gnuradio-blocks/240426>\
**Category:** GNU Radio\
**Created:** [April 14, 2014, 4:59am UTC](https://www.ruby-forum.com/t/using-python-scripts-in-gnuradio-blocks/240426 "2014-04-14T04:59:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [April 14, 2014, 4:59am UTC](https://www.ruby-forum.com/t/using-python-scripts-in-gnuradio-blocks/240426/1 "2014-04-14T04:59:56Z")

</div>

I have a flow graph where I’d like to run ffmpeg/avconv, and tscbrmux as  
blocks. Is there a way to use FFMPEG and other scripts as GRC blocks?

---

<div class="post-metadata">

**Author:** ![jowijo](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e95f7d/32.png) [@jowijo](https://www.ruby-forum.com/u/jowijo)\
**Post date:** [April 14, 2014, 9:01am UTC](https://www.ruby-forum.com/t/using-python-scripts-in-gnuradio-blocks/240426/2 "2014-04-14T09:01:10Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

Hi Jordan,

ok, there’s two questions here:

1. Can I run arbitrary python code as block?
2. How do I use external programs in a block? (ffmpeg and the  
transcode tools are not python modules but executables on their own)

So there’s two answers here:

1. That’s exactly what a python block is. Follow the “how to write an  
out-of-tree module” guide in the GNU Radio wiki. Just fill in your  
functionality in the work method.
2. This gets a little trickier. Since these programs are external, you  
can’t rely on them giving you a fixed amount of output per input.  
Usually, they work on complete files – which is quite the opposite of  
what’s the idea behind GNU Radio. Two ideas:  
a.) (if the used program allows you to stream data into it using  
stdin) use the python subprocess module to start the program and pipe  
samples into it. Block the work() until you get sufficient output from  
the process. This is a hack and has lots of downsides.  
b.) see if you can find the functionality wrapped for python (I don’t  
think there is a working python binding for ffmpeg right now,maybe  
there are bindings for libav, maybe use gstreamer or so). Use that.  
If python bindings don’t exist, instead of writing a python block,  
write a C++ block.

Greetings,  
Marcus

On 14.04.2014 04:58, Jordan J. wrote:

> I have a flow graph where I’d like to run ffmpeg/avconv, and  
> tscbrmux as blocks. Is there a way to use FFMPEG and other scripts  
> as GRC blocks?
> 
> \_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_ Discuss-gnuradio  
> mailing list [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [Discuss-gnuradio Info Page](https://lists.gnu.org/mailman/listinfo/discuss-gnuradio)

-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1  
Comment: Using GnuPG with Thunderbird - [http://www.enigmail.net/](http://www.enigmail.net/)

iQEcBAEBAgAGBQJTS4ddAAoJEBQ6EdjyzlHtzVIH/jp56DjBLyzjH46J2FExUYMG  
EkP8m3cQ16M4SxVCVr3agwasqgnROSTylKZbsUAUoigsJo6eJ4Vqvqp/0EfRoL0M  
yNA1H12L+9TFRZ1F1J/85XxnDT9kgYc7MsJlINySiy3ilag0dzP59GbAdh23X5N/  
KjPSDneYZhlmACOaR58JvoN1czNLOlDQYOQyVA8O8riZZnwzibmhUCS/dlhz1yST  
YJ04Yp8OgtREENYzIwbH2rclxo3dRpdSSA2x81MT2C+icH3tFkRbkfXdrOW7d0lC  
9E/qVeho98VGLWjGwASXwxpumwfmS/qeG+Iz/ijB9PPNHrLqzPg6ZwgRI0nfgXs=  
=Y00L  
-----END PGP SIGNATURE-----
