Skip to content

Commit aa03e28

Browse files
author
Clement Champetier
committed
USAGE: added "API" and "Projects which uses avTranscoder" sections
1 parent 99188e2 commit aa03e28

File tree

1 file changed

+152
-22
lines changed

1 file changed

+152
-22
lines changed

USAGE.md

Lines changed: 152 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,124 @@
11
# How to use avTranscoder
22

3-
Check out applications contained in the project to see examples of how to use the library in C++, Java or Python.
3+
## When to use avTranscoder
4+
* when you need to access the API of ffmpeg, but you want to avoid the head-hurting part of AVPacket, AV_TIME_BASE and all the stuff deep inside ffmpeg.
5+
* when you would like to access the ffmpeg features in your language (currently Java and python, tomorrow what you want!).
46

5-
#### In C++
6-
Set environment:
7-
```
8-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/ffmpeg/lib:/path/to/avtranscoder/lib
9-
export PATH=$PATH:/path/to/avtranscoder/bin
10-
```
117

12-
#### In Java
13-
Add argument to the JVM:
14-
```
15-
-Djava.library.path=/path/to/avtranscoder/lib/java
8+
## API
9+
The original code is in C++, but almost all the methods are translated into python/java without any changes.
10+
So a good way to start is to have a look at the [C++ code](src/AvTranscoder) (since the generated python/java code is ugly).
11+
12+
In the sake of brevity, the example code of the following section is written in python.
13+
14+
#### At the beginning
15+
Before starting anything, you need to register all the codecs, formats, filters which are enabled at configuration time.
16+
So your first avTranscoder instruction should be:
17+
```python
18+
avtranscoder.preloadCodecsAndFormats()
1619
```
17-
Set environment:
20+
21+
#### Analyse media
22+
To analyse a media, you can create an [__InputFile__](src/AvTranscoder/file/InputFile.hpp) and have access to all header [__properties__](src/AvTranscoder/properties).
23+
```python
24+
# create InputFile
25+
inputFile = avtranscoder.InputFile("/path/to/media/file.mov")
26+
27+
# get access to properties
28+
properties = inputFile.getProperties()
29+
30+
# print all format properties
31+
for prop, value in properties.asVector():
32+
print(prop + ": " + str(value))
33+
34+
# print all properties of each stream
35+
for stream in properties.getStreamProperties():
36+
print("------ Properties of stream at index " + str(stream.getStreamIndex()) + " -----")
37+
for prop, value in stream.asVector():
38+
print(prop + ": " + str(value))
39+
40+
# write all media properties as JSON in a file
41+
import json
42+
with open('data.txt', 'w') as outfile:
43+
json.dump(properties.allPropertiesAsJson(), outfile)
1844
```
19-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/ffmpeg/lib
45+
46+
Some properties could have a value of _null_ because:
47+
* the property is not indicated in the media.
48+
* the property is not accessible in the header.
49+
50+
For the second point, you can launch a deeper analysis.
51+
This is the case if you would like to have access to the GOP structure of a video stream:
52+
```python
53+
# create InputFile
54+
inputFile = avtranscoder.InputFile("/path/to/media/file.mov")
55+
56+
# analyse first GOP (show progression in console)
57+
progress = avtranscoder.NoDisplayProgress()
58+
inputFile.analyse(progress, avtranscoder.eAnalyseLevelFirstGop)
59+
60+
# get access to properties
61+
properties = inputFile.getProperties()
62+
videoProperties = properties.getVideoProperties()[0]
63+
print videoProperties.getGopSize()
64+
print videoProperties.getGopStructure()
2065
```
2166

22-
#### In Python
23-
Set environment:
67+
Check out [__avmeta__](app/avMeta/avMeta.cpp) application to see a C++ example of this use case.
68+
69+
#### Process media
70+
An important part of the API concerns media processing. The general overview of the workflow could be separate in 2 main cases:
71+
* _transcoding_: demuxing, decoding, transform, encoding and muxing. Here we can update all parts of the media, from the container to the codec used to encode data.
72+
See the [transcoding process](https://ffmpeg.org/ffmpeg.html#toc-Detailed-description) in ffmpeg documentation.
73+
* _rewrap_: omit the decoding, transform and encoding steps. It is useful for changing the container format or modifying container-level metadata.
74+
See the [copy](https://ffmpeg.org/ffmpeg.html#Stream-copy) paramer in ffmpeg documentation.
75+
76+
The main class to process media is the [__Transcoder__](src/AvTranscoder/transcoder/Transcoder.hpp).
77+
78+
Here a rewrapping example to update container (from AVI to MOV):
79+
```python
80+
ouputFile = avtranscoder.OutputFile("/path/to/output/media.mov")
81+
transcoder = avtranscoder.Transcoder(ouputFile)
82+
transcoder.add("/path/to/input/media.avi")
83+
transcoder.process()
84+
```
85+
Check out [__pyrewrap__](app/pyRewrap/pyrewrap.py) application to see a python example of this use case.
86+
87+
Here a transcoding example to encode video and audio streams:
88+
```python
89+
ouputFile = avtranscoder.OutputFile("/path/to/output/media.mov")
90+
transcoder = avtranscoder.Transcoder(ouputFile)
91+
92+
# transcode a video stream at index 0 to H264 High Quality
93+
transcoder.add("/path/to/input/media.avi", 0, "h264-hq")
94+
# transcode an audio stream at index 1 to PCM 24bits 48kHz mono
95+
transcoder.add("/path/to/input/media.wav", 1, "wave24b48kmono")
96+
97+
# show the progression in console
98+
progress = avtranscoder.ConsoleProgress()
99+
transcoder.process(progress)
24100
```
25-
export PYTHONPATH=$PYTHONPATH:/path/to/avtranscoder/lib/python<version>/site-packages/
26-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/ffmpeg/lib
101+
Check out [__avprocessor__](app/avProcessor/avProcessor.cpp) application to see a C++ example of this use case.
102+
103+
An other important parameter is the transcoding policy, which defines how we manage the process in case of several streams. By default the process ends at the end of the longest stream (so the shorter streams are filled with silence or black images).
104+
To change the transcoding policy:
105+
```python
106+
# stop the process when the output stream at index 0 is finished
107+
transcoder.setProcessMethod(avtranscoder.eProcessMethodBasedOnStream, 0)
108+
109+
# stop the process when the output file has a duration of 50s
110+
transcoder.setProcessMethod(avtranscoder.eProcessMethodBasedOnDuration, 0, 50)
27111
```
28112

29-
#### Use profiles
113+
#### More on process: use profiles
30114
To wrap/unwrap/encode/decode, avTranscoder manipulates profiles.
31115
A profile is a set of key-value given as parameters to the InputFile(unwrap), the OutputFile(wrap), the Video/AudioDecoder(decode) or the Video/AudioEncoder(encode).
32116
There are two ways to manipulate profiles:
33117
* create profiles inside your code, by instanciate ```Map``` structures.
34-
* create profiles outside your code, by create text files.
118+
* create profiles outside your code, by create text files. You have examples [here](avprofiles).
119+
35120
To indicate the path to the text files, export environment variable:
36-
```
121+
```bash
37122
export AVPROFILES=/path/to/profiles
38123
```
39124

