View Full Version : Using FFMPEG to encode to Blu-ray format
lyinawake
25th March 2014, 18:59
Hello,
I have been tearing my hair out trying to find the optimal way to encode an already x264 compressed 720p29.97 video file into a Bluray compatible format using ffmpeg. There are lots of resources for using the stand-alone x264.exe, but I want to retain the audio track in my file, so I believe ffmpeg would be the best way to go (please correct me if I'm wrong).
Ideally I would like to use ffmpeg so that I can also use the libfdk_aac audio encoder. Here is the command that I have built from various resources including the sticky at the top of this forum:
ffmpeg -i [filein] -c:v libx264 -level:v 4.1 -preset veryslow -tune film -crf 16 -r 59.94 -x264opts bluray-compat=1:weightp=0:bframes=3:ref=3:nal-hrd=vbr:vbv-maxrate=40000:vbv-bufsize=30000:keyint=60:b-pyramid=strict:slices=4:tff=1:aud=1:colorprim=bt709:transfer=bt709:colormatrix=bt709:sar=1/1 -c:a copy [fileout]
I am comparing the output of this command with that of multiAVCHD's built-in transcoding and have found the quality of the multiAVHCD built-in transcoding noticably better. However, I would like to do this through the command line instead of GUI so I can automate.
Could anyone please review my ffmpeg command and indicate why I am not able to get the same quality as I can with the multiAVHCD transcode process? I know that multiAVHCD uses AVISynth scripts, but shouldn't I be able to achieve the same thing with the ffmpeg cli?
I also need to use ffmpeg to create a letterboxed DVD-format of the same file. I honestly haven't spent a lot of time on figuring out how to crop/resize appropriately and whether anything besides the "target ntsc-dvd" flag is required for compatibility, but if someone has the command line handy for it I'd really appreciate that.
Thank you!
smok3
25th March 2014, 19:37
You'd probably want to know;
a. what version of x264 are both using
b. are the encoding commands exactly the same
c. there could be something silly happening with -r 59.94 < just guessing
lyinawake
25th March 2014, 20:11
Thanks for the response. Good points.
a.) I'd think my version is newer than multiAVCHD's version as that was last built in 2012 and I cross-compiled my ffmpeg on Dec 2013. However I'm not certain what the version # of my x264 is... My memory of the cross-compile and how I wound up doing it is unfortunately foggy
b.) No, multiAVCHD uses AVISynth scripts and I'm using ffmpeg CLI so I'd imagine they'd be quite different. However, I should probably try to intercept the script while multiAVCHD is whirring away and see what's in the guts...
c.) 720p Blu-ray doesn't support 29.97fps so the best thing I can think to do is go to 59.94fps so I don't lose any frames.
smok3
25th March 2014, 23:29
b. I meant the x264 command line (That should have little/none to do with avisynth).
pandy
27th March 2014, 15:55
b.) No, multiAVCHD uses AVISynth scripts and I'm using ffmpeg CLI so I'd imagine they'd be quite different.
-x264opts should be the same, ffmpeg in your case is a x264 frontend, avisynth is used to process raw video
just copy x264 settings from multiAVCHD - if raw video is same quality then results should be comparable (assumption that x264 same version is used) - if this is different then perhaps raw video quality is different - avisynth perform way better raw video processing than ffmpeg.
c.) 720p Blu-ray doesn't support 29.97fps so the best thing I can think to do is go to 59.94fps so I don't lose any frames.
check http://mewiki.project357.com/wiki/X264_Settings#pulldown settings - perhaps framerate conversion is not required.
use -x264opts to pass pulldown to ffmpeg
poisondeathray
27th March 2014, 16:14
It's --pulldown double with x264.exe
https://sites.google.com/site/x264bluray/home/720p-encoding
But not all options are available in ffmpeg libx264; not sure if the pulldown options are available. Sometimes -x264-params works, but -x264opts doesn't for ffmpeg libx264. For example, -x264-params open-gop=1 works, but -x264opts open-gop=1 doesn't get passed
foxyshadis
28th March 2014, 02:05
Odd, that's normally libav behavior, they don't understand -x264opts. ffmpeg supports both for libav compatibility. Well, use whatever works.
lyinawake
2nd May 2014, 19:32
I've had no luck as of yet. Adobe Encore is still seeing my output as non-compliant and having to transcode it again. Here is my latest set of commands:
x264options = "bluray-compat=1:force-cfr=1:weightp=0:bframes=3:ref=3:nal-hrd=vbr:vbv-maxrate=40000:vbv-bufsize=30000:keyint=60:b-pyramid=strict:slices=4:tff=1:aud=1:colorprim=bt709:transfer=bt709:colormatrix=bt709:sar=1/1"
strCmd = "ffmpeg.exe -y -i " & INPUT_PATH & INPUT_FILE & " -c:v libx264 -level:v 4.1 -preset veryslow -tune film -crf 16 -r 59.94 -x264opts " & x264options & " -x264-params " & x264options & " -c:a copy " & OUTPUT_NAME
I am now trying to push everything through both x264opts and x264-params. I am unable to use the pulldown options references in the "x264 for Bluray" pages, so this is as close as I seem to be able to get to what they've suggested.
Does anyone know how I would go about using x264.exe instead of ffmpeg to be able to handle the audio stream as well? Or would I need to move to AVISynth to be able to do this? It's a damn shame, but what I'm trying to do just doesn't seem possible with ffmpeg...
poisondeathray
2nd May 2014, 20:00
One thing that sticks out is -r 59.94 . 59.94 is an approximation, it should be 60000/1001. Also "TFF" implies interlaced encoding.
Why do you care about x264 handling/passing audio? You're going to be importing elementary streams anyway
benwaggoner
2nd May 2014, 21:06
One thing that sticks out is -r 59.94 . 59.94 is an approximation, it should be 60000/1001. Also "TFF" implies interlaced encoding.
...and you can only have interlaced in BD at <=30 fps. 50/59.94 is progressive only, and not available at 1080p.
poisondeathray
2nd May 2014, 21:30
...and you can only have interlaced in BD at <=30 fps. 50/59.94 is progressive only, and not available at 1080p.
His source was 720p29.97 ; I'm assuming he's not upscaling it
And that must be a typo because you can have native progressive BD <= 30 FPS eg.1080p24, 1080p23.976 , 720p24, 720p23.976
And it works in ffmpeg for Encore passthrough for the 720p59.94 case when those 2 suggestions are implemented. Make sure you export elementary stream. The pulldown options don't work in ffmpeg libx264 - or at least I couldnt' figure the switches out . That was for a real 59.94 video. For your video you have to use actual frame duplicates
benwaggoner
3rd May 2014, 23:21
And that must be a typo because you can have native progressive BD <= 30 FPS eg.1080p24, 1080p23.976 , 720p24, 720p23.976
I meant that if fps >30, than only progressive scan can be used, and frame size can't be 1080.
lyinawake
5th May 2014, 18:06
Oh, that damn "tff=1"! Thank you very much folks. I think that's going to do it. Testing is pending but all of my videos were actually interlaced and I didn't even notice. That's what I get for copying someone else's switches without double-checking each one. Oy. I'll post back with the results. And I also changed my fps to 60000/1001 to be more exact.
And about x264.exe handling audio, I'm afraid you're talking over my head with the mention of "passing elementary streams", but if you have the patience, I would very much appreciate the education. All I know is that x264.exe will only touch my video, so the output is going to be a video stream. With FFMPEG, I can address audio and video in one command and the output is going to have video and audio streams, so that 1 file can go right in to Encore and get written to a Bluray. How would I go about doing the same with x264.exe to create a file with audio and video streams? It is a moot point if you guys have solved my ffmpeg issue (which I believe you have), but I'd like to figure out my way around all this stuff a little better.
Thank you!!
@lyinawake
You're going off topic ("Using ffmpeg..."). Please open a new thread for your new topic.
lyinawake
12th July 2014, 04:49
I've been trying and trying and thought I was on to something when it was pointed out I was using a flag that triggered interlacing in my output, but after fixing that issue there is still nothing that I can seem to do to get an output from ffmpeg to go into Encore without requiring transcoding. I am now working with elementary streams because Encore really hates taking anything that isn't elementary or that it can't transcode. I have also used Encore to transcode a file, found that resulting file, ran MediaInfo against it and compared my output. Nothing different other than MediaInfo sees my ReFrames @ 3 while the Encore transcode was @ 4. I've tried fiddling with various switches in the command but can't seem to get my ReFrames to read "4" though I hear around various forums that the ReFrame reading from MediaInfo is to be taken with a grain of salt due to the various ways there are to count the reference frames in a video.
My current theory is that Encore will not accept a video that isn't encoded using the MainConcept H.264 encoder. If that is the case then I am a sad panda. I'm hoping that someone on here can prove my theory incorrect.
@poisondeathray - You mentioned you were able to get this to work. Are you 100% positive that you were successful in getting 720p59.94 into Encore without it triggering a transcode? Would you be able to post your ffmpeg.exe or x264.exe command?
sneaker_ger
12th July 2014, 13:29
You can read about example x264.exe command-lines here:
http://www.x264bluray.com/home/720p-encoding (also apply --fps 60000/1001 to be sure)
Also read:
http://forum.doom9.org/showthread.php?t=154533
lyinawake
14th July 2014, 18:53
Thanks for the reply. I've tried the x264 encode instead of going through FFMPEG and Encore still doesn't want to take the video file in. It says it's untranscoded and wants to transcode it itself. Also am fairly well versed with the second article you posted, but I am suspecting it's not the switches I'm using.
Has anyone actually brought a supposedly blu-ray compliant file that was encoded with x264 and not had Encore squawk about it?
poisondeathray
14th July 2014, 19:07
Yes it works in encore . DVDA still has problems with x264 MBAFF, but both MBAFF and progressive variants work in Encore
When you look at "untranscoded" make sure you are looking at the blu-ray status, not the DVD status (I know it sounds stupid, but many people make this mistake)
lyinawake
14th July 2014, 23:38
Yup, I'm doing encore. Just redid an x264 transcode to elementary stream and it actually went into Encore this time (thanks @sneaker_ger for the tip to include the --fps flag), but it still says it's an untranscoded file when I apply the following commands to my 720p59.94 mp4 ~3minute file:
x264 --bitrate 8000 --preset veryslow --tune film --bluray-compat --fps 60000/1001 --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 60 --open-gop --slices 4 --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.mp4
x264 --bitrate 8000 --preset veryslow --tune film --bluray-compat --fps 60000/1001 --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 60 --open-gop --slices 4 --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 1 -o out.264 input.mp4
x264 --bitrate 8000 --preset veryslow --tune film --bluray-compat --fps 60000/1001 --vbv-maxrate 40000 --vbv-bufsize 30000 --level 4.1 --keyint 60 --open-gop --slices 4 --colorprim "bt709" --transfer "bt709" --colormatrix "bt709" --sar 1:1 --pass 2 -o out.264 input.mp4
@poisondeathray Thanks for confirming you're having success with x264. I have a love/hate relationship with the fact that this is working for you. I feel like I'm taking crazy pills, but on the other hand, you're giving me hope that this is possible. I am definitely looking at the Blu-ray columns. I'm only doing progressive (despite my first attempt where I was using an interlaced flag), so I SHOULD be having success.
I've also got threads on the Adobe forums trying to get their heads on this, but so far no responses. The forum members on there appear to be asking or providing guides for using something called x264pro or a standalone MainConcept encoder as a way to get files primed for Encore through command-line.
lyinawake
15th July 2014, 00:15
Alright... after looking closer at my output from x264.exe, I've found out that somehow, I got a 10-bit version of x264.exe. Blu-ray no likey 10-bit encodes. It's working... It's finally working...
Now, a minor annoyance, is that I'm not able to do this from ffmpeg, but I found output in x264.exe that may explain it:
resize [warning]: converting from yuv420p101e to yuv420p161e
Anyone know what's the 101e (from ffmpeg) vs 161e (from x264)? Googling either value results in 1 and 0 results in Google respectively. I mean, I have a way forward now, which I didn't before, so it's not a biggie, but while my hands are this dirty with the topic of "command-line generated blu-ray compliant files", I may was well learn the remaining 1% of what the heck is going on.
Thanks you guys. It's awesome to know you're out there putting effort into helping strangers on the internet.
sneaker_ger
15th July 2014, 00:31
That's a lower-case L, i.e. yuv420p10le and yuv420p16le.
le = little-endian
10 = 10 bit
16 = 16 bit (x264cli converts input to 16 bit before dithering in some cases)
poisondeathray
15th July 2014, 00:36
yuv420p101e is 10bit 4:2:0, little endian. Basically your source file is incompatible, needs to be converted to 4:2:0 8bit
Also, if you're using x264 directly instead of avs input, I would add --force-cfr .
Same with ffmpeg libx264 using -x264opts force-cfr, and -pix_fmt yuv420p to convert to 8bit 4:2:0
EDIT: too slow
foxyshadis
15th July 2014, 02:12
Won't work. libx264 can only be either 8-bit or 10-bit, you can't switch between them at runtime. You need an ffmpeg built with 8-bit libx264.
sneaker_ger
15th July 2014, 15:05
Also, if you're using x264 directly instead of avs input, I would add --force-cfr .
Note: --fps implies --force-cfr
lyinawake
15th July 2014, 21:00
Won't work. libx264 can only be either 8-bit or 10-bit, you can't switch between them at runtime. You need an ffmpeg built with 8-bit libx264.
Wellll... I guess the cross-compile script I've been using takes that liberty of throwing on a 10-bit libx264. I'll try to find where it makes that choice, recompile, and retry with ffmpeg. And I am using -pix_fmt yuv420p as you can see in my initial ffmpeg commands.
Yes, you definitely need the --fps switch for x264. This isn't mentioned in the x264 bluray guide. Don't know if --cfr would work just as well but I think explicitly setting 60000/1001 is a good practice. Just forgot it again and Encore complained that the fps needs to be between 1 and 60 to be imported into the blu-ray project. Oy. What a minefield.
sneaker_ger
15th July 2014, 21:35
Basically x264 needs the exact fps ("60000/1001") and it needs to set the cfr flag. Like poisondeathray implied x264cli will set it to "cfr" for AviSynth input automatically (since AviSynth is only cfr natively) but "vfr" for other - possibly vfr - sources like mp4 files. So if you use avs or a pipe as input and the fps already gets correctly recognized neither "--fps" nor "--force-cfr" would be necessary. You never need to set "--force-cfr" when you already use "--fps" (but it does not do any harm either). I agree that the examples should probably all use "--fps" to reduce user error. It isn't explicitly mentioned in the doom9 thread either.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.