Usage of ffmpeg complex filter


The goal: to pick two segments, 0-10sec and 20-31sec, from a 41 second long video in.mp4, to form a 20 second long video out.mp4.
The code:
ffmpeg.exe -i in.mp4 -filter_complex ^
“[0:v]trim=duration=10[V0]; [0:a]atrim=duration=10[A0]; ^
[0:v]trim=start=20:end=31,setpts=PTS-STARTPTS[V1]; [0:a]atrim=start=20:end=31,asetpts=PTS-STARTPTS[A1];[V0][A0][V1][A1]concat=n=2:v=1:a=1[V01][A01]” -map [V01] -map [A01] out.mp4
Explanation:
-i what’s following is input file.
-filter_complex complex because there are intermediate outputs.
[0:v] 0 means the input file after first -i, in.mp4 in this case. v means video stream.
[V0] the name of output of [0:v] after applying “trim=duration=10”. the first video output
[0:a] similar to [0:v] but audio.
[A0] similar to [V0] but audio. the first audio output
[V1] and [A1] are the output video and audio of second segment.
setpts and asetpts means to reset the Presentation Time Stamps.
-map tells what output to mux into the final output file.
out.mp4 is one of the output files, which is for the -maps preceding it.
what follows -map can be:
-map [V01] filter output name, like in the example above.
-map single_highest_quality_video_stream_from_all_inputs
-map 0 means the video and audio of the first input file

Subtitle Options


There are five places for subtitles, listed innermost layer first.
1. in VCL: Video Coding Layer, as part of the frame video, called hardsub. e.g. by ffmpeg drawtext.
2. in SEI as part of NAL in ES, Network Abstraction Layer, e.g. CEA-708. ffmpeg cannot generate this kind.
3. in track in a video file, e.g. mp4.
ffmpeg -i Party.mp4 -i cap.srt -c:v copy -c:a copy -c:s mov_text -metadata:s:s:0 language=eng PartyCap.mp4
Here is a sample video, playable with vlc, by clicking Menu – Subtitle – Sub Track:
[ http://riowing.net/local/subtitle/track/PartyCap.mp4 ]
4. WebVtt: subtitle in separate file, segmented VTT or not, for both VOD and live.
This sample page is segmented VTT: http://riowing.net/local/subtitle/caption.htm
5. Subtitle as a layer in web page outside video player. e.g. outside JW Player.
This is no longer video technology but HTML

 

PartyCap

ffmpeg output thru http


ffmpeg can output to a remote host that runs web server, e.g nginx.
1. Configure nginx so that it can accept http PUT requests. three items:
Make sure nginx was built with –with-http_dav_module
nginx.conf: under location, add: dav_methods PUT;
Make sure nginx have write access to folder
2. Output to remote host
ffmpeg.exe -i SummerDance2016SC.mp4 -f hls -method PUT http://riowing.net/archive/put/SummerDance2016SC.m3u8

The other option to output to remote requires the remote host to run RTMP server.
The HLS URL generated for playing, of course, is:
http://riowing.net/archive/put/SummerDance2016SC.m3u8

SummerDance2016SC