ffmpeg instead of MediaFileSegmenter?

My Mac X-Code machine is only an old laptop, and I'd like to keep as many CPU/GPU intensive processes on my Win-PC as long as possible.


Could anyone help me figure if it is possible to replicate MediaFileSegmenter functionality using FFMPEG?


Currently I've got a 6 hour uncompressed 1080p video I'd like to compress (to various bitrates) and segment, and becuase of the need for I-frames every 6 seconds, I assume it is optimal to instruct the original compressor to maintain this minimum distance between I-frames?


I mean if I use FFMPEG to first comrpess, then MediaFileSegmenter to segment... MediaFileSegmenter is then constructing I-frames from the compressed video and not the original... that seems weird. I mean I know that's what everyone probably does, but I'm already drawn to try conduct as much of this as possible on my Win-PC (power, memory, storage), so while I'm at it would love to know if people have figure out how to make ffmpeg do just about everything that's needed.


My current attempt is this (for a low bitrate stream)...


ffmpeg -i TR2016-20161127a.mov -map 0:0 -map 0:1 -c:v libx264 -b:v 500k -preset veryslow -profile:v high422 -level 5.1 -s 640x360 -c:a aac -b:a 96k -force_key_frames "expr:gte(t,n_forced*10)" -f segment TR20161127a.m3u8 TR20161127a.ts


And my results are...


P:\RenderATV>ffmpeg -i TR2016-20161127a.mov -map 0:0 -map 0:1 -c:v libx264 -b:v 500k -preset veryslow -profile:v high422 -level 5.1 -s 640x360 -c:a aac -b:a 96k -force_key_frames "expr:gte(t,n_forced*10)" -f segment TR20161127a.m3u8 TR20161127a-%04d.ts


ffmpeg version 3.2 Copyright (c) 2000-2016 the FFmpeg developers

built with gcc 5.4.0 (GCC)

configuration: --enable-gpl --enable-version3 --disable-w32threads --enable-dxva2 --enable-libmfx --enable-nvenc --enable-avisynth --enable-bzlib --enable-libebur128 --enable-fontconfig --enable-frei0r --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libfreetype --enable-libgme --enable-libgsm --enable-libilbc --enable-libmodplug --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librtmp --enable-libschroedinger --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-lzma --enable-decklink --enable-zlib

libavutil 55. 34.100 / 55. 34.100

libavcodec 57. 64.100 / 57. 64.100

libavformat 57. 56.100 / 57. 56.100

libavdevice 57. 1.100 / 57. 1.100

libavfilter 6. 65.100 / 6. 65.100

libswscale 4. 2.100 / 4. 2.100

libswresample 2. 3.100 / 2. 3.100

libpostproc 54. 1.100 / 54. 1.100

[mov,mp4,m4a,3gp,3g2,mj2 @ 00000000026e2fc0] Referenced QT chapter track not found

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'TR2016-20161127a.mov':

Metadata:

major_brand : qt

minor_version : 537199360

compatible_brands: qt

creation_time : 2016-12-06T14:54:12.000000Z

Duration: 06:05:33.54, start: 0.000000, bitrate: 995891 kb/s

Stream #0:0(eng): Video: rawvideo (2vuy / 0x79757632), uyvy422(bt709, progressive), 1920x1080, 994333 kb/s, SAR 1:1 DAR 16:9, 29.97 fps, 29.97 tbr, 30k tbn, 30k tbc (default)

Metadata:

creation_time : 2016-12-06T14:54:12.000000Z

handler_name : Apple Alias Data Handler

encoder : Uncompressed YUV 8 bit 4:2:2

timecode : 00:00:00;00

Stream #0:1(eng): Audio: pcm_s16le (sowt / 0x74776F73), 48000 Hz, stereo, s16, 1536 kb/s (default)

Metadata:

creation_time : 2016-12-06T14:54:12.000000Z

handler_name : Apple Alias Data Handler

timecode : 00:00:00;00

Stream #0:2(eng): Data: none (tmcd / 0x64636D74) (default)

Metadata:

creation_time : 2016-12-06T14:54:12.000000Z

handler_name : Apple Alias Data Handler

timecode : 00:00:00;00

File 'TR20161127a-%04d.ts' already exists. Overwrite ? [y/N] y

No pixel format specified, yuv422p for H.264 encoding chosen.

Use -pix_fmt yuv420p for compatibility with outdated media players.

No pixel format specified, yuv422p for MPEG-2 encoding chosen.

Use -pix_fmt yuv420p for compatibility with outdated media players.

[libx264 @ 00000000026e6f00] using SAR=1/1

[libx264 @ 00000000026e6f00] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX

[libx264 @ 00000000026e6f00] profile High 4:2:2, level 5.1, 4:2:2 8-bit

[libx264 @ 00000000026e6f00] 264 - core 148 r2721 72d53ab - H.264/MPEG-4 AVC codec - Copyleft 2003-2016 - http://www.videolan.org/x264.html - options: cabac=1 ref=16 deblock=1:0:0 analyse=0x3:0x133 me=umh subme=10 psy=1 psy_rd=1.00:0.00 mixed_ref=1 me_range=24 chroma_me=1 trellis=2 8x8dct=1 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=11 lookahead_threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=8 b_pyramid=2 b_adapt=2 b_bias=0 direct=3 weightb=1 open_gop=0 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=60 rc=abr mbtree=1 bitrate=500 ratetol=1.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.40 aq=1:1.00

[segment @ 00000000026e5220] format hls not supported.

Could not write header for output file #0 (incorrect codec parameters ?): Invalid argumentStream mapping:

Stream #0:0 -> #0:0 (rawvideo (native) -> h264 (libx264))

Stream #0:1 -> #0:1 (pcm_s16le (native) -> aac (native))

Stream #0:0 -> #1:0 (rawvideo (native) -> mpeg2video (native))

Stream #0:1 -> #1:1 (pcm_s16le (native) -> mp2 (native))

Last message repeated 1 times

[libx264 @ 00000000026e6f00] final ratefactor: 30.03

[aac @ 0000000000709520] Qavg: nan


...I think I'm getting stuck on something very basic.


Does anyone have any ffmpeg examples they can throw at me? Thanks. -Gord

Well first of all, don't use 4:2:2 video as that's not going to decode in hardware.

add -pix_fmt yuv420p before -c:v libx264 and omit -profile:v and -level to encode standard 4:2:0

Look at https://ffmpeg.org/ffmpeg-formats.html#Examples-6

Maybe something like this:

ffmpeg -i TR2016-20161127a.mov -map 0:0 -map 0:1 -pix_fmt yuv420p -c:v libx264 -b:v 500k -preset veryslow -s 640x360 -c:a aac -b:a 96k -force_key_frames "expr:gte(t,n_forced*10)" -hls_list_size size 0 -hls_segment_filename 'file%03d.ts' out.m3u8

I think this will make an HLS v3 output (i.e. lots of little TS files) which is sub-optimal. HLS v4 allows for single TS files per layer, and byte range requests, which is much more efficient for the origin server and CDN. You might look into using ffmpeg to just encode your GOP aligned MP4 files, and then use a third party packager like bento4 to make the HLS output.

I'd also strongly suggest you look into Unified Streaming Packager, as they do a very nice job of wrapping HLS (and many other formats), and support the most important DRM systems as well.

ffmpeg instead of MediaFileSegmenter?
 
 
Q