For the past two days I am trying to figure out why FFMPEG produces a glitchy video when transcoding h264 mp4 to HLS with xlib264. It happens to every video. The glitch looks like this :

720p MP4 H264 to 480p HLS

This is the original mp4 file:

Original MP4 H264 720p

EDIT: Not the whole videos are like that, only some frames and, sometimes a whole segment. This happens with every video that I try, from different sources. I am unsure what causes these. I have tested with numerous options, including inserting keyframes exactly every two seconds, playing around with crf setting, bitrate and maxrate, and even removing them completely. I always get these problems at random places in the encoded video.

Here is the current command used, which produces the same results:

/root/bin/ffmpeg -i "$f" -c:v libx264 -crf 26 -b:v 1200k -bufsize 2000k -strict -2 -vf "scale=trunc(oh*a/2)*2:480" -c:a aac -b:a 128k -profile:v main -level 4.1 -preset fast -g 48 -keyint_min 48 -pix_fmt yuv420p -flags -global_header -metadata "service_provider=XXX" -hls_time 10 -hls_playlist_type vod -hls_segment_filename /root/OUTPUT/"$URLENCODED"/480p/"$URLENCODED"_%03d.ts -threads 0 /root/OUTPUT/"$URLENCODED"/480p/playlist.m3u8

I am now a bit lost. Where do I look for errors? I am unable to use Apple's HLS analyzer tool because I do not have a new enough Apple computer. Other than that, all online tools that I have found do not report any errors.

EDIT: Issue persists across FFMPEG version N-93594-g09f8b2 and N-92724-g826655d (the latter built yesterday from ffmpeg.org)

  • Does this happen with other encoders? – Gyan Apr 23 at 16:51
  • Have not yet tested. Not sure, apart from avconv, what other options I have under Linux, but will compile those that I find and will try it out with them. – Vii Apr 23 at 17:02
  • Your command works for me in a single test using version 09f8b2 and playing in mpv. (You omitted -maxrate so -bufsize is being ignored, but that's just an observation and not a suggested solution.) – llogan Apr 23 at 17:40
  • Thank you for testing this out! Are you not getting even a single frame distorted like in the examples that I posted above? – Vii Apr 23 at 18:05
  • When @Gyan was speaking of other encoders, he probably meant libx265 or libvpx-vp9, still using ffmpeg. This would at least rule out some source decoding issues. (Also, why crf and b:v? Choose either option, not both.) Please note that in order to respond to others, you have to add @ and their username. – slhck Apr 23 at 18:06

The issue is completely unrelated to FFMPEG. It was caused by the sub_filter module in the Nginx web server which was being used to apply secure tokens to the videos. I should have tested locally first. To anyone who ends up with the same problem, make sure to use the sub_filter for the .ts fragments and (if using HLS encryption) for the .key file. Do not apply the filter on the manifests.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.