[FFmpeg-user] Change in video length and loss of audio sync
Hi: I have a large number of videos I am converting to a standardized HLS video with a particular format and frame rate and I’ve automated the process. The source videos are in many different formats (16:9, 4:3), densities 720, 1080, 480 and frame rates. After it completed and I tested the videos I found that about 6% of them were shortened and lost audio/video sync in the conversion. They also take an inordinately long time to start streaming. Examining the source videos, it seems that many of them were at unusual frame rates (like15, 24, 25…) I’ve put a test mp4 that I sourced from and the resulting m3u8 video up in http://ipziptv.com/testing/test.mp4 and http://iziptv.com/testing/video.m3u8 Below is mediainfo on the source video (263.8 seconds long) and the converted m3u8 video (220 seconds long), the script I converted with and the ffmpeg output. Any advice on how I can successfully convert these would be appreciated. ==Start of output= Here is mediainfo’s view of that mp4. You can see that (for some reason) it is at 25FPS. mediainfo test.mp4 General Complete name: test.mp4 Format : MPEG-4 Format profile : Base Media Codec ID : isom (isom/iso2/avc1/mp41) File size: 46.9 MiB Duration : 4 min 23 s Overall bit rate : 1 491 kb/s Writing application : Lavf57.83.100 Video ID : 1 Format : AVC Format/Info : Advanced Video Codec Format profile : High@L3.1 Format settings : CABAC / 4 Ref Frames Format settings, CABAC : Yes Format settings, Reference frames: 4 frames Codec ID : avc1 Codec ID/Info: Advanced Video Coding Duration : 4 min 23 s Bit rate : 1 354 kb/s Width: 1 280 pixels Height : 720 pixels Display aspect ratio : 16:9 Frame rate mode : Constant Frame rate : 25.000 FPS Color space : YUV Chroma subsampling : 4:2:0 Bit depth: 8 bits Scan type: Progressive Bits/(Pixel*Frame) : 0.059 Stream size : 42.6 MiB (91%) Writing library : x264 core 148 r2795 aaa9aa8 Encoding settings: 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=22 / 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=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 Codec configuration box : avcC Audio ID : 2 Format : AAC LC Format/Info : Advanced Audio Codec Low Complexity Codec ID : mp4a-40-2 Duration : 4 min 23 s Bit rate mode: Constant Bit rate : 132 kb/s Channel(s) : 2 channels Channel layout : L R Sampling rate: 48.0 kHz Frame rate : 46.875 FPS (1024 SPF) Compression mode : Lossy Stream size : 4.10 MiB (9%) Language : English Default : Yes Alternate group : 1 Here is mediainfo’s view of the first segment of the m3u8. You can see that it is at 29.97FPS. mediainfo video.ts General ID : 1 (0x1) Complete name: video.ts Format : MPEG-TS File size: 1.53 MiB Duration : 5 s 939 ms Overall bit rate mode: Variable Overall bit rate : 2 143 kb/s Video ID
Re: [FFmpeg-user] Trying to solve drop in quality
I figured it out. Pointing out that it was the GOP set me on the right path I eliminated -g and changed: -x264-params "nal-hrd=cbr:scenecut=0:ref=2:cabac=1:force-cfr=1" to -x264-params "nal-hrd=cbr:scenecut=0:ref=1:b-pyramid=0:force-cfr=1" thanks everyone! On November 3, 2020 at 4:45 PM, Eduardo Alarcón wrote: El mar., 3 nov. 2020 a las 18:36, John Harlow via ffmpeg-user (< ffmpeg-user@ffmpeg.org>) escribió: The -g is definitely the quality problem. I tried setting it various to 30*1000/1001, 60*1000/1001 120*1000/1001, 180*1000/1001, 360/1000/1001and even 15*1000/1001. Any of those changes show up in mediainfo as: Format settings : CABAC / 4 Ref Frames Format settings, CABAC : Yes Format settings, Reference frames : 4 frames I would have thought the interval for the ref frames was either 2 seconds (60*1000/1001) or 2 per ts segment which would be (basically) 180*1000/1001. I'm not sure how to get to Reference Frames 2. -g is the gop size in frames, integer, not time, if you want a key frame every 2 seconds you should use -g 60, when using 30fps. With gop 2, you are getting a keyframe every 2 frames, so basically your video is a huge collection of jpeg images ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe". ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".
[FFmpeg-user] Trying to solve drop in quality
I've been trying to hit the specs we need to match for an HLS live stream and I’ve created an ffmpeg 2 pass command to convert some existing mp4 files into HLS so they can be used. The mp4 test file I am using is http://fkwi.com/livestreams/test/currentweather.mp4 and it is 60 seconds long and 16,991,549 in size. The converted HLS file is http://fkwi.com/livestreams/test/test1/video.m3u8 and it is (naturally) 60 seconds long and the .ts files add up to 17,584,392 bytes. The quality of the HLS encode is horrible compared to the original and I can’t figure out where I am going sideways with it. I’m even trying a 2 pass encode. I convert our mp4’s to HLS all the time with no issues (but not to these specs.) We normally use 30FPS, VBR and VFR. You can see the items in the spec I am trying to hit in the mediainfo output at the end of this message. Below is my ffmpeg command, my entire ffmpeg session output plus a mediainfo report on the HLS encode. In the mediainfo output I’ve added (<——REQUIRED BY SPEC) next to the items that are being required of our video. I would appreciate any advice on how to maintain better quality on the HLS stream. ==ffmpeg command == /usr/bin/ffmpeg -i "$SOURCE" \ -profile:v main -level 3.1 -s 1280x720 -vf "fps=fps=30*1000/1001:round=zero" \ -c:v libx264 -pass 1 -preset slow -x264-params "nal-hrd=cbr:scenecut=0:ref=2:force-cfr=1" -g 2 \ -b:v 2M -maxrate 2.0M -minrate 2.0M -bufsize 8M \ -b:a 128k -ar 48000 -f hls logfile && /usr/bin/ffmpeg -i "$SOURCE" \ -profile:v main -level 3.1 -s 1280x720 -vf "fps=fps=30*1000/1001:round=zero" \ -c:v libx264 -pass 2 -preset slow -x264-params "nal-hrd=cbr:scenecut=0:ref=2:force-cfr=1" -g 2 \ -f segment -segment_list_type m3u8 -segment_list_size 0 -segment_time 6.006 -segment_time_delta 0.1 \ -b:v 2M -maxrate 2.0M -minrate 2.0M -bufsize 8M \ -b:a 128k -ar 48000 -start_number 0 \ -hls_time 6 -hls_list_size 0 -f hls \ -hls_base_url "$BASEURL" \ -hls_segment_filename "video%04d.ts == ffmpeg output = ffmpeg version 3.4.8 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-39) configuration: --prefix=/usr --bindir=/usr/bin --datadir=/usr/share/ffmpeg --docdir=/usr/share/doc/ffmpeg --incdir=/usr/include/ffmpeg --libdir=/usr/lib64 --mandir=/usr/share/man --arch=x86_64 --optflags='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic' --extra-ldflags='-Wl,-z,relro ' --extra-cflags=' ' --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-amrwbenc --enable-version3 --enable-bzlib --disable-crystalhd --enable-fontconfig --enable-gcrypt --enable-gnutls --enable-ladspa --enable-libass --enable-libbluray --enable-libcdio --enable-libdrm --enable-indev=jack --enable-libfreetype --enable-libfribidi --enable-libgsm --enable-libmp3lame --enable-nvenc --enable-openal --enable-opencl --enable-opengl --enable-libopenjpeg --enable-libopus --disable-encoder=libopus --enable-libpulse --enable-librsvg --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libv4l2 --enable-libvidstab --enable-libvpx --enable-libx264 --enable-libx265 --enable-libxvid --enable-libzvbi --enable-avfilter --enable-avresample --enable-libmodplug --enable-postproc --enable-pthreads --disable-static --enable-shared --enable-gpl --disable-debug --disable-stripping --shlibdir=/usr/lib64 --enable-libmfx --enable-runtime-cpudetect libavutil 55. 78.100 / 55. 78.100 libavcodec 57.107.100 / 57.107.100 libavformat57. 83.100 / 57. 83.100 libavdevice57. 10.100 / 57. 10.100 libavfilter 6.107.100 / 6.107.100 libavresample 3. 7. 0 / 3. 7. 0 libswscale 4. 8.100 / 4. 8.100 libswresample 2. 9.100 / 2. 9.100 libpostproc54. 7.100 / 54. 7.100 Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'https://fkwi.com/currentweather.mp4': Metadata: major_brand : isom minor_version : 512 compatible_brands: isomiso2avc1mp41 encoder : Lavf57.83.100 Duration: 00:01:00.00, start: 0.00, bitrate: 2265 kb/s Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 2183 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default) Metadata: handler_name: VideoHandler Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 22050 Hz, mono, fltp, 81 kb/s (default) Metadata: handler_name: SoundHandler Stream mapping: Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264)) Stream #0:1 -> #0:1 (aac (native) -> aac (native)) Press [q] to stop, [?] for help [libx264 @ 0x241d860] using SAR=1/1 [libx264 @ 0x241d860] using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2 AVX FMA3 AVX2 LZCNT BMI2 [libx264 @ 0x241d860] profile Main, level 3.1 [libx264 @ 0x241d860] 264 - core 148 r2795 aaa9aa8 -
[FFmpeg-user] Struggling to convert mp4 to HLS with Constant Bit Rate and Constant Frame Rate
I am trying to re-encode a set of mp4 files (a mix of 1080p and 720p, all at 30FPS) to HLS with constant bit and frame rates. I also need a 29.97 frame rate, CABAC/2 and fixed 6.006 sec ts segments. I have experimented with a lot of options, so the ffmpeg string I am using is probably both inefficient and hideous AND I can’t achieve the desired result. I’m trying to use max rate and min rate to hold the bitrate at 2M and fps=fps=29.97 to make the frame rate constant. Here is my current ffmpeg string: /usr/bin/ffmpeg -i "$SOURCE" \ -profile:v high -level 3.1 -s 1280x720 -filter:v fps=fps=29.97 \ -strict -2 -c:a aac -c:v libx264 -g 60 -keyint_min 60 -force_key_frames "expr:gte(t,n_forced*2)" \ -f segment -segment_list_type m3u8 -segment_list_size 0 -segment_time 6.06 -segment_time_delta 0.1 \ -b:v 2M -maxrate 2.0M -minrate 2.0M -bufsize 3M \ -ar 48000 -start_number 0 \ -hls_time 6 -hls_list_size 0 -f hls \ -hls_base_url "$BASEURL" \ -hls_segment_filename "video%04d.ts" \ -strict -2 -threads 8 “video.m3u8" I am running this on centos 7 and my ffmpeg version is 3.4.7. Any advice on how to clean this up and achieve the desired results would be greatly appreciated. Thanks ___ ffmpeg-user mailing list ffmpeg-user@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-user To unsubscribe, visit link above, or email ffmpeg-user-requ...@ffmpeg.org with subject "unsubscribe".