Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > High Efficiency Video Coding (HEVC)

Reply
 
Thread Tools Search this Thread Display Modes
Old 22nd January 2021, 06:09   #1  |  Link
BlueSky00
Registered User
 
Join Date: Feb 2020
Posts: 5
Creating HDR video from a sequence of YUV frames

Hi folks,

This is my first post, but I've been reading the forum for a while.

I have a HDR video, I converted it to YUV frames, and now I want to convert the frames back to HDR video with the same metadata as the original. I used ffmpeg, and did the process but apparently something is wrong as it's not being played. Can someone please help me? I think the part that I mostly need help is converting a sequence of YUV frames to HDR video with the metadata the same as original video.

Thanks for any help
BlueSky00 is offline   Reply With Quote
Old 22nd January 2021, 07:10   #2  |  Link
Blue_MiSfit
Derek Prestegard IRL
 
Blue_MiSfit's Avatar
 
Join Date: Nov 2003
Location: Los Angeles
Posts: 5,800
A series of YUV frames as in what, a single YUV file?

Post your command
Blue_MiSfit is offline   Reply With Quote
Old 22nd January 2021, 19:54   #3  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 3,536
This is how I had to make some of our HDR demo clips for CES 2015. If you've exported your YUV frames as proper SMPTE 2100 (PQ with 2020 primaries), it's pretty trivial to use that as source. I'd probably convert from the frames to a .y4m file in ffmpeg first, just to confirm I've got a single file with the correct metadata. You could also pipe straight to x265. One trick here is using -pix_fmt yuv420p10le -strict -1 in your ffmpeg command line so it'll make a real 10-bit YUV. There's also ffmpeg's turgid image sequence file reading syntax, which you've probably already figured out.

x265 can directly read a .y4m file and will read the height/width/fps/color depth/subsampling from the metadata so you don't have to specify all that.

Here's a sample command line for encoding from .y4m to HDR.

Code:
ffmpeg.exe -i foo.y4m -pix_fmt yuv420p10le -strict -1 -f yuv4mpegpipe - | x265.exe - --y4m --colorprim bt2020 --transfer smpte2084 --colormatrix bt2020nc --hdr --hdr-opt --max-cll "2000,300" -o foo.hevc
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 22nd January 2021, 20:23   #4  |  Link
BlueSky00
Registered User
 
Join Date: Feb 2020
Posts: 5
Quote:
Originally Posted by Blue_MiSfit View Post
A series of YUV frames as in what, a single YUV file?

Post your command
Thanks for your reply.

>> A series of YUV frames as in what, a single YUV file?

Assume I have 30 frames, which I extracted them from a clip. Put all of them in a folder. This is the command I used:

ffmpeg -i video.mp4 -s 1920x1080 -pixel_format yuv420p10le -f segment -segment_time 0.01 frame%02d.yuv


