VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors. Consider supporting us by disable your adblocker or Try ConvertXtoDVD and convert all your movies to DVD. Free trial ! :)
+ Reply to Thread
Results 1 to 23 of 23
Thread
  1. Member
    Join Date
    Jul 2017
    Location
    United Kingdom
    Search Comp PM
    Hello,

    If I have this kind of video:

    Code:
    General
    Complete name                            : video.avi
    Format                                   : AVI
    Format/Info                              : Audio Video Interleave
    File size                                : 3.62 MiB
    Duration                                 : 17 s 17 ms
    Overall bit rate                         : 1 785 kb/s
    
    Video
    ID                                       : 0
    Format                                   : AVC
    Format/Info                              : Advanced Video Codec
    Format profile                           : Baseline@L3
    Format settings, CABAC                   : No
    Format settings, RefFrames               : 2 frames
    Format settings, GOP                     : M=1, N=28
    Codec ID                                 : H264
    Duration                                 : 17 s 17 ms
    Bit rate                                 : 1 772 kb/s
    Width                                    : 704 pixels
    Height                                   : 480 pixels
    Display aspect ratio                     : 3:2
    Frame rate                               : 29.970 (30000/1001) FPS
    Standard                                 : NTSC
    Color space                              : YUV
    Chroma subsampling                       : 4:2:0
    Bit depth                                : 8 bits
    Scan type                                : Progressive
    Bits/(Pixel*Frame)                       : 0.175
    Stream size                              : 3.59 MiB (99%)
    Can I use ffmpeg to decode it? Do I have to use libavcodec? Or are there any other ways?

    What if I have a video that was encoded by libx264? Can I decode it using libavcodec as well?

    Do I have to convert my video into raw video before decoding it?

    Thank you...
    Quote Quote  
  2. ffmpeg can decode it just fine. It doesn't matter which AVC/H.264 encoder created the file, it can decode all of them ((lib)x264 is one of many AVC/H.264 encoders).

    Originally Posted by nothingnew View Post
    Do I have to convert my video into raw video before decoding it?
    I'm not sure what you mean by that. Converting AVC to any other format (including "raw") implies decoding. ffmpeg can convert to other formats with a single command/run. You don't need to run it in two steps.


    Now I answered if it can. Yes. Maybe you wanted to ask how to convert to something specific?
    Quote Quote  
  3. Member
    Join Date
    Jul 2017
    Location
    United Kingdom
    Search Comp PM
    Yes, I mean how to decode it with ffmpeg. I thought that I have to convert it to raw before decoding it using H264.

    Is it possible to recover the original video? I mean, the video before it was encoded by H264. If it is possible, how to do that?
    Quote Quote  
  4. AVC encoding is usually lossy. You cannot recover the original 100% (that would make it lossless). You can convert to the original format (if ffmpeg has encoders/muxers for it) but the quality will not be the same.
    Quote Quote  
  5. Member
    Join Date
    Jul 2017
    Location
    United Kingdom
    Search Comp PM
    Ok, now I'm more confused than before I ask this question.

    Let me clarify something. I thought that H264, x264, and AVC are all refer to the same thing. Are they not?

    FFmpeg has libx264 for encoder. It also has libavcodec with H264 native decoder. So, I should be able to convert to original format. But how do I do that? Do I apply encoding using libx264? Or decode it using H264 native decoder?

    I know how to do encoding using libx264. But, wouldn't encoding the video decrease its quality? I mean, isn't it like doing double compression? Please correct me if I'm wrong.

    I don't know how to decode using libavcodec though... So, please give some pointer if I have to do this.
    Quote Quote  
  6. Originally Posted by nothingnew View Post
    Let me clarify something. I thought that H264, x264, and AVC are all refer to the same thing. Are they not?
    H.264 and AVC are different names for the same thing - a specific video format (specification). x264 is one software implementation that encodes video to a bitstream of said H.264/AVC specification.
    Sometimes people use the words meaning the same thing ignoring these differences - either they don't know better or don't care.

    Originally Posted by nothingnew View Post
    FFmpeg has libx264 for encoder. It also has libavcodec with H264 native decoder. So, I should be able to convert to original format.
    Decoding means converting to an uncompressed video stream. Is that the "original format"? I don't know. You haven't told what the video originally was. Maybe it was captured with a camera to VHS? ffmpeg cannot create VHS.

    Originally Posted by nothingnew View Post
    I know how to do encoding using libx264. But, wouldn't encoding the video decrease its quality? I mean, isn't it like doing double compression? Please correct me if I'm wrong.
    Yes, every time you apply a lossy encoding you have additional loss => quality decreases even further.

    Originally Posted by nothingnew View Post
    I don't know how to decode using libavcodec though... So, please give some pointer if I have to do this.
    ffmpeg chooses the correct decoder automatically.


    Originally Posted by nothingnew View Post
    But how do I do that? Do I apply encoding using libx264? Or decode it using H264 native decoder?
    After reading your posts I only get more confused. What is it that you want to achieve in the end?
    Newbies often ask "how do I do X" without telling us what they want to achieve. In the end it turns out they want to "achieve Z" and to do that they should be "doing Y, not X".

    So: what is it that you want to have in the end? And why?
    Quote Quote  
  7. Member
    Join Date
    Jul 2017
    Location
    United Kingdom
    Search Comp PM
    Alright, please forgive me...

    Actually, it's a CCTV footage that I download from a website. So, I don't know what's the original format as well. I just assume that the original video is in RGB. I want to observe whether decoding it by H264 will increase the quality or not. I also wonder what would happen if I convert the video into RGB (without decoding) or change it into YUV 4:4:4. Will it increase or decrease the quality. Something like that...

    So, what do you think? What should I do?
    Quote Quote  
  8. h.264 and AVC are the names of the specification for encoding. x264 is a particular encoder that conforms to that spec. That is, x264 is an encoder that produces h.264 video.

    h.264/AVC is a lossy compression format. Once you have encoded something to h.264 specs you can never get back the original video from that encoded file, only some that looks like it. How closely it matches depends on how much the video was compressed and what settings were used. That can vary from something that's visually nearly indistinguishable from the original to something that looks almost nothing like the original.

    Re-encoding a video always involves first decoding (decompressing) the video to uncompressed frames, then encoding (compressing) those uncompressed frames with the new codec/settings. So any time you re-compress a video with ffmpeg you are decompressing the video first. Unless you specify an external decoder (for example, using an AviSynth script) you will be using ffmpeg's internal h.264 decoder.
    Last edited by jagabo; 10th Aug 2017 at 16:52.
    Quote Quote  
  9. Originally Posted by nothingnew View Post
    Actually, it's a CCTV footage that I download from a website. So, I don't know what's the original format as well. I just assume that the original video is in RGB. I want to observe whether decoding it by H264 will increase the quality or not. I also wonder what would happen if I convert the video into RGB (without decoding) or change it into YUV 4:4:4. Will it increase or decrease the quality. Something like that...
    You will not increase quality at all.
    If you watch a video it is already being decoded. You are not the guy from "The Matrix" that watches the screen with weird code, right? Every video player decodes. Many even use the ffmpeg decoders.

    Originally Posted by nothingnew View Post
    So, what do you think? What should I do?
    You are speaking of CCTV footage. So my guess it you have footage of maybe a criminal or a criminal's car and want to "enhance" it so you can make out the face or the number of the car license plate or something like that. ffmpeg won't really help with that (or only very limited).
    This is a job for a specialist. You could post the video here but in the past people have done it and no one on this forum was able to help.
    Quote Quote  
  10. Member
    Join Date
    Jul 2017
    Location
    United Kingdom
    Search Comp PM
    Ah, I see... I think I start to understand.
    Quote Quote  
  11. Member
    Join Date
    Jul 2017
    Location
    United Kingdom
    Search Comp PM
    Originally Posted by sneaker View Post
    So my guess it you have footage of maybe a criminal or a criminal's car and want to "enhance" it so you can make out the face or the number of the car license plate or something like that.
    Yeah, that's the big idea. But I'm only doing some kind of experiment here. More like observing the effect of color conversion and subsampling on video.

    Thanks for all the explanations...
    Quote Quote  
  12. Originally Posted by nothingnew View Post
    I'm only doing some kind of experiment here. More like observing the effect of color conversion and subsampling on video.
    https://forum.videohelp.com/threads/294144-Viewing-tests-and-sample-files#post1792760
    Quote Quote  
  13. Member
    Join Date
    Jul 2017
    Location
    United Kingdom
    Search Comp PM
    Many thanks, jagabo...
    Quote Quote  
  14. Member
    Join Date
    Jul 2017
    Location
    United Kingdom
    Search Comp PM
    So, I tried to apply upsampling from YUV 4:2:0 to 4:4:4 and RGB to a CCTV footage using FFmpeg. I also applied the same thing to belle-nuit test chart.

    Originally Posted by sneaker View Post
    You will not increase quality at all.
    You're right. I couldn't see any change in the CCTV footage, while from belle-nuit test chart I got something like this:

    Click image for larger version

