diff --git a/Makefile b/Makefile index f527730..bc13c8a 100644 --- a/Makefile +++ b/Makefile @@ -39,10 +39,14 @@ prefix=/usr/local exec_prefix=$(prefix) bindir=$(exec_prefix)/bin libdir=$(exec_prefix)/lib +mandir=/usr/local/man +man1dir=$(mandir)/man1 +manext=.1 INSTALL=install INSTALL_PROGRAM=$(INSTALL) -m 0555 -s INSTALL_LIB=$(INSTALL) -m 0444 -s +INSTALL_DATA=$(INSTALL) -m 0444 ifdef CROSS_COMPILE @@ -101,6 +105,7 @@ LDFLAGS = -g $(PROFILE_FLAGS) $(ARCH_FLAGS) -lm OBJDIR = obj LIBDIR = lib BINDIR = bin +MANDIR = docs/mdoc # All of our non-program object modules OBJS = \ @@ -167,10 +172,12 @@ STATIC_LIB = $(LIBDIR)/libtstools.a LIBOPTS = $(ARCH_FLAGS) $(STATIC_LIB) ifeq ($(shell uname -s), Darwin) -SHARED_LIB = $(LIBDIR)/libtstools.xxx +SHARED_LIB_NAME = libtstools.xxx else -SHARED_LIB = $(LIBDIR)/libtstools.so +SHARED_LIB_NAME = libtstools.so endif +SHARED_LIB = $(LIBDIR)/$(SHARED_LIB_NAME) + # All of our programs (except the testing ones) PROGS = \ $(BINDIR)/esfilter \ @@ -207,7 +214,6 @@ TEST_PROGS = test_nal_unit_list test_es_unit_list # ------------------------------------------------------------ all: $(BINDIR) $(LIBDIR) $(OBJDIR) $(PROGS) $(SHARED_LIB) - echo "BINDIR=$(BINDIR), bindir=$(bindir)" # ts2ps is not yet an offical program, so for the moment build # it separately @@ -404,13 +410,61 @@ $(OBJDIR)/test_es_unit_list.o: test_es_unit_list.c $(ES_H) version.h # ------------------------------------------------------------ # Directory creation -$(OBJDIR) $(LIBDIR) $(BINDIR) $(DESTDIR)$(bindir) $(DESTDIR)$(libdir): +$(OBJDIR) $(LIBDIR) $(BINDIR) $(DESTDIR)$(bindir) $(DESTDIR)$(libdir) $(DESTDIR)$(man1dir): mkdir -p $@ # ------------------------------------------------------------ -.PHONY: install -install: all $(DESTDIR)$(bindir) $(DESTDIR)$(libdir) +.PHONY: install-man +install-man: $(DESTDIR)$(man1dir) + $(INSTALL_DATA) $(MANDIR)/esfilter.1 $(DESTDIR)$(man1dir)/esfilter$(manext) + $(INSTALL_DATA) $(MANDIR)/ts2es.1 $(DESTDIR)$(man1dir)/ts2es$(manext) + $(INSTALL_DATA) $(MANDIR)/es2ts.1 $(DESTDIR)$(man1dir)/es2ts$(manext) + $(INSTALL_DATA) $(MANDIR)/esdots.1 $(DESTDIR)$(man1dir)/esdots$(manext) + $(INSTALL_DATA) $(MANDIR)/esmerge.1 $(DESTDIR)$(man1dir)/esmerge$(manext) + $(INSTALL_DATA) $(MANDIR)/esreport.1 $(DESTDIR)$(man1dir)/esreport$(manext) + $(INSTALL_DATA) $(MANDIR)/esreverse.1 $(DESTDIR)$(man1dir)/esreverse$(manext) + $(INSTALL_DATA) $(MANDIR)/stream_type.1 $(DESTDIR)$(man1dir)/stream_type$(manext) + $(INSTALL_DATA) $(MANDIR)/psreport.1 $(DESTDIR)$(man1dir)/psreport$(manext) + $(INSTALL_DATA) $(MANDIR)/psdots.1 $(DESTDIR)$(man1dir)/psdots$(manext) + $(INSTALL_DATA) $(MANDIR)/ps2ts.1 $(DESTDIR)$(man1dir)/ps2ts$(manext) + $(INSTALL_DATA) $(MANDIR)/tsinfo.1 $(DESTDIR)$(man1dir)/tsinfo$(manext) + $(INSTALL_DATA) $(MANDIR)/tsreport.1 $(DESTDIR)$(man1dir)/tsreport$(manext) + $(INSTALL_DATA) $(MANDIR)/tsserve.1 $(DESTDIR)$(man1dir)/tsserve$(manext) + $(INSTALL_DATA) $(MANDIR)/tsplay.1 $(DESTDIR)$(man1dir)/tsplay$(manext) + $(INSTALL_DATA) $(MANDIR)/ts_packet_insert.1 $(DESTDIR)$(man1dir)/ts_packet_insert$(manext) + $(INSTALL_DATA) $(MANDIR)/m2ts2ts.1 $(DESTDIR)$(man1dir)/m2ts2ts$(manext) + $(INSTALL_DATA) $(MANDIR)/pcapreport.1 $(DESTDIR)$(man1dir)/pcapreport$(manext) + $(INSTALL_DATA) $(MANDIR)/tsfilter.1 $(DESTDIR)$(man1dir)/tsfilter$(manext) + $(INSTALL_DATA) $(MANDIR)/tsdvbsub.1 $(DESTDIR)$(man1dir)/tsdvbsub$(manext) + $(INSTALL_DATA) $(MANDIR)/rtp2264.1 $(DESTDIR)$(man1dir)/rtp2264$(manext) + +.PHONY: uninstall-man +uninstall-man: + rm -f $(DESTDIR)$(man1dir)/esfilter$(manext) + rm -f $(DESTDIR)$(man1dir)/ts2es$(manext) + rm -f $(DESTDIR)$(man1dir)/es2ts$(manext) + rm -f $(DESTDIR)$(man1dir)/esdots$(manext) + rm -f $(DESTDIR)$(man1dir)/esmerge$(manext) + rm -f $(DESTDIR)$(man1dir)/esreport$(manext) + rm -f $(DESTDIR)$(man1dir)/esreverse$(manext) + rm -f $(DESTDIR)$(man1dir)/stream_type$(manext) + rm -f $(DESTDIR)$(man1dir)/psreport$(manext) + rm -f $(DESTDIR)$(man1dir)/psdots$(manext) + rm -f $(DESTDIR)$(man1dir)/ps2ts$(manext) + rm -f $(DESTDIR)$(man1dir)/tsinfo$(manext) + rm -f $(DESTDIR)$(man1dir)/tsreport$(manext) + rm -f $(DESTDIR)$(man1dir)/tsserve$(manext) + rm -f $(DESTDIR)$(man1dir)/tsplay$(manext) + rm -f $(DESTDIR)$(man1dir)/ts_packet_insert$(manext) + rm -f $(DESTDIR)$(man1dir)/m2ts2ts$(manext) + rm -f $(DESTDIR)$(man1dir)/pcapreport$(manext) + rm -f $(DESTDIR)$(man1dir)/tsfilter$(manext) + rm -f $(DESTDIR)$(man1dir)/tsdvbsub$(manext) + rm -f $(DESTDIR)$(man1dir)/rtp2264$(manext) + +.PHONY: install-prog +install-prog: all $(DESTDIR)$(bindir) $(DESTDIR)$(libdir) $(INSTALL_PROGRAM) $(BINDIR)/esfilter $(DESTDIR)$(bindir)/esfilter $(INSTALL_PROGRAM) $(BINDIR)/ts2es $(DESTDIR)$(bindir)/ts2es $(INSTALL_PROGRAM) $(BINDIR)/es2ts $(DESTDIR)$(bindir)/es2ts @@ -432,7 +486,38 @@ install: all $(DESTDIR)$(bindir) $(DESTDIR)$(libdir) $(INSTALL_PROGRAM) $(BINDIR)/tsfilter $(DESTDIR)$(bindir)/tsfilter $(INSTALL_PROGRAM) $(BINDIR)/tsdvbsub $(DESTDIR)$(bindir)/tsdvbsub $(INSTALL_PROGRAM) $(BINDIR)/rtp2264 $(DESTDIR)$(bindir)/rtp2264 - $(INSTALL_LIB) $(SHARED_LIB) $(DESTDIR)$(libdir) + $(INSTALL_LIB) $(SHARED_LIB) $(DESTDIR)$(libdir)/$(SHARED_LIB_NAME) + +.PHONY: uninstall-prog +uninstall-prog: + rm -f $(DESTDIR)$(bindir)/esfilter + rm -f $(DESTDIR)$(bindir)/ts2es + rm -f $(DESTDIR)$(bindir)/es2ts + rm -f $(DESTDIR)$(bindir)/esdots + rm -f $(DESTDIR)$(bindir)/esmerge + rm -f $(DESTDIR)$(bindir)/esreport + rm -f $(DESTDIR)$(bindir)/esreverse + rm -f $(DESTDIR)$(bindir)/stream_type + rm -f $(DESTDIR)$(bindir)/psreport + rm -f $(DESTDIR)$(bindir)/psdots + rm -f $(DESTDIR)$(bindir)/ps2ts + rm -f $(DESTDIR)$(bindir)/tsinfo + rm -f $(DESTDIR)$(bindir)/tsreport + rm -f $(DESTDIR)$(bindir)/tsserve + rm -f $(DESTDIR)$(bindir)/tsplay + rm -f $(DESTDIR)$(bindir)/ts_packet_insert + rm -f $(DESTDIR)$(bindir)/m2ts2ts + rm -f $(DESTDIR)$(bindir)/pcapreport + rm -f $(DESTDIR)$(bindir)/tsfilter + rm -f $(DESTDIR)$(bindir)/tsdvbsub + rm -f $(DESTDIR)$(bindir)/rtp2264 + rm -f $(DESTDIR)$(libdir)/$(SHARED_LIB_NAME) + +.PHONY: install +install: install-man install-prog + +.PHONY: uninstall +uninstall: uninstall-man uninstall-prog .PHONY: objclean objclean: @@ -457,9 +542,7 @@ clean: objclean .PHONY: distclean distclean: clean - -rmdir $(OBJDIR) - -rmdir $(LIBDIR) - -rmdir $(BINDIR) + -rm -rf $(OBJDIR) $(LIBDIR) $(BINDIR) TESTDATAFILE = /data/video/CVBt_hp_trail.264 diff --git a/docs/mdoc/es2ts.1 b/docs/mdoc/es2ts.1 new file mode 100644 index 0000000..de1e998 --- /dev/null +++ b/docs/mdoc/es2ts.1 @@ -0,0 +1,121 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt ES2TS 1 +.Os +.Sh NAME +.Nm es2ts +.Nd Convert an ES video stream to H.222 TS +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm es2ts +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl quiet | q +.Op Fl pid Ar pid_no +.Op Fl pmt Ar pmt_pid_no +.Op Fl host Ar host Ns Op : Ns Ar port +.Op Fl max Ar max_units | Fl m Ar max_units +.Ar in_file | Fl stdin +.Ar out_file | Op Fl stdout +.Sh DESCRIPTION +Convert an elementary video stream to H.222 transport stream. +Supports input streams conforming to MPEG-2 (H.262), MPEG-4/AVC +(H.264) and AVS. Also supports MPEG-1 input streams, insofar as MPEG-2 +is backwards compatible with MPEG-1. +.Pp +Note that this program works by reading and packaging the elementary +stream packages directly - it does not parse them as H.262 or H.264 +data. +.Ss Files +.Bl -tag +.It Ar in_file +is a file containing the Elementary Stream data (but see -stdin below) +.It Ar out_file +is an H.222 Transport Stream file (but see -stdout and -host below) +.El +.Ss Switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl v , Fl verbose +Output summary information about each ES packet as it is read +.It Fl q , Fl quiet +Only output error messages +.It Fl pid Ar pid_no +.Ar pid_no +is the video PID to use for the data. +Use '-pid 0x' to specify a hex value. +.Bq default = 0x68 +.It Fl pmt Ar pmt_pid_no +.Ar pmt_pid_no +is the PMT PID to use. +Use '-pmt 0x' to specify a hex value. +.Bq default = 0x66 +.It Fl max Ar max_units , Fl m Ar max_units +Maximum number of ES data units to read +.It Fl stdin +Input from standard input, instead of a file +.It Fl stdout +Write output to , instead of a named file +Forces -quiet and -err stderr. +.It Fl host Ar host Ns Op : Ns Ar port +Writes output (over TCP/IP) to the named +.Ar host , +instead of to a named file. If +.Ar port +is not specified, it defaults to 88. +.El +.Ss Stream type +When the TS data is being output, it is flagged to indicate whether +it conforms to H.262, H.264 or AVS. It is important to get this right, +as it will affect interpretation of the TS data. +.Pp +If input is from a file, then the program will look at the start of +the file to determine if the stream is H.264, H.262 or AVS. This +process may occasionally come to the wrong conclusion, in which case +the user can override the choice using the following switches. +.Pp +If input is from standard input (via -stdin), then it is not possible +for the program to make its own decision on the input stream type. +Instead, it defaults to H.262, and relies on the user indicating if +this is wrong. +.Bl -tag +.It Fl h264 , avc +Force the program to treat the input as MPEG-4/AVC. +.It Fl h262 +Force the program to treat the input as MPEG-2. +.It Fl avs +Force the program to treat the input as AVS. +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.Sh BUGS +For the moment, the video input must be H.264 or AVS, and the audio input +ADTS, AC-3 ATSC or MPEG layer 2. Also, the audio is assumed to have a +constant number of samples per frame. + diff --git a/docs/mdoc/esdots.1 b/docs/mdoc/esdots.1 new file mode 100644 index 0000000..2c4397e --- /dev/null +++ b/docs/mdoc/esdots.1 @@ -0,0 +1,108 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt ESDOTS 1 +.Os +.Sh NAME +.Nm esdots +.Nd Present the content of an ES as a sequence of characters +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm esdots +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl max Ar max_units | Fl m Ar max_units +.Op Fl pes | ts +.Op Fl hasheos +.Op Fl es +.Op Fl gop +.Op Fl fr Ar frame_rate +.Ar in_file | Fl stdin +.Sh DESCRIPTION +Present the content of an H.264 (MPEG-4/AVC), H.262 (MPEG-2) or AVS +elementary stream as a sequence of characters, representing access +units/MPEG-2 items/AVS items. +.Pp +(Note that for H.264 it is access units and not frames that are +represented, and for H.262 it is items and not pictures.) +.Ss Files +.Bl -tag +.It Ar in_file +is an H.222 Transport Stream file (but see +.Fl stdin Ns ) +.El +.Ss Switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl stdin +Input from standard input, instead of a file +.It Fl v , Fl verbose +Output extra information about packets +.It Fl q , Fl quiet +Only output error messages +.It Fl max Ar max_units , Fl m Ar max_units +Maximum number of entities to read +.It Fl pes , ts +The input file is TS or PS, to be read via the +PES->ES reading mechanisms +.It Fl hasheos +Print a # on finding an EOS (end-of-stream) NAL unit +rather than stopping (only applies to H.264) +.It Fl es +Report ES units, rather than any 'higher' unit +(not necessarily suppported for all file types) +.It Fl gop +Show the duration of each GOP (for MPEG-2 steams) +OR the distance between random access points (H.264) +.It Fl fr +Set the video frame rate (default = 25 fps) +.El +.Ss Stream type: +If input is from a file, then the program will look at the start of +the file to determine if the stream is H.264 or H.262 data. This +process may occasionally come to the wrong conclusion, in which case +the user can override the choice using the following switches. +.Pp +For AVS data, the program will never guess correctly, so the user must +specify the file type, using -avs. +.Pp +If input is from standard input (via -stdin), then it is not possible +for the program to make its own decision on the input stream type. +Instead, it defaults to H.262, and relies on the user indicating if +this is wrong. +.Bl -tag +.It Fl h264 , avc +Force the program to treat the input as MPEG-4/AVC. +.It Fl h262 +Force the program to treat the input as MPEG-2. +.It Fl avs +Force the program to treat the input as AVS. +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS diff --git a/docs/mdoc/esfilter.1 b/docs/mdoc/esfilter.1 new file mode 100644 index 0000000..8756638 --- /dev/null +++ b/docs/mdoc/esfilter.1 @@ -0,0 +1,149 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt ESFILTER 1 +.Os +.Sh NAME +.Nm esfilter +.Nd Output a filtered or truncated version of an elementary stream +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm esfilter +.Fl copy | filter | strip +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl quiet | q +.Op Fl host Ar dest_ip Ns Op : Ns Ar port +.Op Fl max Ar max_frames | Fl m Ar max_frames +.Op Fl freq Ar keep_frequency +.Op Fl allref +.Op Fl tsout +.Op Fl pes | ts +.Op Fl h264 | avc | h262 +.Ar in_file | Fl stdin +.Ar out_file | Fl stdout +.Sh DESCRIPTION +Output a filtered or truncated version of an elementary stream. +The input is either H.264 (MPEG-4/AVC) or H.262 (MPEG-2). +The output is either an elementary stream, or an H.222 transport +stream +.Pp +If output is to an H.222 Transport Stream, then fixed values for +the PMT PID (0x66) and video PID (0x68) are used. +.Ss Files +.Bl -tag +.It Ar in_file +is the input elementary stream (but see +.Fl stdin +below). +.It Ar out_file +is the output stream, either an equivalent elementary +stream, or an H.222 Transport Stream (but see +.Fl stdout +and +.Fl host +below). +.El +.Ss Actions +.Bl -tag +.It Fl copy +Copy the input data to the output file +(mostly useful as a way of truncating data with +.Fl max Ns ) +.It Fl filter +Filter data from input to output, aiming to keep every +.Ar keep_frequency Ns +th frame (where +.Ar keep_frequency +is specified by +.Fl freq Ns +). +.It Fl strip +For H.264, output just the IDR and I pictures, for H.262, +output just the I pictures, but see +.Fl allref +below. +.El +.Ss Switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl stdin +Input from standard input, instead of a file +.It Fl v , Fl verbose +Output extra information about packets +.It Fl q , Fl quiet +Only output error messages +.It Fl host Ar dest_ip Ns Op : Ns Ar port +Writes output (over TCP/IP) to the named +.Ar host , +instead of to a named file. If +.Ar port +is not specified, it defaults to 88. Implies +.Fl tsout . +.It Fl max Ar max_frames , Fl m Ar max_frames +Maximum number of frames to read (for +.Fl filter +and +.Fl strip Ns ), +or ES units/NAL units (for +.Fl copy Ns ). +.It Fl freq Ar keep_frequency +Specify the frequency of frames to try to keep +with -filter. Defaults to 8. +.It Fl allref +With +.Fl strip , +keep all reference pictures (H.264) +or all I and P pictures (H.262) +.It Fl tsout +Output data as Transport Stream PES packets +(the default is as Elementary Stream) +.It Fl pes , ts +The input file is TS or PS, to be read via the +PES->ES reading mechanisms. Not allowed with +.Fl stdin . +.El +.Ss Stream type: +If input is from a file, then the program will look at the start of +the file to determine if the stream is H.264 or H.262 data. This +process may occasionally come to the wrong conclusion, in which case +the user can override the choice using the following switches. +.Pp +If input is from standard input (via -stdin), then it is not possible +for the program to make its own decision on the input stream type. +Instead, it defaults to H.262, and relies on the user indicating if +this is wrong. +.Bl -tag +.It Fl h264 , avc +Force the program to treat the input as MPEG-4/AVC. +.It Fl h262 +Force the program to treat the input as MPEG-2. +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS diff --git a/docs/mdoc/esmerge.1 b/docs/mdoc/esmerge.1 new file mode 100644 index 0000000..9c2c290 --- /dev/null +++ b/docs/mdoc/esmerge.1 @@ -0,0 +1,107 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt ESMERGE 1 +.Os +.Sh NAME +.Nm esmerge +.Nd Merge the contents of two ES to make a TS +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm esmerge +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl quiet | q +.Op Fl x +.Op Fl h264 | avs +.Op Fl vidrate Ar video_hz +.Op Fl rate Ar audio_hz | Fl cd | dat +.Op Fl adts | l2 | mp2adts | mp4adts | ac3 +.Op Fl patpmtfreq Ar pat_freq +.Ar video_file audio_file out_file +.Sh DESCRIPTION +Merge the contents of two Elementary Stream (ES) files, one containing +video data, and the other audio, to produce an output file containing +Transport Stream (TS). +.Ss Files +.Bl -tag +.It Ar video_file +is the ES file containing video. +.It Ar audio_file +is the ES file containing audio. +.It Ar out_file +is the resultant TS file. +.El +.Ss Switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl stdin +Input from standard input, instead of a file +.It Fl v , Fl verbose +Output extra information about each audio/video frame +.It Fl q , Fl quiet +Only output error messages +.It Fl x +Output diagnostic information. +.It Fl h264 +The video stream is H.264 (the default) +.It Fl avs +The video stream is AVS +.It Fl vidrate Ar video_hz +Video frame rate in Hz - defaults to 25Hz. +.It Fl rate Ar audio_hz +Audio sample rate in Hertz - defaults to 44100, i.e., 44.1KHz. +.It Fl cd +Equivalent to +.Fl rate Cm 44100 No (CD rate), the default. +.It Fl dat +Equivalent to +.Fl rate Cm 48000 No (DAT rate). +.It Fl adts +The audio stream is ADTS (the default) +.It Fl l2 +The audio stream is MPEG layer 2 audio +.It Fl mp2adts +The audio stream is MPEG-2 style ADTS regardless of ID bit +.It Fl mp4adts +The audio stream is MPEG-4 style ADTS regardless of ID bit +.It Fl ac3 +The audio stream is Dolby AC-3 in ATSC +.It Fl patpmtfreq Ar pat_freq +PAT and PMT will be inserted every +.Ar pat_freq +video frames. By default, +.Ar pat_freq No = 0 and PAT/PMT are inserted only at +the start of the output stream. +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.Sh BUGS +For the moment, the video input must be H.264 or AVS, and the audio input +ADTS, AC-3 ATSC or MPEG layer 2. Also, the audio is assumed to have a +constant number of samples per frame. diff --git a/docs/mdoc/esreport.1 b/docs/mdoc/esreport.1 new file mode 100644 index 0000000..ce3c825 --- /dev/null +++ b/docs/mdoc/esreport.1 @@ -0,0 +1,128 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt ESREPORT 1 +.Os +.Sh NAME +.Nm esreport +.Nd Report on the contents of an ES +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm esmerge +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl quiet | q +.Op Fl frames | findfields | afd | es +.Op Fl framesize +.Op Fl frametype +.Op Fl x +.Op Fl max Ar max-units | Fl m Ar max_units +.Op Fl pes | ts +.Op Fl pesreport +.Op Fl h264 | avc | h262 | avs +.Ar in_file | Fl stdin +.Sh DESCRIPTION +Report on the content of an elementary stream containing H.264 +(MPEG-4/AVC), H.262 (MPEG-2) or AVS video data. +.Ss Files +.Bl -tag +.It Ar in_file +is the Elementary Stream file (but see -stdin below) +.El +.Ss What to report +The default is to report on H.262 items, AVS frames or H.264 NAL units. +Other choices are: +.Bl -tag +.It Fl frames +Report by frames. The default for AVS. +.It Fl findfields +Report on any fields in the data. Ignored for AVS. +.It Fl afd +Report (just) on AFD changes in H.262. Ignored for the other types of file. +.It Fl es +Report on ES units. +.El +.Pp +Reporting on frames may be modified by: +.Bl -tag +.It Fl framesize +Report on the sizes of frames (mean, etc.). +.It Fl frametype +Report on the numbers of different type of frame. +.El +.Pp +(in fact, both of these imply -frame). +.Ss Switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl stdin +Input from standard input, instead of a file +.It Fl v , Fl verbose +For H.262 data, output information about the data +in each MPEG-2 item. For ES units, output information +about the data in each ES unit. Ignored for H.264 data. +.It Fl q , Fl quiet +Only output summary information (i.e., the number +of entities in the file, statistics, etc.) +.It Fl x +Show details of each NAL unit as it is read. +.It Fl stdin +Take input from , instead of a named file +.It Fl max Ar max_units , Fl m Ar max_units +Maximum number of NAL units/MPEG-2 items/AVS frames/ES units +to read. If -frames, then the program will stop after +that many frames. If reading 'frames', MPEG-2 and AVS will +also count sequence headers and sequence end. +.It Fl pes , ts +The input file is TS or PS, to be read via the PES to +ES reading mechanisms +.It Fl pesreport +Report on PES headers. Implies +.Fl pes No and Fl q . +.El +.Ss Stream type: +If input is from a file, then the program will look at the start of +the file to determine if the stream is H.264, H.262 or AVS data. This +process may occasionally come to the wrong conclusion, in which case +the user can override the choice using the following switches. +.Pp +If input is from standard input (via -stdin), then it is not possible +for the program to make its own decision on the input stream type. +Instead, it defaults to H.262, and relies on the user indicating if +this is wrong. +.Bl -tag +.It Fl h264 , avc +Force the program to treat the input as MPEG-4/AVC. +.It Fl h262 +Force the program to treat the input as MPEG-2. +.It Fl avs +Force the program to treat the input as AVS. +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS diff --git a/docs/mdoc/esreverse.1 b/docs/mdoc/esreverse.1 new file mode 100644 index 0000000..495dbc0 --- /dev/null +++ b/docs/mdoc/esreverse.1 @@ -0,0 +1,111 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt ESREVERSE 1 +.Os +.Sh NAME +.Nm esreverse +.Nd Report on the contents of an ES +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm esreverse +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl quiet | q +.Op Fl host Ar host Ns Op : Ns Ar port +.Op Fl max Ar max_frames | Fl m Ar max_frames +.Op Fl freq Ar frame_freq +.Op Fl tsout +.Op Fl pes |-ts +.Op Fl server +.Op Fl x +.Op Fl h264 | avc | h262 +.Ar in_file +.Ar out_file | Fl stdout +.Sh DESCRIPTION +Output a reversed stream derived from the input H.264 (MPEG-4/AVC) +or H.262 (MPEG-2) elementary stream. +.Pp +If output is to an H.222 Transport Stream, then fixed values for +the PMT PID (0x66) and video PID (0x68) are used. +.Ss Files +.Bl -tag +.It Ar in_file +is the input elementary stream. +.It Ar out_file +is the output stream, either an equivalent elementary +stream, or an H.222 Transport Stream (but see +Fl stdout No and Fl host below). +.El +.Ss Switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl v , Fl verbose +Output additional (debugging) messages +.It Fl q , Fl quiet +Only output error messages +.It Fl stdout +Write output to , instead of a named file. Forces +.Fl quiet No and Fl "err stderr". +.It Fl host Ar host Ns Op : Ns Ar port +Writes output (over TCP/IP) to the named , +instead of to a named file. If is not +specified, it defaults to 88. Implies +.Fl tsout . +.It Fl max Ar max_frames | Fl m Ar max_frames +Maximum number of frames to read +.It Fl freq Ar frame_freq +Specify the frequency of frames to try to keep +when reversing. Defaults to 8. +.It Fl tsout +Output H.222 Transport Stream +.It Fl pes , ts +The input file is TS or PS, to be read via the +PES to ES reading mechanisms +.It Fl server +Also output as normal forward video as reversal +data is being collected. Implies +.Fl pes No and Fl tsout . +.It Fl x +Temporary extra debugging information +.El +.Ss Stream type: +If input is from a file, then the program will look at the start of +the file to determine if the stream is H.264 or H.262 data. This +process may occasionally come to the wrong conclusion, in which case +the user can override the choice using the following switches. +.Bl -tag +.It Fl h264 , avc +Force the program to treat the input as MPEG-4/AVC. +.It Fl h262 +Force the program to treat the input as MPEG-2. +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + diff --git a/docs/mdoc/m2ts2ts.1 b/docs/mdoc/m2ts2ts.1 new file mode 100644 index 0000000..dbb39d5 --- /dev/null +++ b/docs/mdoc/m2ts2ts.1 @@ -0,0 +1,75 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt M2TS2TS 1 +.Os +.Sh NAME +.Nm m2ts2ts +.Nd convert .m2ts to .ts +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm m2ts2ts +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl quiet | q +.Op Fl buffer Ar buf_pkts | Fl b Ar buf_pkts +.Ar in_file | Fl stdin +.Ar out_file | Fl stdout +.Sh DESCRIPTION +Converts BDAV MPEG-2 Transport Stream file (M2TS) to an 'ordinary' TS file +.Ss Files +.Bl -tag +.It Ar in_file +is a BDAV MPEG-2 Transport Stream file (M2TS)(but see +.Fl stdin +below). +.It Ar out_file +is an H.222 Transport Stream file (but see +.Fl stdout +below). +.El +.Ss General switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl v , Fl verbose +Output extra information +.It Fl q , Fl quiet +Only output error messages +.It Fl stdin +Input from standard input instead of a file +.It Fl stdout +Output to standard output instead of a file. Forces +.Fl quiet No and Fl "err stderr" . +.It Fl b Ar buf_pkts , Fl buffer Ar buf_pkts +Number of TS packets to buffer for reordering +.Bq default = 4 +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + diff --git a/docs/mdoc/pcapreport.1 b/docs/mdoc/pcapreport.1 new file mode 100644 index 0000000..4c74f64 --- /dev/null +++ b/docs/mdoc/pcapreport.1 @@ -0,0 +1,178 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt PCAPREPORT 1 +.Os +.Sh NAME +.Nm pcapreport +.Nd Get info about a TS in a pcap +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm pcapinfo +.Fl h | help Op Cm detail +.Nm pcapinfo +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl name Ar base_name | Fl n Ar base_name +.Op Fl extract | Fl x +.Op Fl csvgen | Fl c +.Op Fl output Ar udp_name | Fl o Ar udp_name +.Op Fl max Ar max_read | Fl m Ar max_read +.Op Fl data +.Op Fl a +.Op Fl d Ar dest_ip Ns Op : Ns Ar port +.Op Fl g | Fl good-ts-only +.Op Fl keep-bad +.Op Fl tfmt Ar time_format +.Op Fl dump-data | Fl D +.Op Fl extra-dump | Fl E +.Op Fl times | Fl t +.Op Fl skew-discontinuity-threshold Ar threshold | Fl skew Ar threshold +.Ar file + +.Sh DESCRIPTION +Report and/or extract the Transport Streams in a .pcap. In analyse mode ( +.Fl a +) the timing info in the TS (PCRs) can be compared with the timing info in +the pcap. +.Bl -tag +.It Fl h , help +Produce usage summary +.It Fl h Cm detail , Fl help Cm detail +Produce usage + more detail on what the output actually means +.It Fl a , analyse +Analyse. Produces summary info on every TS in the pcap +.It Fl d Ar dest_ip Ns Oo : Ns Ar port Oc , Fl destip Ar dest_ip Ns Oo : Ns Ar port Oc +Select data with the given destination IP and port. +If the +.Ar port +is not specified, it defaults to 0 (see below). +.It Fl g , Fl good-ts-only +Only extract/analyse packets that seem entirely good. +By default there is a bit of slack in determining if a +packet is good and some dodgy packets are let through. +This switch ensures that all packets pass simple testing +.It Fl keep-bad +Extract all packets including bad ones. Is implied if +an ip & port filter is set. Overriden by +.Fl -good-ts-only . +.It Fl tfmt Ar time_format +Sets the format for printed times +.Pp +.Ar time_format +is one of +.Bl -tag +.It Cm 90 +.Bq Default +show as 90KHz timestamps (suffix 't' on the values: e.g., 4362599t). +.It Cm 27 +Show as 27MHz timestamps (similar, e.g., 25151:000t). +.It Cm 32 +Show as 90KHz timestamps, but only the low 32 bits. +.It Cm ms +Show as milliseconds. +.It Cm hms +Show as hours/minutes/seconds (H:MM:SS.ssss, the H +can be more than one digit if necessary) +.El +.It Fl dump-data , Fl D +Dump any data in the input file to stdout. +.It Fl extra-dump , Fl E +Dump only data which isn't being sent to the +Fl o +file. +.It Fl times , Fl t +Report continuously on PCR vs PCAP timing for the destination specified in +.Fl d . +.It Fl skew-discontinuity-threshold Ar threshold , Fl skew Ar threshold +Gives the skew discontinuity threshold in 90kHz units. +A value of 0 disables this. +.Bq "default = 6*90000" +.It Fl split-section +Split extracted streams into multiple files on section +(discontinutity) boundries +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl v , Fl verbose +Output extra information about packets +.It Ar file +The pcap stream file to get info on +.El +.Pp +Specifying 0.0.0.0 for destination IP will capture all hosts, specifying 0 +as a destination port will capture all ports on the destination host. +.Pp +Network packet numbers start at 1 (like wireshark) +.Pp +TS packet numbers start at 0. +.Ss Analyse output +.Bl -tag +.It Times +(packet and PCR) +The times associated with packets and PCR are held internally in 90kHz units +and are displayed in those units by default +.It Stream +A set of packets to the same IP & Port. TS streams are detected by looking +for 0x47s at appropriate places in the packets +.It Section +A part of a stream which appears to have a continuous TS embedded in it. If +the PCR jumps then a new section should be started (though this will not +generate a separate .ts file if the extraction option is in effect unless +.Fl split-section +is specified, nor will it generate a new .csv file.) +.Pp +As it stands pcapreport will only report on a single PCR pid within a TS. If +multiple pids with PCRs are detected then this will be reported but the other +PCRs will be ignored +.It Skew +This is the difference between the time in the pcap for a UDP packet and any +PCR found in the TS contained within that packet. The accuracy of this figure +obviously depends on how good the clock was in the capture process. Skew is +arbitrarily set to zero at the start of a section. A skew of >6s is assumed +to be a discontinuity and will start a new section. +.Pp +Positive skew means that we received too low a PCR for this timestamp. +.It Drift +This is skew over time and (assuming that the playout process is good) +represents the difference in speed between the transmitters clock and the +receivers clock. The algorithm for determining this isn't very sophisticated +so if you have a large maximum jitter or a short sample this should be taken +with a pinch of salt. Beware also that PC clocks (like the one in the m/c +doing the tcpdump) are not always amongst the most stable or accurate; however +they should be good enough to detect gross errors +.It Jitter +This is measured as the difference between the maximum and minimum skews over +a 10sec (max 1024 samples) period. This should be long enough to capture a +good baseline but short enough that drift has a negligible effect +.It Max Jitter +The maximum value of jitter (see above) found in a section +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr tsinfo 1 , +.Xr tsreport 1 +.Xr rtp2264 1 +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.Sh BUGS +pcapreport can only deal with IPv4. IPv6 is beyond its current capabilities. diff --git a/docs/mdoc/ps2ts.1 b/docs/mdoc/ps2ts.1 new file mode 100644 index 0000000..b93ced8 --- /dev/null +++ b/docs/mdoc/ps2ts.1 @@ -0,0 +1,194 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt ps2ts 1 +.Os +.Sh NAME +.Nm ps2ts +.Nd Extract a program stream from a Transport Stream +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm ps2ts +.Fl pid Ar pid | Fl video | audio +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl quiet | q +.Op Fl max Ar max_pkts | Fl m Ar max_pkts +.Op Fl dvd | notdvd | nodvd +.Op Fl vstream Ar vstream_no +.Op Fl astream Ar astream_no +.Op Fl ac3stream Ar ac3stream_no +.Op Fl host Ar host Ns Op : Ns port +.Op Fl vpid Ar vpid_no +.Op Fl apid Ar apid_no +.Op Fl noaudio +.Op Fl pmt Ar pmt_pid_no +.Op Fl prepeat Ar pat_freq +.Op Fl pad Ar pad_pkts +.Op Fl h264 | avc | h262 | mp42 | vtype Ar video_type +.Op Fl dolby Cm dvd | atsc +.Ar in_file | Fl stdin +.Ar out_file | Fl stdout +.Sh DESCRIPTION +Convert an H.222 program stream to H.222 transport stream. +.Pp +This program does not make use of any Program Stream Map packets +in the data (mainly because I have yet to see data with any). This +means that the program has to determine the stream type of the data +based on the first few ES units. +.Pp +This program does not output more than one video and one audio +stream. If the program stream data contains more than one of each, +the first will be used, and the others ignored (with a message +indicating this). +.Pp +It is assumed that the video stream will contain DTS values in its +PES packets at reasonable intervals, which can be used as PCR values +in the transport stream, and thus the video stream's PID can be used +as the PCR PID in the transport stream. +.Ss Files +.Bl -tag +.It Ar in_file +is a file containing the program stream data +(but see -stdin below) +.It Ar out_file + is a transport stream file +(but see -stdout and -host below) +.El +.Ss input switches +.Bl -tag +.It Fl stdin +take input from , instead of a named file +.It Fl dvd +The PS data is from a DVD. This is the default. +This switch has no effect on MPEG-1 PS data. +.It Fl notdvd , nodvd +The PS data is not from a DVD. +The DVD specification stores AC-3 (Dolby), DTS and +other audio in a specialised manner in private_stream_1. +.It Fl vstream Ar vstream_no +Take video from video stream +.Ar vstream_no +(0..7). The default is the first video stream found. +.It Fl astream Ar astream_no +Take audio from audio stream +.Ar astream_no +(0..31). The default is the first audio stream found +(this includes private_stream_1 on non-DVD streams). +.It Fl ac3stream Ar astream_no +Take audio from AC3 substream +.Ar ac3stream_no +(0..7), from private_stream_1. This implies -dvd. +(If audio is being taken from a substream, the user +is assumed to have determined which one is wanted, +e.g., using psreport) +.El +.Ss Output Switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl host Ar host Ns Op : Ns Arport +Writes output (over TCP/IP) to the named , +instead of to a named file. If +.Ar +is not specified, it defaults to 88. +.It Fl vpid Ar vpid_no +.Ar vpid_no is the video PID to use for the data. +Use '-vpid 0x' to specify a hex value. +Defaults to 0x68. +.It Fl apid Ar apid_no +.Ar apid_no +is the audio PID to use for the data. +Use '-apid 0x' to specify a hex value. +Defaults to 0x67. +.It Fl noaudio +Don't output the audio data +.It Fl pmt Ar pmt_pid_no +.Ar pmt_pid_no is the PMT PID to use. +Use '-pmt 0x' to specify a hex value. +Defaults to 0x66 +.It Fl prepeat Ar pat_freq +Output the program data (PAT/PMT) after every +.Ar pat_freq +PS packs. Defaults to 100. +.It Fl pad Ar pad_pkts +Pad the start with +.Ar pad_pkts +filler TS packets, to allow +a TS reader to synchronize with the datastream. +Defaults to 8. +.El +.Ss General switches +.Bl -tag +.It Fl v , Fl verbose +Print a 'v' for each video packet and an 'a' for +each audio packet, as it is read +.It Fl q , Fl quiet +Only output error messages +.It Fl max Ar max_pkts , Fl m Ar max_pkts +Maximum number of PS packets to read. +.El +.Ss Stream type +When the TS data is being output, it is flagged to indicate whether +it conforms to H.262, H.264, etc. It is important to get this right, as +it will affect interpretation of the TS data. +.Pp +If input is from a file, then the program will look at the start of +the file to determine if the stream is H.264 or H.262 data. This +process may occasionally come to the wrong conclusion, in which case +the user can override the choice using the following switches. +.Pp +If input is from standard input (via -stdin), then it is not possible +for the program to make its own decision on the input stream type. +Instead, it defaults to H.262, and relies on the user indicating if +this is wrong. +.Bl -tag +.It Fl h264 , avc +Force the program to treat the input as MPEG-4/AVC. +.It Fl h262 +Force the program to treat the input as MPEG-2. +.It Fl mp42 +Force the program to treat the input as MPEG-4/Part 2. +.It Fl vtype Ar video_type +Force the program to treat the input as video of +stream type (e.g., 0x42 means AVS video). It is +up to the user to specify a valid . +.El +If the audio stream being output is Dolby (AC-3), then the stream type +used to output it differs for DVB (European) and ATSC (USA) data. It +may be specified as follows: +.Bl -tag +.It Fl dolby Cm dvb +Use stream type 0x06 (the default) +.It Fl dolby Cm atsc +Use stream type 0x81 +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + + diff --git a/docs/mdoc/psdots.1 b/docs/mdoc/psdots.1 new file mode 100644 index 0000000..4a43f0a --- /dev/null +++ b/docs/mdoc/psdots.1 @@ -0,0 +1,63 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt PSDOTS 1 +.Os +.Sh NAME +.Nm psdots +.Nd Present the content of an PS as a sequence of characters +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm psdots +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl max Ar max_pkts | Fl m Ar max_pkts +.Ar in_file | Fl stdin +.Sh DESCRIPTION +Present the content of a Program Stream file as a sequence of + characters, representing the packets. +.Ss Files +.Bl -tag +.It Ar in_file +is an H.222 Program Stream file (but see +.Fl stdin Ns ) +.El +.Ss Switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl stdin +Input from standard input, instead of a file +.It Fl v , Fl verbose +Output a description of the characters used +.It Fl max Ar max_pkts , Fl m Ar max_pkts +Maximum number of PS packets to read +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + diff --git a/docs/mdoc/psreport.1 b/docs/mdoc/psreport.1 new file mode 100644 index 0000000..9470086 --- /dev/null +++ b/docs/mdoc/psreport.1 @@ -0,0 +1,73 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt PSREPORT 1 +.Os +.Sh NAME +.Nm psreport +.Nd Report on the contents of a PS +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm psreport +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl max Ar max_pkts | Fl m Ar max_pkts +.Op Fl dvd | notdvd | nodvd +.Ar in_file | Fl stdin +.Sh DESCRIPTION +Report on the packets in a Program Stream. +.Ss Files +.Bl -tag +.It Ar in_file +is an H.222 Program Stream file (but see +.Fl stdin +below) +.El +.Ss Switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl stdin +Input from standard input, instead of a file +.It Fl v , Fl verbose +Output packet data as well +.It Fl stdin +Take input from , instead of a named file +.It Fl max Ar max_pkts , Fl m Ar max_pkts +Maximum number of PS packets to read +.It Fl dvd +The PS data is from a DVD. This is the default. +This switch has no effect on MPEG-1 PS data. +.It Fl notdvd , nodvd +The PS data is not from a DVD. +The DVD specification stores AC-3 (Dolby), DTS and +other audio in a specialised manner in private_stream_1. +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + diff --git a/docs/mdoc/rtp2264.1 b/docs/mdoc/rtp2264.1 new file mode 100644 index 0000000..615accb --- /dev/null +++ b/docs/mdoc/rtp2264.1 @@ -0,0 +1,52 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt RTP2264 1 +.Os +.Sh NAME +.Nm rtp2264 +.Nd convert H.264 in RTP into H.264 ES +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm rtp2264 +.Ar in_file +.Ar out_file +.Op Ar b64_block Ns Op , Ns Ar b64_block Ns Op ,... +.Sh DESCRIPTION +Take a RTP file (probably generated by +.Xr pcapreport 1 Ns ) +containing +an H.264 stream and convert it into an Annex B encoded .264 +elementary stream file. +.Pp +If +.Ar b64_block Ns s +are specified then it is assumed to be one or more +B64 encoded blocks containing SPS or PPS or other similar blocks. +These will each have a 00 00 00 01 sequence added at the start and +then written at the start of the out_file +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr pcapreport 1 +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + diff --git a/docs/mdoc/stream_type.1 b/docs/mdoc/stream_type.1 new file mode 100644 index 0000000..42589a3 --- /dev/null +++ b/docs/mdoc/stream_type.1 @@ -0,0 +1,97 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt STREAM_TYPE 1 +.Os +.Sh NAME +.Nm stream-type +.Nd Guess the type of a stream file +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm stream-type +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl quiet | q +.Ar in_file +.Sh DESCRIPTION +Attempt to determine if an input stream is Transport Stream, +Program Stream, or Elementary Stream, and if the latter, if it +is H.262 or H.264 (i.e., MPEG-2 or MPEG-4/AVC respectively). +The mechanisms used are fairly crude, assuming that: +.Bl -dash +.It +data is byte aligned +.It +for TS, the first byte in the file will be the start of a NAL unit, +and PAT/PMT packets will be findable +.It +for PS, the first packet starts immediately at the start of the +file, and is a pack header +.It +if the first 1000 packets could be H.262 *or* H.264, then the data +is assumed to be H.264 (the program doesn't try to determine +sensible sequences of H.262/H.264 packets, so this is a reasonable +way of guessing) +.El +It is quite possible that data which is not relevant will be +misidentified +.Ss Files +.Bl -tag +.It Ar in_file +is the file to analyse +.El +.Ss Switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl v , Fl verbose +Output more detailed information about how it is making its decision +.It Fl q , Fl quiet +Only output error messages +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.Sh RETURN VALUES +The program exit value is: +.Bl -tag +.It 10 +if it detects Transport Stream, +.It 11 +if it detects Program Stream, +.It 12 +if it detects Elementary Stream containing H.262 (MPEG-2), +.It 14 +if it detects Elementary Stream containing H.264 (MPEG-4/AVC), +.It 5 +if it looks like it might be PES, +.It 9 +if it really cannot decide, or +.It 0 +if some error occurred +.El +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + + diff --git a/docs/mdoc/ts2es.1 b/docs/mdoc/ts2es.1 new file mode 100644 index 0000000..6ecf61a --- /dev/null +++ b/docs/mdoc/ts2es.1 @@ -0,0 +1,90 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt TS2ES 1 +.Os +.Sh NAME +.Nm ts2es +.Nd Extract a program stream from a Transport Stream +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm ts2es +.Fl pid Ar pid | Fl video | audio +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl quiet | q +.Op Fl max Ar max_pkts | Fl m Ar max_pkts +.Op Fl pes | ps +.Ar in_file | Fl stdin +.Ar out_file | Fl stdout +.Sh DESCRIPTION +Extract a single (elementary) program stream from a Transport Stream +(or Program Stream). +.Ss Files +.Bl -tag +.It Ar in_file +is an H.222 Transport Stream file (but see -stdin and -pes) +.It Ar out_file +is a single elementary stream file (but see -stdout) +.El +.Ss Which stream to extract: +.Bl -tag +.It Fl pid Ar pid +Output data for the stream with the given +.Ar pid . +Use +.Fl pid No 0x Ns Ar pid No to specify a hex value +.It Fl video +Output data for the (first) video stream +named in the (first) PMT. This is the default. +.It Fl audio +Output data for the (first) audio stream +named in the (first) PMT +.El +.Ss Switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl stdin +Input from standard input, instead of a file +.It Fl v , Fl verbose +Output extra information about packets +.It Fl q , Fl quiet +Only output error messages +.It Fl max Ar max_pkts , Fl m Ar max_pkts +Maximum number of TS packets to read. +.It Fl pes , ps +Use the PES interface to read ES units from +the input file. This allows PS data to be read +(there is no point in using this for TS data). +Does not support +.Fl pid , stdin No or Fl stdout. +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + diff --git a/docs/mdoc/ts_packet_insert.1 b/docs/mdoc/ts_packet_insert.1 new file mode 100644 index 0000000..e39fd68 --- /dev/null +++ b/docs/mdoc/ts_packet_insert.1 @@ -0,0 +1,75 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt TS_PACKET_INSERT 1 +.Os +.Sh NAME +.Nm ts_packet_insert +.Nd Insert TS packets into a Transport Stream +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm ts_packet_insert +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl p Ar positions +.Op Fl pid Ar pid_no +.Op Fl s string +.Op Fl o Ar out_file +.Ar in_file +.Sh DESCRIPTION +Insert TS packets into a Transport Stream at positions +specified by the user. +.Ss Input +.Bl -tag +.It Ar in_file +An H.222 Transport Stream file. +.El +.Ss Switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl p Ar positions +This a a colon (':') delimited string of numbers +between 0 and 1, representing how far through to put +each TS packet. E.g., -p 0.1:0.4:0.7:0.9 will insert +4 packets at 10%, 40%, 70% and 90% through the file. +.It Fl pid Ar pid_no +The inserted packets will have the PID specfied. +.Bq default = 0x68 +.It Fl s Ar string +The inserted packets will contain +.Ar string +as their payload. +.Bq default = 'Inserted packet' +.It Fl o Ar out_file +The new TS file will be written out with the given name +.Bq default = out.ts +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.Sh EXAMPLES +ts_packet_insert -p 0.3:0.6 -o out.ts -pid 89 -s "AD=start" in.ts +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + diff --git a/docs/mdoc/tsdvbsub.1 b/docs/mdoc/tsdvbsub.1 new file mode 100644 index 0000000..3ea6d5e --- /dev/null +++ b/docs/mdoc/tsdvbsub.1 @@ -0,0 +1,82 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt TSDVBSUB 1 +.Os +.Sh NAME +.Nm tsdvbsub +.Nd Dump DVB subtitling from a stream +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm tsdvbsub +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl quiet | q +.Op Fl max Ar max_pkts | Fl m Ar max_pkts +.Op Fl pid Ar pid_no +.Op Fl prog Ar prog_no +.Ar in_file | Fl stdin +.Sh DESCRIPTION +Parse & dump the contents of a single DVB subtitling stream from a +Transport Stream (or Program Stream). +.Ss Files +.Bl -tag +.It Ar in_file +is an H.222 Transport Stream file (but see +.Fl stdin +and +.Fl pes +below). +.El +.Ss Stream to extract +.Bl -tag +.It Fl pid Ar pid_no +Output data for the stream with the given +.Ar pid_no . +Use -pid 0x to specify a hex value +.Bq default = the stream will be located from the PMT info +.It Fl prog Ar prog_no +Program number +.Bq default = 1 +.El +.Ss general switches +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl v , Fl verbose +Output informational/diagnostic messages +.It Fl q , Fl quiet +Only output error messages +.It Fl stdin +Input from standard input, instead of a file +.It Fl m Ar max_pkts , Fl max Ar max_pkts +Maximum number of TS packets to read +.El +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + diff --git a/docs/mdoc/tsfilter.1 b/docs/mdoc/tsfilter.1 new file mode 100644 index 0000000..27e0b67 --- /dev/null +++ b/docs/mdoc/tsfilter.1 @@ -0,0 +1,62 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt TSFILTER 1 +.Os +.Sh NAME +.Nm tsfilter +.Nd Output a filtered or truncated version of a transport stream +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm tsfilter +.Op Fl verbose | Fl v +.Op Fl i Ar in_file +.Op Fl o Ar out_file +.Op Fl max Ar max_pkts | Fl m Ar max_pkts +.Op Fl \&! | Fl invert +.Ar pid_no Oo Ar pid_no Oc No ... +.Sh DESCRIPTION +Filter the given +.Ar pid_no Ns s +out of stdin and write the result on stdout. +.Bl -tag +.It Fl i Ar in_file +Take input from this file and not stdin. +.It Fl o Ar out_file +Send output to this file and not stdout. +.It Fl v , verbose +Be verbose. +.It Fl m Ar max_pkts, Fl max Ar max_pkts +All packets after the nth are regarded as +not matching any pids. +.It Fl \&! , invert +Invert whatever your decision was before +applying it - the output contains only +pids not in the list up to max packets +and all packets in the input from then +on. +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr esdots 1 , +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + diff --git a/docs/mdoc/tsinfo.1 b/docs/mdoc/tsinfo.1 new file mode 100644 index 0000000..3249e85 --- /dev/null +++ b/docs/mdoc/tsinfo.1 @@ -0,0 +1,71 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt TSINFO 1 +.Os +.Sh NAME +.Nm tsinfo +.Nd get info about the contents of a transport stream +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm tsinfo +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl stdin +.Op Fl verbose | Fl v +.Op Fl max Ar max_scan | Fl m Ar max_scan +.Op Fl repeat Ar PMT_count +.Op Ar file +.Sh DESCRIPTION +Report on the program streams in a Transport Stream. This command just dumps +the initial PAT/PMT pairing. If you want more info on the program streams +within the transport stream then use +.Xr tsreport 1 . +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl stdin +Input from standard input, instead of a file +.It Fl v , Fl verbose +Output extra information about packets +.It Fl m Ar max_scan , Fl max Ar max_scan +.Ar max_qscan +is the Number of TS packets to scan. Defaults to 10000. +.It Fl repeat Ar PMT_count +Look for +.Ar PMT_count +PMT packets, and report on each +.It Ar file +The transport stream file to get info on. If +.Fl stdin +is specified then no +.Ar file +is expected +.El +.\" The following commands should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr tsreport 1 +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + diff --git a/docs/mdoc/tsplay.1 b/docs/mdoc/tsplay.1 new file mode 100644 index 0000000..27fc8bd --- /dev/null +++ b/docs/mdoc/tsplay.1 @@ -0,0 +1,115 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt TSPLAY 1 +.Os +.Sh NAME +.Nm tsplay +.Nd stream a file +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm tsplay +.Fl help +.Op Ar subject +.Nm tsplay +.Op Fl details +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl quiet | q +.Op Fl verbose | v +.Op Fl loop +.Op Fl max Ar max_pkts | Fl m Ar max_pkts +.Op Fl mcastif Ar mcast_if | Fl i Ar mcast_if +.Op Fl tcp | udp +.Ar in_file | Fl stdin +.Ar host Ns Oo : Ns Ar port Oc | +.Fl output Ar out_file | Fl o Ar out_file | Fl stdout +.Sh DESCRIPTION +Act as a server which plays the given file (containing Transport +Stream or Program Stream data). The output is always Transport +Stream. +.Ss Input +.Bl -tag +.It Ar in_file +Input is from the named H.222 TS file. +.It Fl stdin +Input is from standard input. +.El +.Ss Output +.Bl -tag +.It Ar host Ns Op : Ns Ar port +Normally, output is to a named host. If +.Ar port +is not specified, it defaults to 88. +Output defaults to UDP. +.It Fl o Ar out_file , Fl output Ar out_file +Output is to file +.Ar out_file . +.It Fl tcp +Output to the host is via TCP. +.It Fl udp +Output to the host is via UDP. +.Bq default +.It Fl stdout +Output is to standard output. Forces +.Fl quiet No and Fl "err stderr" . +.It Fl i Ar mcast_if , Fl mcastif Ar mcast_if +If output is via UDP, and +.Ar host +is a multicast +address, then +.Ar mcast_if +is the IP address of the network interface to use. This may not be supported +on some versions of Windows. +.El +.Ss General Switches +.Bl -tag +.It Fl details +Print out more detailed help information, +including some less common options. +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl v , Fl verbose +Output additional diagnostic messages +.It Fl q , Fl quiet +Suppress informational and warning messages +.It Fl help +Summarise the +.Ar subject Ns s +that can be specified +.It Fl help Ar subject +Show help on a particular subject +.It Fl m Ar max_pkts , Fl max Ar max_pkts +Maximum number of TS/PS packets to read. +See -details for more information. +.It Fl loop +Play the input file repeatedly. Can be combined with +Fl max . +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr tsinfo 1 , +.Xr pcapreport 1 +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + diff --git a/docs/mdoc/tsreport.1 b/docs/mdoc/tsreport.1 new file mode 100644 index 0000000..9c18c98 --- /dev/null +++ b/docs/mdoc/tsreport.1 @@ -0,0 +1,138 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt TSREPORT 1 +.Os +.Sh NAME +.Nm tsreport +.Nd get info about the streams within a transport stream. +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm tsinfo +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl timing | Fl t +.Op Fl max Ar max_read | Fl m Ar max_read +.Op Fl data +.Ar file | Fl stdin +.Nm tsinfo +.Fl buffering | Fl b +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl verbose | Fl v +.Op Fl quiet | Fl q +.Op Fl max Ar max_read | Fl m Ar max_read +.Op Fl o Ar csv_file Op Fl 32 +.Op Fl cnt +.Op Fl prog Ar prog_no +.Op Fl tfmt Ar time_format +.Op Fl tafmt Ar time_format +.Ar file | Fl stdin +.Nm tsinfo +.Fl justpid Ar pid +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl max Ar max_read | Fl m Ar max_read +.Ar file | Fl stdin +.Sh DESCRIPTION +Report on the streams in a Transport Stream. In general the most +useful inforation is returned by the +.Fl b +option. +.Ss Common options +.Bl -tag +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl v , Fl verbose +Output extra information about packets +.It Fl q , Fl quiet +Output less information +.It Fl m Ar max_scan , Fl max Ar max_scan +.Ar max_scan +is the Number of TS packets to scan. Defaults to the entire file. +.It Fl stdin +Input from standard input, instead of a file +.It Ar file +The transport stream file to get info on. If +.Fl stdin +is specified then no +.Ar file +is expected +.El +.Ss Fl b , Fl buffering +Report on the differences between PCR and PTS, and +between PCR and DTS. This is relevant to the size of +buffers needed in the decoder. Also reports bitrates; +the max bitrate is calculated over 0.5sec +.Bl -tag +.It Fl o Ar csv_file Op Fl 32 +Output timing in to a CSV file called +.Ar csv_file . +If +.Fl 32 +is used as well then the timing ifo is restricted to the bottom 32 bits +.It Fl cnt Ar pid +Check values of continuity_counter for pid +.Ar pid . +Writes all the values of the counter to a file called +.Pa continuity_counter.txt . +.It Fl prog Ar prog_no +Report on program prog_no +.Bq "default = 1" +(hopefully default will be 'all' in the future) +.It Fl tfmt Ar time_format +Specify format of time differences. +.It Fl tafmt Ar time_format +Specify format of absolute times. +.Pp +.Ar time_format +is one of +.Bl -tag +.It Cm 90 +.Bq Default +show as 90KHz timestamps (suffix 't' on the values: e.g., 4362599t). +.It Cm 27 +Show as 27MHz timestamps (similar, e.g., 25151:000t). +.It Cm 32 +Show as 90KHz timestamps, but only the low 32 bits. +.It Cm ms +Show as milliseconds. +.It Cm hms +Show as hours/minutes/seconds (H:MM:SS.ssss, the H +can be more than one digit if necessary) +.El +.El +.Ss Fl justpid Ar pid +Just show data (file offset, index, adaptation field +and payload) for TS packets with the given PID. +PID 0 is allowed (i.e., the PAT) +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr tsinfo 1 , +.Xr pcapreport 1 +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + + diff --git a/docs/mdoc/tsserve.1 b/docs/mdoc/tsserve.1 new file mode 100644 index 0000000..b18415a --- /dev/null +++ b/docs/mdoc/tsserve.1 @@ -0,0 +1,124 @@ +.\" The following commands are required for all man pages. +.Dd October 28, 2015 +.Dt TSSERVE 1 +.Os +.Sh NAME +.Nm tsserve +.Nd get info about the streams within a transport stream +.\" This next command is for sections 2 and 3 only. +.\" .Sh LIBRARY +.Sh SYNOPSIS +.Nm tsserve +.Op Fl details +.Op Fl "err stdout" +.Op Fl "err stderr" +.Op Fl quiet | q +.Op Fl verbose | v +.Op Fl port Ar port_no +.Op Fl noaudio +.Op Fl pad Ar filler_pkts +.Op Fl noseqhdr +.Op Fl prepeat Ar pat_freq +.Op Fl h264 | avc | h262 +.Op Fl dolby Cm dvb | atsc +.Op Fl 0 +.Ar file0 +.Op Fl 1 Ar file1 +.Op Fl 2 Ar file2 +.Ns ... +.Sh DESCRIPTION +Act as a server which plays the given file (containing Transport +Stream or Program Stream data). The output is always Transport +Stream. +.Ss Input: +.Bl -tag +.It Ar infile +An H.222.0 TS or PS file to serve to the client. +This will be treated as file 0 (see below). +.It Fl 0 Ar file0 No .. Fl 9 Ar file9 +Specify files 0 through 9, selectable with command +characters 0 through 9. The lowest numbered file +will be the default for display. +.El +.Ss General Switches: +.Bl -tag +.It Fl details +Print out more detailed help information, +including some less common options. +.It Fl "err stdout" +Write error messages to standard output (the default) +.It Fl "err stderr" +Write error messages to standard error (Unix traditional) +.It Fl v , Fl verbose +Output additional diagnostic messages +.It Fl q , Fl quiet +Suppress informational and warning messages +.It Fl port Ar port_no +Listen for a client on port +.Ar port_no +.Bq default = 88 +.It Fl noaudio +Ignore any audio data +.It Fl pad Ar filler_pkts +Pad the start of the output with +.Ar filler_pkts +filler TS packets, to allow the client to synchronize with +the datastream. +.Bq default = 8 +.It Fl noseqhdr +Do not output sequence headers for fast forward/reverse +data. Only relevant to H.262 data. +.El +.Ss Program Stream Switches: +.Bl -tag +.It Fl prepeat Ar pat_freq +Output the program data (PAT/PMT) after every +.Ar pat_freq +PS packs. +.Bq default = 100 +.It Fl h264 , avc +Force the program to treat the input as MPEG-4/AVC. +.It Fl h262 +Force the program to treat the input as MPEG-2. +.El +Both of these affect the stream type of the output data. +.Pp +If the audio stream being output is Dolby (AC-3), then the stream type +used to output it differs for DVB (European) and ATSC (USA) data. It +may be specified as follows: +.Bl -tag +.It Fl dolby Cm dvb +Use stream type 0x06. +.Bq default +.It Fl dolby Cm atsc +Use stream type 0x81 +.El +.Pp +For information on using the program in other modes, see +.Fl details. +.\" The following cnds should be uncommented and +.\" used where appropriate. +.\" .Sh IMPLEMENTATION NOTES +.\" This next command is for sections 2, 3 and 9 function +.\" return values only. +.\" .Sh RETURN VALUES +.\" This next command is for sections 1, 6, 7 and 8 only. +.\" .Sh ENVIRONMENT +.\" .Sh FILES +.\" .Sh EXAMPLES +.\" This next command is for sections 1, 6, 7, 8 and 9 only +.\" (command return values (to shell) and +.\" fprintf/stderr type diagnostics). +.\" .Sh DIAGNOSTICS +.\" .Sh COMPATIBILITY +.\" This next command is for sections 2, 3 and 9 error +.\" and signal handling only. +.\" .Sh ERRORS +.Sh SEE ALSO +.Xr tsinfo 1 , +.Xr pcapreport 1 +.\" .Sh STANDARDS +.\" .Sh HISTORY +.\" .Sh AUTHORS +.\" .Sh BUGS + diff --git a/pcapreport.c b/pcapreport.c index b83af21..63e64bd 100644 --- a/pcapreport.c +++ b/pcapreport.c @@ -1425,6 +1425,8 @@ static void print_usage() " -skew-discontinuity-threshold \n" " -skew Gives the skew discontinuity threshold in 90kHz units.\n" " A value of 0 disables this. [default = 6*90000]\n" + " -split-section Split extracted streams into multiple files on section\n" + " (discontinutity) boundries\n" "\n" " -err stdout Write error messages to standard output (the default)\n" " -err stderr Write error messages to standard error (Unix traditional)\n" diff --git a/rtp2264.c b/rtp2264.c index 099e3eb..213077f 100644 --- a/rtp2264.c +++ b/rtp2264.c @@ -1,281 +1,301 @@ -/* - * Report on a pcap (.pcap) file. - * - * 2008-09-05 - * - * ***** BEGIN LICENSE BLOCK ***** - * Version: MPL 1.1 - * - * The contents of this file are subject to the Mozilla Public License Version - * 1.1 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * http://www.mozilla.org/MPL/ - * - * Software distributed under the License is distributed on an "AS IS" basis, - * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License - * for the specific language governing rights and limitations under the - * License. - * - * The Original Code is the MPEG TS, PS and ES tools. - * - * The Initial Developer of the Original Code is Amino Communications Ltd. - * Portions created by the Initial Developer are Copyright (C) 2008 - * the Initial Developer. All Rights Reserved. - * - * Contributor(s): - * Richard Watts, Kynesim - * - * ***** END LICENSE BLOCK ***** - */ - -// H.264 over RTP is defined in RFC3984 - -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef _WIN32 -#include -#endif // _WIN32 - -#include "compat.h" -#include "version.h" -#include "misc_fns.h" -#include "fmtx.h" - -#define RTP_HDR_LEN 8 - -#define RTP_PREFIX_STRING "RTP " -#define RTP_PREFIX_LEN 4 -#define RTP_LEN_OFFSET 4 - -static int c642b(const char c) -{ - return (c >= 'A' && c <= 'Z') ? c - 'A' : - (c >= 'a' && c <= 'z') ? c - 'a' + 26 : - (c >= '0' && c <= '9') ? c - '0' + 52 : - (c == '+' || c == '-') ? 62 : - (c == '/' || c == '_') ? 63 : - (c == '=') ? -1 : -2; -} - -static size_t b64str2binn(byte * const dest0, const size_t dlen, const char ** const plast, const char * src) -{ - byte * dest = dest0; - uint32_t a = 0; - ssize_t i = 4; - size_t slen = (dlen * 4 + 5) / 3; - int b; - - while ((b = c642b(*src++)) >= 0 && --slen != 0) - { - a = (a << 6) | b; - if (--i == 0) - { - *dest++ = (a >> 16) & 0xff; - *dest++ = (a >> 8) & 0xff; - *dest++ = a & 0xff; - i = 4; - } - } - - // Tidy up at the end - if (i < 3) // i == 4 good, all done, i == 3 error - { - a <<= i * 6; - *dest++ = (a >> 16) & 0xff; - - // Consume '=' - if (b == -1) - b = c642b(*src++); - - if (i == 1) - { - *dest++ = (a >> 8) & 0xff; - } - else if (b == -1) - ++src; - } - - if (plast != NULL) - *plast = src - 1; - - return dest - dest0; -} - - -int main(int argc, char **argv) -{ - FILE *f_in = NULL; - FILE *f_out = NULL; - const char * fname_in; - const char * fname_out; - int zcount = 0; - - if (argc < 3) - { - fprintf(stderr, "Usage: \n"); - return 1; - } - - fname_in = argv[1]; - fname_out = argv[2]; - - if ((f_in = fopen(fname_in, "rb")) == NULL) - { - perror(argv[1]); - return 1; - } - - if ((f_out = fopen(fname_out, "wb")) == NULL) - { - perror(argv[2]); - return 1; - } - - if (argc > 3) - { - byte psbuf[0x1000]; - const char * eo64 = argv[3]; - - psbuf[0] = 0; - psbuf[1] = 0; - psbuf[2] = 0; - psbuf[3] = 1; - - do - { - size_t len = b64str2binn(psbuf + 4, sizeof(psbuf) - 4, &eo64, eo64); - - if ((*eo64 != 0 && *eo64 != ',') || len == 0) - { - fprintf(stderr, "Bad B64 string: '%s' (len=%zd, chr=%d)\n", argv[3], len, *eo64); - exit(1); - } - - if (fwrite(psbuf, len + 4, 1, f_out) != 1) - { - perror(fname_out); - exit(1); - } - } while (*eo64++ == ','); - } - - for (;;) - { - byte buf[0x10000]; - uint32_t rtplen; - - if (fread(buf, RTP_HDR_LEN, 1, f_in) != 1) - { - if (ferror(f_in)) - perror(fname_in); - break; - } - if (memcmp(buf, RTP_PREFIX_STRING, RTP_PREFIX_LEN) != 0) - { - fprintf(stderr, "### Bad RTP prefix\n"); - break; - } - rtplen = uint_32_be(buf + RTP_LEN_OFFSET); - if (rtplen > sizeof(buf) || rtplen < 12) - { - fprintf(stderr, "### Bad RTP len: %" PRIu32 "\n", rtplen); - break; - } - - if (fread(buf, rtplen, 1, f_in) != 1) - { - if (ferror(f_in)) - perror(fname_in); - else - fprintf(stderr, "### Unexpected EOF\n"); - break; - } - - { - size_t offset = 12 + (buf[0] & 0xf) * 4; - size_t padlen = ((buf[0] & 0x20) != 0) ? buf[rtplen - 1] : 0; - - // Check for extension - if ((buf[0] & 0x10) != 0) // X bit - offset += 4 + uint_16_be(buf + offset + 2); - - if (rtplen < offset + padlen + 1) - { - fprintf(stderr, "### Bad RTP offset + padding\n"); - } - - // OK - got payload - - { - const byte * p = buf + offset; - const byte * p_end = buf + rtplen - padlen; - byte buf2[0x18000]; // Allow for max expansion - byte * q = buf2; - byte sc1 = *p++; - - if ((sc1 & 0x1f) == 28) - { - byte sc2 = *p++; - if ((sc2 & 0x80) != 0) // S bit - { - // Start of fragmented unit - sc1 = (sc1 & 0xe0) | (sc2 & 0x1f); - *q++ = 0; - *q++ = 0; - *q++ = 0; - *q++ = 1; - *q++ = sc1; - zcount = 0; - - printf("Fragmented block with code: %x\n", sc1); - } - } - else - { - // Normal start code - *q++ = 0; - *q++ = 0; - *q++ = 0; - *q++ = 1; - *q++ = sc1; - zcount = 0; - printf("Start block with code: %x\n", sc1); - } - - - // Engage emulation protect - while (p < p_end) - { - const byte b = *p++; - - if (zcount == 2 && b <= 3) - { - *q++ = 3; - zcount = 0; - } - - *q++ = b; - zcount = (b == 0) ? zcount + 1 : 0; - } - - if (fwrite(buf2, q - buf2, 1, f_out) != 1) - { - perror(fname_out); - exit(1); - } - } - } - - } - - fclose(f_out); - fclose(f_in); - return 0; -} - +/* + * Filter a transport stream by a list of pids. + * + * ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is the MPEG TS, PS and ES tools. + * + * The Initial Developer of the Original Code is Amino Communications Ltd. + * Portions created by the Initial Developer are Copyright (C) 2008 + * the Initial Developer. All Rights Reserved. +* + * Contributor(s): + * Amino Communications Ltd, Swavesey, Cambridge UK + * + * ***** END LICENSE BLOCK ***** + */ + +// H.264 over RTP is defined in RFC3984 + +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef _WIN32 +#include +#endif // _WIN32 + +#include "compat.h" +#include "version.h" +#include "misc_fns.h" +#include "fmtx.h" + +#define RTP_HDR_LEN 8 + +#define RTP_PREFIX_STRING "RTP " +#define RTP_PREFIX_LEN 4 +#define RTP_LEN_OFFSET 4 + +static int c642b(const char c) +{ + return (c >= 'A' && c <= 'Z') ? c - 'A' : + (c >= 'a' && c <= 'z') ? c - 'a' + 26 : + (c >= '0' && c <= '9') ? c - '0' + 52 : + (c == '+' || c == '-') ? 62 : + (c == '/' || c == '_') ? 63 : + (c == '=') ? -1 : -2; +} + +static size_t b64str2binn(byte * const dest0, const size_t dlen, const char ** const plast, const char * src) +{ + byte * dest = dest0; + uint32_t a = 0; + ssize_t i = 4; + size_t slen = (dlen * 4 + 5) / 3; + int b; + + while ((b = c642b(*src++)) >= 0 && --slen != 0) + { + a = (a << 6) | b; + if (--i == 0) + { + *dest++ = (a >> 16) & 0xff; + *dest++ = (a >> 8) & 0xff; + *dest++ = a & 0xff; + i = 4; + } + } + + // Tidy up at the end + if (i < 3) // i == 4 good, all done, i == 3 error + { + a <<= i * 6; + *dest++ = (a >> 16) & 0xff; + + // Consume '=' + if (b == -1) + b = c642b(*src++); + + if (i == 1) + { + *dest++ = (a >> 8) & 0xff; + } + else if (b == -1) + ++src; + } + + if (plast != NULL) + *plast = src - 1; + + return dest - dest0; +} + + +static void usage(void) +{ + print_msg( + "Usage: rtp2264 [[,...]]\n" + "\n"); + REPORT_VERSION("rtp2264"); + print_msg( + "\n" + " Take a RTP file (probably generated by pcapreport) containing\n" + " an H.264 stream and convert it into an Annex B encoded .264\n" + " elementary stream file.\n" + "\n" + " If s are specified then they are one or more\n" + " B64 encoded blocks containing SPS or PPS or other similar headers.\n" + " These will each have a 00 00 00 01 sequence added at the start and\n" + " then written at the start of \n" + "\n" + "Switches:\n" + " none\n" + ); + exit(1); +} + +int main(int argc, char **argv) +{ + FILE *f_in = NULL; + FILE *f_out = NULL; + const char * fname_in; + const char * fname_out; + int zcount = 0; + + if (argc < 3) + { + usage(); + } + + fname_in = argv[1]; + fname_out = argv[2]; + + if ((f_in = fopen(fname_in, "rb")) == NULL) + { + perror(argv[1]); + return 1; + } + + if ((f_out = fopen(fname_out, "wb")) == NULL) + { + perror(argv[2]); + return 1; + } + + if (argc > 3) + { + byte psbuf[0x1000]; + const char * eo64 = argv[3]; + + psbuf[0] = 0; + psbuf[1] = 0; + psbuf[2] = 0; + psbuf[3] = 1; + + do + { + size_t len = b64str2binn(psbuf + 4, sizeof(psbuf) - 4, &eo64, eo64); + + if ((*eo64 != 0 && *eo64 != ',') || len == 0) + { + fprintf(stderr, "Bad B64 string: '%s' (len=%zd, chr=%d)\n", argv[3], len, *eo64); + exit(1); + } + + if (fwrite(psbuf, len + 4, 1, f_out) != 1) + { + perror(fname_out); + exit(1); + } + } while (*eo64++ == ','); + } + + for (;;) + { + byte buf[0x10000]; + uint32_t rtplen; + + if (fread(buf, RTP_HDR_LEN, 1, f_in) != 1) + { + if (ferror(f_in)) + perror(fname_in); + break; + } + if (memcmp(buf, RTP_PREFIX_STRING, RTP_PREFIX_LEN) != 0) + { + fprintf(stderr, "### Bad RTP prefix\n"); + break; + } + rtplen = uint_32_be(buf + RTP_LEN_OFFSET); + if (rtplen > sizeof(buf) || rtplen < 12) + { + fprintf(stderr, "### Bad RTP len: %" PRIu32 "\n", rtplen); + break; + } + + if (fread(buf, rtplen, 1, f_in) != 1) + { + if (ferror(f_in)) + perror(fname_in); + else + fprintf(stderr, "### Unexpected EOF\n"); + break; + } + + { + size_t offset = 12 + (buf[0] & 0xf) * 4; + size_t padlen = ((buf[0] & 0x20) != 0) ? buf[rtplen - 1] : 0; + + // Check for extension + if ((buf[0] & 0x10) != 0) // X bit + offset += 4 + uint_16_be(buf + offset + 2); + + if (rtplen < offset + padlen + 1) + { + fprintf(stderr, "### Bad RTP offset + padding\n"); + } + + // OK - got payload + + { + const byte * p = buf + offset; + const byte * p_end = buf + rtplen - padlen; + byte buf2[0x18000]; // Allow for max expansion + byte * q = buf2; + byte sc1 = *p++; + + if ((sc1 & 0x1f) == 28) + { + byte sc2 = *p++; + if ((sc2 & 0x80) != 0) // S bit + { + // Start of fragmented unit + sc1 = (sc1 & 0xe0) | (sc2 & 0x1f); + *q++ = 0; + *q++ = 0; + *q++ = 0; + *q++ = 1; + *q++ = sc1; + zcount = 0; + + printf("Fragmented block with code: %x\n", sc1); + } + } + else + { + // Normal start code + *q++ = 0; + *q++ = 0; + *q++ = 0; + *q++ = 1; + *q++ = sc1; + zcount = 0; + printf("Start block with code: %x\n", sc1); + } + + + // Engage emulation protect + while (p < p_end) + { + const byte b = *p++; + + if (zcount == 2 && b <= 3) + { + *q++ = 3; + zcount = 0; + } + + *q++ = b; + zcount = (b == 0) ? zcount + 1 : 0; + } + + if (fwrite(buf2, q - buf2, 1, f_out) != 1) + { + perror(fname_out); + exit(1); + } + } + } + + } + + fclose(f_out); + fclose(f_in); + return 0; +} +