Since the work on NihAV
is nearing the point when I can release it to public without that much shame (main features I wanted to implement are there and I’ve even documentation for all public interfaces plus some overview, you can’t ask for more than that) I want to give $title.
nihav-tool
This is the oldest tool oriented mostly to test decoders functionality. By default it will try to decode every stream in a file and output it either into a wave file or a sequence of images (PPM for RGB video, PGMYUV for YUV). Beside that it can also not decode a stream (and if you choose to decode neither then it tests demuxer or dumps raw frames).
Here is the list of switches it understands:
-noout
makes it decode data but not produce any output (good for testing decoding process if you don’t currently care about decoder output);-an/-vn
makes it ignore audio or video streams correspondingly;-nm=count/pktpts/frmpts
makenihav-tool
write frame numbers as a sequence or using PTS from input packet or decoded frame correspondingly;-skip=key/inter
tells video codec (if it is willing to listen) to skip less significant frames and decode only keyframes or intra- and interframes but no B-frames;-seek time
tells the tool to seek to the given position before decoding;-apfx/-vpfx prefix
specify the prefix for output filename(s) which comes useful when decoding files in a batch;-ignerr
tellsnihav-tool
to keep decoding ignoring errors the decoders report;-dumpfrm
tellsnihav-tool
to dump raw frames. This is both useful for obtaining raw audio frames (I could not makeavconv
do that) and because of the way it is implemented (it dumps packet contents first and then tries to decode it) if you use it along with the decoder and it errors out you’ll have raw frame on which it errored out.
Additionally you can specify end time after giving input name if you don’t need to decode the whole file.
As you can see this is not the most feature-rich tool but it works good enough for the declared goal (hence I use it mostly a debug build of it).
nihav-player
This is another quick and dirty tool that appeared when I decided that looking at long sequences of images is not the best way to ensure that decoding goes right. So I wrote something that can pass in a bad light for a player since it can show moving pictures and play sound that sometimes even goes in sync instead of deadlocking audio playback thread.
Currently it’s written using patched SDL1 crate (removing dependencies on num
and rand
and adding YUV overlay support and audio interface that you can actually use from Rust; patches will be available in the same repository) because my primary development system is too old and I don’t want to mess with various libraries or finding which version of sdl2
crate would compile using my current version of Rust (1.31 or 1.33.
In either case it’s a temporary solution used mostly for visual debugging and I want to write a proper media player based on SDL2 that would play audio-only files just as fine (so I can move to dogfooding). After all, can you really call yourself a multimedia developer if haven’t written a single player?
nihav-encoder
And finally the tool that appeared out of need to debug encoders instead of decoders. Hopefully it will become more useful than that one day but at least its interface should give you the idea what it does and what it will do in the future.
I still consider one of the main problems with ffmpeg
(the tool) and later avconv
the positional order of arguments. Except when the order does not matter. If you’ve never been annoyed by the fact you should put some arguments before -i infile
in order for them to take effect on input and the rest of arguments should be put before output file name—well, in this case you’re luckier than me. So I’ve decided to have it in a more free-form format.
nihav-encoder
command line looks a list of options in no particular order and some of them take complex arguments and then you provide a comma-separated list in form --options-list option1,option2=value,option3=...
. Here is the list of recognised options:
--list-{decoders,encoders,demuxers,muxers}
obviously lists the corresponding category and quits after listing all requested lists and options (see the next item);--query-{decoder,encoder,demuxer,muxer}-options name
prints the list of options supported by the corresponding codec or (de)muxer. Of course you can request options for several different things to be listed by adding this option several times;--input inputfile
and--output outputfile
;--input-format format
and--output-format format
force (de)muxer to use the provided format when autodetection fails;--demuxer-options options
takes a comma-separated list of options for demuxer (BTW you can also force input format with e.g.--demuxer-options format=avi
);--muxer-options options
takes a comma-separated list of options for muxer (BTW you can also force output format with e.g.--muxer-options format=avi
);--no-audio
and--no-video
tellnihav-encoder
to ignore all audio or video streams correspondingly;--start time
and--end time
tellnihav-encoder
to start decoding at given time and end at given time. The times are absolute so--start 1:10:00 --end 1:11:00
will process just a second of data;--istreamX options
and--ostreamX options
set options for input and output streams with given numbers (starting with zero of course). More about them below.
nihav-encoder
has two modes of operation: query mode, in which you specify which e.g. demuxers or codec options you want listed, and the program quits after listing them; and transcode mode, in which you specify input and output file and what you want to do with them. Maybe I’ll add a probe mode but I’ve never cared much about it before.
So what happens when you specify input and output? nihav-encoder
will try to see which streams can be output (e.g. when transcoding from AVI to WAV there’s no point to even attempt to do anything with video stream), then it will try to copy input streams to the output unless anything else is specified. Of course you can specify that you want to discard some input stream with e.g. --istream0 drop
. And for output streams you can also specify encoder and its parameters. For example my command line for testing Cinepak encoding looks like this:
./nihav-encoder –input laser05.avi –output cinepak.avi –no-audio –ostream0 encoder=cinepak,quant_mode=mediancut,nstrips=4
It takes input file laser05.avi
, discards audio stream, encodes remaining video stream with Cinepak encoder that has options quant_mode
and nstrips
set explicitly, and writes the result to cinepak.avi
.
As you can see, this tool has enough features to serve as a daily base transcoder but no complex features like taking input from several files, arbitrary mapping input streams from them to output streams and maybe applying some effects while at it. In my opinion that’s the task for some more complex application that builds a complex processing graph probably using a domain-specific language to specify inputs and outputs and what to do with them (and it should be a proper command file instead of command line that is impossible to type correctly even from the eighth try). Since I never had interest in GStreamer
I’m definitely not going even to play with that. But a simple transcoder should serve my needs just fine.