VideoHelp Forum
+ Reply to Thread
Results 1 to 17 of 17
Thread
  1. I have downloaded ffmpeg static build.
    Failed to get code to work.

    FOURCC code 'HEVC'
    FFMPEG / x265 lossless
    YUV420P16
    Quote Quote  
  2. How to use lossless encoding with ffmpeg and x265:

    https://trac.ffmpeg.org/wiki/Encode/H.265#Losslessencoding

    If you query ffmpeg x265 pixel format capabilities:
    Code:
    ffmpeg -h encoder=libx265 >libx265.txt

    Then you get:
    Code:
    Encoder libx265 [libx265 H.265 / HEVC]:
        Supported pixel formats: yuv420p yuvj420p yuv422p yuvj422p yuv444p yuvj444p gbrp yuv420p10le yuv422p10le yuv444p10le gbrp10le yuv420p12le yuv422p12le yuv444p12le gbrp12le gray gray10le gray12le
    Obviously YUV420P16 is NOT supported by x265.
    Quote Quote  
  3. I saved a video to FFMPEG HEVC x265 lossless YUV420P16 using VDub.

    FOURCC code 'HEVC'
    FFMPEG / x265 lossless
    YUV420P16
    Quote Quote  
  4. Normally HEVC support up to 12 bit per component - to encode 16 bit per component you need to use profile 'Main 4:4:4 16 Intra' - AFAIK x265 doesn't support this profile also i'm not aware of any open HEVC implementation supporting such profile.

    Perhaps your 16 bit per component source was converted silently into 12 bit or less.

    Btw - after decode 12 bit may be inserted to 16 bit (for example to speedup operation as CPU generally deal poorly with non aligned data).
    Verify if your source is truly 16 bit or just carried by 16 bit pixel format.
    Quote Quote  
  5. Originally Posted by Tom4 View Post
    I saved a video to FFMPEG HEVC x265 lossless YUV420P16 using VDub.

    FOURCC code 'HEVC'
    FFMPEG / x265 lossless
    YUV420P16
    YUV420P16 an intermediate pixel type that vdub2 can use, but x265 does not support YUV420P16

    You can check your video with mediainfo to verify
    Quote Quote  
  6. Originally Posted by poisondeathray View Post
    Originally Posted by Tom4 View Post
    I saved a video to FFMPEG HEVC x265 lossless YUV420P16 using VDub.

    FOURCC code 'HEVC'
    FFMPEG / x265 lossless
    YUV420P16
    YUV420P16 an intermediate pixel type that vdub2 can use, but x265 does not support YUV420P16

    You can check your video with mediainfo to verify
    It had me very confused because vdub2 had it under ffmpeg.
    Thanks Pandy and poisondeathray, its making sense now.

    As best I can tell this is the highest quality mp4 save format for vdub2?
    Please let me know if their is a better vdub2 option!
    PHP Code:
    SELECT VIDEO COMPRESSION
    Video Compression
    FFMPEG x265 lossless

    Video codec information
    .
    About.
    Delta frames Yes
    FOURCC code  
    'HEVC'
    Driver name  avlib-1.vdplugin 
    Comment
    Works with VD formats.

    x265 Configuration.
    YUV 4:2:0
    Bit depth
    12
    Quality
    lossless

    Output format to compressor
    .
    Actual outputYUV420P16
    4
    :2:0 planar YCbCr 16-bit

    Saved Video
    Video
    ID                                       
    0
    Format                                   
    HEVC
    Format
    /Info                              High Efficiency Video Coding
    Codec ID                                 
    HEVC 
    I am interested to know the ffmpeg cmd for highest quality mp4 encode?

    The idea is to force the highest quality mp4 output, which might differ from the meaning of lossless because the input quality is irrelevant.
    This is only for editing experiments, so size is not an issue.
    As mentioned, I have the ffmpeg static build.
    Last edited by Tom4; 16th Jan 2024 at 18:26.
    Quote Quote  
  7. Originally Posted by Tom4 View Post
    I am interested to know the ffmpeg cmd for highest quality mp4 encode?
    This is only for editing experiments, so size is not an issue.
    As mentioned, I have the ffmpeg static build.

    Highest quality would be your source pixel format (or output pixel format from a filter chain if using filters)

    There is a chance that you actually get lower quality - despite lossless encoding - if you don't perform the pixel type conversion(s) correctly

    Describe your initial source, any steps or filters in between

    For example, if you actually had YUV420P16 content - and wanted to keep 16bit - you would use FFV1 . You can configure the FFV1 settings and pixel type in the encoder configuration


    Editing with "what" ? There are types of pixel formats and compression types will not be compatible with some editors . You couldn't import a 16bit 4:2:0 FFV1 into Premiere Pro for example
    Quote Quote  
  8. Sorry, I must have been typing when you replied.
    adding: The idea is to force the highest quality mp4 output, which might differ from the meaning of lossless because the input quality is irrelevant. Even if this process ended up reducing quality through pixel type conversion.
    Just curious how to write the code to start?

    I did not have any editing software in mind.

    As mentioned, I saved HEVC YUV420P16 through configuration in vdub2.
    Loaded the HEVC mp4 in Hitpaw out of curiosity, it can load, process and save.
    Not that I like or use Hitpaw, just used for example.



    Originally Posted by poisondeathray View Post

    For example, if you actually had YUV420P16 content - and wanted to keep 16bit - you would use FFV1 . You can configure the FFV1 settings and pixel type in the encoder configuration


    Editing with "what" ? There are types of pixel formats and compression types will not be compatible with some editors . You couldn't import a 16bit 4:2:0 FFV1 into Premiere Pro for example
    Getting back to the highest quality 265 mp4 format available from ffmpeg cmd.
    Which might differ from the meaning of lossless because the input quality is irrelevant.
    I will test what software accepts it and worry about compatibility after!

    Could you offer me an example code how it might be written for ffmpeg cmd?
    Last edited by Tom4; 16th Jan 2024 at 19:02.
    Quote Quote  
  9. Originally Posted by Tom4 View Post
    Getting back to the highest quality 265 mp4 format available from ffmpeg cmd.
    Which might differ from the meaning of lossless because the input quality is irrelevant.
    I will test what software accepts it and worry about compatibility after!

    Could you offer me an example code how it might be written for ffmpeg cmd?
    The highest quality is lossless encoding in the same pixel format .

    Lossless encoding is irrelevant of input "quality". If your input video is "garbage quality", the output video is lossless and preserves the exact same "garbage quality" .

    Lossless is the highest "quality", because there is no additional quality loss. Everything else not lossless is "lossy" encoding, which means data loss and therefore quality loss.

    Something can only be lossless , and the highest quality, if it's the same pixel type. If your input was 16 bit data , it's not supported by x265 - so you lose quality. So the pixel format matters. (Theoretically you could increase the bit depth, and upsample chroma, but if it's not done correctly for the up and down step, you lose quality)

    This is for video only
    Code:
    ffmpeg -i input.ext -c:v libx265 -an -x265-params lossless=1 output.mp4
    Quote Quote  
  10. I understand pretty much exactly what you are saying poisondeathray, garbage in equals garbage out.
    If you process a video 10 times to improve quality, you need to save and retain your edit details and quality with each proceeding save.
    So by the 10th process you are no longer saving the same file and detail in the original but the file that has been processed to contain perhaps 10x as much detail and data.

    This subject can lead to arguments because of the different needs, wants and opinion of so many forum members.
    Thanks for your understanding poisondeathray, really helpful


    ffmpeg -i input.mp4 -c:a copy -c:v libx265 -preset placebo -crf 0 -pix_fmt yuv444p12le out.mp4
    (Note: I have not tested the code above for errors, internet access and offline processing PC are in different locations!)

    Or

    ffmpeg -i input.mp4 -c:a copy -c:v libx265 -an -x265-params lossless=1 out.mp4

    I normally save audio wave file to be added back after.
    Just out of curiosity, can we just copy audio as above with this code?
    Last edited by Tom4; 16th Jan 2024 at 20:03.
    Quote Quote  
  11. Originally Posted by Tom4 View Post
    ffmpeg -i input.mp4 -c:a copy -c:v libx265 -preset placebo -crf 0 -pix_fmt yuv444p12le out.mp4
    -crf 0 is not lossless for libx265
    Quote Quote  
  12. Originally Posted by Tom4 View Post
    ffmpeg -i input.mp4 -c:a copy -c:v libx265 -preset placebo -crf 0 -pix_fmt yuv444p12le out.mp4

    Or

    ffmpeg -i input.mp4 -c:a copy -c:v libx265 -an -x265-params lossless=1 out.mp4

    I normally save audio wave file to be added back after.
    Just out of curiosity, can we just copy audio as above with this code?
    PCM wav is incompatible in MP4 container using open source muxers . You would need a MKV container

    If your wav is separate file

    Code:
    ffmpeg -i input.mp4 -i input.wav -map 0:0 -map 1:0 -c:v libx265  -x265-params lossless=1 -c:a copy out.mkv
    Quote Quote  
  13. Originally Posted by poisondeathray View Post
    Originally Posted by Tom4 View Post
    ffmpeg -i input.mp4 -c:a copy -c:v libx265 -preset placebo -crf 0 -pix_fmt yuv444p12le out.mp4
    -crf 0 is not lossless for libx265
    Is "0" the wrong value for lossless, or -crf not compatible?
    Sorry, I am confused.
    Quote Quote  
  14. Originally Posted by Tom4 View Post
    Originally Posted by poisondeathray View Post
    Originally Posted by Tom4 View Post
    ffmpeg -i input.mp4 -c:a copy -c:v libx265 -preset placebo -crf 0 -pix_fmt yuv444p12le out.mp4
    -crf 0 is not lossless for libx265
    Is "0" the wrong value for lossless, or -crf not compatible?
    Sorry, I am confused.
    -crf 0 is still lossy for x265 (or 10bit x264)

    lossless mode for x265 specifically requires the lossless switch to activate it
    Quote Quote  
  15. Like this?
    PHP Code:
    ffmpeg -i input.mp4 -c:a copy -c:v libx265 -an -x265-params lossless=-pix_fmt yuv444p12le out.mp4 
    Quote Quote  
  16. Originally Posted by Tom4 View Post
    Like this?
    PHP Code:
    ffmpeg -i input.mp4 -c:a copy -c:v libx265 -an -x265-params lossless=-pix_fmt yuv444p12le out.mp4 

    -pix_fmt yuv444p12le forces a conversion to yuv444p12le , but it might not be an optimal conversion depending on the source characteristics of input.mp4
    Quote Quote  
  17. Originally Posted by Tom4 View Post
    I understand pretty much exactly what you are saying poisondeathray, garbage in equals garbage out.
    And that is the desired result , because it's exactly the same garbage ; not different garbage

    If you process a video 10 times to improve quality, you need to save and retain your edit details and quality with each proceeding save.
    So by the 10th process you are no longer saving the same file and detail in the original but the file that has been processed to contain perhaps 10x as much detail and data.

    This subject can lead to arguments because of the different needs, wants and opinion of so many forum members.
    Thanks for your understanding poisondeathray, really helpful
    You potentially lose quality from improper handling of pixel types and possibly other processing steps

    Also some editors do not handle all "lossless" formats correctly - you lose quality each time because they are not handled properly in the editor. A common example are most lossless YUV codecs in "pro" NLE's . They often clip YUV data and convert to RGB

    => Lossless means you can get back the original uncompressed data, exactly. Bit for bit. There is no data change, rounding errors, artifacts or any type loss. If you were to measure the quality with PSNR, "lossless" would yield "infinity" dB . Anything else would indicate some quality loss

    Even if you use lossless compression - you can lose quality with other processing steps, such as improper handling of pixel types, improper handling of lossless compression (E.g. some editors)

    For example if input was 4:2:0 , and you force usage the default ffmpeg chroma upscaler to 4:4:4, that is non reversible operation and technically additional quality loss compared to the input . If you were to measure PSNR of the output file against the input file, the PSNR would decrease. If you upscale the chroma with lossless encoding, you also increase the filesize for no benefit. (But if you chroma upsampled it properly with "nearest neighbor", then the upsample can be lossless, if the downsample uses nearest neighbor as well.)

    Same with bit depth increases - if they are not handled properly (e.g. often dithering is applied on the down conversion step) - you can get quality loss. If you increase the original bit depth with lossless encoding, you also increase the filesize for no benefit.

    The more things you do for no good reason (think of it as "more moving parts" to break down) - the more things can go wrong if not done properly
    Quote Quote  



Similar Threads

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