av icon indicating copy to clipboard operation
av copied to clipboard

Divisible height/width

Open muschellij2 opened this issue 5 years ago • 3 comments

Ran into this in the past with ffmpeg, so I figured it may be a good use case for vfilter or something to put as a check so users can see a way to fix it. The error is shown in the std_err where it says width not divisible by 2 (959x720). Fix from https://stackoverflow.com/questions/20847674/ffmpeg-libx264-height-not-divisible-by-2 shows that this works.

library(av)
    outfile = tempfile(fileext = ".mp4")
    xx = av_demo(width = 959, output = outfile)
#> Error: FFMPEG error in 'avcodec_open2': Generic error in an external library
    xx
#> Error in eval(expr, envir, enclos): object 'xx' not found
    file.exists(outfile)
#> [1] FALSE
    
    xx = av_demo(width = 959, output = outfile,
                 vfilter = "scale=trunc(iw/2)*2:trunc(ih/2)*2")
    xx
#> NULL
    file.exists(outfile)
#> [1] TRUE

standard output and standard error


Generating plot 1/150...
Generating plot 2/150...
Generating plot 3/150...
Generating plot 4/150...
Generating plot 5/150...
Generating plot 6/150...
Generating plot 7/150...
Generating plot 8/150...
Generating plot 9/150...
Generating plot 10/150...
Generating plot 11/150...
Generating plot 12/150...
Generating plot 13/150...
Generating plot 14/150...
Generating plot 15/150...
Generating plot 16/150...
Generating plot 17/150...
Generating plot 18/150...
Generating plot 19/150...
Generating plot 20/150...
Generating plot 21/150...
Generating plot 22/150...
Generating plot 23/150...
Generating plot 24/150...
Generating plot 25/150...
Generating plot 26/150...
Generating plot 27/150...
Generating plot 28/150...
Generating plot 29/150...
Generating plot 30/150...
Generating plot 31/150...
Generating plot 32/150...
Generating plot 33/150...
Generating plot 34/150...
Generating plot 35/150...
Generating plot 36/150...
Generating plot 37/150...
Generating plot 38/150...
Generating plot 39/150...
Generating plot 40/150...
Generating plot 41/150...
Generating plot 42/150...
Generating plot 43/150...
Generating plot 44/150...
Generating plot 45/150...
Generating plot 46/150...
Generating plot 47/150...
Generating plot 48/150...
Generating plot 49/150...
Generating plot 50/150...
Generating plot 51/150...
Generating plot 52/150...
Generating plot 53/150...
Generating plot 54/150...
Generating plot 55/150...
Generating plot 56/150...
Generating plot 57/150...
Generating plot 58/150...
Generating plot 59/150...
Generating plot 60/150...
Generating plot 61/150...
Generating plot 62/150...
Generating plot 63/150...
Generating plot 64/150...
Generating plot 65/150...
Generating plot 66/150...
Generating plot 67/150...
Generating plot 68/150...
Generating plot 69/150...
Generating plot 70/150...
Generating plot 71/150...
Generating plot 72/150...
Generating plot 73/150...
Generating plot 74/150...
Generating plot 75/150...
Generating plot 76/150...
Generating plot 77/150...
Generating plot 78/150...
Generating plot 79/150...
Generating plot 80/150...
Generating plot 81/150...
Generating plot 82/150...
Generating plot 83/150...
Generating plot 84/150...
Generating plot 85/150...
Generating plot 86/150...
Generating plot 87/150...
Generating plot 88/150...
Generating plot 89/150...
Generating plot 90/150...
Generating plot 91/150...
Generating plot 92/150...
Generating plot 93/150...
Generating plot 94/150...
Generating plot 95/150...
Generating plot 96/150...
Generating plot 97/150...
Generating plot 98/150...
Generating plot 99/150...
Generating plot 100/150...
Generating plot 101/150...
Generating plot 102/150...
Generating plot 103/150...
Generating plot 104/150...
Generating plot 105/150...
Generating plot 106/150...
Generating plot 107/150...
Generating plot 108/150...
Generating plot 109/150...
Generating plot 110/150...
Generating plot 111/150...
Generating plot 112/150...
Generating plot 113/150...
Generating plot 114/150...
Generating plot 115/150...
Generating plot 116/150...
Generating plot 117/150...
Generating plot 118/150...
Generating plot 119/150...
Generating plot 120/150...
Generating plot 121/150...
Generating plot 122/150...
Generating plot 123/150...
Generating plot 124/150...
Generating plot 125/150...
Generating plot 126/150...
Generating plot 127/150...
Generating plot 128/150...
Generating plot 129/150...
Generating plot 130/150...
Generating plot 131/150...
Generating plot 132/150...
Generating plot 133/150...
Generating plot 134/150...
Generating plot 135/150...
Generating plot 136/150...
Generating plot 137/150...
Generating plot 138/150...
Generating plot 139/150...
Generating plot 140/150...
Generating plot 141/150...
Generating plot 142/150...
Generating plot 143/150...
Generating plot 144/150...
Generating plot 145/150...
Generating plot 146/150...
Generating plot 147/150...
Generating plot 148/150...
Generating plot 149/150...
Generating plot 150/150...done!
width not divisible by 2 (959x720)

Generating plot 1/150...
Generating plot 2/150...
Generating plot 3/150...
Generating plot 4/150...
Generating plot 5/150...
Generating plot 6/150...
Generating plot 7/150...
Generating plot 8/150...
Generating plot 9/150...
Generating plot 10/150...
Generating plot 11/150...
Generating plot 12/150...
Generating plot 13/150...
Generating plot 14/150...
Generating plot 15/150...
Generating plot 16/150...
Generating plot 17/150...
Generating plot 18/150...
Generating plot 19/150...
Generating plot 20/150...
Generating plot 21/150...
Generating plot 22/150...
Generating plot 23/150...
Generating plot 24/150...
Generating plot 25/150...
Generating plot 26/150...
Generating plot 27/150...
Generating plot 28/150...
Generating plot 29/150...
Generating plot 30/150...
Generating plot 31/150...
Generating plot 32/150...
Generating plot 33/150...
Generating plot 34/150...
Generating plot 35/150...
Generating plot 36/150...
Generating plot 37/150...
Generating plot 38/150...
Generating plot 39/150...
Generating plot 40/150...
Generating plot 41/150...
Generating plot 42/150...
Generating plot 43/150...
Generating plot 44/150...
Generating plot 45/150...
Generating plot 46/150...
Generating plot 47/150...
Generating plot 48/150...
Generating plot 49/150...
Generating plot 50/150...
Generating plot 51/150...
Generating plot 52/150...
Generating plot 53/150...
Generating plot 54/150...
Generating plot 55/150...
Generating plot 56/150...
Generating plot 57/150...
Generating plot 58/150...
Generating plot 59/150...
Generating plot 60/150...
Generating plot 61/150...
Generating plot 62/150...
Generating plot 63/150...
Generating plot 64/150...
Generating plot 65/150...
Generating plot 66/150...
Generating plot 67/150...
Generating plot 68/150...
Generating plot 69/150...
Generating plot 70/150...
Generating plot 71/150...
Generating plot 72/150...
Generating plot 73/150...
Generating plot 74/150...
Generating plot 75/150...
Generating plot 76/150...
Generating plot 77/150...
Generating plot 78/150...
Generating plot 79/150...
Generating plot 80/150...
Generating plot 81/150...
Generating plot 82/150...
Generating plot 83/150...
Generating plot 84/150...
Generating plot 85/150...
Generating plot 86/150...
Generating plot 87/150...
Generating plot 88/150...
Generating plot 89/150...
Generating plot 90/150...
Generating plot 91/150...
Generating plot 92/150...
Generating plot 93/150...
Generating plot 94/150...
Generating plot 95/150...
Generating plot 96/150...
Generating plot 97/150...
Generating plot 98/150...
Generating plot 99/150...
Generating plot 100/150...
Generating plot 101/150...
Generating plot 102/150...
Generating plot 103/150...
Generating plot 104/150...
Generating plot 105/150...
Generating plot 106/150...
Generating plot 107/150...
Generating plot 108/150...
Generating plot 109/150...
Generating plot 110/150...
Generating plot 111/150...
Generating plot 112/150...
Generating plot 113/150...
Generating plot 114/150...
Generating plot 115/150...
Generating plot 116/150...
Generating plot 117/150...
Generating plot 118/150...
Generating plot 119/150...
Generating plot 120/150...
Generating plot 121/150...
Generating plot 122/150...
Generating plot 123/150...
Generating plot 124/150...
Generating plot 125/150...
Generating plot 126/150...
Generating plot 127/150...
Generating plot 128/150...
Generating plot 129/150...
Generating plot 130/150...
Generating plot 131/150...
Generating plot 132/150...
Generating plot 133/150...
Generating plot 134/150...
Generating plot 135/150...
Generating plot 136/150...
Generating plot 137/150...
Generating plot 138/150...
Generating plot 139/150...
Generating plot 140/150...
Generating plot 141/150...
Generating plot 142/150...
Generating plot 143/150...
Generating plot 144/150...
Generating plot 145/150...
Generating plot 146/150...
Generating plot 147/150...
Generating plot 148/150...
Generating plot 149/150...
Generating plot 150/150...done!
using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 BMI2 AVX2
profile High, level 6.0
264 - core 152 r2854 e9a5903 - H.264/MPEG-4 AVC codec - Copyleft 2003-2017 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x3:0x113 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=16 chroma_me=1 trellis=1 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=6 lookahead_threads=1 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=5 keyint_min=1 scenecut=40 intra_refresh=0 rc_lookahead=5 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00
Output #0, mp4, to '/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//RtmpTITrPW/fileef6a6a48f65.mp4':
  Metadata:
    encoder         : Lavf58.12.100
    Stream #0:0: Video: h264 (libx264) (avc1 / 0x31637661), yuv420p, 958x720, q=-1--1, 90k tbn
    Stream #0:1: Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 128 kb/s

