forked from mltframework/shotcut
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathavformatproducerwidget.cpp
More file actions
723 lines (668 loc) · 28.3 KB
/
avformatproducerwidget.cpp
File metadata and controls
723 lines (668 loc) · 28.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
/*
* Copyright (c) 2012-2018 Meltytech, LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "avformatproducerwidget.h"
#include "ui_avformatproducerwidget.h"
#include "util.h"
#include "mltcontroller.h"
#include "shotcut_mlt_properties.h"
#include "jobqueue.h"
#include "jobs/ffprobejob.h"
#include "jobs/ffmpegjob.h"
#include "jobs/meltjob.h"
#include "jobs/postjobaction.h"
#include "settings.h"
#include "util.h"
#include "Logger.h"
#include <QtWidgets>
bool ProducerIsTimewarp( Mlt::Producer* producer )
{
return QString::fromUtf8(producer->get("mlt_service")) == "timewarp";
}
char* GetFilenameFromProducer( Mlt::Producer* producer )
{
char* resource = NULL;
if (ProducerIsTimewarp(producer))
{
resource = producer->get("warp_resource");
}
else
{
resource = producer->get("resource");
}
return resource;
}
double GetSpeedFromProducer( Mlt::Producer* producer )
{
double speed = 1.0;
if (ProducerIsTimewarp(producer) )
{
speed = fabs(producer->get_double("warp_speed"));
}
return speed;
}
DecodeTask::DecodeTask(AvformatProducerWidget* widget)
: QObject(0)
, QRunnable()
, m_frame(widget->producer()->get_frame())
{
connect(this, SIGNAL(frameDecoded()), widget, SLOT(onFrameDecoded()));
}
void DecodeTask::run()
{
mlt_image_format format = mlt_image_none;
int w = MLT.profile().width();
int h = MLT.profile().height();
m_frame->get_image(format, w, h);
emit frameDecoded();
}
AvformatProducerWidget::AvformatProducerWidget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::AvformatProducerWidget)
, m_defaultDuration(-1)
, m_recalcDuration(true)
{
ui->setupUi(this);
Util::setColorsToHighlight(ui->filenameLabel);
connect(this, SIGNAL(producerChanged(Mlt::Producer*)), SLOT(onProducerChanged()));
}
AvformatProducerWidget::~AvformatProducerWidget()
{
delete ui;
}
Mlt::Producer* AvformatProducerWidget::newProducer(Mlt::Profile& profile)
{
Mlt::Producer* p = 0;
if ( ui->speedSpinBox->value() == 1.0 )
{
p = new Mlt::Producer(profile, GetFilenameFromProducer(producer()));
}
else
{
double warpspeed = ui->speedSpinBox->value();
char* filename = GetFilenameFromProducer(producer());
QString s = QString("%1:%L2:%3").arg("timewarp").arg(warpspeed).arg(filename);
p = new Mlt::Producer(profile, s.toUtf8().constData());
p->set(kShotcutProducerProperty, "avformat");
}
if (p->is_valid())
p->set("video_delay", double(ui->syncSlider->value()) / 1000);
return p;
}
void AvformatProducerWidget::setProducer(Mlt::Producer* p)
{
AbstractProducerWidget::setProducer(p);
emit producerChanged(p);
}
void AvformatProducerWidget::keyPressEvent(QKeyEvent* event)
{
if (ui->speedSpinBox->hasFocus() &&
(event->key() == Qt::Key_Enter || event->key() == Qt::Key_Return)) {
ui->speedSpinBox->clearFocus();
} else {
QWidget::keyPressEvent(event);
}
}
void AvformatProducerWidget::onProducerChanged()
{
QThreadPool::globalInstance()->start(new DecodeTask(this));
}
void AvformatProducerWidget::reopen(Mlt::Producer* p)
{
int length = ui->durationSpinBox->value();
int out = m_producer->get_out();
int position = m_producer->position();
double speed = m_producer->get_speed();
if( m_recalcDuration )
{
double oldSpeed = GetSpeedFromProducer(producer());
double newSpeed = ui->speedSpinBox->value();
double speedRatio = oldSpeed / newSpeed;
int in = m_producer->get_in();
length = qRound(length * speedRatio);
p->set("length", length);
p->set_in_and_out(qMin(qRound(in * speedRatio), length - 1),
qMin(qRound(out * speedRatio), length - 1));
position = qRound(position * speedRatio);
}
else
{
p->set("length", length);
if (out + 1 >= m_producer->get_length())
p->set("out", length - 1);
else if (out >= length)
p->set("out", length - 1);
else
p->set("out", out);
if (position > p->get_out())
position = p->get_out();
p->set("in", m_producer->get_in());
}
if (MLT.setProducer(p)) {
AbstractProducerWidget::setProducer(0);
return;
}
MLT.stop();
emit producerReopened();
emit producerChanged(p);
MLT.seek(position);
MLT.play(speed);
setProducer(p);
}
void AvformatProducerWidget::recreateProducer()
{
Mlt::Producer* p = newProducer(MLT.profile());
p->pass_list(*m_producer, "audio_index, video_index, force_aspect_ratio,"
"video_delay, force_progressive, force_tff,"
kAspectRatioNumerator ","
kAspectRatioDenominator ","
kShotcutHashProperty ","
kPlaylistIndexProperty ","
kShotcutSkipConvertProperty);
Mlt::Controller::copyFilters(*m_producer, *p);
if (m_producer->get(kMultitrackItemProperty)) {
emit producerChanged(p);
delete p;
} else {
reopen(p);
}
}
void AvformatProducerWidget::onFrameDecoded()
{
int tabIndex = ui->tabWidget->currentIndex();
ui->tabWidget->setTabEnabled(0, false);
ui->tabWidget->setTabEnabled(1, false);
ui->tabWidget->setTabEnabled(2, false);
if (m_defaultDuration == -1)
m_defaultDuration = m_producer->get_length();
double warpSpeed = GetSpeedFromProducer(producer());
QString resource = QString::fromUtf8(GetFilenameFromProducer(producer()));
QString name = Util::baseName(resource);
QString caption = name;
if(warpSpeed != 1.0)
caption = QString("%1 (%2x)").arg(name).arg(warpSpeed);
m_producer->set(kShotcutCaptionProperty, caption.toUtf8().constData());
m_producer->set(kShotcutDetailProperty, resource.toUtf8().constData());
ui->filenameLabel->setText(ui->filenameLabel->fontMetrics().elidedText(caption, Qt::ElideLeft, width() - 30));
ui->filenameLabel->setToolTip(resource);
ui->notesTextEdit->setPlainText(QString::fromUtf8(m_producer->get(kCommentProperty)));
ui->durationSpinBox->setValue(m_producer->get_length());
m_recalcDuration = false;
ui->speedSpinBox->setValue(warpSpeed);
// populate the track combos
int n = m_producer->get_int("meta.media.nb_streams");
int videoIndex = 1;
int audioIndex = 1;
int totalAudioChannels = 0;
bool populateTrackCombos = (ui->videoTrackComboBox->count() == 0 &&
ui->audioTrackComboBox->count() == 0);
for (int i = 0; i < n; i++) {
QString key = QString("meta.media.%1.stream.type").arg(i);
QString streamType(m_producer->get(key.toLatin1().constData()));
if (streamType == "video") {
key = QString("meta.media.%1.codec.name").arg(i);
QString codec(m_producer->get(key.toLatin1().constData()));
key = QString("meta.media.%1.codec.width").arg(i);
QString width(m_producer->get(key.toLatin1().constData()));
key = QString("meta.media.%1.codec.height").arg(i);
QString height(m_producer->get(key.toLatin1().constData()));
QString name = QString("%1: %2x%3 %4")
.arg(videoIndex)
.arg(width)
.arg(height)
.arg(codec);
if (populateTrackCombos) {
if (ui->videoTrackComboBox->count() == 0)
ui->videoTrackComboBox->addItem(tr("None"), -1);
ui->videoTrackComboBox->addItem(name, i);
}
if (i == m_producer->get_int("video_index")) {
key = QString("meta.media.%1.codec.long_name").arg(i);
QString codec(m_producer->get(key.toLatin1().constData()));
ui->videoTableWidget->setItem(0, 1, new QTableWidgetItem(codec));
key = QString("meta.media.%1.codec.pix_fmt").arg(i);
ui->videoTableWidget->setItem(3, 1, new QTableWidgetItem(
m_producer->get(key.toLatin1().constData())));
ui->videoTrackComboBox->setCurrentIndex(videoIndex);
}
ui->tabWidget->setTabEnabled(0, true);
videoIndex++;
}
else if (streamType == "audio") {
key = QString("meta.media.%1.codec.name").arg(i);
QString codec(m_producer->get(key.toLatin1().constData()));
key = QString("meta.media.%1.codec.channels").arg(i);
int channels(m_producer->get_int(key.toLatin1().constData()));
totalAudioChannels += channels;
key = QString("meta.media.%1.codec.sample_rate").arg(i);
QString sampleRate(m_producer->get(key.toLatin1().constData()));
QString name = QString("%1: %2 ch %3 KHz %4")
.arg(audioIndex)
.arg(channels)
.arg(sampleRate.toDouble()/1000)
.arg(codec);
if (populateTrackCombos) {
if (ui->audioTrackComboBox->count() == 0)
ui->audioTrackComboBox->addItem(tr("None"), -1);
ui->audioTrackComboBox->addItem(name, i);
}
if ( QString::number(i) == m_producer->get("audio_index")) {
key = QString("meta.media.%1.codec.long_name").arg(i);
QString codec(m_producer->get(key.toLatin1().constData()));
ui->audioTableWidget->setItem(0, 1, new QTableWidgetItem(codec));
const char* layout = mlt_channel_layout_name(mlt_channel_layout_default(channels));
QString channelsStr = QString("%1 (%2)").arg(channels).arg(layout);
ui->audioTableWidget->setItem(1, 1, new QTableWidgetItem(channelsStr));
ui->audioTableWidget->setItem(2, 1, new QTableWidgetItem(sampleRate));
key = QString("meta.media.%1.codec.sample_fmt").arg(i);
ui->audioTableWidget->setItem(3, 1, new QTableWidgetItem(
m_producer->get(key.toLatin1().constData())));
ui->audioTrackComboBox->setCurrentIndex(audioIndex);
}
ui->tabWidget->setTabEnabled(1, true);
audioIndex++;
}
}
if (populateTrackCombos && ui->audioTrackComboBox->count() > 2)
ui->audioTrackComboBox->addItem(tr("All"), "all");
if (m_producer->get("audio_index") == QString("-1")) {
ui->audioTrackComboBox->setCurrentIndex(0);
ui->audioTableWidget->setItem(0, 1, new QTableWidgetItem(""));
ui->audioTableWidget->setItem(1, 1, new QTableWidgetItem("0"));
ui->audioTableWidget->setItem(2, 1, new QTableWidgetItem(""));
ui->audioTableWidget->setItem(3, 1, new QTableWidgetItem(""));
}
else if (m_producer->get("audio_index") == QString("all")) {
ui->audioTrackComboBox->setCurrentIndex(ui->audioTrackComboBox->count()-1);
ui->audioTableWidget->setItem(0, 1, new QTableWidgetItem(""));
ui->audioTableWidget->setItem(1, 1, new QTableWidgetItem(QString::number(totalAudioChannels)));
ui->audioTableWidget->setItem(2, 1, new QTableWidgetItem(""));
ui->audioTableWidget->setItem(3, 1, new QTableWidgetItem(""));
}
if (m_producer->get("video_index") == QString("-1")) {
ui->videoTrackComboBox->setCurrentIndex(0);
ui->videoTableWidget->setItem(0, 1, new QTableWidgetItem(""));
ui->videoTableWidget->setItem(1, 1, new QTableWidgetItem(""));
ui->videoTableWidget->setItem(2, 1, new QTableWidgetItem(""));
ui->videoTableWidget->setItem(3, 1, new QTableWidgetItem(""));
}
// Restore the previous tab, or select the first enabled tab.
if (ui->tabWidget->isTabEnabled(tabIndex))
ui->tabWidget->setCurrentIndex(tabIndex);
else if (ui->tabWidget->isTabEnabled(0))
ui->tabWidget->setCurrentIndex(0);
else if (ui->tabWidget->isTabEnabled(1))
ui->tabWidget->setCurrentIndex(1);
int width = m_producer->get_int("meta.media.width");
int height = m_producer->get_int("meta.media.height");
if (width || height)
ui->videoTableWidget->setItem(1, 1, new QTableWidgetItem(QString("%1x%2").arg(width).arg(height)));
double sar = m_producer->get_double("meta.media.sample_aspect_num");
if (m_producer->get_double("meta.media.sample_aspect_den") > 0)
sar /= m_producer->get_double("meta.media.sample_aspect_den");
if (m_producer->get("force_aspect_ratio"))
sar = m_producer->get_double("force_aspect_ratio");
int dar_numerator = width * sar;
int dar_denominator = height;
if (height > 0) {
switch (int(sar * width / height * 100)) {
case 133:
dar_numerator = 4;
dar_denominator = 3;
break;
case 177:
dar_numerator = 16;
dar_denominator = 9;
break;
case 56:
dar_numerator = 9;
dar_denominator = 16;
}
}
if (m_producer->get(kAspectRatioNumerator))
dar_numerator = m_producer->get_int(kAspectRatioNumerator);
if (m_producer->get(kAspectRatioDenominator))
dar_denominator = m_producer->get_int(kAspectRatioDenominator);
ui->aspectNumSpinBox->blockSignals(true);
ui->aspectNumSpinBox->setValue(dar_numerator);
ui->aspectNumSpinBox->blockSignals(false);
ui->aspectDenSpinBox->blockSignals(true);
ui->aspectDenSpinBox->setValue(dar_denominator);
ui->aspectDenSpinBox->blockSignals(false);
double fps = m_producer->get_double("meta.media.frame_rate_num");
if (m_producer->get_double("meta.media.frame_rate_den") > 0)
fps /= m_producer->get_double("meta.media.frame_rate_den");
if (m_producer->get("force_fps"))
fps = m_producer->get_double("fps");
bool isVariableFrameRate = m_producer->get_int("meta.media.variable_frame_rate");
if (fps != 0.0 ) {
ui->videoTableWidget->setItem(2, 1, new QTableWidgetItem(QString("%L1 %2").arg(fps)
.arg(isVariableFrameRate? tr("(variable)") : "")));
}
int progressive = m_producer->get_int("meta.media.progressive");
if (m_producer->get("force_progressive"))
progressive = m_producer->get_int("force_progressive");
ui->scanComboBox->setCurrentIndex(progressive);
int tff = m_producer->get_int("meta.media.top_field_first");
if (m_producer->get("force_tff"))
tff = m_producer->get_int("force_tff");
ui->fieldOrderComboBox->setCurrentIndex(tff);
ui->fieldOrderComboBox->setEnabled(!progressive);
if (populateTrackCombos) {
for (int i = 0; i < m_producer->count(); i++) {
QString name(m_producer->get_name(i));
if (name.startsWith("meta.attr.") && name.endsWith(".markup")) {
int row = ui->metadataTable->rowCount();
ui->metadataTable->setRowCount(row + 1);
ui->metadataTable->setItem(row, 0, new QTableWidgetItem(name.section('.', -2, -2)));
ui->metadataTable->setItem(row, 1, new QTableWidgetItem(m_producer->get(i)));
ui->tabWidget->setTabEnabled(2, true);
}
}
}
ui->syncSlider->setValue(qRound(m_producer->get_double("video_delay") * 1000.0));
if (Settings.showConvertClipDialog()
&& !m_producer->get_int(kShotcutSkipConvertProperty)
&& !m_producer->get_int(kPlaylistIndexProperty)
&& !m_producer->get(kMultitrackItemProperty)) {
m_producer->set(kShotcutSkipConvertProperty, true);
if (isVariableFrameRate) {
MLT.pause();
LOG_INFO() << resource << "is variable frame rate";
TranscodeDialog dialog(tr("This file is variable frame rate, which is not reliable for editing. "
"Do you want to convert it to an edit-friendly format?\n\n"
"If yes, choose a format below and then click OK to choose a file name. "
"After choosing a file name, a job is created. "
"When it is done, double-click the job to open it.\n"), this);
dialog.showCheckBox();
convert(dialog);
}
if (QFile::exists(resource) && !MLT.isSeekable(m_producer.data())) {
MLT.pause();
LOG_INFO() << resource << "is not seekable";
TranscodeDialog dialog(tr("This file does not support seeking and cannot be used for editing. "
"Do you want to convert it to an edit-friendly format?\n\n"
"If yes, choose a format below and then click OK to choose a file name. "
"After choosing a file name, a job is created. "
"When it is done, double-click the job to open it.\n"), this);
dialog.showCheckBox();
convert(dialog);
}
}
}
void AvformatProducerWidget::on_resetButton_clicked()
{
ui->speedSpinBox->setValue(1.0);
Mlt::Producer* p = newProducer(MLT.profile());
ui->durationSpinBox->setValue(m_defaultDuration);
ui->syncSlider->setValue(0);
Mlt::Controller::copyFilters(*m_producer, *p);
if (m_producer->get(kMultitrackItemProperty)) {
emit producerChanged(p);
delete p;
} else {
reopen(p);
}
}
void AvformatProducerWidget::on_videoTrackComboBox_activated(int index)
{
if (m_producer) {
m_producer->set("video_index", ui->videoTrackComboBox->itemData(index).toInt());
recreateProducer();
}
}
void AvformatProducerWidget::on_audioTrackComboBox_activated(int index)
{
if (m_producer) {
m_producer->set("audio_index", ui->audioTrackComboBox->itemData(index).toString().toUtf8().constData());
recreateProducer();
}
}
void AvformatProducerWidget::on_scanComboBox_activated(int index)
{
if (m_producer) {
int progressive = m_producer->get_int("meta.media.progressive");
ui->fieldOrderComboBox->setEnabled(!progressive);
if (m_producer->get("force_progressive") || progressive != index)
// We need to set these force_ properties as a string so they can be properly removed
// by setting them NULL.
m_producer->set("force_progressive", QString::number(index).toLatin1().constData());
emit producerChanged(producer());
}
}
void AvformatProducerWidget::on_fieldOrderComboBox_activated(int index)
{
if (m_producer) {
int tff = m_producer->get_int("meta.media.top_field_first");
if (m_producer->get("force_tff") || tff != index)
m_producer->set("force_tff", QString::number(index).toLatin1().constData());
emit producerChanged(producer());
}
}
void AvformatProducerWidget::on_aspectNumSpinBox_valueChanged(int)
{
if (m_producer) {
double new_sar = double(ui->aspectNumSpinBox->value() * m_producer->get_int("meta.media.height")) /
double(ui->aspectDenSpinBox->value() * m_producer->get_int("meta.media.width"));
double sar = m_producer->get_double("meta.media.sample_aspect_num");
if (m_producer->get_double("meta.media.sample_aspect_den") > 0)
sar /= m_producer->get_double("meta.media.sample_aspect_den");
if (m_producer->get("force_aspect_ratio") || new_sar != sar) {
m_producer->set("force_aspect_ratio", QString::number(new_sar).toLatin1().constData());
m_producer->set(kAspectRatioNumerator, ui->aspectNumSpinBox->text().toLatin1().constData());
m_producer->set(kAspectRatioDenominator, ui->aspectDenSpinBox->text().toLatin1().constData());
}
emit producerChanged(producer());
}
}
void AvformatProducerWidget::on_aspectDenSpinBox_valueChanged(int i)
{
on_aspectNumSpinBox_valueChanged(i);
}
void AvformatProducerWidget::on_durationSpinBox_editingFinished()
{
if (!m_producer)
return;
if (ui->durationSpinBox->value() == m_producer->get_length())
return;
recreateProducer();
}
void AvformatProducerWidget::on_speedSpinBox_editingFinished()
{
if (!m_producer)
return;
m_recalcDuration = true;
recreateProducer();
}
void AvformatProducerWidget::on_syncSlider_valueChanged(int value)
{
if (m_producer)
m_producer->set("video_delay", double(value) / 1000);
}
void AvformatProducerWidget::on_actionOpenFolder_triggered()
{
Util::showInFolder(GetFilenameFromProducer(producer()));
}
void AvformatProducerWidget::on_menuButton_clicked()
{
QMenu menu;
if (!MLT.resource().contains("://")) // not a network stream
menu.addAction(ui->actionOpenFolder);
menu.addAction(ui->actionCopyFullFilePath);
menu.addAction(ui->actionFFmpegInfo);
menu.addAction(ui->actionFFmpegIntegrityCheck);
menu.addAction(ui->actionFFmpegConvert);
menu.addAction(ui->actionReverse);
menu.exec(ui->menuButton->mapToGlobal(QPoint(0, 0)));
}
void AvformatProducerWidget::on_actionCopyFullFilePath_triggered()
{
qApp->clipboard()->setText(GetFilenameFromProducer(producer()));
}
void AvformatProducerWidget::on_notesTextEdit_textChanged()
{
m_producer->set(kCommentProperty, ui->notesTextEdit->toPlainText().toUtf8().constData());
}
void AvformatProducerWidget::on_actionFFmpegInfo_triggered()
{
QStringList args;
args << "-v" << "quiet";
args << "-print_format" << "ini";
args << "-pretty";
args << "-show_format" << "-show_programs" << "-show_streams";
args << GetFilenameFromProducer(producer());
AbstractJob* job = new FfprobeJob(args.last(), args);
job->start();
}
void AvformatProducerWidget::on_actionFFmpegIntegrityCheck_triggered()
{
QString resource = GetFilenameFromProducer(producer());
QStringList args;
args << "-xerror";
args << "-err_detect" << "+explode";
args << "-v" << "info";
args << "-i" << resource;
args << "-f" << "null" << "pipe:";
JOBS.add(new FfmpegJob(resource, args));
}
void AvformatProducerWidget::on_actionFFmpegConvert_triggered()
{
TranscodeDialog dialog(tr("Choose an edit-friendly format below and then click OK to choose a file name. "
"After choosing a file name, a job is created. "
"When it is done, double-click the job to open it.\n"), this);
convert(dialog);
}
void AvformatProducerWidget::convert(TranscodeDialog& dialog)
{
int result = dialog.exec();
if (dialog.isCheckBoxChecked()) {
Settings.setShowConvertClipDialog(false);
}
if (result == QDialog::Accepted) {
QString resource = QString::fromUtf8(GetFilenameFromProducer(producer()));
QString path = Settings.savePath();
QStringList args;
args << "-loglevel" << "verbose";
args << "-i" << resource;
// transcode all streams
args << "-map" << "0";
// except data, subtitles, and attachments
args << "-map" << "-0:d" << "-map" << "-0:s" << "-map" << "-0:t" << "-ignore_unknown";
switch (dialog.format()) {
case 0:
path.append("/%1.mp4");
args << "-f" << "mp4" << "-codec:a" << "aac" << "-b:a" << "512k" << "-codec:v" << "libx264";
args << "-preset" << "medium" << "-g" << "1" << "-crf" << "11";
break;
case 1:
args << "-f" << "mov" << "-codec:a" << "alac" << "-codec:v" << "prores_ks" << "-profile:v" << "standard";
path.append("/%1.mov");
break;
case 2:
args << "-f" << "matroska" << "-codec:a" << "flac" << "-codec:v" << "ffv1" << "-coder" << "1";
args << "-context" << "1" << "-g" << "1" << "-threads" << QString::number(QThread::idealThreadCount());
path.append("/%1.mkv");
break;
}
QFileInfo fi(resource);
path = path.arg(fi.baseName());
QString filename = QFileDialog::getSaveFileName(this, dialog.windowTitle(), path);
if (!filename.isEmpty()) {
if (filename == QDir::toNativeSeparators(resource)) {
QMessageBox::warning(this, dialog.windowTitle(),
QObject::tr("Unable to write file %1\n"
"Perhaps you do not have permission.\n"
"Try again with a different folder.")
.arg(fi.fileName()));
return;
}
if (Util::warnIfNotWritable(filename, this, dialog.windowTitle()))
return;
Settings.setSavePath(QFileInfo(filename).path());
args << filename;
FfmpegJob* job = new FfmpegJob(filename, args, false);
job->setPostJobAction(new FilePropertiesPostJobAction(resource, filename));
JOBS.add(job);
}
}
}
void AvformatProducerWidget::on_actionReverse_triggered()
{
TranscodeDialog dialog(tr("Choose an edit-friendly format below and then click OK to choose a file name. "
"After choosing a file name, a job is created. "
"When it is done, double-click the job to open it.\n"), this);
dialog.setWindowTitle(tr("Reverse..."));
int result = dialog.exec();
if (dialog.isCheckBoxChecked()) {
Settings.setShowConvertClipDialog(false);
}
if (result == QDialog::Accepted) {
QString resource = QString::fromUtf8(GetFilenameFromProducer(producer()));
QString path = Settings.savePath();
QStringList args;
args << QString("timewarp:-1.0:").append(resource);
// In and out points do not work reliably.
// args << QString("in=%1").arg(m_producer->get_int("in"));
// args << QString("out=%1").arg(m_producer->get_int("out"));
args << "-consumer" << "avformat";
if (m_producer->get_int("audio_index") == -1) {
args << "an=1" << "audio_off=1";
} else if (qstrcmp(m_producer->get("audio_index"), "all")) {
int index = m_producer->get_int("audio_index");
QString key = QString("meta.media.%1.codec.channels").arg(index);
const char* channels = m_producer->get(key.toLatin1().constData());
args << QString("channels=").append(channels);
}
if (m_producer->get_int("video_index") == -1)
args << "vn=1" << "video_off=1";
switch (dialog.format()) {
case 0:
path.append("/%1 - %2.mp4");
args << "acodec=aac" << "ab=512k" << "vcodec=libx264";
args << "vpreset=medium" << "g=1" << "crf=11";
break;
case 1:
args << "acodec=alac" << "vcodec=prores_ks" << "vprofile=standard";
path.append("/%1 - %2.mov");
break;
case 2:
args << "acodec=flac" << "vcodec=ffv1" << "coder=1";
args << "context=1" << "g=1" << QString::number(QThread::idealThreadCount()).prepend("threads=");
path.append("/%1 - %2.mkv");
break;
}
QFileInfo fi(resource);
path = path.arg(fi.completeBaseName()).arg(tr("Reversed"));
QString filename = QFileDialog::getSaveFileName(this, dialog.windowTitle(), path);
if (!filename.isEmpty()) {
if (filename == QDir::toNativeSeparators(resource)) {
QMessageBox::warning(this, dialog.windowTitle(),
QObject::tr("Unable to write file %1\n"
"Perhaps you do not have permission.\n"
"Try again with a different folder.")
.arg(fi.fileName()));
return;
}
if (Util::warnIfNotWritable(filename, this, dialog.windowTitle()))
return;
Settings.setSavePath(QFileInfo(filename).path());
args << QString("target=").append(filename);
MeltJob* job = new MeltJob(filename, args);
job->setPostJobAction(new FilePropertiesPostJobAction(resource, filename));
JOBS.add(job);
}
}
}