Recover H264 encoded ts segments that dont have PPS/SPS

Nicolas Dufresne nicolas at ndufresne.ca
Wed May 3 19:47:18 UTC 2023


Le mercredi 03 mai 2023 à 10:22 -0700, Guru Govindan via gstreamer-devel a
écrit :
> Hi There,
> I am having an issue where a lot of video footage from a security camera was
> recorded without the sprop-parameters-set (SPS/PPS).
> 
> I am unable to play or transcode these ts files as it does not have SPS/PPS
> values. 
> 
> I tried the following by sending the h264parse the stream format but that
> failed

The only way to recover is to find the origin SPS/PPS, note, this is static on
most cameras. The sprop-parameters contains it, just it may need to be
transformed. Then something like this may work, but never tried`

gst-launch-1.0 \
  filesrc location=truncated.ts ! tsdemux ! filesink location=truncated.h264
cat recovered-header.h264 > fixed.h264
cat truncated.h264 >> fixed.h264
gst-launch-1.0 \
  filesrc location=fixed.h264 ! h264parse ! mpegtsmux ! filesink
location=fixed.ts

This is video only though, totally untested.

Nicolas

> 
> ```
> gst-launch-1.0 -v filesrc location=2.ts ! tsparse ! tsdemux name=demux demux.
> ! queue ! h264parse ! video/x-h264,stream-format=avc,alignment=au ! decodebin
> ! videoconvert ! vaapih264enc ! h264parse ! mpegtsmux alignment=-1 ! filesink
> location=output.ts
> ```
> failed with /
> GstPipeline:pipeline0/GstH264Parse:h264parse0.GstPad:sink: caps = video/x-
> h264, stream-format=(string)byte-stream
> ERROR: from element /GstPipeline:pipeline0/GstH264Parse:h264parse0: No valid
> frames found before end of stream
> 
> I then tried to split it as per keyframes and then mux it.. like below but
> that failed as well
> 
> ```
> gst-launch-1.0 -v filesrc location=2.ts ! tsdemux name=demux ! h264parse !
> splitmuxsink max-size-time=1000000000 location=segment%02d.ts mpegtsmux
> name=mux ! filesink location=output.ts demux.video_0 ! queue ! mux.
> ```
> failed with h264parse0: No valid frames found before end of stream
> 
> Since it could not find EOS.. I thoiught of sending the entire manifest.. but
> that didnt work as well
> 
> ```
> gst-launch-1.0 -v filesrc location="<manifest uri>" ! hlsdemux ! h264parse !
> video/x-h264,stream-format='(string)avc,alignment=(string)au' ! mpegtsmux !
> h264parse config-interval=-1 ! mpegtsmux ! filesink location=output.ts
> ```
> 
> Just like how we can add config-interval to a rtp stream, is there a way to
> add it to a ts segment?
> 
> Best Regards,
> Guru
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20230503/98732481/attachment-0001.htm>


More information about the gstreamer-devel mailing list