I am trying to convert a sequence of png images to a lossless video while upscaling (keeping the same aspect ratio). I have attached one png image

png image.

However, every lossless option I use either is obviously not lossless, or results in corrupted video.

I have tried ffmpeg -framerate 60 -i %d.png -vf scale=-1:2160 -c:v libx264 -crf 0 -preset veryslow -c:a libmp3lame -b:a 320k output.mp4 I tried to add the cmd line output but this website complains my question is spam if I do and won't let me post it.

Which I think should be lossless due to the -crf 0, however doing this produces a corrupted video according to vlc, windows media player and firefox. However, chrome does manage to play it, but the results in this case are obviously lossy. Shown here, you can see very clearly thick concentric bands of colour that are not there in the actual .png, which instead falls off smoothly. Lossy Compression

I have tested this with both the full set of images that I want to make into a video, and just 3 frames so that I can be sure that there is nothing wrong with the input .png, in both cases the same results occur.

I have found after searching online that adding -pix_fmt yuv420p can help, so have tried this

ffmpeg -framerate 60 -i %d.png -vf scale=-1:2160 -c:v libx264 -crf 0 -preset veryslow -c:a libmp3lame -b:a 320k -pix_fmt yuv420p output.mp4

Doing so allows VLC to now open it (however firefox and windows media player still say it is corrupted). However, it is still obviously lossy compressed in both chrome and VLC.

I have then tried ffmpeg -framerate 60 -i %d.png -vf scale=-1:2160 -c:v libvpx-vp9 -lossless 1 output.webm

Which I gather should be lossless due to -lossless 1 , however doing this results in a very weird output. In VLC and firefox, the output is just black. However in chrome, the output is mainly a green background that goes from dark green at the bottom of the screen to light green at the top, with a darker green circle in the middle, and the text in the top left has became pink. In windows media player, the output is similar however there is no dark green circle in the center, and the text in the top left has changed to a very bright light green and also been duplicated below itself in a lower resolution but bigger font and changed to a dark pink with a black outline.I don't understand how this could possibly happen

very weird windows media player output

I have then tried adding -pix_fmt yuv420p to this as before, ffmpeg -framerate 60 -i %d.png -vf scale=-1:2160 -c:v libvpx-vp9 -lossless 1 -pix_fmt yuv420p output.webm

When doing this, the output in VLC and firefox is still blank, however chrome and windows media player now show normal outputs, however the result is again obviously lossy compression.

I have then attempted ffmpeg -framerate 60 -i %d.png -vf scale=-1:2160 -c:v ffv1 -c:a libmp3lame -b:a 320k output.avi

However the output is just a blank black screen in VLC, freshly installed both on a windows 10 machine and ubuntu machine. The cmd output for this is

ffmpeg -framerate 60 -i %d.png -vf scale=-1:2160 -c:v ffv1 -c:a libmp3lame -b:a 320k output.avi ffmpeg version N-91999-g148a21611d Copyright (c) 2000-2018 the FFmpeg developers built with gcc 8.2.1 (GCC) 20180813 configuration: --enable-gpl --enable-version3 --enable-sdl2 --enable-fontconfig --enable-gnutls --enable-iconv --enable-libass --enable-libbluray --enable-libfreetype --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libopus --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libtheora --enable-libtwolame --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libzimg --enable-lzma --enable-zlib --enable-gmp --enable-libvidstab --enable-libvorbis --enable-libvo-amrwbenc --enable-libmysofa --enable-libspeex --enable-libxvid --enable-libaom --enable-libmfx --enable-amf --enable-ffnvcodec --enable-cuvid --enable-d3d11va --enable-nvenc --enable-nvdec --enable-dxva2 --enable-avisynth libavutil 56. 19.101 / 56. 19.101 libavcodec 58. 30.100 / 58. 30.100 libavformat 58. 18.102 / 58. 18.102 libavdevice 58. 4.103 / 58. 4.103 libavfilter 7. 32.100 / 7. 32.100 libswscale 5. 2.100 / 5. 2.100 libswresample 3. 2.100 / 3. 2.100 libpostproc 55. 2.100 / 55. 2.100 Input #0, image2, from '%d.png': Duration: 00:00:10.00, start: 0.000000, bitrate: N/A Stream #0:0: Video: png, rgb24(pc), 3840x1408, 60 fps, 60 tbr, 60 tbn, 60 tbc Codec AVOption b (set bitrate (in bits/s)) specified for output file #0 (output.avi) has not been used for any stream. The most likely reason is either wrong type (e.g. a video option with no video streams) or that it is a private option of some encoder which was not actually used for any stream. Stream mapping: Stream #0:0 -> #0:0 (png (native) -> ffv1 (native)) Press [q] to stop, [?] for help Output #0, avi, to 'output.avi': Metadata: ISFT : Lavf58.18.102 Stream #0:0: Video: ffv1 (FFV1 / 0x31564646), bgr0, 5891x2160, q=2-31, 200 kb/s, 60 fps, 60 tbn, 60 tbc Metadata: encoder : Lavc58.30.100 ffv1 frame= 600 fps=4.0 q=-0.0 Lsize= 100850kB time=00:00:10.00 bitrate=82616.4kbits/s speed=0.067x video:100830kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.019776%

Attached is a link to the file output https://cernbox.cern.ch/index.php/s/ggEtDZmwxqzap3Y

How do I turn a sequence of png images into a losslessly compressed video?

Thank you for any help

  • What specifically do you mean with "obviously lossy" in the case of the first command? That should produce what you want, except that many players cannot handle YUV 4:4:4 as pixel format. Make sure you are using a somewhat recent version of VLC. Is your requirement that the video should be playable on most devices / players? In this case you cannot go “fully lossless”, as the color will have to be subsampled to 4:2:0. – slhck Sep 26 '18 at 12:23
  • @slhck No, I have no requirements that it should be playable on any devices other than my own. By obviously lossy I mean I can see immediately the output is very compressed, the diffuse red circular spot in the first image comes out as a series of very visible thick concentric bands of colour. – Jack Sep 26 '18 at 12:24
  • @slhck I have edited the main post to include a screenshot of the obviously lossy video. (I thought perhaps this might have to do with upscaling but I tried without upscaling and the same concentric bands are visible) I am fairly confident I should be using a recent version of VLC. I am not sure how you check what specific version you are on, but I only just downloaded it yesterday from here videolan.org/vlc/download-windows.html (specifically because windows media player wouldn't load it) and when I check for updates it tells me I have the latest version of VLC media player. – Jack Sep 26 '18 at 12:44
  • The problem you're experiencing (color banding) is due to converting from the RGB color space to YUV (strictly speaking YCbCr). Use a video codec that supports the RGB color space, e.g. ffv1 (it's lossless, no need to set any parameters) – slhck Sep 26 '18 at 13:12
  • Hi @slhck , thanks very much. Sorry I know very little about video encoding, so just to doublecheck, do you mean change ffmpeg -framerate 60 -i %d.png -vf scale=-1:2160 -c:v libx264 -crf 0 -preset veryslow -c:a libmp3lame -b:a 320k output.mp4 to ffmpeg -framerate 60 -i %d.png -vf scale=-1:2160 -c:v ffv1 -c:a libmp3lame -b:a 320k output.mp4 ? Thanks again for the help – Jack Sep 26 '18 at 13:20

Your Answer

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

Browse other questions tagged or ask your own question.