Name:	ori-u444-colour shift.png
Views:	51
Size:	2.4 KB
ID:	42861

    Name:  ori-u444-loss detail.png
Views: 2382
Size:  5.4 KB

    I don't understand. Why did that happen to the CCTV result?
    Quote Quote  
  15. Pretty much all digital distribution methods use YUV 4:2:0. So your CCTV video (h.264?) is likely already 4:2:0. The damage has already been done. Upscaling to 4:4:4 just resizes the U and V planes (typically with a bilinear or bicubic filter).
    Quote Quote  
  16. Member
    Join Date
    Jul 2017
    Location
    United Kingdom
    Search Comp PM
    Originally Posted by jagabo View Post
    Pretty much all digital distribution methods use YUV 4:2:0. So your CCTV video (h.264?) is likely already 4:2:0. The damage has already been done. Upscaling to 4:4:4 just resizes the U and V planes (typically with a bilinear or bicubic filter).
    Yes, it's h.264. So, the conversion between 4:4:4 to 4:2:0 is irreversible? Is it because the chroma planes don't have enough information to produce the original color?
    Quote Quote  
  17. Converting 4:4:4 to 4:2:0 is a lossy process. You throw away 3/4 of all color information. It's not reversable. How 4:2:0 to 4:4:4 will look depends on the scaling algo (just like upscaling SD to HD .. well, which it basically is). Don't expect any miracles from ffmpeg. Even from the better algos. The reason 4:2:0 is often used is we humans have a hard time noticing it anyways.

    But scientists like the ones at Google are working on image recovery with impressive results. Haven't seen anything usable for us low-life endusers yet, though.
    Quote Quote  
  18. Member
    Join Date
    Jul 2017
    Location
    United Kingdom
    Search Comp PM
    That's true. So, theoretically the scaling algorithm only have 1/4 of the color information. Even with the better algorithm, the scaling result will highly depend on those information.
    Quote Quote  
  19. Originally Posted by nothingnew View Post
    That's true. So, theoretically the scaling algorithm only have 1/4 of the color information. Even with the better algorithm, the scaling result will highly depend on those information.
    You can play around with different scaling algorithms for the chroma. But with very sharp video you get oversharpening halos if you use sharp resizers like Lanczos, Spline64, even Bicubic. A Point (AKA Nearest Neighbor) resize gets you sharp edges without halos but will generally look bad. An exception will be color charts with only vertical and horizontal edges aligned at even pixel boundaries -- who's chroma was downscaled with a point resize as well.
    Quote Quote  
  20. Member
    Join Date
    Jul 2017
    Location
    United Kingdom
    Search Comp PM
    Thanks jagabo. I will try them and report it here.

    I can try them using something like this, right?
    Code:
    -vf scale=flags=lanczos
    Quote Quote  
  21. I'm not that familiar with ffmpeg. I don't know if that controls chroma upscaling as well as scaling the entire frame.
    Quote Quote  
  22. You can use scaler flags - example
    Code:
    scale=iw*2:-8:sws_flags=spline+accurate_rnd+full_chroma_int+full_chroma_inp
    Quote Quote  
  23. Member
    Join Date
    Jul 2017
    Location
    United Kingdom
    Search Comp PM
    Thanks pandy
    Quote Quote  



Similar Threads