@@ -44,19 +129,64 @@ avProfileLongName=profileLongName
44129
avProfileType=avProfileTypeFormat
45130
format=formatName
46131
```
47-
48132
The minimum video profile (encode/decode) is:
49133
```
50134
avProfileName=profileName
51135
avProfileLongName=profileLongName
52136
avProfileType=avProfileTypeVideo
53137
codec=codecName
54138
```
55-
56139
The minimum audio profile (encode/decode) is:
57140
```
58141
avProfileName=profileName
59142
avProfileLongName=profileLongName
60143
avProfileType=avProfileTypeAudio
61144
codec=codecName
62145
```
146+
147+
To encode a video stream using your custom profile:
148+
```python
149+
ouputFile = avtranscoder.OutputFile("/path/to/output/media.mov")
150+
transcoder = avtranscoder.Transcoder(ouputFile)
151+
transcoder.add("/path/to/input/media.avi", 0, "profileName")
152+
transcoder.process()
153+
```
154+
155+
## Environment
156+
#### In C++
157+
Set environment:
158+
```bash
159+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/ffmpeg/lib:/path/to/avtranscoder/lib
160+
export PATH=$PATH:/path/to/avtranscoder/bin
161+
```
162+
163+
#### In Java
164+
Add argument to the JVM:
165+
```bash
166+
-Djava.library.path=/path/to/avtranscoder/lib/java
167+
```
168+
Set environment:
169+
```bash
170+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/ffmpeg/lib
171+
```
172+
173+
#### In Python
174+
Set environment:
175+
```bash
176+
export PYTHONPATH=$PYTHONPATH:/path/to/avtranscoder/lib/python<version>/site-packages/
177+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/ffmpeg/lib
178+
```
179+
180+
## Projects which uses avTranscoder
181+
#### TuttleOFX
182+
TuttleOFX is a library to connect and batch operations with OpenFx plugins. It comes with a set of plugins that allows you to batch process on movies and file sequences.
183+
TuttOFX uses avTranscoder for the [AudioVideo plugin](https://github.com/tuttleofx/TuttleOFX/tree/develop/plugins/image/io/AudioVideo), one of its io plugins.
184+
185+
#### PADdef / Slingshot
186+
PADdef is a platform developed by [Mikros Image](http://www.mikrosimage.eu/) for France Télévisions's new digital distribution centers. Its purpose is to handle the delivery of ready-to-broadcast feature material.
187+
Slingshot is its mirror project for Belgium broadcasters: Medialaan, RTBF and RTL.
188+
PADdef / Slingshot uses avTranscoder in one of its application to transcode media in post-production labs.
189+
190+
#### Ploud
191+
A set of applications developed by [Mikros Image](http://www.mikrosimage.eu/) to analyse, visualize and correct the loudness.
192+
PADdef / Slingshot uses avTranscoder in [one of its application](https://github.com/mikrosimage/loudness_validator/tree/develop/app/mediaAnalyser) to give decoded data to the loudness analyser.

0 commit comments

Comments
 (0)