Skip to content
This repository has been archived by the owner on Dec 23, 2022. It is now read-only.

Add hvc1 tag to codec and copy cover art for mp4 and m4v #127

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

upekshapriya
Copy link
Contributor

Add hvc1 tag to codec so HEVC is playable by Quicktime in mp4 and m4v containers on MacOS. See https://danconnor.com/posts/21d8bd7c22f6ae6b423c3c09/how_to_encode_h_265_hevc_video_that_will_play_in_quicktime_on_macos_using_ffmpeg_

Copy second video stream assuming it is mjpeg cover art and map it to the output file.
@upekshapriya
Copy link
Contributor Author

Copy the second video stream assuming it is an mjpeg stream masquerading as cover art.

@upekshapriya upekshapriya changed the title Add hvc1 tag to codec Add hvc1 tag to codec and copy cover art Nov 21, 2018
@upekshapriya upekshapriya changed the title Add hvc1 tag to codec and copy cover art Add hvc1 tag to codec and copy cover art for mp4 and m4v Nov 21, 2018
@upekshapriya
Copy link
Contributor Author

Only do this for m4v and mp4 files, not mkv files.

@upekshapriya
Copy link
Contributor Author

Workaround for ffmpeg not remapping channels for libopus automatically

@upekshapriya
Copy link
Contributor Author

Sorry this is all a bit of a mess but it mimics what I've done in the compiled version on my Mac which works perfectly for the files I'm converting, which I've been using for the last six months.

I also didn't realise that I had closed it last time I added a change I made.

Attaching the file I edited on my computer that I used as the basis for the changes here, which I found at /usr/local/lib/node_modules/h265ize/h265ize but added .txt so it could be uploaded here.

h265ize.txt
Sorry I'm not used to using Github

@upekshapriya upekshapriya reopened this Jun 28, 2019
// Video streams

if (args.outputFormat !== 'mkv') {
_.each(_self.streams.videoStreams, function(stream, i) {
Copy link
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
Contributor Author

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

Copy link
Contributor Author

@upekshapriya upekshapriya left a comment

Choose a reason for hiding this comment

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

Deleted

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants