Eu tenho um script que corta e emende alguns vídeos do youtube com ffmpeg para criar uma miniatura de mpeg. O resultado final é um mp4 que funciona bem com a tag HTML <video>
no Mac OSX Safari, Chrome e Android Chrome. Mas quando se trata de Safari ou Chrome no iOS, ele falha. Aqui está o script que estou usando para gerar a miniatura:
#!/bin/bash
video_name=waterfalls
if [ ! -f $video_name.mp4 ]; then
youtube-dl -f 134 -o $video_name.mp4 https://www.youtube.com/watch?v=_henIN18dz0
fi
rm "$video_name"_clip_{1,2,3}.mp4
rm "$video_name"_thumbnail.mp4
ffmpeg -ss 00:00:30 -i $video_name.mp4 -t 00:00:02 -c:v libx264 -vprofile baseline -level 3.0 "$video_name"_clip_1.mp4
ffmpeg -ss 00:01:58 -i $video_name.mp4 -t 00:00:02 -c:v libx264 -vprofile baseline -level 3.0 "$video_name"_clip_2.mp4
ffmpeg -ss 00:05:31 -i $video_name.mp4 -t 00:00:02 -c:v libx264 -vprofile baseline -level 3.0 "$video_name"_clip_3.mp4
ffmpeg -i "concat:"$video_name"_clip_1.mp4|"$video_name"_clip_2.mp4|"$video_name"_clip_3.mp4" -c:v \
libx264 -vprofile baseline -level 3.0 "$video_name"_thumbnail.mp4
rm "$video_name"_clip_{1,2,3}.mp4
Eu tenho os comandos de perfil do link
Aqui está a saída inteira do script:
rm: waterfalls_1.mp4: No such file or directory
rm: waterfalls_2.mp4: No such file or directory
rm: waterfalls_3.mp4: No such file or directory
ffmpeg version 2.6 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
libavutil 54. 20.100 / 54. 20.100
libavcodec 56. 26.100 / 56. 26.100
libavformat 56. 25.101 / 56. 25.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 11.102 / 5. 11.102
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'waterfalls.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6avc1mp41
creation_time : 2014-12-09 05:24:08
Duration: 00:06:06.63, start: 0.000000, bitrate: 522 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 519 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
Metadata:
creation_time : 2014-12-09 05:24:08
handler_name : VideoHandler
[libx264 @ 0x7feff4001200] using SAR=1/1
[libx264 @ 0x7feff4001200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7feff4001200] profile Constrained Baseline, level 3.0
[libx264 @ 0x7feff4001200] 264 - core 142 r2495 6a301b6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=0 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=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 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 'waterfalls_1.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6avc1mp41
encoder : Lavf56.25.101
Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc (default)
Metadata:
creation_time : 2014-12-09 05:24:08
handler_name : VideoHandler
encoder : Lavc56.26.100 libx264
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 59 fps=0.0 q=-1.0 Lsize= 164kB time=00:00:02.00 bitrate= 669.7kbits/s
video:163kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.640156%
[libx264 @ 0x7feff4001200] frame I:1 Avg QP:23.93 size: 29612
[libx264 @ 0x7feff4001200] frame P:58 Avg QP:24.82 size: 2350
[libx264 @ 0x7feff4001200] mb I I16..4: 17.3% 0.0% 82.7%
[libx264 @ 0x7feff4001200] mb P I16..4: 0.3% 0.0% 0.2% P16..4: 38.0% 10.1% 3.5% 0.0% 0.0% skip:47.8%
[libx264 @ 0x7feff4001200] coded y,uvDC,uvAC intra: 71.4% 65.9% 23.0% inter: 12.4% 8.8% 0.1%
[libx264 @ 0x7feff4001200] i16 v,h,dc,p: 25% 36% 12% 27%
[libx264 @ 0x7feff4001200] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 16% 15% 6% 7% 7% 7% 7% 8%
[libx264 @ 0x7feff4001200] i8c dc,h,v,p: 52% 24% 18% 7%
[libx264 @ 0x7feff4001200] ref P L0: 70.7% 14.6% 14.7%
[libx264 @ 0x7feff4001200] kb/s:674.14
ffmpeg version 2.6 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
libavutil 54. 20.100 / 54. 20.100
libavcodec 56. 26.100 / 56. 26.100
libavformat 56. 25.101 / 56. 25.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 11.102 / 5. 11.102
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'waterfalls.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6avc1mp41
creation_time : 2014-12-09 05:24:08
Duration: 00:06:06.63, start: 0.000000, bitrate: 522 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 519 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
Metadata:
creation_time : 2014-12-09 05:24:08
handler_name : VideoHandler
[libx264 @ 0x7fc64c824200] using SAR=1/1
[libx264 @ 0x7fc64c824200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fc64c824200] profile Constrained Baseline, level 3.0
[libx264 @ 0x7fc64c824200] 264 - core 142 r2495 6a301b6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=0 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=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 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 'waterfalls_2.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6avc1mp41
encoder : Lavf56.25.101
Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc (default)
Metadata:
creation_time : 2014-12-09 05:24:08
handler_name : VideoHandler
encoder : Lavc56.26.100 libx264
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 59 fps=0.0 q=-1.0 Lsize= 217kB time=00:00:02.00 bitrate= 888.4kbits/s
video:216kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.481812%
[libx264 @ 0x7fc64c824200] frame I:1 Avg QP:25.17 size: 37772
[libx264 @ 0x7fc64c824200] frame P:58 Avg QP:25.58 size: 3153
[libx264 @ 0x7fc64c824200] mb I I16..4: 2.2% 0.0% 97.8%
[libx264 @ 0x7fc64c824200] mb P I16..4: 0.0% 0.0% 0.6% P16..4: 44.7% 14.1% 5.7% 0.0% 0.0% skip:34.9%
[libx264 @ 0x7fc64c824200] coded y,uvDC,uvAC intra: 92.6% 79.0% 23.0% inter: 15.2% 11.0% 0.0%
[libx264 @ 0x7fc64c824200] i16 v,h,dc,p: 11% 29% 25% 36%
[libx264 @ 0x7fc64c824200] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 27% 12% 13% 7% 8% 9% 7% 7% 8%
[libx264 @ 0x7fc64c824200] i8c dc,h,v,p: 48% 22% 22% 8%
[libx264 @ 0x7fc64c824200] ref P L0: 58.1% 21.8% 20.2%
[libx264 @ 0x7fc64c824200] kb/s:896.54
ffmpeg version 2.6 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
libavutil 54. 20.100 / 54. 20.100
libavcodec 56. 26.100 / 56. 26.100
libavformat 56. 25.101 / 56. 25.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 11.102 / 5. 11.102
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'waterfalls.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6avc1mp41
creation_time : 2014-12-09 05:24:08
Duration: 00:06:06.63, start: 0.000000, bitrate: 522 kb/s
Stream #0:0(und): Video: h264 (Main) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 519 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
Metadata:
creation_time : 2014-12-09 05:24:08
handler_name : VideoHandler
[libx264 @ 0x7fb7e982c200] using SAR=1/1
[libx264 @ 0x7fb7e982c200] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fb7e982c200] profile Constrained Baseline, level 3.0
[libx264 @ 0x7fb7e982c200] 264 - core 142 r2495 6a301b6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=0 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=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 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 'waterfalls_3.mp4':
Metadata:
major_brand : dash
minor_version : 0
compatible_brands: iso6avc1mp41
encoder : Lavf56.25.101
Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc (default)
Metadata:
creation_time : 2014-12-09 05:24:08
handler_name : VideoHandler
encoder : Lavc56.26.100 libx264
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 59 fps=0.0 q=-1.0 Lsize= 205kB time=00:00:02.00 bitrate= 838.3kbits/s
video:204kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.510744%
[libx264 @ 0x7fb7e982c200] frame I:1 Avg QP:24.41 size: 29398
[libx264 @ 0x7fb7e982c200] frame P:58 Avg QP:24.57 size: 3081
[libx264 @ 0x7fb7e982c200] mb I I16..4: 3.2% 0.0% 96.8%
[libx264 @ 0x7fb7e982c200] mb P I16..4: 0.1% 0.0% 0.3% P16..4: 51.1% 13.2% 4.6% 0.0% 0.0% skip:30.7%
[libx264 @ 0x7fb7e982c200] coded y,uvDC,uvAC intra: 87.8% 88.1% 37.6% inter: 21.4% 15.1% 0.0%
[libx264 @ 0x7fb7e982c200] i16 v,h,dc,p: 16% 12% 56% 16%
[libx264 @ 0x7fb7e982c200] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 20% 15% 14% 8% 10% 8% 9% 7% 10%
[libx264 @ 0x7fb7e982c200] i8c dc,h,v,p: 50% 19% 23% 7%
[libx264 @ 0x7fb7e982c200] ref P L0: 72.3% 18.2% 9.5%
[libx264 @ 0x7fb7e982c200] kb/s:845.61
ffmpeg version 2.6 Copyright (c) 2000-2015 the FFmpeg developers
built with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
libavutil 54. 20.100 / 54. 20.100
libavcodec 56. 26.100 / 56. 26.100
libavformat 56. 25.101 / 56. 25.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 11.102 / 5. 11.102
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7fa5eb800a00] Found duplicated MOOV Atom. Skipped it
Last message repeated 1 times
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'concat:waterfalls_1.mp4|waterfalls_2.mp4|waterfalls_3.mp4':
Metadata:
encoder : Lavf56.25.101
minor_version : 512
major_brand : isom
compatible_brands: isomiso2avc1mp41
Duration: 00:00:01.97, start: 0.033000, bitrate: 2436 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 676 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
[libx264 @ 0x7fa5ec000a00] using SAR=1/1
[libx264 @ 0x7fa5ec000a00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX
[libx264 @ 0x7fa5ec000a00] profile Constrained Baseline, level 3.0
[libx264 @ 0x7fa5ec000a00] 264 - core 142 r2495 6a301b6 - H.264/MPEG-4 AVC codec - Copyleft 2003-2014 - http://www.videolan.org/x264.html - options: cabac=0 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=12 lookahead_threads=2 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=0 weightp=0 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 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 'waterfalls_thumbnail.mp4':
Metadata:
compatible_brands: isomiso2avc1mp41
minor_version : 512
major_brand : isom
encoder : Lavf56.25.101
Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x360 [SAR 1:1 DAR 16:9], q=-1--1, 29.97 fps, 30k tbn, 29.97 tbc (default)
Metadata:
handler_name : VideoHandler
encoder : Lavc56.26.100 libx264
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
Press [q] to stop, [?] for help
frame= 59 fps=0.0 q=-1.0 Lsize= 143kB time=00:00:01.96 bitrate= 593.6kbits/s
video:142kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.726841%
[libx264 @ 0x7fa5ec000a00] frame I:1 Avg QP:23.67 size: 28609
[libx264 @ 0x7fa5ec000a00] frame P:58 Avg QP:24.52 size: 1996
[libx264 @ 0x7fa5ec000a00] mb I I16..4: 18.9% 0.0% 81.1%
[libx264 @ 0x7fa5ec000a00] mb P I16..4: 0.3% 0.0% 0.2% P16..4: 35.8% 9.6% 2.5% 0.0% 0.0% skip:51.5%
[libx264 @ 0x7fa5ec000a00] coded y,uvDC,uvAC intra: 68.6% 68.5% 22.1% inter: 9.8% 9.0% 0.1%
[libx264 @ 0x7fa5ec000a00] i16 v,h,dc,p: 22% 39% 12% 27%
[libx264 @ 0x7fa5ec000a00] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 28% 16% 14% 6% 7% 7% 7% 7% 7%
[libx264 @ 0x7fa5ec000a00] i8c dc,h,v,p: 51% 24% 18% 7%
[libx264 @ 0x7fa5ec000a00] ref P L0: 73.9% 13.6% 12.4%
[libx264 @ 0x7fa5ec000a00] kb/s:586.73
e finalmente, aqui está o ffprobe do vídeo final:
ffprobe version 2.6 Copyright (c) 2007-2015 the FFmpeg developers
built with Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn)
configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-vda
libavutil 54. 20.100 / 54. 20.100
libavcodec 56. 26.100 / 56. 26.100
libavformat 56. 25.101 / 56. 25.101
libavdevice 56. 4.100 / 56. 4.100
libavfilter 5. 11.102 / 5. 11.102
libavresample 2. 1. 0 / 2. 1. 0
libswscale 3. 1.101 / 3. 1.101
libswresample 1. 1.100 / 1. 1.100
libpostproc 53. 3.100 / 53. 3.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'waterfalls_thumbnail.mp4':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf56.25.101
Duration: 00:00:01.97, start: 0.000000, bitrate: 593 kb/s
Stream #0:0(und): Video: h264 (Constrained Baseline) (avc1 / 0x31637661), yuv420p, 640x360 [SAR 1:1 DAR 16:9], 589 kb/s, 29.97 fps, 29.97 tbr, 30k tbn, 59.94 tbc (default)
Metadata:
handler_name : VideoHandler
O ogirinal mp4, qualquer um dos clipes e o último mp4 não são reproduzidos no iOS em uma página da Web usando esta tag de vídeo:
<video width="320" height="180" poster="/static/images/waterfalls_poster.jpg" autoplay loop controls>
<source src="/static/videos/waterfalls_thumbnail" type="video/mp4"/>
Your browser does not support the video tag.
</video>