View Full Version : x264 + ffmpeg + MythTV
Quantumstate
22nd March 2009, 20:09
I've been looking for a high-quality way to transcode ATSC mpeg2 to H.264 for some months now, without success. I've found scripts, which invariably are buggy or have some other problem, and I've tried composing commands, but just nothing's worked out so far.
I'd like to avoid mencoder as I believe that is dying out; ffmpeg is preferred.
I'd like to encode 720p and 1080i to BluRay compatible format as automatically as possible, with audio passthrough (undecoded), and stored maybe in mkv. I realize that mkv is not BluRay, but it seems to be the most advanced container, and I guess it would be a quick job to translate it to BluRay. My archival storage is hard disk.
Myth can accept a long command in a User Job, or I can integrate a script. If anyone has suggestions I'd like to see them.
You need mkvmerge, x264 and some tool that decodes the input video and feeds it to x264. Both MPlayer (or MEncoder) and ffmpeg should work equally well for decoding but MPlayer has a set of filters that ffmpeg still lacks. Both MPlayer and ffmpeg are active and well maintained projects and MEncoder is not going anywhere until the functionality is moved to FFmpeg's libswscale and libavfilter. At that point it should be trivial to swap from MEncoder to ffmpeg or whatever frontend we will be using.
MEncoder + libx264 is perhaps the easiest scriptable solution. Output raw H.264 stream (-of rawvideo -o output.264) and mux the resulting video with mkvmerge along with audio from the original file.
If you don't want to use MPlayer and MEncoder and you don't need filters, decode the video with ffmpeg and pipe a yuv4mpeg stream to x264 (through a FIFO file with .y4m as suffix).
Other tips:
- Avoid using libx264 through ffmpeg if you can. Some x264 settings can't be set through ffmpeg's command-line interface. MEncoder's -x264encopts is parsed by libx264, so it is nicer.
- If you need to filter the video (deinterlace, deblock, denoise, ...), use either MPlayer/MEncoder or AviSynth+Avs2YUV with Wine.
- There is no automatic solution to get optimal results from both 30i and 30p source videos. NTSC and ATSC are especially difficult because sometimes you need to deinterlace and sometimes IVTC. 720p60 may require decimating duplicate frames. Then there may be hybrid interlaced / progressive (telecined) content that should be encoded as VFR video. The easiest solution is to encode the video as it is: 1080i as interlaced and 720p60 without decimating frames. You lose some disk space and you still need to filter 1080i during playback, but difficult sources don't get so badly broken as they probably would with more complex automatic filtering.
Quantumstate
23rd March 2009, 15:07
Thanks, but you are way over my head. About all I got was that mencoder is still a good solution.
:script:
Quantumstate
24th March 2009, 15:14
Can anyone give a resource I can study?
Ok, maybe it would be best to start experimenting with tools that have a graphical interface and perhaps later write scripts that do the same thing. Try Handbrake and Avidemux first. Both are powerful tools that have the necessary filters for deinterlacing and IVTC. They also have lots of good documentation in their Wikis.
Handbrake has a very nice command-line interface in addition to the GUI. Avidemux also has some support for command-line usage, but it is not as friendly as Handbrake.
Quantumstate
24th March 2009, 18:03
OK, I'll study handbrake.
I am surprised that there hasn't been derived by now a few standard scripts which do widely-needed functions like I am asking. I am a real estate manager and am not a video expert, but I guess I have to learn to be one and make New Science.
Edit: Handbrake doesn't give the final command-line it's composed, so I guess this is no help in setting up a Myth job. Thanks anyway.
I am surprised that there hasn't been derived by now a few standard scripts which do widely-needed functions like I am asking. I am a real estate manager and am not a video expert, but I guess I have to learn to be one and make New Science.
Properly handling all the different types of video expected in NTSC/ATSC broadcasts is a difficult problem. It would require writing or porting interlace/telecine detection filters and doing lots of experimenting. Another problem is the variety of outputs that people need.
Writing such a script or tool is certainly achievable up to some point and it would be an interesting project. Froggy1's h264enc and xvidenc are impressive scripts that take a few steps to this direction, but they are interactive in nature.
Edit: Handbrake doesn't give the final command-line it's composed, so I guess this is no help in setting up a Myth job. Thanks anyway.
The command-line is well documented (http://trac.handbrake.fr/wiki/CLIGuide) too and you can easily find out what options match the GUI elements.
Quantumstate
24th March 2009, 19:16
Sure, but it would take weeks of experimentation to come up with that mix of parameters to do a convert from ATSC 720p and 1080i to BluRay compatible mkv at the lowest bitrate and all the millions of other options, while retaining quality for the smallest file size. I'll be starting from scratch...
Reinventing the wheel.
I just can't believe that there aren't some standard stock answers by now, but there don't seem to be, or else everyone is keeping secrets.
Esurnir
24th March 2009, 22:43
Sure, but it would take weeks of experimentation to come up with that mix of parameters to do a convert from ATSC 720p and 1080i to BluRay compatible .264
Fixed ^^;
Unless you mean a file playable "easely" from blu-ray. But if you meaned readable in a blu-ray player, that's not the same thing.
Unless you mean a file playable "easely" from blu-ray. But if you meaned readable in a blu-ray player, that's not the same thing.
He acknowledged this in the first post.
Esurnir
25th March 2009, 00:01
Reading quickly ftl. You might want to create .264 elementary stream instead of mkv, they would tend to destroy the --aud delimiter. (if not the --nal-hrd though for that one I got no clue).
Quantumstate
25th March 2009, 06:03
'Elementary stream'? But would that include the audio?
Only reason I say mkv is it seems to be the most advanced container. Reason I say BluRay compatible is I believe this has the best chance of long-term compatibility, for archiving purposes. Main storage method is hard disk, but occasionally may burn to BluRay.
My goal is to transcode the video to h.264 and pass-thru the audio, whether 5.1 or stereo, although if ATSC audio is not BluRay compatible I can transcode that.
There are a thousand video settings though, and it's impossible to review the minutiae of each. I just can't believe there's no consensus setup. I wish I had time to analyze the settings and devise a script, but I must make a living.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.