1 #include "qhandbrake.h"
3 QHandBrake::QHandBrake( QObject *parent ) : QObject( parent )
5 hbHandle = hb_init_express( HB_DEBUG_NONE, 1 );
9 QHandBrake::~QHandBrake()
11 hb_close( &hbHandle );
14 QString displayDuration( const QTime t )
16 return QString( "%1 %2, %3 %4, %5 %6").arg(t.hour()).arg(t.hour() == 1 ? "hour" : "hours").arg(t.minute()).arg(t.minute() == 1 ? "minute" : "minutes").arg(t.second()).arg(t.second() == 1 ? "second" : "seconds");
19 QStandardItemModel *QHandBrake::titleListModel()
24 hbTitles = hb_get_titles( hbHandle );
25 titleCount = hb_list_count( hbTitles );
26 titleModel = new QStandardItemModel( titleCount, 2, this );
28 titleModel->setHorizontalHeaderItem( 0, new QStandardItem("Title") );
29 titleModel->setHorizontalHeaderItem( 1, new QStandardItem("Duration") );
31 for( i = 0; i < titleCount; ++i )
33 hb_title_t *t = ( hb_title_t * )hb_list_item( hbTitles, i );
35 QTime d = QTime( t->hours, t->minutes, t->seconds );
36 QString s = QString( "Title %1" ).arg( t->index );
37 QStandardItem *siTitle = new QStandardItem( s );
38 QStandardItem *siDuration = new QStandardItem( displayDuration( d ) );
39 titleModel->setItem( i, 0, siTitle );
40 titleModel->setItem( i, 1, siDuration );
42 siTitle->setCheckable( true );
43 siTitle->setEditable( false );
44 siTitle->setData( i, Qt::UserRole );
46 siDuration->setEditable( false );
52 void QHandBrake::startScan( const QString sDevice )
58 if( sDevice.isEmpty() )
60 qDebug("Passed an empty device/path");
64 hb_scan( hbHandle, sDevice.toLocal8Bit(), 0 );
67 hb_get_state( hbHandle, &s );
68 qApp->processEvents();
69 if( s.state == HB_STATE_SCANNING )
71 titleCurrent = s.param.scanning.title_cur;
72 titleCount = s.param.scanning.title_count;
74 if( titleCurrent > 0 )
76 emit scanProgress( titleCurrent, titleCount );
77 qApp->processEvents();
80 } while( s.state != HB_STATE_SCANDONE );
82 if( hb_list_count( hb_get_titles( hbHandle ) ) )
84 emit scanProgress( titleCount, titleCount );
88 qDebug("Scanning failed");
93 void QHandBrake::encode()
95 if( hbHandle == NULL )
97 qDebug("Encode called too early");
102 hb_list_t *titles = hb_get_titles( hbHandle );
104 for( i = 0; i < titleModel->rowCount(); ++i )
106 QStandardItem *si = titleModel->item( i, 0 );
107 if( si->checkState() == Qt::Checked )
109 hbTitle = ( hb_title_t * )hb_list_item( titles, si->data( Qt::UserRole ).toInt() );
110 hb_job_t *job = hbTitle->job;
111 // FIXME hardcoded params here! need to fix
112 job->pixel_ratio = 1;
113 job->vcodec = HB_VCODEC_FFMPEG;
114 job->vquality = -1.0;
115 job->vbitrate = 1600;
116 job->acodec = HB_ACODEC_LAME;
118 job->mux = HB_MUX_MP4;
121 job->file = strdup("/tmp/foo.mp4");
122 hb_add( hbHandle, job );
126 fprintf(stderr, "Calling hb_start...\n");
127 hb_start( hbHandle );