Class Converter
- java.lang.Object
-
- com.avpkit.core.Converter
-
public class Converter extends java.lang.Object
An example class that shows how to use the AVPKit library to open, decode, re-sample, encode and write media files.This class is called by the
AVPKitclass to do all the heavy lifting. It is meant as a Demonstration class and implements a small subset of the functionality that the (much more full-featured)ffmpegcommand line tool implements. It is really meant to show people how the AVPKit library is used from java.Read the Converter.java source for a good example of a class exercising this library.
It is not our intent to replicate all features in the
ffmpegcommand line tool in this class.If you are just trying to convert pre-existing media files from one format to another with a batch-processing program we strongly recommend you use the
ffmpegcommand-line tool to do it. Look, here's even the documentation for that program.If on the other hand you need to programatically decide when and how you do video processing, or process only parts of files, or do transcoding live within a Java server without calling out to another process, then by all means use AVPKit and use this class as an example of how to do conversion. But please recognize you will likely need to implement code specific to your application. This class is no substitute for actually understanding the how to use the AVPKit API within your specific use-case
And if you haven't gotten the impression, please stop asking us to support
ffmpegoptions like "-re" in this class. This class is only meant as a teaching-aide for the underlying AVPKit API.Instead implement your own Java class based off of this that does real-time playback yourself. Really. Please. We'd appreciate it very much.
Now, all that said, here's how to create a main class that uses this Converter class:
public static void main(String[] args) { Converter converter = new Converter(); try { // first define options Options options = converter.defineOptions(); // And then parse them. CommandLine cmdLine = converter.parseOptions(options, args); // Finally, run the converter. converter.run(cmdLine); } catch (Exception exception) { System.err.printf("Error: %s\n", exception.getMessage()); } }Pass "--help" to your main class as the argument to see the list of accepted options.
- Author:
- aclarke
-
-
Constructor Summary
Constructors Constructor Description Converter()Create a new Converter object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected IAudioSamplesalterAudioFrame(IAudioSamples audioFrame)Allow child class to override this method to alter the audio frame before it is rencoded and written.protected IVideoPicturealterVideoFrame(IVideoPicture videoFrame)Allow child class to override this method to alter the video frame before it is rencoded and written.org.apache.commons.cli.OptionsdefineOptions()Define all the command line options this program can take.static voidmain(java.lang.String[] args)A simple test of core, this program takes an input file, and outputs it as an output file.org.apache.commons.cli.CommandLineparseOptions(org.apache.commons.cli.Options opt, java.lang.String[] args)Given a set of arguments passed into this object, return back a parsed command line.voidrun(org.apache.commons.cli.CommandLine cmdLine)Takes a given command line and decodes the input file, and encodes with new parameters to the output file.
-
-
-
Constructor Detail
-
Converter
public Converter()
Create a new Converter object.
-
-
Method Detail
-
defineOptions
public org.apache.commons.cli.Options defineOptions()
Define all the command line options this program can take.- Returns:
- The set of accepted options.
-
parseOptions
public org.apache.commons.cli.CommandLine parseOptions(org.apache.commons.cli.Options opt, java.lang.String[] args) throws org.apache.commons.cli.ParseException
Given a set of arguments passed into this object, return back a parsed command line.- Parameters:
opt- A set of options as defined bydefineOptions().args- A set of command line arguments passed into this class.- Returns:
- A parsed command line.
- Throws:
org.apache.commons.cli.ParseException- If there is an error in the command line.
-
alterAudioFrame
protected IAudioSamples alterAudioFrame(IAudioSamples audioFrame)
Allow child class to override this method to alter the audio frame before it is rencoded and written. In this implementation the audio frame is passed through unmodified.- Parameters:
audioFrame- the source audio frame to be modified- Returns:
- the modified audio frame
-
alterVideoFrame
protected IVideoPicture alterVideoFrame(IVideoPicture videoFrame)
Allow child class to override this method to alter the video frame before it is rencoded and written. In this implementation the video frame is passed through unmodified.- Parameters:
videoFrame- the source video frame to be modified- Returns:
- the modified video frame
-
run
public void run(org.apache.commons.cli.CommandLine cmdLine)
Takes a given command line and decodes the input file, and encodes with new parameters to the output file.- Parameters:
cmdLine- A command line returned fromparseOptions(Options, String[]).
-
main
public static void main(java.lang.String[] args)
A simple test of core, this program takes an input file, and outputs it as an output file.- Parameters:
args- The command line args passed to this program.
-
-