Skip to content
This repository was archived by the owner on Dec 23, 2022. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions lib/classes/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,11 @@ class Video {

if (_self.streams.videoStreams.length > 1) {
// TODO implement feature
_self.encoder.logger.alert('More than one video stream detected. Using the video stream with the greatest duration.');
_self.encoder.logger.alert('More than one video stream detected. Using the video stream with the greatest duration. Assuming the second one is Cover Art masquerading as video.');
// copy the second stream assuming it is mjpeg Cover Art - if not mkv
if (args.outputFormat !== 'mkv') {
command.outputOptions('-c:v:1', 'copy');
}
videoIndex = 0;
}
let videoStream = _self.videoStream = _self.streams.videoStreams[videoIndex];
Expand Down Expand Up @@ -377,7 +381,13 @@ class Video {
break;
}
}


// add hvc1 tag to codec so it is playable by Quicktime - if not mkv

if (args.outputFormat !== 'mkv') {
command.outputOptions('-tag:v:'+ videoIndex, 'hvc1');
}

// Make sure we are only attempting to use 8 bit with fallback
// binary
// TODO
Expand Down Expand Up @@ -697,14 +707,29 @@ class Video {
mapStreams() {
let _self = this;
return new Promise(function(resolve, reject) {

_self.ffmpegCommand.outputOptions('-map', _self.videoStream.input + ':' + _self.videoStream.index);
_self.encoder.logger.debug('Video stream', _self.videoStream.input + ':' + _self.videoStream.index, 'mapped.', {
size: _self.videoStream.width + 'x' + _self.videoStream.height,
codec: _self.videoStream.codec_long_name,
profile: _self.videoStream.profile,
'bit depth': _self.videoBitDepth
});

// Video streams

if (args.outputFormat !== 'mkv') {
_.each(_self.streams.videoStreams, function(stream, i) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is only safe to map the first video stream. With your changes above (line 343) you can safely map a second stream, but not more than 2. Can you reduce this to only mapping the first 2 possible video streams.

Copy link
Copy Markdown
Contributor Author

@upekshapriya upekshapriya Oct 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for responding to my pull however I'm not exactly sure what you are suggesting here regarding mapping 2 video streams. But I'll explain my reasoning for mapping the second video track.

It appears that ffmpeg recognises cover art as a video stream. So for the video at https://d2qguwbxlx1sbt.cloudfront.net/TextInMotion-VideoSample-720p.mp4 from https://textinmotion.com/help/samples ffmpeg sees this as follows:

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '/Users/upekshapriya/Movies/TextInMotion-VideoSample-720p.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.25.100
  Duration: 00:00:30.23, start: 0.000000, bitrate: 3701 kb/s
    Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s (default)
    Metadata:
      handler_name    : SoundHandler
    Stream #0:1(eng): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 3509 kb/s, 25 fps, 25 tbr, 12800 tbn, 50 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:2: Video: mjpeg, yuvj444p(pc, bt470bg/unknown/unknown), 1920x1080 [SAR 72:72 DAR 16:9], 90k tbr, 90k tbn, 90k tbc

while MediaInfo sees it with one video stream but with Cover-Yes:

File  
Name TextInMotion-VideoSample-576p.mp4
Size 10.5 MB (10454044 bytes)
Kind MPEG-4 Video
UTI public.mpeg-4
Location /Users/upekshapriya/Movies
Created 2 October 2019 at 01:28:15
Modified 2 October 2019 at 01:28:26
Downloaded From https://d2qguwbxlx1sbt.cloudfront.net/TextInMotion-VideoSample-576p.mp4,https://textinmotion.com/
Container  
Format MPEG-4
Format profile Base Media
Codec ID isom (isom/iso2/avc1/mp41)
Duration 30 s 234 ms
Overall bit rate 2 766 kb/s
Writing application Lavf57.25.100
Cover Yes
Video  
ID 2
Format AVC
Format/Info Advanced Video Codec
Format profile Main@L3.1
Format settings CABAC / 4 Ref Frames
Format settings, CABAC Yes
Format settings, ReFrames 4 frames
Codec ID avc1
Codec ID/Info Advanced Video Coding
Duration 30 s 40 ms
Bit rate 2 568 kb/s
Width 1 024 pixels
Height 576 pixels
Pixel aspect ratio 1.000
Display aspect ratio 16:9
Frame rate mode Constant
Frame rate 25.000 FPS
Frame count 751
Color space YUV
Chroma subsampling 4:2:0
Bit depth 8 bits
Scan type Progressive
Bits/(Pixel*Frame) 0.174
Stream size 9.64 MB (92.2%)
Writing library x264 core 148
Encoding settings cabac=1 / ref=3 / deblock=1:0:0 / analyse=0x1:0x111 / me=hex / subme=7 / psy=1 / psy_rd=1.00:0.00 / mixed_ref=1 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=0 / cqm=0 / deadzone=21,11 / fast_pskip=1 / chroma_qp_offset=-2 / threads=18 / lookahead_threads=3 / sliced_threads=0 / nr=0 / decimate=1 / interlaced=0 / bluray_compat=0 / constrained_intra=0 / bframes=3 / b_pyramid=2 / b_adapt=1 / b_bias=0 / direct=1 / weightb=1 / open_gop=0 / weightp=2 / keyint=90 / keyint_min=9 / scenecut=40 / intra_refresh=0 / rc_lookahead=40 / rc=crf / mbtree=1 / crf=22.0 / qcomp=0.60 / qpmin=0 / qpmax=69 / qpstep=4 / vbv_maxrate=6000 / vbv_bufsize=100000 / crf_max=0.0 / nal_hrd=none / filler=0 / ip_ratio=1.40 / aq=1:1.00
Language English
Codec configuration box avcC
Audio  
ID 1
Format AAC LC
Format/Info Advanced Audio Codec Low Complexity
Codec ID mp4a-40-2
Duration 30 s 234 ms
Duration_LastFrame -22 ms
Bit rate mode Constant
Bit rate 128 kb/s
Channel(s) 2 channels
Channel layout L R
Sampling rate 44.1 kHz
Frame rate 43.066 FPS (1024 SPF)
Frame count 1303
Compression mode Lossy
Stream size 484 KB (4.6%)
Language English
Default Yes
Alternate group 1

It's a failing of ffmpeg that seems to cause this, as recognised by https://superuser.com/a/1357462

_self.ffmpegCommand.outputOptions('-map', stream.input + ':' + stream.index);
_self.encoder.logger.debug('Video stream', stream.input + ':' + stream.index, 'mapped.', {
size: stream.width + 'x' + stream.height,
codec: stream.codec_long_name,
profile: stream.profile,
'bit depth': _self.videoBitDepth
});
});
}
else {
_self.ffmpegCommand.outputOptions('-map', _self.videoStream.input + ':' + _self.videoStream.index);
_self.encoder.logger.debug('Video stream', _self.videoStream.input + ':' + _self.videoStream.index, 'mapped.', {
size: _self.videoStream.width + 'x' + _self.videoStream.height,
codec: _self.videoStream.codec_long_name,
profile: _self.videoStream.profile,
'bit depth': _self.videoBitDepth
});
}

// Handle native language detection and default audio track selection
_.each(_self.streams.audioStreams, function(stream, i) {
Expand Down