~andrewsomething/imagination/debian

« back to all changes in this revision

Viewing changes to src/export.c

  • Committer: Andrew Starr-Bochicchio
  • Date: 2009-10-20 00:11:10 UTC
  • mfrom: (1.1.3)
  • Revision ID: a.starr.b@gmail.com-20091020001110-4n2wp5ntluojqw2x
Tags: 2.1-1
* New upstream release. (Closes: #551120)
* Split arch independent files into new binary, imagination-common.
 - Rename debian/imagination.doc-base to debian/imagination-common.doc-base
 - Add debian/imagination-common.install and debian/imagination.install
 - debian/control:
  + Add new binary, imagination-common.
  + Add depends on imagination-common (= ${source:Version})
  + Make imagination-common Conflict/Replace imagination (<= 2.0-1)
 - debian/rules:
  + Fill binary-indep target.
  + Install to debian/tmp/
* debian/patches:
 - 10_link_math_lib.patch: Adjust for new release.
 - 15_PLUGINS_INSTALLED.patch: New patch, correctly load transitions. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include "callbacks.h"
23
23
#include "audio.h"
24
24
#include "img_sox.h"
 
25
#include <fcntl.h>
25
26
#include <glib/gstdio.h>
26
27
 
27
28
static void
66
67
img_exporter_ogg( img_window_struct *img );
67
68
static void
68
69
img_exporter_flv( img_window_struct *img );
 
70
static void
 
71
img_exporter_3gp( img_window_struct *img );
69
72
 
70
73
 
71
74
/*
86
89
img_get_exporters_list( Exporter **exporters )
87
90
{
88
91
        Exporter *list;             /* List of all exporters */
89
 
        gint      no_exporters = 3; /* Total number of exporters */
 
92
        gint      no_exporters = 4; /* Total number of exporters */
90
93
        gint      i = 0;
91
94
        
92
95
        list = g_slice_alloc( sizeof( Exporter ) * no_exporters );
98
101
        list[i++].func = G_CALLBACK( img_exporter_ogg );
99
102
        list[i].description = g_strdup( "FLV (Flash video)" );
100
103
        list[i++].func = G_CALLBACK( img_exporter_flv );
 
104
        list[i].description = g_strdup( "3GP (Mobile Phones)" );
 
105
        list[i++].func = G_CALLBACK( img_exporter_3gp );
101
106
 
102
107
        *exporters = list;
103
108
 
432
437
        gtk_tree_model_get_iter_first( model, &iter );
433
438
        gtk_tree_model_get( model, &iter, 1, &entry, -1 );
434
439
 
435
 
        if( ! entry->filename )
 
440
        if( ! entry->o_filename )
436
441
        {
437
442
                img_scale_gradient( entry->gradient, entry->g_start_point,
438
443
                                                        entry->g_stop_point, entry->g_start_color,
441
446
        }
442
447
        else
443
448
        {
444
 
                img_scale_image( entry->filename, img->video_ratio,
 
449
                img_scale_image( entry->r_filename, img->video_ratio,
445
450
                                                 0, 0, img->distort_images,
446
451
                                                 img->background_color, NULL, &img->image2 );
447
452
        }
510
515
img_stop_export( img_window_struct *img )
511
516
{
512
517
        /* Do any additional tasks */
 
518
        if( img->export_is_running > 3 )
 
519
        {
 
520
                kill( img->ffmpeg_export, SIGINT );
 
521
                g_source_remove( img->source_id );
 
522
 
 
523
                close(img->file_desc);
 
524
                g_spawn_close_pid( img->ffmpeg_export );
 
525
 
 
526
                /* Destroy images that were used */
 
527
                cairo_surface_destroy( img->image1 );
 
528
                cairo_surface_destroy( img->image2 );
 
529
                cairo_surface_destroy( img->image_from );
 
530
                cairo_surface_destroy( img->image_to );
 
531
                cairo_surface_destroy( img->exported_image );
 
532
 
 
533
                /* Close export dialog */
 
534
                gtk_widget_destroy( img->export_dialog );
 
535
        }
 
536
 
513
537
        if( img->export_is_running > 1 )
514
538
        {
515
539
                /* Kill sox thread */
519
543
 
520
544
                        if( g_atomic_int_get( &img->sox_flags ) != 2 )
521
545
                        {
 
546
                                gint   fd;
 
547
                                guchar buf[1024];
 
548
 
522
549
                                g_atomic_int_set( &img->sox_flags, 1 );
523
550
 
524
 
                                /* Export some more frames to unblock write on audio pipe */
525
 
                                for( i = 0; i < 10; i++ )
526
 
                                        img_export_frame_to_ppm( img->exported_image,
527
 
                                                                                         img->file_desc );
 
551
                                /* Flush any buffered audio data from pipe */
 
552
                                fd = open( img->fifo, O_RDONLY );
 
553
                                while( read( fd, buf, sizeof( buf ) ) )
 
554
                                        ;
 
555
                                close( fd );
528
556
                        }
529
557
 
530
558
                        /* Wait for thread to finish */
538
566
                }
539
567
        }
540
568
 
541
 
        if( img->export_is_running > 3 )
542
 
        {
543
 
                kill( img->ffmpeg_export, SIGINT );
544
 
                g_source_remove( img->source_id );
545
 
 
546
 
                close(img->file_desc);
547
 
                g_spawn_close_pid( img->ffmpeg_export );
548
 
 
549
 
                /* Destroy images that were used */
550
 
                cairo_surface_destroy( img->image1 );
551
 
                cairo_surface_destroy( img->image2 );
552
 
                cairo_surface_destroy( img->image_from );
553
 
                cairo_surface_destroy( img->image_to );
554
 
                cairo_surface_destroy( img->exported_image );
555
 
 
556
 
                /* Close export dialog */
557
 
                gtk_widget_destroy( img->export_dialog );
558
 
        }
559
 
 
560
569
        /* If we created FIFO, we need to destroy it now */
561
570
        if( img->fifo )
562
571
        {
614
623
                                                                        g_list_last( img->work_slide->points )->data :
615
624
                                                                        NULL );
616
625
 
617
 
        if( gtk_tree_model_iter_next( model, &img->cur_ss_iter ) )
 
626
        if( last_transition && gtk_tree_model_iter_next( model, &img->cur_ss_iter ) )
618
627
        {
619
628
                /* We have next iter, so prepare for next round */
620
629
                cairo_surface_destroy( img->image1 );
621
630
                img->image1 = img->image2;
622
631
                gtk_tree_model_get( model, &img->cur_ss_iter, 1, &img->work_slide, -1 );
623
632
 
624
 
                if( ! img->work_slide->filename )
 
633
                if( ! img->work_slide->o_filename )
625
634
                {
626
635
                        img_scale_gradient( img->work_slide->gradient,
627
636
                                                                img->work_slide->g_start_point,
632
641
                                                                img->video_size[1], NULL, &img->image2 );
633
642
                }
634
643
                else if( preview && img->low_quality )
635
 
                        img_scale_image( img->work_slide->filename, img->video_ratio,
 
644
                        img_scale_image( img->work_slide->r_filename, img->video_ratio,
636
645
                                                         0, img->video_size[1], img->distort_images,
637
646
                                                         img->background_color, NULL, &img->image2 );
638
647
                else
639
 
                        img_scale_image( img->work_slide->filename, img->video_ratio,
 
648
                        img_scale_image( img->work_slide->r_filename, img->video_ratio,
640
649
                                                         0, 0, img->distort_images,
641
650
                                                         img->background_color, NULL, &img->image2 );
642
651
 
1600
1609
 
1601
1610
        gtk_widget_destroy( dialog );
1602
1611
}
 
1612
 
 
1613
static void
 
1614
img_exporter_3gp( img_window_struct *img )
 
1615
{
 
1616
        gchar          *cmd_line;
 
1617
        const gchar    *filename;
 
1618
        GtkWidget      *dialog;
 
1619
        GtkEntry       *entry;
 
1620
        GtkWidget      *vbox;
 
1621
 
 
1622
        /* Additional options - 3GP  only */
 
1623
        GtkWidget *frame1, *frame2;
 
1624
        GtkWidget *label;
 
1625
        GtkWidget *hbox;
 
1626
        GtkWidget *normal_combo;
 
1627
        gint       width, height;
 
1628
 
 
1629
        /* This function call should be the first thing exporter does, since this
 
1630
         * function will take some preventive measures. */
 
1631
        dialog = img_create_export_dialog( img, _("3GP export"),
 
1632
                                                                           GTK_WINDOW( img->imagination_window ),
 
1633
                                                                           &entry, &vbox );
 
1634
 
 
1635
        /* If dialog is NULL, abort. */
 
1636
        if( dialog == NULL )
 
1637
                return;
 
1638
 
 
1639
        /* Add any export format specific GUI elements here */
 
1640
        hbox = gtk_hbox_new( TRUE, 5 );
 
1641
        gtk_container_add( GTK_CONTAINER( vbox ), hbox );
 
1642
        
 
1643
        frame1 = gtk_frame_new( NULL );
 
1644
        gtk_box_pack_start( GTK_BOX( hbox ), frame1, FALSE, FALSE, 0 );
 
1645
 
 
1646
        label = gtk_label_new( _("<b>Video Size</b>") );
 
1647
        gtk_label_set_use_markup( GTK_LABEL( label ), TRUE );
 
1648
        gtk_frame_set_label_widget( GTK_FRAME( frame1 ), label );
 
1649
 
 
1650
        normal_combo = _gtk_combo_box_new_text(FALSE);
 
1651
        gtk_container_add (GTK_CONTAINER (frame1), normal_combo);
 
1652
        {
 
1653
                GtkTreeIter   iter;
 
1654
                GtkListStore *store = GTK_LIST_STORE( gtk_combo_box_get_model(GTK_COMBO_BOX( normal_combo ) ) );
 
1655
 
 
1656
                gtk_list_store_append( store, &iter );
 
1657
                gtk_list_store_set( store, &iter, 0, "128 x 96", -1 );
 
1658
                gtk_list_store_append( store, &iter );
 
1659
                gtk_list_store_set( store, &iter, 0, "176 x 144", -1 );
 
1660
                gtk_list_store_append( store, &iter );
 
1661
                gtk_list_store_set( store, &iter, 0, "352 x 288", -1 );
 
1662
                gtk_list_store_append( store, &iter );
 
1663
                gtk_list_store_set( store, &iter, 0, "704 x 576", -1 );
 
1664
        }
 
1665
        gtk_combo_box_set_active( GTK_COMBO_BOX( normal_combo ), 0 );
 
1666
        gtk_widget_show_all( dialog );
 
1667
 
 
1668
        /* Run dialog and abort if needed */
 
1669
        if( gtk_dialog_run( GTK_DIALOG( dialog ) ) != GTK_RESPONSE_ACCEPT )
 
1670
        {
 
1671
                gtk_widget_destroy( dialog );
 
1672
                return;
 
1673
        }
 
1674
 
 
1675
        /* User is serious, so we better prepare ffmpeg command line;) */
 
1676
        img->export_is_running = 1;
 
1677
        img->export_fps = 25;
 
1678
        filename = gtk_entry_get_text( entry );
 
1679
 
 
1680
        /* Any additional calculation can be placed here. */
 
1681
        switch(gtk_combo_box_get_active(GTK_COMBO_BOX(normal_combo)) )
 
1682
        {
 
1683
                case 0:
 
1684
                width  = 128;
 
1685
                height = 96;
 
1686
                break;
 
1687
 
 
1688
                case 1:
 
1689
                width  = 176;
 
1690
                height = 144;
 
1691
                break;
 
1692
 
 
1693
                case 2:
 
1694
                width  = 352;
 
1695
                height = 288;
 
1696
                break;
 
1697
 
 
1698
                case 3:
 
1699
                width  = 704;
 
1700
                height = 576;
 
1701
                break;
 
1702
        }
 
1703
 
 
1704
        cmd_line = g_strdup_printf( "ffmpeg -f image2pipe -vcodec ppm -r %.02f "
 
1705
                                                                "-i pipe: <#AUDIO#> -f 3gp -s %dx%d "
 
1706
                                                                "-vcodec h263 -acodec libfaac -b 192k -ab 32k "
 
1707
                                                                "-ar 8000 -ac 1 -y \"%s.3gp\"",
 
1708
                                                                img->export_fps,
 
1709
                                                                width, height, filename );
 
1710
        img->export_cmd_line = cmd_line;
 
1711
 
 
1712
        /* Initiate stage 2 of export - audio processing */
 
1713
        g_idle_add( (GSourceFunc)img_prepare_audio, img );
 
1714
 
 
1715
        gtk_widget_destroy( dialog );
 
1716
}
1603
1717
/* ****************************************************************************
1604
1718
 * End exporters
1605
1719
 * ************************************************************************* */