<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Feb 10, 2022 at 1:14 AM John Regan via Libav-user <<a href="mailto:libav-user@ffmpeg.org">libav-user@ffmpeg.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi there, I was hoping somebody could offer advice on how to loop a<br>
video with libavformat/libavcodec.<br>
<br>
I have a filter graph created, so my core decoding code is basically:<br>
<br>
if( (err = av_read_frame(inputCtx, packet)) < 0) {<br>
    if(err != AVERROR_EOF) {<br>
        /* handle errors, return */<br>
    }<br>
    avformat_seek_file(inputCtx,videoStreamIndex, 0, 0, 0, 0));<br>
    avcodec_flush_buffers(codecCtx);<br>
}<br>
<br>
if(packet.stream_index == videoStreamIndex) {<br>
    avcodec_send_packet(codecCtx,packet);<br>
    avcodec_receive_frame(codecCtx,tmpFrame);<br>
    av_buffersrc_write_frame(bufferSrcCtx,tmpFrame);<br>
    if(av_buffersink_get_frame(bufferSinkCrx,frame) >= 0) {<br>
        /* we have a frame */<br>
    }<br>
}<br>
<br>
I'm not sure if there's steps that need to be taken to reset the filter<br>
graph? Like is there a timestamp discontinuity?<br>
<br>
It seems like this should work - but I'm missing something, it seems<br>
like the buffersink_get_frame stops producing frames after I reset.<br>
<br>
Thank you in advance,<br>
-John<br>
_______________________________________________<br>
Libav-user mailing list<br>
<a href="mailto:Libav-user@ffmpeg.org" target="_blank">Libav-user@ffmpeg.org</a><br>
<a href="https://ffmpeg.org/mailman/listinfo/libav-user" rel="noreferrer" target="_blank">https://ffmpeg.org/mailman/listinfo/libav-user</a><br>
<br>
To unsubscribe, visit link above, or email<br>
<a href="mailto:libav-user-request@ffmpeg.org" target="_blank">libav-user-request@ffmpeg.org</a> with subject "unsubscribe".<br>
</blockquote></div><br clear="all"><div>Hello,</div><div><br></div><div>I dont think you need to reset the filter graph, in the end it simply takes in AVFrame* and does some processing. Timestamps in filters are only changed if you specify a different timebase for the filters (as far as I am aware). But timestamp discontinuity is something you have to take care of. For example you could generate them by using this formula</div><div><br></div><div>frame_timestamp = iteration_count * max_timestamp + current_frame_timestamp </div><div><br></div><div>max_timestamp is the last timestamp of the video stream. </div><div>This should enable you to get a looped sequence of frames that can be properly played. On the other hand, check if you are actually getting a frame from your decoder by saving it to a PGM file. Here is the code</div><div><br></div>static void pgm_save(unsigned char* buf, int wrap, int xsize, int ysize, const char* filename)<br>{<br><blockquote style="margin:0 0 0 40px;border:none;padding:0px">FILE* f;<br>int i;</blockquote><br><blockquote style="margin:0 0 0 40px;border:none;padding:0px">f = fopen(filename, "w");<br>fprintf(f, "P5\n%d %d\n%d\n", xsize, ysize, 255);<br>for (i = 0; i < ysize; i++)<br></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><blockquote style="margin:0 0 0 40px;border:none;padding:0px">fwrite(buf + i * wrap, 1, xsize, f);</blockquote></blockquote><blockquote style="margin:0 0 0 40px;border:none;padding:0px">fclose(f);</blockquote>}<div><br></div><div>-- <br><div dir="ltr" class="gmail_signature"><br>Regards<br>Strahinja Radman</div></div></div>