Skip to content
This repository was archived by the owner on Mar 25, 2019. It is now read-only.

Commit 100b50d

Browse files
author
Sjoerd Tieleman
committed
Updated README, added segmenting-only job.
1 parent 38b6090 commit 100b50d

2 files changed

Lines changed: 42 additions & 20 deletions

File tree

README.markdown

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,23 +165,17 @@ The `thumbnail_options` object is optional and contains a set of thumbnails that
165165

166166
If you specify thumbnails but an error occurs during generation, your job will be marked as failed. If you don't specify a valid `seconds` or `percentages` option thumbnail generation will be skipped but the job can still be completed successfully.
167167

168-
The `segments_options` object is optional and contains segment time (duration) in seconds.
169-
Segmented videos are used in [HLS](https://en.wikipedia.org/wiki/HTTP_Live_Streaming).
170-
These options applied to encoded video, thus `encoder_options` are required.
171-
Moreover `encoder_options` should prepare video for segmenting, because bitstream
172-
filter [h264_mp4toannexb](https://www.ffmpeg.org/ffmpeg-bitstream-filters.html#h264_005fmp4toannexb) will be applied to the video.
168+
The `segments_options` object is optional and contains segment time (duration) in seconds. Segmented videos are used in [HLS](https://en.wikipedia.org/wiki/HTTP_Live_Streaming). These options are applied to the encoded video, thus `encoder_options` are required. Moreover `encoder_options` should prepare video for segmenting, because bitstream
169+
filter [h264_mp4toannexb](https://www.ffmpeg.org/ffmpeg-bitstream-filters.html#h264_005fmp4toannexb) will be applied to the video. Therefore it is recommended to transcode to an MP4 file before segmenting.
173170

174171
The segmenting command looks like:
175-
```
176-
ffmpeg -i /tmp/46ee0a404a4b75d85c09d98a7c6b403579ee9f99.mp4 -codec copy -map 0 \
177-
-f segment -vbsf h264_mp4toannexb -flags -global_header -segment_format mpegts \
178-
-segment_list /path/to/dest_file_dir/dest_file_name.m3u8 -segment_time 10 \
179-
/path/to/dest_file_dir/dest_file_name-%06d.ts
180-
```
181-
182-
"46ee0a404a4b75d85c09d98a7c6b403579ee9f99.mp4" is a temporary encoded file which is not moved to destination folder yet.
183172

173+
ffmpeg -i /tmp/46ee0a404a4b75d85c09d98a7c6b403579ee9f99.mp4 -codec copy -map 0 \
174+
-f segment -vbsf h264_mp4toannexb -flags -global_header -segment_format mpegts \
175+
-segment_list /path/to/dest_file_dir/dest_file_name.m3u8 -segment_time 10 \
176+
/path/to/dest_file_dir/dest_file_name-%06d.ts
184177

178+
`46ee0a404a4b75d85c09d98a7c6b403579ee9f99.mp4` is a temporary encoded file (generated by Codem). After transcoding and segmenting you end up with the transcoded file, as well as the segments/playlist.
185179

186180
### Thumbnail-only job
187181

@@ -284,15 +278,14 @@ Thumbnail-only job (160x90 in PNG format every 10% of the video).
284278

285279
Segmenting job.
286280

287-
# curl -d '{"source_file": "/tmp/video.mp4", "destination_file": "/tmp/output/test.mp4", "encoder_options": "-vb 2000k -minrate 2000k -maxrate 2000k -bufsize 2000k -vf scale=min'(iw,1280)':-1 -s 1280x720 -acodec libfdk_aac -ab 192000 -ar 44100 -ac 2 -vcodec libx264 -movflags faststart -sn -r 29.97 -threads 0", "segments_options": {"segment_time": 10} }' http://localhost:8080/jobs
281+
# curl -d '{"source_file": "/tmp/video.mp4", "destination_file": "/tmp/output/test.mp4", "encoder_options": "-vb 2000k -minrate 2000k -maxrate 2000k -bufsize 2000k -s 1280x720 -acodec aac -strict -2 -ab 192000 -ar 44100 -ac 2 -vcodec libx264 -movflags faststart", "segments_options": {"segment_time": 10} }' http://localhost:8080/jobs
288282

289283
Output: {"message":"The transcoder accepted your job.","job_id":"7dc3c268783d7f3c737f3a134ccf1d4f15bb8442"}
290284

291285
Status of finished job:
292286

293287
# curl http://localhost:8080/jobs/7dc3c268783d7f3c737f3a134ccf1d4f15bb8442
294288

295-
```javascript
296289
Output:
297290
{
298291
"id": "7dc3c268783d7f3c737f3a134ccf1d4f15bb8442",
@@ -311,8 +304,32 @@ Segmenting job.
311304
"/tmp/output/test-000005.ts"
312305
]
313306
}
314-
```
315307

308+
Segmenting-only job (you are expected to have a valid MP4 file suitable for segmenting as the input).
309+
310+
# curl -d '{"source_file": "/tmp/video.mp4","destination_file":"/tmp/segments/video.mp4","encoder_options": "", "segments_options": {"segment_time": 10} }' http://localhost:8080/jobs
311+
312+
Output: {"message":"The transcoder accepted your job.","job_id":"c7599790527c0bb173cc7a0c44411aaca5c1550a"}
313+
314+
Status of finished job:
315+
316+
# curl http://localhost:8080/jobs/c7599790527c0bb173cc7a0c44411aaca5c1550a
317+
318+
Output:
319+
{
320+
"id":"c7599790527c0bb173cc7a0c44411aaca5c1550a",
321+
"status":"success",
322+
"progress":1,
323+
"duration":26,
324+
"filesize":6734045,
325+
"message":"finished segmenting job.",
326+
"playlist":"/tmp/segments/video.m3u8",
327+
"segments":[
328+
"/tmp/segments/video-000000.ts",
329+
"/tmp/segments/video-000001.ts",
330+
"/tmp/segments/video-000002.ts"
331+
]
332+
}
316333
## Issues and support
317334

318335
If you run into any issues while using codem-transcode please use the Github issue tracker to see if it is a known problem

lib/job.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,9 @@ var Job = JobUtils.getDatabase().define('Job', {
309309
var playlistDir = path.dirname(destinationFile);
310310
var playlistPath = [playlistDir, playlistName].join(path.sep) + '.m3u8';
311311
var segmentsFormat = [playlistDir, playlistName].join(path.sep) + '-%06d.ts'
312-
313-
args.push('-i', job.tmpFile,
312+
var inputFile = (this.parsedOpts()['encoder_options'].length > 0) ? job.tmpFile : this.parsedOpts()['source_file']
313+
314+
args.push('-i', inputFile,
314315
'-codec', 'copy', '-map', '0', '-f', 'segment',
315316
'-vbsf', 'h264_mp4toannexb', '-flags', '-global_header',
316317
'-segment_format', 'mpegts', '-segment_list', playlistPath,
@@ -410,8 +411,12 @@ var Job = JobUtils.getDatabase().define('Job', {
410411
}
411412

412413
if (!job.tmpFile) {
413-
// No tmpFile, hence no transcoding, only thumbnails
414-
job.exitHandler(code, 'finished thumbnail job.');
414+
// No tmpFile, hence no transcoding, only thumbnails or segmenting
415+
if (job.parsedOpts()['thumbnail_options']) {
416+
job.exitHandler(code, 'finished thumbnail job.');
417+
} else {
418+
job.exitHandler(code, 'finished segmenting job.');
419+
}
415420
return;
416421
}
417422

0 commit comments

Comments
 (0)