MEncoder Video Conversion AppleScript Droplets

smile

Use these Applets to convert video files of various formats to iPod 5G compatible files, iPod Touch/iPhone compatible files, or MPEG-2 files for creating video DVDs.


IMPORTANT NOTE: The purpose of these AppleScript applets is to provide output with quality high enough for TV playback - the highest quality compatible output for the target device (iPod, iPhone, or DVD). If you just want to get your video onto the iPod or iPhone, you may want to simply consider using HandBrake instead.


Laine Lee

llee040@sbcglobal.net


What's new?


All droplets accepting exports from EyeTV recordings from the Hauppauge HD-PVR now accept the H.264 single muxed (multiplexed) audio and video file format available from the export formats pop-up menu in EyeTV rather than separate audio and video file pairs exported using the MPEG Elementary Streams export option.


Hauppauge 720p Roku or iTunes muxed (AAC) to mpeg-2 video 16X9.app and Hauppauge 720p Roku or iTunes muxed (AC3) to mpeg-2 video 16X9.app have been added to the group of apps that convert captured and exported EyeTV recordings to mpeg-2 format for authoring DVD video. These droplets provide compatibility for conversion of 720p sources such as the output of the ROKU XDS or iTunes movies captured from iPhone through the Apple Component Video Adapter.


Hauppauge 720p Roku or iTunes muxed to iPad video 16X9.app has been added to the group of apps that convert captured and exported EyeTV recordings for playback on the iPad (also compatible with iPhone 4). This droplet provides compatibility with 720p sources such as the output of the ROKU XDS or iTunes movies captured from an iPhone through the Apple Component Video Adapter.


Mpeg-2 Audio Offset internal or external audio telecine.app and Mpeg-2 Audio Offset re-encode 16X9 telecine.app have been added to provide a soft telecining option for mpeg-2 output for greater compliance and compatibility when authoring DVD video (see "Note about soft telecining" below).


Two droplets have been included in the group of apps for Fixing Sync and Other Problems for MPEG-2 Output that provide re-encoding to reduce file size, one which adds soft telecining and one which doesn't (see "Note about soft telecining" below).


Requirements


Snow Leopard (Mac OS X 10.6.x) or higher

