Skip to content

Commit

Permalink
cleanup swig examples
Browse files Browse the repository at this point in the history
- change deprecated `sdl` consumer to `sdl2`
- remove defunct, low priority consumer `rescale`="none"
- fix python module import
- fix play.py error handling
- add auto-profile to play.py
  • Loading branch information
ddennedy committed Oct 5, 2024
1 parent fd30d28 commit c75721e
Show file tree
Hide file tree
Showing 14 changed files with 47 additions and 51 deletions.
3 changes: 1 addition & 2 deletions src/swig/csharp/play.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ public static void Main(String[] args) {
Profile profile = new Profile("");
Producer p = new Producer(profile, args[0], null);
if (p.is_valid()) {
Consumer c = new Consumer(profile, "sdl", null);
c.set("rescale", "none");
Consumer c = new Consumer(profile, "sdl2", null);
c.connect(p);
c.start();
while (!c.is_stopped())
Expand Down
5 changes: 1 addition & 4 deletions src/swig/java/Play.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ public static void main (String[] args) {
p.set ("eof", "loop");

// Create the consumer
Consumer c = new Consumer( profile, "sdl", null);
Consumer c = new Consumer( profile, "sdl2", null);

// Turn off the default rescaling
c.set("rescale", "none");

// Connect the producer to the consumer
c.connect(p);

Expand Down
3 changes: 1 addition & 2 deletions src/swig/lua/play.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ mlt.Factory_init()
profile = mlt.Profile()
producer = mlt.Producer( profile, arg[1] )
if producer:is_valid() then
consumer = mlt.Consumer( profile, "sdl" )
consumer:set( "rescale", "none" )
consumer = mlt.Consumer( profile, "sdl2" )
consumer:set( "terminate_on_pause", 1 )
consumer:connect( producer )
event = consumer:setup_wait_for( "consumer-stopped" )
Expand Down
2 changes: 1 addition & 1 deletion src/swig/nodejs/play.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ if (!producer.is_valid()) {

console.log('get_fps', producer.get_fps())

let consumer = new Consumer(profile, 'sdl')
let consumer = new Consumer(profile, 'sdl2')

consumer.connect(producer)
consumer.start()
Expand Down
5 changes: 1 addition & 4 deletions src/swig/perl/play.pl
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
$p->set( "eof", "loop" );

# Create the consumer
$c = new mlt::FilteredConsumer( $profile, "sdl" );

# Turn of the default rescaling
$c->set( "rescale", "none" );
$c = new mlt::FilteredConsumer( $profile, "sdl2" );

# Connect the producer to the consumer
$c->connect( $p );
Expand Down
2 changes: 1 addition & 1 deletion src/swig/php/play.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
$profile = new_profile("dv_ntsc");
$p = new_producer( $profile, $filename );
if ( $p ) {
$c = new_consumer( $profile, "sdl" );
$c = new_consumer( $profile, "sdl2" );
consumer_connect( $c, $p );
$e = properties_setup_wait_for( $c, "consumer-stopped" );
consumer_start( $c );
Expand Down
14 changes: 7 additions & 7 deletions src/swig/python/codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@

# Import required modules
from __future__ import print_function
import mlt
import mlt7 as mlt

# Start the mlt system
mlt.Factory().init( )
mlt.Factory().init()

# Create the consumer
c = mlt.Consumer( mlt.Profile(), "avformat" )
c = mlt.Consumer(mlt.Profile(), "avformat")

# Ask for video codecs supports
c.set( 'vcodec', 'list' )
c.set('vcodec', 'list')

# Start the consumer to generate the list
c.start()

# Get the vcodec property
codecs = mlt.Properties( c.get_data( 'vcodec' ) )
codecs = mlt.Properties(c.get_data('vcodec'))

# Print the list of codecs
for i in range( 0, codecs.count()):
print(codecs.get( i ))
for i in range(0, codecs.count()):
print(codecs.get(i))
2 changes: 1 addition & 1 deletion src/swig/python/getimage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import mlt
import mlt7 as mlt
import sys
from PIL import Image

Expand Down
39 changes: 23 additions & 16 deletions src/swig/python/play.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,43 @@

# Import required modules
from __future__ import print_function
import mlt
import mlt7 as mlt
import time
import sys

# Start the mlt system
mlt.Factory().init( )
mlt.Factory().init()

# Establish a profile
profile = mlt.Profile( )
# Establish a default (usually "dv_pal") profile
profile = mlt.Profile()

# Create the producer
p = mlt.Producer( profile, sys.argv[1] )
p = mlt.Producer(profile, sys.argv[1])

if p.is_valid():
# Derive a profile based on the producer
profile.from_producer(p)

# Reload the producer using the derived profile
p = mlt.Producer(profile, sys.argv[1])

if p:
# Create the consumer
c = mlt.Consumer( profile, "sdl" )
c = mlt.Consumer(profile, "sdl2")

if not c.is_valid():
print("Failed to open the sdl2 consumer")
sys.exit(1)

# Turn off the default rescaling
c.set( "rescale", "none" )

# Connect the producer to the consumer
c.connect( p )
c.connect(p)

# Start the consumer
c.start( )
c.start()

# Wait until the user stops the consumer
while c.is_stopped( ) == 0:
time.sleep( 1 )
while not c.is_stopped():
time.sleep(1)
else:
# Diagnostics
print("Unable to open ", sys.argv[ 1 ])

print("Unable to open ", sys.argv[1])
sys.exit(1)
2 changes: 1 addition & 1 deletion src/swig/python/switcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

# Import required modules
import mlt
import mlt7 as mlt
import time
import sys
import tornado.ioloop
Expand Down
2 changes: 1 addition & 1 deletion src/swig/python/test_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

from __future__ import print_function
import mlt
import mlt7 as mlt

p = mlt.Properties()
p.anim_set("foo", "bar", 10)
Expand Down
2 changes: 1 addition & 1 deletion src/swig/python/waveforms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import mlt
import mlt7 as mlt
from PIL import Image

mlt.Factory.init()
Expand Down
2 changes: 1 addition & 1 deletion src/swig/python/webvfx_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

# Import required modules
import mlt
import mlt7 as mlt
import time
import sys
import tornado.ioloop
Expand Down
15 changes: 6 additions & 9 deletions src/swig/ruby/play.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,24 @@
raise "Usage: test.rb file" if file.nil?

# Create the producer
producer = Mlt::Factory::producer( profile, file )
producer = Mlt::Factory::producer(profile, file)
raise "Unable to load #{file}" if !producer.is_valid

# Create the consumer
consumer = Mlt::Consumer.new( profile, "sdl" )
raise "Unable to open sdl consumer" if !consumer.is_valid

# Turn off the default rescaling
consumer.set( "rescale", "none" )
consumer = Mlt::Consumer.new(profile, "sdl2")
raise "Unable to open sdl2 consumer" if !consumer.is_valid

# Set up a 'wait for' event
event = consumer.setup_wait_for( "consumer-stopped" )
event = consumer.setup_wait_for("consumer-stopped")

# Start the consumer
consumer.start

# Connect the producer to the consumer
consumer.connect( producer )
consumer.connect(producer)

# Wait until the user stops the consumer
consumer.wait_for( event )
consumer.wait_for(event)

# Clean up consumer
consumer.stop
Expand Down

0 comments on commit c75721e

Please sign in to comment.