And then I used this command to make the video again and add metadata to it (I am not sure if it's a right thing to do). I want to have the same metadata as the original file though.

ffmpeg -y -s 1920x1080 -pix_fmt yuv420p -threads 4 -r 24 -stream_loop -1 -f rawvideo -i frame*.yuv -vf scale=out_h_chr_pos=0ut_v_chr_pos=0, format=yuv420p10le -c:v libx265 -tag:v hvc1 -t 10 -pix_fmt yuv420p10le -preset medium -x265-params crf=12:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display="G(13250,34500)B(7500,3000)R(34000,16000)WP(15700,17550)L(10000000,500):max-cll="4000,400" -an hdr_video.mp4
BlueSky00 is offline   Reply With Quote
Old 22nd January 2021, 20:29   #5  |  Link
BlueSky00
Registered User
 
Join Date: Feb 2020
Posts: 5
Quote:
Originally Posted by benwaggoner View Post
This is how I had to make some of our HDR demo clips for CES 2015. If you've exported your YUV frames as proper SMPTE 2100 (PQ with 2020 primaries), it's pretty trivial to use that as source. I'd probably convert from the frames to a .y4m file in ffmpeg first, just to confirm I've got a single file with the correct metadata. You could also pipe straight to x265. One trick here is using -pix_fmt yuv420p10le -strict -1 in your ffmpeg command line so it'll make a real 10-bit YUV. There's also ffmpeg's turgid image sequence file reading syntax, which you've probably already figured out.

x265 can directly read a .y4m file and will read the height/width/fps/color depth/subsampling from the metadata so you don't have to specify all that.

Here's a sample command line for encoding from .y4m to HDR.

Code:
ffmpeg.exe -i foo.y4m -pix_fmt yuv420p10le -strict -1 -f yuv4mpegpipe - | x265.exe - --y4m --colorprim bt2020 --transfer smpte2084 --colormatrix bt2020nc --hdr --hdr-opt --max-cll "2000,300" -o foo.hevc
Thanks for your reply. I will try your approach. I also posted my commands in my previous reply. Can you please let me know what you think about that?
And btw, I am using Mac and probably need to make some changes in your command (.exe). I am new to ffmpeg and sorry for my novice questions.
BlueSky00 is offline   Reply With Quote
Old 23rd January 2021, 02:03   #6  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 3,536
I'd take out everything from the ffmpeg processing that you don't need. For example, x265 and ffmpeg don't (or didn't; maybe ffmpeg added support at some point) process anything different with different chromaloc, so letting the metadata be the default is the safest.

What's your use case, and what are you trying to be compatible with? Normally I'd set --level-idc, --vbv-maxrate, and --vbv-bufsize to match the spec. And I'd use at least --preset slower for content I'm trying to get good quality at a constrained bitrate with.

You can probably do it all in ffmpeg with the params like you had set up. I just don't do it that way and don't have any experience to share. I've often used particular x265 builds and like not having to update ffmpeg all the time.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 23rd January 2021, 03:11   #7  |  Link
BlueSky00
Registered User
 
Join Date: Feb 2020
Posts: 5
Quote:
Originally Posted by benwaggoner View Post
This is how I had to make some of our HDR demo clips for CES 2015. If you've exported your YUV frames as proper SMPTE 2100 (PQ with 2020 primaries), it's pretty trivial to use that as source. I'd probably convert from the frames to a .y4m file in ffmpeg first, just to confirm I've got a single file with the correct metadata. You could also pipe straight to x265. One trick here is using -pix_fmt yuv420p10le -strict -1 in your ffmpeg command line so it'll make a real 10-bit YUV. There's also ffmpeg's turgid image sequence file reading syntax, which you've probably already figured out.

x265 can directly read a .y4m file and will read the height/width/fps/color depth/subsampling from the metadata so you don't have to specify all that.

Here's a sample command line for encoding from .y4m to HDR.

Code:
ffmpeg.exe -i foo.y4m -pix_fmt yuv420p10le -strict -1 -f yuv4mpegpipe - | x265.exe - --y4m --colorprim bt2020 --transfer smpte2084 --colormatrix bt2020nc --hdr --hdr-opt --max-cll "2000,300" -o foo.hevc
Hi Ben,

Thanks for your comments. I got that. I think the command you proposed originally can meet my need. Just one more question.

I tried making a y4m but I got stuck.

Here is what I tried to do:

1. Combine all YUV frames into a single yuv file using cat command (cat *.yuv > movie.yuv)

2. Convert YUV file to y4m using the following command:

Code:
ffmpeg -s 1920x1080 -strict -1 -pix_fmt yuv420p10le -strict -1 -i all.yuv output.y4m
And get this error:

'yuv420p10le' is not an official yuv4mpegpipe pixel format. Use '-strict -1' to encode to this pixel format.

Can you help me to understand why? Thank you
BlueSky00 is offline   Reply With Quote
Old 23rd January 2021, 21:04   #8  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 3,536
Quote:
Originally Posted by BlueSky00 View Post
I tried making a y4m but I got stuck.