Adding frame 1 at timestamp 0.00sec (10%)
Adding frame 1 at timestamp 0.20sec (10%)Could not update timestamps for skipped samples.

Adding frame 3 at timestamp 0.40sec (11%)
Adding frame 4 at timestamp 0.60sec (12%)
Adding frame 5 at timestamp 0.80sec (12%)
Adding frame 6 at timestamp 1.00sec (13%)
Adding frame 7 at timestamp 1.20sec (14%)
Adding frame 8 at timestamp 1.40sec (14%)
Adding frame 9 at timestamp 1.60sec (15%)
Adding frame 10 at timestamp 1.80sec (16%)
Adding frame 11 at timestamp 2.00sec (16%)
Adding frame 12 at timestamp 2.20sec (17%)
Adding frame 13 at timestamp 2.40sec (18%)
Adding frame 14 at timestamp 2.60sec (18%)
Adding frame 15 at timestamp 2.80sec (19%)
Adding frame 16 at timestamp 3.00sec (20%)
Adding frame 17 at timestamp 3.20sec (20%)
Adding frame 18 at timestamp 3.40sec (21%)
Adding frame 19 at timestamp 3.60sec (22%)
Adding frame 20 at timestamp 3.80sec (22%)
Adding frame 21 at timestamp 4.00sec (23%)
Adding frame 22 at timestamp 4.20sec (24%)
Adding frame 23 at timestamp 4.40sec (24%)
Adding frame 24 at timestamp 4.60sec (25%)
Adding frame 25 at timestamp 4.80sec (26%)
Adding frame 26 at timestamp 5.00sec (26%)
Adding frame 27 at timestamp 5.20sec (27%)
Adding frame 28 at timestamp 5.40sec (28%)
Adding frame 29 at timestamp 5.60sec (28%)
Adding frame 30 at timestamp 5.80sec (29%)
Adding frame 31 at timestamp 6.00sec (30%)
Adding frame 32 at timestamp 6.20sec (30%)
Adding frame 33 at timestamp 6.40sec (31%)
Adding frame 34 at timestamp 6.60sec (32%)
Adding frame 35 at timestamp 6.80sec (32%)
Adding frame 36 at timestamp 7.00sec (33%)
Adding frame 37 at timestamp 7.20sec (34%)
Adding frame 38 at timestamp 7.40sec (34%)
Adding frame 39 at timestamp 7.60sec (35%)
Adding frame 40 at timestamp 7.80sec (36%)
Adding frame 41 at timestamp 8.00sec (36%)
Adding frame 42 at timestamp 8.20sec (37%)
Adding frame 43 at timestamp 8.40sec (38%)
Adding frame 44 at timestamp 8.60sec (38%)
Adding frame 45 at timestamp 8.80sec (39%)
Adding frame 46 at timestamp 9.00sec (40%)
Adding frame 47 at timestamp 9.20sec (40%)
Adding frame 48 at timestamp 9.40sec (41%)
Adding frame 49 at timestamp 9.60sec (42%)
Adding frame 50 at timestamp 9.80sec (42%)
Adding frame 51 at timestamp 10.00sec (43%)
Adding frame 52 at timestamp 10.20sec (44%)
Adding frame 53 at timestamp 10.40sec (44%)
Adding frame 54 at timestamp 10.60sec (45%)
Adding frame 55 at timestamp 10.80sec (46%)
Adding frame 56 at timestamp 11.00sec (46%)
Adding frame 57 at timestamp 11.20sec (47%)
Adding frame 58 at timestamp 11.40sec (48%)
Adding frame 59 at timestamp 11.60sec (48%)
Adding frame 60 at timestamp 11.80sec (49%)
Adding frame 61 at timestamp 12.00sec (50%)
Adding frame 62 at timestamp 12.20sec (50%)
Adding frame 63 at timestamp 12.40sec (51%)
Adding frame 64 at timestamp 12.60sec (52%)
Adding frame 65 at timestamp 12.80sec (52%)
Adding frame 66 at timestamp 13.00sec (53%)
Adding frame 67 at timestamp 13.20sec (54%)
Adding frame 68 at timestamp 13.40sec (54%)
Adding frame 69 at timestamp 13.60sec (55%)
Adding frame 70 at timestamp 13.80sec (56%)
Adding frame 71 at timestamp 14.00sec (56%)
Adding frame 72 at timestamp 14.20sec (57%)
Adding frame 73 at timestamp 14.40sec (58%)
Adding frame 74 at timestamp 14.60sec (58%)
Adding frame 75 at timestamp 14.80sec (59%)
Adding frame 76 at timestamp 15.00sec (60%)
Adding frame 77 at timestamp 15.20sec (60%)
Adding frame 78 at timestamp 15.40sec (61%)
Adding frame 79 at timestamp 15.60sec (62%)
Adding frame 80 at timestamp 15.80sec (62%)
Adding frame 81 at timestamp 16.00sec (63%)
Adding frame 82 at timestamp 16.20sec (64%)
Adding frame 83 at timestamp 16.40sec (64%)
Adding frame 84 at timestamp 16.60sec (65%)
Adding frame 85 at timestamp 16.80sec (66%)
Adding frame 86 at timestamp 17.00sec (66%)
Adding frame 87 at timestamp 17.20sec (67%)
Adding frame 88 at timestamp 17.40sec (68%)
Adding frame 89 at timestamp 17.60sec (68%)
Adding frame 90 at timestamp 17.80sec (69%)
Adding frame 91 at timestamp 18.00sec (70%)
Adding frame 92 at timestamp 18.20sec (70%)
Adding frame 93 at timestamp 18.40sec (71%)
Adding frame 94 at timestamp 18.60sec (72%)
Adding frame 95 at timestamp 18.80sec (72%)
Adding frame 96 at timestamp 19.00sec (73%)
Adding frame 97 at timestamp 19.20sec (74%)
Adding frame 98 at timestamp 19.40sec (74%)
Adding frame 99 at timestamp 19.60sec (75%)
Adding frame 100 at timestamp 19.80sec (76%)
Adding frame 101 at timestamp 20.00sec (76%)
Adding frame 102 at timestamp 20.20sec (77%)
Adding frame 103 at timestamp 20.40sec (78%)
Adding frame 104 at timestamp 20.60sec (78%)
Adding frame 105 at timestamp 20.80sec (79%)
Adding frame 106 at timestamp 21.00sec (80%)
Adding frame 107 at timestamp 21.20sec (80%)
Adding frame 108 at timestamp 21.40sec (81%)
Adding frame 109 at timestamp 21.60sec (82%)
Adding frame 110 at timestamp 21.80sec (82%)
Adding frame 111 at timestamp 22.00sec (83%)
Adding frame 112 at timestamp 22.20sec (84%)
Adding frame 113 at timestamp 22.40sec (84%)
Adding frame 114 at timestamp 22.60sec (85%)
Adding frame 115 at timestamp 22.80sec (86%)
Adding frame 116 at timestamp 23.00sec (86%)
Adding frame 117 at timestamp 23.20sec (87%)
Adding frame 118 at timestamp 23.40sec (88%)
Adding frame 119 at timestamp 23.60sec (88%)
Adding frame 120 at timestamp 23.80sec (89%)
Adding frame 121 at timestamp 24.00sec (90%)
Adding frame 122 at timestamp 24.20sec (90%)
Adding frame 123 at timestamp 24.40sec (91%)
Adding frame 124 at timestamp 24.60sec (92%)
Adding frame 125 at timestamp 24.80sec (92%)
Adding frame 126 at timestamp 25.00sec (93%)
Adding frame 127 at timestamp 25.20sec (94%)
Adding frame 128 at timestamp 25.40sec (94%)
Adding frame 129 at timestamp 25.60sec (95%)
Adding frame 130 at timestamp 25.80sec (96%)
Adding frame 131 at timestamp 26.00sec (96%)
Adding frame 132 at timestamp 26.20sec (97%)
Adding frame 133 at timestamp 26.40sec (98%)
Adding frame 134 at timestamp 26.60sec (98%)
Adding frame 135 at timestamp 26.80sec (99%)
Adding frame 136 at timestamp 27.00sec (100%)
Adding frame 137 at timestamp 27.20sec (100%)
Adding frame 138 at timestamp 27.40sec (100%)
Adding frame 139 at timestamp 27.60sec (100%)
Adding frame 140 at timestamp 27.80sec (100%)
Adding frame 141 at timestamp 28.00sec (100%)
Adding frame 142 at timestamp 28.20sec (100%)
Adding frame 143 at timestamp 28.40sec (100%)
Adding frame 144 at timestamp 28.60sec (100%)
Adding frame 145 at timestamp 28.80sec (100%)
Adding frame 146 at timestamp 29.00sec (100%)
Adding frame 147 at timestamp 29.20sec (100%)
Adding frame 148 at timestamp 29.40sec (100%)
Adding frame 149 at timestamp 29.60sec (100%)
Adding frame 150 at timestamp 29.80sec (100%)
Adding frame 151 at timestamp 30.00sec (100%)Could not update timestamps for discarded samples.
 - video stream completed!
