-1

I have HD 1920x1080 YUV format videos. I would like to compress them to 640x480and other convert to other format(mp4/avi..) I used the follwing command:

ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1920x1080 -r 25 -i input.yuv -c:v libx264 output.mp4
It converts the video but it looks **blurry** and **broken**.

Does any one have better solution for my problem? [There are lot of solutions i found as like as the above one but none of them works good] I would most appreciate your help.

mrana
  • 1,008
  • 3
  • 10
  • 16
  • Can you add sample frames? – Rekin Aug 08 '15 at 16:38
  • @Rekin, I am not sure what u mean. can u give me code i would try if that helps to compress and.. – mrana Aug 08 '15 at 18:30
  • Can you upload a screenshot somewhere of a comparison of input and output to indicate why you believe the quality is bad? It sounds to me like you're not selecting any ratecontrol/quality variables for the video encoding, so I'd start by choosing some of these. E.g., try -b:v 1024k -preset:v veryslow (after -c:v libx264, but before output.mp4). See also https://trac.ffmpeg.org/wiki/Encode/H.264 – Ronald S. Bultje Aug 08 '15 at 18:53
  • original(yuv):https://www.dropbox.com/s/a1hf5hv6omqthaw/original.png?dl=0 After compression(mp4): https://www.dropbox.com/s/2m7f43vwvtjvyuo/after-compression.png?dl=0 – mrana Aug 08 '15 at 22:17
  • @RonaldS.Bultje this code: ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1920x1080 -r 25 -i input.yuv -c:v libx264 -b:v 1024k -preset:v veryslow output.mp4 Broken output: https://www.dropbox.com/s/7bhq6pe4cpz2u5x/test2.png?dl=0 – mrana Aug 09 '15 at 09:16
  • The first screenshot (2m7f43vwvtvyuo) suggests the input is not raw yuv at 1920x1080. I don't know what it is, I'll need the first 10-20MB of the file to figure that out. I'm guessing it's y4m or some other raw yuv format with a header around it. What does "ffprobe input.yuv" say? – Ronald S. Bultje Aug 09 '15 at 10:51
  • @RonaldS.Bultje this will be great if you try any video from this list: ftp://ftp.ivc.polytech.univ-nantes.fr/IRCCyN_IVC_1080i_Database/1080i_Videos/ – mrana Aug 09 '15 at 11:59
  • Before I download anything, can you give the output of ffprobe file.yuv first? – Ronald S. Bultje Aug 09 '15 at 12:01
  • command: `ffprobe input.yuv` Result >> `[IMGUTILS @ 0x7fff50400140] Picture size 0x0 is invalid Last message repeated 1 times [rawvideo @ 0x7fe99a802a00] Could not find codec parameters for stream 0 (Video: rawvideo (I420 / 0x30323449), yuv420p, -4 kb/s): unspecified size Consider increasing the value for the 'analyzeduration' and 'probesize' options input.yuv: Operation not permitted` – mrana Aug 09 '15 at 14:16
  • @RonaldS.Bultje have you found anything? Thanks – mrana Aug 10 '15 at 07:22
  • @RonaldS.Bultje can u please try to answer this question: http://stackoverflow.com/questions/33378548/ffmpeg-crop-a-video-without-loosing-the-quality?noredirect=1#comment54560796_33378548 – mrana Oct 28 '15 at 10:09

2 Answers2

1

Your videos are not yuv420p, they are yuv422p. Use the following commandline:

ffmpeg -f rawvideo -pix_fmt yuv422p -s:v 1920x1080 -r 25 -i input.yuv -c:v libx264 output.mp4

And then use rate control variables for H264 encoding as documented here.

Ronald S. Bultje
  • 10,828
  • 26
  • 47
  • This is excellent!! How i can convert the video to the ration: 640 × 480 Thanks so much. – mrana Aug 10 '15 at 13:44
  • ffmpeg -f rawvideo -pix_fmt yuv422p -s:v 1920x1080 -r 25 -i input.yuv -c:v libx264 -vf scale=640:480 output.mp4 – Ronald S. Bultje Aug 10 '15 at 15:01
  • Dear @Ronald I don't want loss of quality from the original to new one. How can i proof that the video quality did not change, may be PSNR value? Also, if the video quality changes then can we do less number of distortion of the video quality? I would be grateful to have some ideas. Thanks again. – mrana Aug 12 '15 at 20:40
  • No quality loss means "lossless", check the lossless section in https://trac.ffmpeg.org/wiki/Encode/H.264 - to check for that, use e.g. the psnr filter: ffmpeg -f rawvideo -pix_fmt yuv422p -s:v 1920x1080 -r 25 -i input.yuv -i output.mp4 -lavfi psnr -f null -, and check for the line "[Parsed_psnr_0 @ 0x7f8b98525600] PSNR y:inf u:inf v:inf average:inf min:inf max:inf" in the output. A value of inf means the conversion was lossless. A typical value is around 40, anything substantially higher (50 or 60) is incredible good quality, and anything below (e.g. 30) is pretty terrible. – Ronald S. Bultje Aug 13 '15 at 11:43
  • Dear Ronald, thanks so much (i will respond you on this later). I posted another question: http://stackoverflow.com/questions/31981455/how-to-extract-framesor-a-perticular-frame-from-a-yuv-video-using-ffmpeg/31983830?noredirect=1#comment51877289_31983830 Still no solution i got, can u please check that too. Many thanks – mrana Aug 13 '15 at 15:52
  • Dear @Ronald I have more 2 issues to ask you: 1. I have resized the video from 1920x1080 to 480:270 (good ratio) losslessly by the following command: `ffmpeg -f rawvideo -pix_fmt yuv422p -s:v 1920x1080 -r 25 -i above_marathon_250.yuv -c:v libx264 -vf scale=480:270 -qp 0 above_marathon_250.mp4` Once i try to find the PSNR value i get the following problem: https://www.dropbox.com/s/h2djohk3d3q6uj6/Screen%20Shot%202015-08-20%20at%2018.43.24.png?dl=0 2. What is the minimum value of PSNR for no visible artifact(no visible distortion), and how can i set it? Thanks so much. – mrana Aug 20 '15 at 16:46
  • Hi mrana, you probably want to open a new question, this is pretty off-topic for this question, which isn't helpful for overall stackoverflow searchability. – Ronald S. Bultje Aug 20 '15 at 17:18
  • I have posted it here: (not sure how to post for experts) http://stackoverflow.com/questions/32125123/how-to-set-psnr-value-also-what-is-the-minimum-psnr-value-which-shows-no-visibl – mrana Aug 20 '15 at 17:55
  • Ronald, can u please check this post: http://stackoverflow.com/questions/32125123/how-to-set-psnr-value-also-what-is-the-minimum-psnr-value-which-shows-no-visibl – mrana Aug 21 '15 at 08:22
0

You are not specifying a quality factor, or a bit rate, So a default value is being chosen for you. try adding something like -crf 18.

szatmary
  • 29,969
  • 8
  • 44
  • 57
  • Adding -crf 18 gives me the broken output: ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1920x1080 -r 25 -i input.yuv -c:v libx264 -crf 18 output.mp4 Output: https://www.dropbox.com/s/q0typhkyna3mc6r/test1.png?dl=0 – mrana Aug 09 '15 at 07:28
  • ffmpeg -f rawvideo -pix_fmt yuv420p -s:v 1920x1080 -r 25 -i input.yuv -c:v libx264 -crf 18 output.mp4 Not good result: https://www.dropbox.com/s/q0typhkyna3mc6r/test1.png?dl=0 @szatmary – mrana Aug 09 '15 at 09:24