Here is what I tried to do:

1. Combine all YUV frames into a single yuv file using cat command (cat *.yuv > movie.yuv)

2. Convert YUV file to y4m using the following command:

Code:
ffmpeg -s 1920x1080 -strict -1 -pix_fmt yuv420p10le -strict -1 -i all.yuv output.y4m
And get this error:

'yuv420p10le' is not an official yuv4mpegpipe pixel format. Use '-strict -1' to encode to this pixel format.
You have -strict 1 listed twice in your command line. It works for me if it is following -pix_fmt. Try removing the first one.

As to why, the ineffable inner workings of ffmpeg are not for humankind to understand or question .

Also, there is no metadata in a .yuv frame, so you'll need to specify resolution, fps, chroma subsampling, pixel depth, etcetera in ffmpeg. That's why I do a single-step .yuv frames to .y4m file conversion, so I can examine the .y4m and confirm it works correctly before compression.

Also, not that scaling HDR in ffmpeg isn't optimal, because it presumes gamma, not PQ. You can wind up getting materially different output values in areas of high local contrast scaling in ffmpeg compared to doing a proper linear light scaling based on nit values.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Old 26th January 2021, 19:31   #9  |  Link
BlueSky00
Registered User
 
Join Date: Feb 2020
Posts: 5
Quote:
Originally Posted by benwaggoner View Post
You have -strict 1 listed twice in your command line. It works for me if it is following -pix_fmt. Try removing the first one.

As to why, the ineffable inner workings of ffmpeg are not for humankind to understand or question ;).

Also, there is no metadata in a .yuv frame, so you'll need to specify resolution, fps, chroma subsampling, pixel depth, etcetera in ffmpeg. That's why I do a single-step .yuv frames to .y4m file conversion, so I can examine the .y4m and confirm it works correctly before compression.

Also, not that scaling HDR in ffmpeg isn't optimal, because it presumes gamma, not PQ. You can wind up getting materially different output values in areas of high local contrast scaling in ffmpeg compared to doing a proper linear light scaling based on nit values.

Thanks for your response Ben!

Having two -strict -1 was my mistake when I was transferring my code here. I don't have 2 in my actual code. However, even with one, it does not work and I get the same error.

Code:
ffmpeg  -s 1920x1080  -pix_fmt yuv420p10le  -strict -1  -i all.yuv output.y4m
And here is the error:

'yuv420p10le' is not an official yuv4mpegpipe pixel format. Use '-strict -1' to encode to this pixel format.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
BlueSky00 is offline   Reply With Quote
Old 26th January 2021, 22:26   #10  |  Link
benwaggoner
Moderator
 
Join Date: Jan 2006
Location: Portland, OR
Posts: 3,536
Quote:
Originally Posted by BlueSky00 View Post
Thanks for your response Ben!

Having two -strict -1 was my mistake when I was transferring my code here. I don't have 2 in my actual code. However, even with one, it does not work and I get the same error.

Code:
ffmpeg  -s 1920x1080  -pix_fmt yuv420p10le  -strict -1  -i all.yuv output.y4m
And here is the error:

'yuv420p10le' is not an official yuv4mpegpipe pixel format. Use '-strict -1' to encode to this pixel format.
Could not write header for output file #0 (incorrect codec parameters ?): Invalid argument
This is baffling, as you already have a -strict -1 right there! And it's the same order of parameters that I have, so I have no idea why you're getting that error. You may need to consult with some ffmpeg experts.

Also, can you share your entire line? It's possible that something is going weird parsing the original .yuv frames or file. Lots of required parameters to specify.
__________________
Ben Waggoner
Principal Video Specialist, Amazon Prime Video

My Compression Book
benwaggoner is offline   Reply With Quote
Reply

Tags
ffmpeg, hdr, metadata, yuv420p

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 14:09.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.