@@ -323,34 +323,108 @@ module FFMPEG
323
323
describe "pre_encode_if_necessary" do
324
324
let ( :output_path ) { "#{ tmp_path } /pre_encode_out.mp4" }
325
325
326
- it 'returns early if only a single video file' do
326
+ it 'returns early if only a single video file and no dynamic resolution ' do
327
327
transcoder = Transcoder . new ( movie , output_path , EncodingOptions . new )
328
+ allow ( movie ) . to receive ( :has_dynamic_resolution ) . and_return ( false )
328
329
expect ( movie ) . not_to receive ( :height )
329
330
transcoder . send ( :pre_encode_if_necessary )
330
331
end
331
332
333
+ it 'requires pre-encoding when movie has a single path and dynamic resolution is permitted' do
334
+ transcoder = Transcoder . new ( movie , output_path , EncodingOptions . new , { permit_dynamic_resolution_pre_encode : true } )
335
+ allow ( movie ) . to receive ( :has_dynamic_resolution ) . and_return ( true )
336
+ expect ( transcoder . requires_pre_encode ) . to be true
337
+ end
338
+
339
+ it 'does not require pre-encoding when movie has a single path and dynamic resolution is not permitted' do
340
+ transcoder = Transcoder . new ( movie , output_path , EncodingOptions . new , { permit_dynamic_resolution_pre_encode : false } )
341
+ allow ( movie ) . to receive ( :has_dynamic_resolution ) . and_return ( true )
342
+ expect ( transcoder . requires_pre_encode ) . to be false
343
+ end
344
+
332
345
describe 'creates interim inputs with scaling correctly applied based on input files' do
333
346
it 'with audio' do
334
347
transcoder = Transcoder . new ( movie_with_multiple_dimension_inputs , output_path , EncodingOptions . new )
348
+
349
+ expect ( Open3 ) . to receive ( :popen3 ) . exactly ( 2 ) . times # prevent ffprobe calls from being evaluated (check_frame_resolutions)
335
350
expect ( Open3 ) . to receive ( :popen3 ) . twice . with match ( /.*\[ 0\: v\] scale\= 854\: 480.*pad\= 854\: 480\: \( ow\- iw\) \/ 2\: \( oh\- ih\) \/ 2\: color\= black.*\- map \" 0\: a\" .*/ )
336
- transcoder . send ( :pre_encode_if_necessary )
337
351
352
+ transcoder . send ( :pre_encode_if_necessary )
338
353
end
339
354
340
355
it 'with silent audio' do
341
356
transcoder = Transcoder . new ( movie_with_multiple_dimension_inputs_with_partial_audio , output_path , EncodingOptions . new )
357
+
358
+ expect ( Open3 ) . to receive ( :popen3 ) . exactly ( 2 ) . times # prevent ffprobe calls from being evaluated (check_frame_resolutions)
342
359
# Match silent audio fill
343
360
expect ( Open3 ) . to receive ( :popen3 ) . once . with match ( /.*\[ 0\: v\] scale\= 960\: 540.*pad\= 960\: 540\: \( ow\- iw\) \/ 2\: \( oh\- ih\) \/ 2\: color\= black.*\- map \" \[ a\] \" .*/ )
344
361
# Retain "real" audio
345
362
expect ( Open3 ) . to receive ( :popen3 ) . once . with match ( /.*\[ 0\: v\] scale\= 960\: 540.*pad\= 960\: 540\: \( ow\- iw\) \/ 2\: \( oh\- ih\) \/ 2\: color\= black.*\- map \" 0\: a\" .*/ )
363
+
346
364
transcoder . send ( :pre_encode_if_necessary )
347
365
end
348
366
349
367
it 'without any audio' do
350
368
transcoder = Transcoder . new ( movie_with_multiple_dimension_inputs_with_no_audio , output_path , EncodingOptions . new )
369
+
370
+ expect ( Open3 ) . to receive ( :popen3 ) . exactly ( 2 ) . times # prevent ffprobe calls from being evaluated (check_frame_resolutions)
351
371
expect ( Open3 ) . to receive ( :popen3 ) . twice . with match ( /.*\[ 0\: v\] scale\= 960\: 540.*pad\= 960\: 540\: \( ow\- iw\) \/ 2\: \( oh\- ih\) \/ 2\: color\= black.*((?!\- map \" 0\: a\" )(?!\- map \" \[ a\] \" )).*/ )
372
+
373
+ transcoder . send ( :pre_encode_if_necessary )
374
+ end
375
+ end
376
+
377
+ describe "correctly applies the complex filter" do
378
+ it "when more than one input is provided will apply the complex filter" do
379
+ transcoder = Transcoder . new ( movie_with_two_inputs , output_path , EncodingOptions . new )
380
+
381
+ expect ( Open3 ) . to receive ( :popen3 ) . exactly ( 2 ) . times # prevent ffprobe calls from being evaluated (check_frame_resolutions)
382
+ expect ( Open3 ) . to receive ( :popen3 ) . twice . with match ( /-filter_complex/ )
383
+
352
384
transcoder . send ( :pre_encode_if_necessary )
353
385
end
386
+
387
+ it "when only one input is provided does not apply the complex filter" do
388
+ transcoder_options = { permit_dynamic_resolution_pre_encode : true }
389
+ transcoder = Transcoder . new ( movie , output_path , EncodingOptions . new , transcoder_options )
390
+ allow ( movie ) . to receive ( :has_dynamic_resolution ) . and_return ( true )
391
+
392
+ expect ( Open3 ) . not_to receive ( :popen3 ) . with ( '-filter_complex' )
393
+
394
+ transcoder . send ( :pre_encode_if_necessary )
395
+ end
396
+ end
397
+ end
398
+
399
+ describe "#requires_pre_encode" do
400
+ let ( :output_path ) { "#{ tmp_path } /output.mp4" }
401
+
402
+ it 'requires pre-encoding when movie has multiple paths' do
403
+ transcoder = Transcoder . new ( movie_with_two_inputs , output_path , EncodingOptions . new )
404
+ expect ( transcoder . requires_pre_encode ) . to be true
405
+ end
406
+
407
+ it 'requires pre-encoding when movie has a single path and dynamic resolution is permitted' do
408
+ movie = Movie . new ( "#{ fixture_path } /movies/awesome movie.mov" )
409
+ transcoder_options = { permit_dynamic_resolution_pre_encode : true }
410
+ transcoder = Transcoder . new ( movie , output_path , EncodingOptions . new , transcoder_options )
411
+ allow ( movie ) . to receive ( :has_dynamic_resolution ) . and_return ( true )
412
+ expect ( transcoder . requires_pre_encode ) . to be true
413
+ end
414
+
415
+ it 'does not require pre-encoding when movie has a single path and dynamic resolution is not permitted' do
416
+ movie = Movie . new ( "#{ fixture_path } /movies/awesome movie.mov" )
417
+ transcoder_options = { permit_dynamic_resolution_pre_encode : false }
418
+ transcoder = Transcoder . new ( movie , output_path , EncodingOptions . new , transcoder_options )
419
+ allow ( movie ) . to receive ( :has_dynamic_resolution ) . and_return ( true )
420
+ expect ( transcoder . requires_pre_encode ) . to be false
421
+ end
422
+
423
+ it 'does not require pre-encoding when movie has a single path without dynamic resolution' do
424
+ movie = Movie . new ( "#{ fixture_path } /movies/awesome movie.mov" )
425
+ transcoder = Transcoder . new ( movie , output_path , EncodingOptions . new )
426
+ allow ( movie ) . to receive ( :has_dynamic_resolution ) . and_return ( false )
427
+ expect ( transcoder . requires_pre_encode ) . to be false
354
428
end
355
429
end
356
430
end
0 commit comments