VideoHelp Forum




+ Reply to Thread
Results 1 to 9 of 9
  1. I aim to generate an animation in MP4 format (to use as a GIF in Telegram) from a series of PNG images. The images are named sequentially as 1.png, 2.png, 3.png, and so on. They are stored in a folder named "Anime" within the ffmpeg directory. I want to use a batch script because I plan to do this many times for other images, so using a batch script will be the fastest way rather than typing in the command line each time. I also want to ensure the highest possible quality and color preservation, so I would prefer a lossless method if available. Here is what I tried with no luck:

    Code:
    ffmpeg -framerate 10 -i Anime\*.png Animation.mp4
    Could find no file with path 'Anime\*.png' and index in the range 0-4
    Anime\*.png: No such file or directory
    Code:
    ffmpeg -framerate 10 -i Anime\%d.png Animation.mp4
    Anime\d.png: No such file or directory
    The second command executed successfully in the command line console, but the quality was bad. I also attempted the following command in the command line console:

    Code:
    ffmpeg -framerate 10 -i Anime\%d.png -vcodec copy Animation.mp4
    The quality was good, but the file could not be played in Telegram. Consequently, I face two problems: first, using ffmpeg in a batch script, and second, determining the optimal conversion settings to maintain the highest possible quality.
    Last edited by amymor; 1st Dec 2023 at 11:13.
    Quote Quote  
  2. Banned
    Join Date
    Nov 2023
    Location
    Europe
    Search Comp PM
    Is the codec supposed to be an mp4 with gif codec or something? ellse if you want to use an mp4 video to this telegram website, must it maybe be an h.264 mp4 video? what codec is in this mp4 now? mpeg-4? maybe if you change -vcodec copy to -vcodec libx264 it will be able to play on the telegram website.. if you use "-preset veryslow" it will take longer to encode but give better quality! you could try "-cmp chroma", maybe it will look nice!
    Quote Quote  
  3. You can use a higher quality setting such as -crf 10 . Lower values result in larger filesizes and higher quality . When you don't specify a codec for MP4 output, ffmpeg currently uses x264 in 8bit YUV 4:2:0 mode. So the PNG RGB is being converted and the color is downsampled to 1/2 width, 1/2 height - so that's a potentially major loss in quality depending on what the original, original sources were , even if you use "lossless" compression

    Lossless from PNG input would require RGB, using -c:v libx264rgb and -qp 0 . Telegram might not support AVC in RGB mode .

    If you find out what is supported by Telegram, there might be better options. For example , if it supported QT animation codec in RGB. Or maybe it supports APNG etc...

    The end GIF quality will be terrible eitherway - since GIF only supports 256 colors
    Quote Quote  
  4. Originally Posted by poisondeathray View Post
    You can use a higher quality setting such as -crf 10 . Lower values result in larger filesizes and higher quality . When you don't specify a codec for MP4 output, ffmpeg currently uses x264 in 8bit YUV 4:2:0 mode. So the PNG RGB is being converted and the color is downsampled to 1/2 width, 1/2 height - so that's a potentially major loss in quality depending on what the original, original sources were , even if you use "lossless" compression

    Lossless from PNG input would require RGB, using -c:v libx264rgb and -qp 0 . Telegram might not support AVC in RGB mode .

    If you find out what is supported by Telegram, there might be better options. For example , if it supported QT animation codec in RGB. Or maybe it supports APNG etc...

    The end GIF quality will be terrible eitherway - since GIF only supports 256 colors
    Thank you for the detailed information. The APNG format is very good, but unfortunately, Telegram does not support APNG. It only supports GIF and MP4 (When you send an MP4 video that lacks audio, Telegram treats it as a GIF animation).
    I tried what you recommended with the following command:
    Code:
    ffmpeg -framerate 10 -i Anime\%d.png -c:v libx264rgb -qp 0 -preset veryslow Animation-libx264rgb.mp4
    I have tried many Slideshow/Animation creator apps too, but the result of the above command is the best among them. I also noticed that Telegram supports WebM videos, but the extension must be .mp4. This suggests that the vp8 and vp9 codecs can be used. However, I am unsure if the result would be the same as libx264rgb or not, and what settings should be used to achieve the best quality.
    Thank you for taking the time to read this ❤️
    Quote Quote  
  5. Did Telegram accept the MP4 using libx264rgb with qp 0 ?

    If yes, you can't get better than lossless quality (qp 0) in RGB from a RGB source - there is no point exploring vp8/9 , AV1 etc...or anything else

    If it allows pass through (if you upload a GIF, and it does not re-process it, rather it keeps it as-is), then potentially that would be the best quality, because you can custom make the GIF using your own parameters, pallette options, dithering options
    Quote Quote  
  6. Originally Posted by poisondeathray View Post
    Did Telegram accept the MP4 using libx264rgb with qp 0 ?

    If yes, you can't get better than lossless quality (qp 0) in RGB from a RGB source - there is no point exploring vp8/9 , AV1 etc...or anything else

    If it allows pass through (if you upload a GIF, and it does not re-process it, rather it keeps it as-is), then potentially that would be the best quality, because you can custom make the GIF using your own parameters, pallette options, dithering options
    Yes, Telegram accepts it, so I gonna use it, thanks.
    Quote Quote  
  7. Banned
    Join Date
    Nov 2023
    Location
    Europe
    Search Comp PM
    Originally Posted by amymor View Post
    Originally Posted by poisondeathray View Post
    You can use a higher quality setting such as -crf 10 . Lower values result in larger filesizes and higher quality . When you don't specify a codec for MP4 output, ffmpeg currently uses x264 in 8bit YUV 4:2:0 mode. So the PNG RGB is being converted and the color is downsampled to 1/2 width, 1/2 height - so that's a potentially major loss in quality depending on what the original, original sources were , even if you use "lossless" compression

    Lossless from PNG input would require RGB, using -c:v libx264rgb and -qp 0 . Telegram might not support AVC in RGB mode .

    If you find out what is supported by Telegram, there might be better options. For example , if it supported QT animation codec in RGB. Or maybe it supports APNG etc...

    The end GIF quality will be terrible eitherway - since GIF only supports 256 colors
    Thank you for the detailed information. The APNG format is very good, but unfortunately, Telegram does not support APNG. It only supports GIF and MP4 (When you send an MP4 video that lacks audio, Telegram treats it as a GIF animation).
    I tried what you recommended with the following command:
    Code:
    ffmpeg -framerate 10 -i Anime\%d.png -c:v libx264rgb -qp 0 -preset veryslow Animation-libx264rgb.mp4
    I have tried many Slideshow/Animation creator apps too, but the result of the above command is the best among them. I also noticed that Telegram supports WebM videos, but the extension must be .mp4. This suggests that the vp8 and vp9 codecs can be used. However, I am unsure if the result would be the same as libx264rgb or not, and what settings should be used to achieve the best quality.
    Thank you for taking the time to read this ❤️
    Nice! if you want to try .webm instead of .mp4 for example you can use "-vcodec libvpx" and it should be an .webm video with vp8 codec! It is google that are owners of this VP8 codec, i think before this it was Optima SC (might help if you want to find old info). I think the VP8 codec is the H264 Contender and the VP9 codec is the H265 Contender..

    Edit: and yeah you might need to the output format to .webm allso and the output filename from .mp4 to .webm!
    Last edited by Swedaniel; 1st Dec 2023 at 12:09.
    Quote Quote  
  8. Originally Posted by Swedaniel View Post

    Nice! if you want to try .webm instead of .mp4 for example you can use "-vcodec libvpx" and it should be an .webm video with vp8 codec! It is google that are owners of this VP8 codec, i think before this it was Optima SC (might help if you want to find old info). I think the VP8 codec is the H264 Contender and the VP9 codec is the H265 Contender..

    Edit: and yeah you might need to the output format to .webm allso and the output filename from .mp4 to .webm!
    I tried both VP8 and VP9 with the following commands:
    Code:
    ffmpeg -framerate 10 -i Anime\%%d.png -c:v libvpx -qmin 0 -qmax 4 -crf 4 -b:v 6M Animation_vp8.webm
    ffmpeg -framerate 10 -i Anime\%%d.png -c:v libvpx-vp9 -crf 0 -b:v 0 Animation_vp9_crf.webm
    ffmpeg -framerate 10 -i Anime\%%d.png -c:v libvpx-vp9 -lossless 1 Animation_vp9_lossless.webm
    The result is the same as with the other methods, the colors do not preserve. So, I use the libx264rgb.
    Anyway, thank you for taking your time. ❤️
    Last edited by amymor; 1st Dec 2023 at 13:49.
    Quote Quote  
  9. Banned
    Join Date
    Nov 2023
    Location
    Europe
    Search Comp PM
    Originally Posted by amymor View Post
    Originally Posted by Swedaniel View Post

    Nice! if you want to try .webm instead of .mp4 for example you can use "-vcodec libvpx" and it should be an .webm video with vp8 codec! It is google that are owners of this VP8 codec, i think before this it was Optima SC (might help if you want to find old info). I think the VP8 codec is the H264 Contender and the VP9 codec is the H265 Contender..

    Edit: and yeah you might need to the output format to .webm allso and the output filename from .mp4 to .webm!
    I tried both VP8 and VP9 with the following commands:
    Code:
    ffmpeg -framerate 10 -i Anime\%%d.png -c:v libvpx -qmin 0 -qmax 4 -crf 4 -b:v 6M Animation_vp8.webm
    ffmpeg -framerate 10 -i Anime\%%d.png -c:v libvpx-vp9 -crf 0 -b:v 0 Animation_vp9_crf.webm
    ffmpeg -framerate 10 -i Anime\%%d.png -c:v libvpx-vp9 -lossless 1 Animation_vp9_lossless.webm
    The result is the same as with the other methods, the colors do not preserve. So, I use the libx264rgb.
    Anyway, thank you for taking your time. ❤️
    Ok! i dont know many commands for the colors and such to help very much on that front, only command i know, yet that i tested adding/removing is the "-cmp chroma" and the video seemed nicer with it then without it, alltough i never really compared the original image to the new one to notice if it preserved any colors from previous, i mostly just check the new result to see if it is an worth video to keep around! I might have to test this one rgb thing allso, i had some success to play videos with rgb a few weeks back while the other options failed!

    Edit: Maybe this rgb command thing work for webm/vp8 allso? ie. to use "libvpxrgb"? When i open an .webm video with VP8 codec in VLC Media Player it say "ITU-R BT.601 Range" and when i open them in DivX Player it does not say anything about this on the same place where it normally list Standard RGB32, it only say DirectShow Video Renderer! ill try later sometime!

    Either way the command line i use for some of my WebM videos is from an MP4 command line, it give real nice result for WebM with VP8 allso! If this libvpxrgb thing work out, you can use the "-qmin" thing allso, try run same command line but use libvpx/libvpxrgb instead of libx264/libvpxrgb! (allso change format/name to .webm instead of mp4). If it then play on that website im not sure but my WebM's with MP4 command line play where i want them to play, atleast for the moment!

    If this (ffmpeg -framerate 10 -i Anime\%d.png -c:v libx264rgb -qp 0 -preset veryslow Animation-libx264rgb.mp4) was the command that worked out for MP4, possibly this one can work out for WebM allso! Example: "ffmpeg -framerate 10 -i Anime\%d.png -c:v libvpxrgb -qp 0 -preset veryslow Animation-libvpxrgb.webm".. this rgb thing untested from my part tough and normally i use -vcodec and bit rate values (b:v).
    Last edited by Swedaniel; 1st Dec 2023 at 16:23.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!