<html><head><style>pre,code,address {
margin: 0px;
}
h1,h2,h3,h4,h5,h6 {
margin-top: 0.2em;
margin-bottom: 0.2em;
}
ol,ul {
margin-top: 0em;
margin-bottom: 0em;
}
blockquote {
margin-top: 0em;
margin-bottom: 0em;
}
</style></head><body><div>Hi,</div><div><br></div><div>Le dimanche 02 juillet 2023 à 23:40 -0400, Judemir Ribeiro via gstreamer-devel a écrit :</div><blockquote type="cite" style="margin:0 0 0 .8ex; border-left:2px #729fcf solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default">Hello,</div><div class="gmail_default"><br></div><div class="gmail_default">I created a few videos using a wrong pipeline and now I dont know how to read the streams to recover them.</div><div class="gmail_default"><br></div><div class="gmail_default">The pipeline was:</div><div class="gmail_default"><br></div><div class="gmail_default"><pre style="margin-top:0px;border:0px;font-variant-numeric:inherit;font-variant-east-asian:inherit;font-variant-alternates:inherit;font-stretch:inherit;font-kerning:inherit;font-feature-settings:inherit;vertical-align:baseline;box-sizing:inherit;width:auto;max-height:600px;overflow:auto"><code style="margin:0px;padding:0px;border:0px;font-style:inherit;font-variant:inherit;font-weight:inherit;font-stretch:inherit;line-height:inherit;font-kerning:inherit;font-feature-settings:inherit;vertical-align:baseline;box-sizing:inherit;background-color:transparent;white-space:inherit;border-radius:0px">libcamera-vid -t 0 -n -o - | gst-launch1.0 fdsrc fd=0 ! h264parse config-interval=-1 ! tee name=output .output ! queue ! rtph264pay ! udpsink host=127.0.0.1 port=5600 .output ! queue ! filesink location=/video/$(date).h264
</code></pre>As we can see I created the tee after the h264parse step, when it should have been before. </div><div class="gmail_default"><br></div><div class="gmail_default">How can I convert these files back to h264 streams? I have tried ffmpeg, and other programs but nothing can recognize the files dumped by this wrong pipeline.</div></div></blockquote><div><br></div><div>Looking at <span style="font-style: inherit; font-variant-caps: inherit; white-space: inherit;">rtph264pay, AVC is placed before Byte Stream (the usual file format). In short, I suspect that the file is made of AVCc NALs (size of nal header instead of startcodes/0x000001). I simulated that, and its a bit hard to recover. Some work on h264parse would be needed to make this work inside gst-launch-1.0. Please find attached a python script to help with your task. Please follow the procedure:<br><br>1. Find the original codec_data</span></div><div><span style="font-style: inherit; font-variant-caps: inherit; white-space: inherit;"><br></span></div><div><span style="font-style: inherit; font-variant-caps: inherit; white-space: inherit;">For this, rerun the "</span><span style="font-style: inherit; font-variant-caps: inherit; white-space: inherit;">libcamera-vid -t 0 -n -o - | gst-launch1.0 fdsrc..." pipeline but add the -v option. Look for </span><span style="font-style: inherit; font-variant-caps: inherit; white-space: inherit;"><br>"codec_data=(buffer)<somebighex>" and same that. This is the stream headers, they will always be the same for the same source/sensor/pipeline, but they are not being saved in your erroneous pipeline.</span></div><div><br></div><div>2. Run the recovery script provided, a file called fixed.h264 will be created</div><div><br></div><pre>python3 recover.py <avc_filename> <codec_data></pre><div><br></div><div>In my test, I produced a bad file this way:</div><div><br></div><pre>gst-launch-1.0 videotestsrc num-buffers=1000 ! video/x-raw,format=I420 ! x264enc tune=zerolatency ! h264parse ! tee name=t t. ! queue ! rtph264pay ! fakesink t. ! queue ! filesink location=test.avc -v<br>python3 recover.py test.avc 01640014ffe1001d67640014acb20283f602d418181a94000003000400000300f23c50a92001000568ebccb22c</pre><pre><br></pre><div>regards,</div><div>Nicolas</div><div><br></div><div>p.s. for those who want to know, but don't want to open the script, the recovery pipeline is:<br><br><pre>f"appsrc name=src block=true caps=\"video/x-h264,stream-format=(string)avc,codec_data=(buffer){codec_data}\"" +</pre><pre> " ! h264parse ! video/x-h264,stream-format=(string)byte-stream ! filesink location=fixed.h264"</pre><pre><br></pre><div>And the script just push the data using python API into appsrc. The difference with that and filesrc, is that appsrc will push a caps event, which properly signals AVCc, codec_data and no alignment to h264parse. If anyone have suggestion on how to fix this, one way could be to introduce a caps properly to filesrc, like udpsrc has.</div></div><div><span></span></div></body></html>