rff 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/processor.rb +129 -114
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85caedebb36e13844d236773c51542dcc733c674
|
4
|
+
data.tar.gz: 62dfc4ea0911ed91883b7d6cb9043d607fcfab3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c89679dfc28a4fac00235c0f0654dc55fdabdc422e03ddf5814a157ab930ca842e1736253dd487c273d9659bde7e98a4e3101b8866ae46ce31cedc34fcbbd509
|
7
|
+
data.tar.gz: 08362ca73be9df3f60914de717a16c6f8d88147918071eb93b18dc04257c0367fb7739460d3a7892bbaca5fc1283150b7dd763b4ae3967b5308de50cb146d0e7
|
data/lib/processor.rb
CHANGED
@@ -3,11 +3,11 @@ require_relative 'output_reader'
|
|
3
3
|
require 'open3'
|
4
4
|
require 'time'
|
5
5
|
module RFF
|
6
|
-
|
6
|
+
|
7
7
|
# The main processing class of the _rff_ gem. It spawns FFmpeg conversion process and parses its output, providing information about input and output files and current process status
|
8
|
-
|
8
|
+
|
9
9
|
class Processor
|
10
|
-
|
10
|
+
|
11
11
|
# This constructor initializes the class with the following arguments:
|
12
12
|
# * _input_ <b>(required)</b> - the full path to the input file
|
13
13
|
# * <i>output_type</i> <b>(required)</b> - defines the type of the output. Must be one of [:mp3, :ogg, :wav] for audio conversion or [:mp4, :ogv, :webm] for video conversion
|
@@ -17,7 +17,7 @@ module RFF
|
|
17
17
|
# * <i>recommended_audio_quality</i> - determines if recommended by FFmpeg community audio quality settings should be used. Defaults to true, which means audio conversion with good, recommended quality. Set to false if you are giving additional arguments that determine this quality.
|
18
18
|
# * <i>disable_subtitles_decoding</i> - in some formats subtitle decoding causes problems. This option disables this feature. Defaults to true to bypass problems by default.
|
19
19
|
# This method also validates arguments, determines full output name, generates appropriate FFmpeg command, determines conversion type and initializes status (it is :pending at this point).
|
20
|
-
|
20
|
+
|
21
21
|
def initialize input, output_type, output_path=nil, quality="5000k", custom_args=nil, recommended_audio_quality=true, disable_subtitles_decoding=true
|
22
22
|
if input.nil? || input.empty? || output_type.nil?
|
23
23
|
raise RFF::ArgumentError.new("Input and output type can not be empty nor nil!")
|
@@ -40,9 +40,9 @@ module RFF
|
|
40
40
|
end
|
41
41
|
@status = :pending
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
# This method runs the FFmpeg conversion process in a separate thread. First it initializes processing percentage and then spawns a new thread, in which FFmpeg conversion process is spawned through Open3.popen2e. It sets the processing status, passes the command output to OutputReader instance and initializes all the needed structures for information. Then it parses the output until it ends to extract the information, which is available through this class' getter methods. All the information is filled in as soon as it appears in the command output. When the process finishes, it cleans up the streams, sets percentage to 100% and gets the command' s exit status. Then it sets :completed or :failed status according to the command' s status. At the end it catches and displays any exceptions that can occur in the thread
|
45
|
-
|
45
|
+
|
46
46
|
def fire
|
47
47
|
@processing_percentage = 0
|
48
48
|
@processing_thread = Thread.new do |th|
|
@@ -87,7 +87,7 @@ module RFF
|
|
87
87
|
if @conversion_type == :audio
|
88
88
|
if @parser_status == :meta
|
89
89
|
#puts "DEBUG: Parser in metadata parsing mode"
|
90
|
-
if line[0..7] == "Duration" || line[0..5] == "Stream" || line[0] == "[" || line[0..5] == "Output" || line[0..4] == "Input"
|
90
|
+
if line[0..7] == "Duration" || line[0..5] == "Stream" || line[0] == "[" || line[0..5] == "Output" || line[0..4] == "Input"
|
91
91
|
@parser_status = :normal
|
92
92
|
else
|
93
93
|
#puts "DEBUG: Reading metadata line..."
|
@@ -173,25 +173,40 @@ module RFF
|
|
173
173
|
elsif @conversion_type == :video
|
174
174
|
if @parser_status == :meta
|
175
175
|
#puts "DEBUG: Parser in metadata parsing mode"
|
176
|
-
if line[0..7] == "Duration" || line[0..5] == "Stream" || line[0] == "[" || line[0..5] == "Output" || line[0..4] == "Input"
|
176
|
+
if line[0..7] == "Duration" || line[0..5] == "Stream" || line[0] == "[" || line[0..5] == "Output" || line[0..4] == "Input"
|
177
177
|
@parser_status = :normal
|
178
178
|
else
|
179
179
|
#puts "DEBUG: Reading metadata line..."
|
180
|
+
name = line.split(":")[0]
|
181
|
+
if !name.nil?
|
182
|
+
name = name.downcase[0..-2].to_sym
|
183
|
+
else
|
184
|
+
#puts "DEBUG: Skipping because of nil name..."
|
185
|
+
next
|
186
|
+
end
|
187
|
+
#puts "DEBUG: Name: #{name}"
|
188
|
+
value = line.split(":")[1]
|
189
|
+
if value.nil?
|
190
|
+
value = ""
|
191
|
+
else
|
192
|
+
value = value[1..-1]
|
193
|
+
end
|
194
|
+
#puts "DEBUG: Value: #{value}"
|
180
195
|
if @last_met_io == :input
|
181
196
|
if @last_stream_type == nil
|
182
|
-
@input_meta_common[
|
197
|
+
@input_meta_common[name] = value
|
183
198
|
elsif @last_stream_type == :audio
|
184
|
-
@input_meta_audio[
|
199
|
+
@input_meta_audio[name] = value
|
185
200
|
elsif @last_stream_type == :video
|
186
|
-
@input_meta_video[
|
201
|
+
@input_meta_video[name] = value
|
187
202
|
end
|
188
203
|
elsif @last_met_io == :output
|
189
204
|
if @last_stream_type == nil
|
190
|
-
@output_meta_common[
|
205
|
+
@output_meta_common[name] = value
|
191
206
|
elsif @last_stream_type == :audio
|
192
|
-
@output_meta_audio[
|
207
|
+
@output_meta_audio[name] = value
|
193
208
|
elsif @last_stream_type == :video
|
194
|
-
@output_meta_video[
|
209
|
+
@output_meta_video[name] = value
|
195
210
|
end
|
196
211
|
end
|
197
212
|
end
|
@@ -322,303 +337,303 @@ module RFF
|
|
322
337
|
end
|
323
338
|
end
|
324
339
|
end
|
325
|
-
|
340
|
+
|
326
341
|
# This method returns full input path
|
327
|
-
|
342
|
+
|
328
343
|
def input
|
329
344
|
@input
|
330
345
|
end
|
331
|
-
|
346
|
+
|
332
347
|
# This method returns output type read from the filename
|
333
|
-
|
348
|
+
|
334
349
|
def output_type
|
335
350
|
@output_type
|
336
351
|
end
|
337
|
-
|
352
|
+
|
338
353
|
# This method returns output type read by FFmpeg
|
339
|
-
|
354
|
+
|
340
355
|
def detected_output_type
|
341
356
|
@detected_output_type
|
342
357
|
end
|
343
|
-
|
358
|
+
|
344
359
|
# This method returns full output name
|
345
|
-
|
360
|
+
|
346
361
|
def output_name
|
347
362
|
@output_name
|
348
363
|
end
|
349
|
-
|
364
|
+
|
350
365
|
# This method returns path where the output is (being) saved
|
351
|
-
|
366
|
+
|
352
367
|
def output_path
|
353
368
|
@output_path
|
354
369
|
end
|
355
|
-
|
370
|
+
|
356
371
|
# This method returns used video quality
|
357
|
-
|
372
|
+
|
358
373
|
def quality
|
359
374
|
@quality
|
360
375
|
end
|
361
|
-
|
376
|
+
|
362
377
|
# This method returns the FFmpeg command used for conversion
|
363
|
-
|
378
|
+
|
364
379
|
def command
|
365
380
|
@command
|
366
381
|
end
|
367
|
-
|
382
|
+
|
368
383
|
# This method returns custom arguments passed to FFmpeg
|
369
|
-
|
384
|
+
|
370
385
|
def custom_args
|
371
386
|
@custom_args
|
372
387
|
end
|
373
|
-
|
388
|
+
|
374
389
|
# This method returns conversion type (:audio or :video)
|
375
|
-
|
390
|
+
|
376
391
|
def conversion_type
|
377
392
|
@conversion_type
|
378
393
|
end
|
379
|
-
|
394
|
+
|
380
395
|
# This method returns full path to the output file
|
381
|
-
|
396
|
+
|
382
397
|
def full_output_path
|
383
398
|
"#{@output_path}/#{@output_name}.#{@output_type.to_s}"
|
384
399
|
end
|
385
|
-
|
400
|
+
|
386
401
|
# This method returns raw command output as an array of lines after getting rid of unneeded whitespaces
|
387
|
-
|
402
|
+
|
388
403
|
def raw_command_output
|
389
404
|
@rawoutput
|
390
405
|
end
|
391
|
-
|
406
|
+
|
392
407
|
# This method returns current processing status (:pending, :processing, :completed, :failed, :aborted)
|
393
|
-
|
408
|
+
|
394
409
|
def status
|
395
410
|
@status
|
396
411
|
end
|
397
|
-
|
412
|
+
|
398
413
|
# This method returns current output parser status
|
399
|
-
|
414
|
+
|
400
415
|
def parser_status
|
401
416
|
@parser_status
|
402
417
|
end
|
403
|
-
|
418
|
+
|
404
419
|
# This method returns common metadata for input streams as a hash with keys being symbols representing each metadata downcased name
|
405
|
-
|
420
|
+
|
406
421
|
def common_input_metadata
|
407
422
|
@input_meta_common
|
408
423
|
end
|
409
|
-
|
424
|
+
|
410
425
|
# This method returns metadata for audio input stream as a hash with keys being symbols representing each metadata downcased name
|
411
|
-
|
426
|
+
|
412
427
|
def audio_input_metadata
|
413
428
|
@input_meta_audio
|
414
429
|
end
|
415
|
-
|
430
|
+
|
416
431
|
# This method returns metadata for video input stream as a hash with keys being symbols representing each metadata downcased name
|
417
|
-
|
432
|
+
|
418
433
|
def video_input_metadata
|
419
434
|
@input_meta_video
|
420
435
|
end
|
421
|
-
|
436
|
+
|
422
437
|
# This method returns common metadata for output streams as a hash with keys being symbols representing each metadata downcased name
|
423
|
-
|
438
|
+
|
424
439
|
def common_output_metadata
|
425
440
|
@output_meta_common
|
426
441
|
end
|
427
|
-
|
442
|
+
|
428
443
|
# This method returns metadata for audio output stream as a hash with keys being symbols representing each metadata downcased name
|
429
|
-
|
444
|
+
|
430
445
|
def audio_output_metadata
|
431
446
|
@output_meta_audio
|
432
447
|
end
|
433
|
-
|
448
|
+
|
434
449
|
# This method returns metadata for video output stream as a hash with keys being symbols representing each metadata downcased name
|
435
|
-
|
450
|
+
|
436
451
|
def video_output_metadata
|
437
452
|
@output_meta_video
|
438
453
|
end
|
439
|
-
|
454
|
+
|
440
455
|
# This method returns a hash which represents current processing status (eg. frames processed, time processed etc.) with keys being symbols representing each status value
|
441
|
-
|
456
|
+
|
442
457
|
def processing_status
|
443
458
|
@processing_status
|
444
459
|
end
|
445
|
-
|
460
|
+
|
446
461
|
# This method returns audio stream mapping information (input_format -> output_format)
|
447
|
-
|
462
|
+
|
448
463
|
def audio_stream_mapping
|
449
464
|
@stream_mapping_audio
|
450
465
|
end
|
451
|
-
|
466
|
+
|
452
467
|
# This method returns video stream mapping information (input_format -> output_format)
|
453
|
-
|
468
|
+
|
454
469
|
def video_stream_mapping
|
455
470
|
@stream_mapping_video
|
456
471
|
end
|
457
|
-
|
472
|
+
|
458
473
|
# This method returns FFmpeg version line
|
459
|
-
|
474
|
+
|
460
475
|
def ffmpeg_version_line
|
461
476
|
@ff_versionline
|
462
477
|
end
|
463
|
-
|
478
|
+
|
464
479
|
# This method returns FFmpeg build line
|
465
|
-
|
480
|
+
|
466
481
|
def ffmpeg_build_line
|
467
482
|
@ff_buildline
|
468
483
|
end
|
469
|
-
|
484
|
+
|
470
485
|
# This method returns input type detected by FFmpeg
|
471
|
-
|
486
|
+
|
472
487
|
def input_type
|
473
488
|
@input_type
|
474
489
|
end
|
475
|
-
|
490
|
+
|
476
491
|
# This method returns input duration
|
477
|
-
|
492
|
+
|
478
493
|
def input_duration
|
479
494
|
@input_duration
|
480
495
|
end
|
481
|
-
|
496
|
+
|
482
497
|
# This method returns start point of the input
|
483
|
-
|
498
|
+
|
484
499
|
def input_start
|
485
500
|
@input_start
|
486
501
|
end
|
487
|
-
|
502
|
+
|
488
503
|
# This method returns input bitrate (from the duration line)
|
489
|
-
|
504
|
+
|
490
505
|
def input_bitrate
|
491
506
|
@input_bitrate
|
492
507
|
end
|
493
|
-
|
508
|
+
|
494
509
|
# This method returns format of audio input
|
495
|
-
|
510
|
+
|
496
511
|
def audio_input_format
|
497
512
|
@audio_input_format
|
498
513
|
end
|
499
|
-
|
514
|
+
|
500
515
|
# This method returns frequency of audio input
|
501
|
-
|
516
|
+
|
502
517
|
def audio_input_frequency
|
503
518
|
@audio_input_freq
|
504
519
|
end
|
505
|
-
|
520
|
+
|
506
521
|
# This method returns channel mode (eg. mono, stereo) of audio input
|
507
|
-
|
522
|
+
|
508
523
|
def audio_input_channelmode
|
509
524
|
@audio_input_channelmode
|
510
525
|
end
|
511
|
-
|
526
|
+
|
512
527
|
# This method returns type of format of audio input
|
513
|
-
|
528
|
+
|
514
529
|
def audio_input_format_type
|
515
530
|
@audio_input_format_type
|
516
531
|
end
|
517
|
-
|
532
|
+
|
518
533
|
# This method returns bitrate of audio input (from input information line)
|
519
|
-
|
534
|
+
|
520
535
|
def audio_input_bitrate2
|
521
536
|
@audio_input_bitrate2
|
522
537
|
end
|
523
|
-
|
538
|
+
|
524
539
|
# This method returns format of audio output
|
525
|
-
|
540
|
+
|
526
541
|
def audio_output_format
|
527
542
|
@audio_output_format
|
528
543
|
end
|
529
|
-
|
544
|
+
|
530
545
|
# This method returns frequency of audio output
|
531
|
-
|
546
|
+
|
532
547
|
def audio_output_frequency
|
533
548
|
@audio_output_freq
|
534
549
|
end
|
535
|
-
|
550
|
+
|
536
551
|
# This method returns channel mode (eg. mono, stereo) of audio output
|
537
|
-
|
552
|
+
|
538
553
|
def audio_output_channelmode
|
539
554
|
@audio_output_channelmode
|
540
555
|
end
|
541
|
-
|
556
|
+
|
542
557
|
# This method returns type of format of audio output
|
543
|
-
|
558
|
+
|
544
559
|
def audio_output_format_type
|
545
560
|
@audio_output_format_type
|
546
561
|
end
|
547
|
-
|
562
|
+
|
548
563
|
# This method returns bitrate of audio output (from output information line)
|
549
|
-
|
564
|
+
|
550
565
|
def audio_output_bitrate2
|
551
566
|
@audio_output_bitrate2
|
552
567
|
end
|
553
|
-
|
568
|
+
|
554
569
|
# This method returns format of video input
|
555
|
-
|
570
|
+
|
556
571
|
def video_input_format
|
557
572
|
@video_input_format
|
558
573
|
end
|
559
|
-
|
574
|
+
|
560
575
|
# This method returns color space of video input
|
561
|
-
|
576
|
+
|
562
577
|
def video_input_colorspace
|
563
578
|
@video_input_colorspace
|
564
579
|
end
|
565
|
-
|
580
|
+
|
566
581
|
# This method returns resolution of video input
|
567
|
-
|
582
|
+
|
568
583
|
def video_input_resolution
|
569
584
|
@video_input_resolution
|
570
585
|
end
|
571
|
-
|
586
|
+
|
572
587
|
# This method returns additional information about video input as an array of values
|
573
|
-
|
588
|
+
|
574
589
|
def video_input_additional
|
575
590
|
@video_input_additional
|
576
591
|
end
|
577
|
-
|
592
|
+
|
578
593
|
# This method returns format of video output
|
579
|
-
|
594
|
+
|
580
595
|
def video_output_format
|
581
596
|
@video_output_format
|
582
597
|
end
|
583
|
-
|
598
|
+
|
584
599
|
# This method returns color space of video output
|
585
|
-
|
600
|
+
|
586
601
|
def video_output_colorspace
|
587
602
|
@video_output_colorspace
|
588
603
|
end
|
589
|
-
|
604
|
+
|
590
605
|
# This method returns resolution of video output
|
591
|
-
|
606
|
+
|
592
607
|
def video_output_resolution
|
593
608
|
@video_output_resolution
|
594
609
|
end
|
595
|
-
|
610
|
+
|
596
611
|
# This method returns additional information about video output as an array of values
|
597
|
-
|
612
|
+
|
598
613
|
def video_output_additional
|
599
614
|
@video_output_additional
|
600
615
|
end
|
601
|
-
|
616
|
+
|
602
617
|
# This method returns percentage of process completion
|
603
|
-
|
618
|
+
|
604
619
|
def processing_percentage
|
605
620
|
@processing_percentage || 0
|
606
621
|
end
|
607
|
-
|
622
|
+
|
608
623
|
# This method returns percentage of process completion formatted for output
|
609
|
-
|
624
|
+
|
610
625
|
def format_processing_percentage
|
611
626
|
@processing_percentage.nil? ? "0%" : @processing_percentage.to_s + "%"
|
612
627
|
end
|
613
|
-
|
628
|
+
|
614
629
|
# This method returns the exit status of the FFmpeg command
|
615
|
-
|
630
|
+
|
616
631
|
def command_exit_status
|
617
632
|
@exit_status
|
618
633
|
end
|
619
|
-
|
634
|
+
|
620
635
|
# This method kills processing thread and sets status to :aborted
|
621
|
-
|
636
|
+
|
622
637
|
def kill
|
623
638
|
@processing_thread.kill
|
624
639
|
@status = :aborted
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phitherek_
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: This gem provides a simple Ruby interface to FFmpeg enabling users to
|
14
14
|
convert audio and video to HTML5 supported formats and monitor the process as it
|
@@ -37,12 +37,12 @@ require_paths:
|
|
37
37
|
- lib
|
38
38
|
required_ruby_version: !ruby/object:Gem::Requirement
|
39
39
|
requirements:
|
40
|
-
- -
|
40
|
+
- - ">="
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: 1.9.2
|
43
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
requirements:
|