Audio stream complete!
frame I:151   Avg QP:13.84  size:  5818
mb I  I16..4: 61.1% 33.4%  5.5%
8x8 transform intra:33.4%
coded y,uvDC,uvAC intra: 2.9% 2.3% 1.7%
i16 v,h,dc,p: 86% 10%  4%  0%
i8 v,h,dc,ddl,ddr,vr,hd,vl,hu: 66%  4% 31%  0%  0%  0%  0%  0%  0%
i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 49% 23% 18%  1%  2%  2%  2%  2%  2%
i8c dc,h,v,p: 86%  5%  9%  0%
kb/s:232.71
Qavg: 348.080
[WARNING] Could not parse YAML metadata at line 1 column 1: :6:25: Unexpected '
  '

Created on 2018-10-06 by the reprex package (v0.2.0).

muschellij2 avatar Oct 06 '18 15:10 muschellij2

So are you suggesting that we verify that the width/height are even?

jeroen avatar Oct 06 '18 15:10 jeroen

Don't know best course of action. Warning? Error? Or add in the truncation so it will work with a warning?

muschellij2 avatar Oct 06 '18 15:10 muschellij2

I'd say enforce divisible height/width when output type is mp4 as libx264 requires it.

muschellij2 avatar Sep 11 '19 17:09 muschellij2