Recent builds of x264, ffmpeg, yasm, MPlayer (includes MEncoder), and FAAC. Building these requires that Developer Tools (http://developer.apple.com/mac/) be installed.


Instructions for building and installing the required open source packages can be found at:

https://sites.google.com/site/llee040/Home/hdtv_to_dvd/


How the applets work


When you drop one or more video source files on one of the AppleScript application's icons, the applet will create a shell command file and execute it in the Terminal. The shell command file runs in the Terminal to perform the video conversion so that progress can be monitored. When the encoding process has finished, the shell command file will be moved to the Trash so you can remove and examine it, if desired, to see precisely what tasks were performed. The converted video files are created in the same location as the dropped files. Although multiple files may be dropped for encoding, please keep in mind that encoding can take time, so it may not be practical to drop many at once.


Why are there so many AppleScripts?


It's my observation that most people, including me, need only a few conversion methods to meet their particular needs. I prefer to find the most complete and correct solutions by choosing from among several options rather than learning how to make a single feature-laden application work, an occupation that increases my risk of having wasted time should I discover that the application can't do what I wanted anyway.


How to use the applets


The basic usage of the applet is to make sure the source video file(s) exist on a writable volume having enough available free space to allow production of the converted file(s), drop the source video file(s) onto the appropriate AppleScript application, and wait for the converted file(s) to be completely created in the same directory that contains the dropped source video file. Yes, you may drop multiple files at once on an application's icon provided you have enough time and free disk space on the dropped files' containing volume for the conversions to be completed.


To determine the appropriate conversion methods for your videos and devices, refer to the following device compatibility table.


Device Category Name               Compatibility

iPod 5G                                        5th generation iPod with video

iPod Touch                                   iPod Touch Generations 1-3, iPhone through the 3GS model

iPad                                              iPad, iPhone 4, iPod Touch 4th Generation


I haven't checked compatibility for iOS devices not listed here (iPod Nano models, for example).


Each application falls into one of several categories. The names of the individual AppleScript applications help to identify their individual functions. Here are further explanations about the categories (which correspond to folders into which the AppleScript applications have been placed), and explanations for what the various video conversion and production applications do. Use the device compatibility table above to determine which of the scripts is needed to output video that will be compatible with your device.



Common video sources to iOS device


These scripts can be useful for converting various source video formats, limited mainly by what the open source MPlayer and MEncoder applications on which they rely can decode, into video files that can be added to iTunes for delivery to the various Apple video devices with which that application is compatible. These applications were designed to accomplish conversion of YouTube or other generic types of downloaded videos into formats playable on your iOS devices.



m2ts to iOS Devices


If you backup your Blu-ray discs using a third party Blu-ray drive (at the time of this writing, Apple doesn't include any Blu-ray drives in the Macintosh) and MakeMKV, you can drag the m2ts files created by MakeMKV to the icons of these applications to make the conversions for the various devices indicated by the application names. It is probably noteworthy that the name extension .mkv attached to files created and named that way by MakeMKV can be changed to .m2ts for use with the applications.



m2ts to mpeg-2


These convert MakeMKV output to MPEG-2 files that can be authored to DVD video using various methods. I recommend using SmallDVD 2 (http://www.smallsoftware.co.uk/downloads/) or Toast. It should be noted that the output requires no further conversion for compatibility with most DVD players, so the re-encoding option in SmallDVD should be turned off. See "Note about soft telecining" below.



Native HD-PVR EyeTV export to mpeg-2 single pass


The applications in these folders can be used to create MPEG-2 (DVD) versions of EyeTV 3 recordings made using the Hauppauge HD-PVR. Recordings must be captured using the component video input with S/PDIF audio input settings for 1080i video sources or component video input with either S/PDIF or stereo RCA cables configured for 720p sources (such as content from the ROKU XDS or iTunes Store content captured from iPhone through the Apple Component Video Adapter). To create a file that can be dropped onto these applets, export the recording to  a single .mp4 video using the H.264 export format preset in EyeTV 3.  If the duration of the source video approaches 2 hours, a dual layer DVD disc with the capacity of 8.5 gigabytes may be required to author to DVD video disc from the output (See "Fixing Sync and Other Problems for MPEG-2 Output" below). Hauppauge 720p Roku or iTunes muxed (AAC) to mpeg-2 video 16X9.app, Hauppauge 720p Roku or iTunes muxed (AAC) to mpeg-2 video 2.35X1.app, Hauppauge 720p Roku or iTunes muxed (AC3) to mpeg-2 video 16X9.app, and Hauppauge 720p Roku or iTunes muxed (AC3) to mpeg-2 video 2.35X1.app have been added to the group. These droplets provide compatibility for conversion of 720p sources such as the output of the ROKU XDS or iTunes movies captured from iPhone through the Apple Component Video Adapter.



Native HD-PVR EyeTV export to mpeg-2 multipass


These applications have the same function and usage as those in the Native HD-PVR EyeTV export to mpeg-2 single pass folder with the exception that the processing options include 2-pass encoding which may or may not yield higher quality output.



Native HD-PVR EyeTV h.264 export iOS devices


Make high quality iPod, iPhone, and iPad compatible versions of EyeTV 3 recordings made using the Hauppauge HD-PVR. The recordings should be captured using the 1080i component video with S/PDIF audio input settings configured for the HD-PVR. Recordings captured using RCA audio inputs should be compatible also. To create a file that can be dropped onto these applets, export the recording to .mp4 file containing both the audio and video components of the source media using the H.264 export format preset in EyeTV 3. Hauppauge 720p Roku or iTunes muxed to iPad video 16X9.app and Hauppauge 720P Roku or iTunes muxed to iPad video 2.35X1.app have been added to this group of apps. This droplet provides compatibility with 720p sources such as the output of the ROKU XDS or iTunes movies captured from an iPhone through the Apple Component Video Adapter.



Fixing Sync and Other Problems for MPEG-2 Output

(Changing audio duration requires installation of SoX - see https://sites.google.com/site/llee040/Home/hdtv_to_dvd/, also MPlayerX or MPlayer OSX Extended, and optionally MPEG Streamclip)


If files you've converted to MPEG-2 have synch problems, you may wish to use the applications in this folder to fix them. If the audio is out of sync with the video by the same amount at both the beginning and at end of the video, you may be able to fix it just by remultiplexing (remuxing) audio and video using the Mpeg-2 Audio Offset same or external audio application included in this folder. Just drag the .mpg file onto the application's icon and enter the appropriate information including the value for offset, which can be determined using the instructions included below. The process is pretty quick, so if you don't get it right the first time, it's probably worth the trouble to try again, this time entering a different offset value. The reason that "same or external audio" is included in the application's name is that not only can you remux the audio and video components of the existing .mpg file, you can alternatively choose to replace the audio in the existing .mpg file with audio from a separate .ac3 file, the duration of which you have presumably already adjusted using another application in this folder, Drop audio media duration changer 448k. 


You may wish to either re-encode to reduce file size so the output can fit available DVD media, or remux to add soft telecining, or apply combinations of these conversions in your workflow. The other applications in this folder provide methods for doing so.


Note about soft telecining: You may want to use Toast or SmallDVD 2 to author DVDs from the mpeg-2 output of applications in this package. Mpeg-2 Audio Offset internal or external audio telecine.app, and Mpeg-2 Audio Offset re-encode 16X9 telecine.app provide soft telecining, which results in standards compliant output for NTSC DVD video. Because of that, if you use Toast with the "Never re-encode" option selected in the encoding preferences for your DVD project, you gain the ability to add Toast scene and chapter menus without having to be restricted to Toast's output frame rate and data rate for the DVDs it makes. Although Toast allows some flexibility for data rates, it always converts the video frame rate of video that it encodes so that its output has a frame rate of 30 FPS, thereby reducing quality for video that was originally produced at 24 FPS. The telecining applications included in the Fixing Sync and Other Problems for MPEG-2 Output folder provide compliant video source files that won't be subjected to this loss in quality by avoiding Toast's re-encoding in order to make standards compliant DVDs. The telecining process that has been provided in this package is only available through use of applications in the "Fixing Sync and Other Problems for MPEG-2 Output" folder, so if you want telecined output, one of the applications that apply it must be used after the conversion, creating a new telecined version of the output stream, whether or not any other adjustments to sync or file size are needed.



Below you'll find most of the information you need to be able to successfully complete the process. Information is also available at https://sites.google.com/site/llee040/Home/hdtv_to_dvd/.


How to fix sync by adjusting duration as well as offset


If you've recorded 1080i content through component video and S/PDIF optical audio cable connections (resulting in AC3 audio output), you may occasionally discover that correct A/V sync may not be maintained from start to finish after the conversion. I haven't encountered such a problem when recording AAC audio sources, so no duration change application for AAC audio has been included in this package.


If the A/V sync offset amount at the beginning of the video differs from that at the end, then the audio duration must be adjusted.


The first step needed to fix sync problems after the encoding process has been completed is to demux the finished .mpg file using MPEG Streamclip. Just drag the .mpg file produced by the HD-PVR to DVD workflow into the MPEG Streamclip window and choose Demux to AC3 from the File > Demux menu, then choose a location for the extracted audio file when prompted. You should choose a location with at least twice as much space as needed for the muxed video (".mpg") file, because when you specify the adjusted file when remixing using the "Mpeg-2 Audio Offset internal or external audio" droplet, it will also place its output .mpg file in the same location. 


There’s a splendid method built into ffmpeg and SoX through which a tempo adjustment can be applied to an audio file in order to shorten the duration of the .ac3 audio to match that of the video with a high degree of accuracy and quality. (Audio is so rarely shorter in duration that video after this kind of conversion that we can safely assume that that won't happen, and as improvements are made to the EyeTV and Hauppauge HD-PVR software, the need to adjust duration is likely to become decreasingly frequent.) Using the included Mpeg-2 Audio Offset same or external audio application in combination with MPlayer OSX Extended, you can apply this amazing adjustment with surprisingly little effort.


You simply need to adjust the duration of the .ac3 file using Drop audio media duration changer 448k, and remux using either of the two Mpeg-2 Audio Offset same or external audio applications, depending on whether or not you wish to apply soft telecining, this time choosing the external .ac3 file with corrected duration to provide for correct a/v sync.


Before using Drop audio media duration changer on your .ac3 file, it will be necessary to determine the tempo adjustment factor that you'll be prompted to enter when you run it. If you’ve already taken steps to synchronize audio and video at the beginning of the movie, then all you have to do is determine the amount of offset needed to fix sync near the end of the movie and just supply that value when prompted when you use Mpeg-2 Audio Offset same or external audio. If not, you’ll just need to add or subtract that value from the value needed to correct sync as near to the end of the movie as possible. Here’s an example. I have converted a long movie that I suspect will require that I slightly increase the tempo (shorten the duration) of the audio in order to maintain A/V sync. I’ll play the encoded .mpg file using MPlayer OSX Extended, noting the value in milliseconds required to move the audio earlier so that synchronization is maintained. Our encoding process may shorten video with respect to audio, practically never the other way around, so the likelihood of having negative values for this factor is almost negligible. For this example, we’ll say that near the end of the video in MPlayer OSX Extended I had to press the plus key (for MPlayerX, this is accomplished using "

⌥["

) 9 times, which had the effect of pushing the audio forward with respect to video by 900 milliseconds, nine tenths of a second (this is a typical value for a 110-minute movie converted using our process). If the A/V sync was correct at the start, then my audio needs to be sped up so that it will end about 900 milliseconds sooner. If I also have a discrepancy in sync at the start of the movie, I have to take that into account and change the audio duration adjustment factor accordingly. For the sake of argument in this example, we’ll say that the audio for the movie remains about 200 milliseconds behind the video at the start. When I take into account that I’ll need to move the entire audio ahead in the amount of 200 milliseconds after I’ve adjusted the duration of the audio, that means that my audio file is actually only 700 milliseconds (.7 seconds) too long. If the audio had been ahead of the video by 200 milliseconds at the beginning, then the adjustment factor would have been 1100 milliseconds. Early audio at the beginning of the movie means that the value of my duration adjustment will be higher than the perceived needed offset at the end of the movie, while late audio at the beginning of the movie indicates that that value is a lower number.


After I’ve calculated the duration adjustment factor (in our case 700), I’ll drop the .ac3 file that I already created onto the icon of “Drop audio media duration changer”. I’ll be prompted to enter that adjustment value in milliseconds, so I'll enter 700, and then the terminal will open and the .ac3 file will be shortened by the factor that I entered. The output file will have a name like “my_file_adjusted.ac3” and will be placed in the same location as the dropped .ac3 file.


Now I want to be sure that the original .mpg file is named appropriately so that when I drop it onto the icon of Mpeg-2 Audio Offset same or external audio and choose the external file option, the audio in the “my_file_adjusted.ac3”, the duration of which I've just fixed, will replace the original audio in the application's output. All I need to do is add "_adjusted" to the .mpg file's name just before the ".mpg" file name extension. Then I can drop “my_file_adjusted.mpg” onto the icon of Mpeg-2 Audio Offset same or external audio, specify the offset amount when prompted, ("0" if no offset is needed to maintain sync), and wait for the sync-repaired .mpg file to be created by the application in the same location as the two source files.


See the documentation at https://sites.google.com/site/llee040/Home/hdtv_to_dvd/ for information about building and installing the open source software components that power the included applications.



Laine Lee


Č
ċ
MEncoder_AopleScrpt_Video_Conversion.dmg
(1319k)
Laine Lee,
Sep 19, 2011, 8:53 AM
Comments