Hello. I am trying to implement some kind of seeking mechanism in H.264 files<br>without any container, just raw H.264 stream. I have some troubles with it.<br><br>1) Problem #1. I am using ffmpeg to cut let's say 143 frames from video in this way:<br>
<br>ffmpeg -i source.h264 -vcodec libx264 -b 1200k -r 30 -vframes 143 result.h264<br><br>It works without any problems. After that i'm getting all frames in pictures from obtained file<br><br>ffmpeg -i result.h264 -vcodec mjpeg img%03d.jpg<br>
<br>It works also fine, but after this i get set of images with names img001.jpg - ... - img142.jpg.<br>So i have 142 images instead of 143. Where is last( or first ) one?<br><br>2) Problem #2. I am trying to get amount of frames in the video using <br>
<div style="margin-left: 40px;">while( av_read_frame( this->pFormatContext, &this->packet ) == 0 )<br><div style="margin-left: 40px;">amount_of_frames++;<br></div></div>In this way i get amount_of_frames = 143 for the previous example. But i'm not sure <br>
about what should i use to get byte position in the file. Does AVPacket packet.pos points <br>to the proper position in the file, so i can use it for calling av_seek_frame? Will it properly<br>take me to the desired position of frame beginning? I'm curious because if i call<br>
avcodec_decode_video2() immediately after av_read_frame, when packet.pos equals 0 <br>( i think, it's start of file ), then 3rd parameter *got_picture_ptr stays equal to zero meaning<br>that no frame could be decompressed.<br>
<br>I need byte positions to create frame index without actual decoding the whole video. After that <br>i should be able to jump through it using av_seek_frame. If it is bad approach for some reason,<br>please give me an advice to the better solution. Thank you.<br>
<em><br></em>