UPDATE 2: I did some more reading about h265 and how more modern hardware is needed to properly render it, and since my PC is over 10 years old, that may be part of the artifact issue I’m seeing with h265 and full 4K size video. I’m going to try playing the clips on more modern hardware and see if the clips are the issue or the hardware.
UPDATE: This isn’t a solution, but is a work-around for now since my clients don’t even have 4K TVs. If I resample the 4K camera video down to HD (1920×1080) and compress with h.265, it gives me a very nice quality clip that is small and that doesn’t have artifacts even though I still see the initial error about the missing key frame. Here is the code I will use until I have a solution to leave the clips in 4K:
ffmpeg -i 4K-input-file.mp4 -c:a copy -c:v libx265 -vf scale=1920:-2:flags=lanczos HD-265-output-file.mp4
– – – – – – – – – – – – – – – – – – – – –
I just got my Panasonic HC-WXF1 4K camcorder and it is pretty nice! I’m running some tests to see what I can do with the resulting 4K video so I can predict better what my clients will get when I shoot their music gigs. The first thing I wanted to do was convert to h.265 to shrink the file size. This is a SLOW process, but the quality is typically great (see my previous post).
I did a 30 second video outside as a test. It was encoded by the camera with h.264 into 4K MP4 (3840×2160). I wanted to then convert this to h.265 to conserve space and compare the quality. However, ffmpeg first gives a couple of errors and the resulting video is full of horrible artifacts. The MP4 from the camera is fine on its own, and plays fine in VLC.
Here is a snapshot comparison of the two visuals (resized):
Link to original 30-sec 4K video on YouTube Youtube probably re-encoded it, so no telling if it is the same as what I had.
I tried to link to the converted file showing the artifacts, but YouTube re-encodes videos and that “corrected” for the issue, though it looks kind of lousy.
Here is the code I used:
ffmpeg -i S1000001.MP4 -c:v libx265 -c:a libfdk_aac -crf 28 265-4k.mp4
Here are the errors that ffmpeg shows just prior to encoding:
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5565a45f0a00] st: 0 edit list: 1 Missing key frame while searching for timestamp: 3003
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x5565a45f0a00] st: 0 edit list 1 Cannot find an index entry before timestamp: 3003
So far, I haven’t seen anyone else report these kinds of errors. The syntax of the error doesn’t bring up any hits. I’m experimenting with converting to an intermediate format in the meantime. Oddly, I even downsampled the video in Corel Video Studio from 4K to standard HD and then tried to convert that via ffmpeg to h.265, thinking that it might be something to do with the frame size. But I got the same error. I’ve tried shooting longer videos as well and had the same result.
I tried converting to TS, which worked fine, but the following conversion from TS to the H.265 was full of the same artifacts. It gave the following errors at the start:
[h264 @ 0x560a620cebc0] non-existing SPS 0 referenced in buffering period
[h264 @ 0x560a620cebc0] SPS unavailable in decode_picture_timing
[h264 @ 0x560a620cebc0] non-existing SPS 0 referenced in buffering period
[h264 @ 0x560a620cebc0] SPS unavailable in decode_picture_timing
All of the errors seem to be related to timing.
When I encode from HD (1920×1080) even from the same camera, I do not get any errors.
The next part is the output of ffmpeg when I do the encoding. I’ve marked in bold the parts that are different than when I encode from HD.
jw@JW-PC:/media/jw/ShareDisk1/4K_CAMERA$ time ffmpeg -i S1020001.MP4 -c:v libx265 -crf 28 -c:a libfdk_aac test.mp4
ffmpeg version N-90524-ge30a37e Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7 (Ubuntu 7.2.0-8ubuntu3.2)
configuration: --prefix=/home/jw/ffmpeg_build --pkg-config-flags=--static --extra-cflags=-I/home/jw/ffmpeg_build/include --extra-ldflags=-L/home/jw/ffmpeg_build/lib --extra-libs='-lpthread -lm' --bindir=/home/jw/bin --enable-pic --enable-pthreads --enable-libx264 --enable-libfdk-aac --enable-libmp3lame --enable-libvorbis --enable-libtheora --enable-libx265 --enable-libvpx --enable-version3 --enable-libass --enable-libxvid --enable-postproc --enable-gpl --enable-nonfree
libavutil 56. 12.100 / 56. 12.100
libavcodec 58. 16.100 / 58. 16.100
libavformat 58. 10.100 / 58. 10.100
libavdevice 58. 2.100 / 58. 2.100
libavfilter 7. 13.100 / 7. 13.100
libswscale 5. 0.102 / 5. 0.102
libswresample 3. 0.101 / 3. 0.101
libpostproc 55. 0.100 / 55. 0.100
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x559875557a40] st: 0 edit list: 1 Missing key frame while searching for timestamp: 3003
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x559875557a40] st: 0 edit list 1 Cannot find an index entry before timestamp: 3003.
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'S1020001.MP4':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: mp42avc1
creation_time : 2018-04-14T16:47:55.000000Z
Duration: 00:00:18.02, start: 0.000000, bitrate: 60862 kb/s
Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 3840x2160 [SAR 1:1 DAR 16:9], 60550 kb/s, 29.97 fps, 29.97 tbr, 90k tbn, 59.94 tbc (default)
Metadata:
creation_time : 2018-04-14T16:47:55.000000Z
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 253 kb/s (default)
Metadata:
creation_time : 2018-04-14T16:47:55.000000Z
Stream mapping:
Stream #0:0 -> #0:0 (h264 (native) -> hevc (libx265))
Stream #0:1 -> #0:1 (aac (native) -> aac (libfdk_aac))
Press [q] to stop, [?] for help
x265 [info]: HEVC encoder version 2.7+20-3440a56acc78
x265 [info]: build info [Linux][GCC 7.2.0][64 bit] 8bit
x265 [info]: using cpu capabilities: MMX2 SSE2Fast SSSE3 SSE4.2
x265 [info]: Main profile, Level-5 (Main tier)
x265 [info]: Thread pool created using 8 threads
x265 [info]: Slices : 1
x265 [info]: frame threads / pool features : 3 / wpp(34 rows) [HD says 17 rows]
x265 [info]: Coding QT: max CU size, min CU size : 64 / 8
x265 [info]: Residual QT: max TU size, max depth : 32 / 1 inter / 1 intra
x265 [info]: ME / range / subpel / merge : hex / 57 / 2 / 2
x265 [info]: Keyframe min / max / scenecut / bias: 25 / 250 / 40 / 5.00
x265 [info]: Lookahead / bframes / badapt : 20 / 4 / 2
x265 [info]: b-pyramid / weightp / weightb : 1 / 1 / 0
x265 [info]: References / ref-limit cu / depth : 3 / on / on
x265 [info]: AQ: mode / str / qg-size / cu-tree : 1 / 1.0 / 32 / 1
x265 [info]: Rate Control / qCompress : CRF-28.0 / 0.60
x265 [info]: tools: rd=3 psy-rd=2.00 rskip signhide tmvp strong-intra-smoothing
x265 [info]: tools: lslices=8 deblock sao
Output #0, mp4, to 'test.mp4':
Metadata:
major_brand : mp42
minor_version : 1
compatible_brands: mp42avc1
encoder : Lavf58.10.100
Stream #0:0(eng): Video: hevc (libx265) (hev1 / 0x31766568), yuv420p(progressive), 3840x2160 [SAR 1:1 DAR 16:9], q=2-31, 29.97 fps, 30k tbn, 29.97 tbc (default)
Metadata:
creation_time : 2018-04-14T16:47:55.000000Z
encoder : Lavc58.16.100 libx265
Stream #0:1(eng): Audio: aac (libfdk_aac) (mp4a / 0x6134706D), 48000 Hz, stereo, s16, 139 kb/s (default)
Metadata:
creation_time : 2018-04-14T16:47:55.000000Z
encoder : Lavc58.16.100 libfdk_aac
frame= 21 fps=0.0 q=0.0 size= 0kB time=00:00:00.46 bitrate= 0.8kbits/sframe= 28 fps= 12 q=0.0 size= 0kB time=00:00:00.96 bitrate= 0.4kbits/s