비디오 스트림을 mp4 파일로 저장하는 방법에 대해서는 상당히 혼란 스럽습니다. 나는 ffmpeg를 사용하고있다. 나에게 문제를 설명하자 : 나는 avformat_open_input (와 RTSP (H.264 스트림)를 통해 네트워크 카메라에 연결네트워크 카메라 (RTSP)에서 mp4 파일로 프레임 저장
- )를 avformat_find_stream_info(), av_read_play(), 나는 av_read_frame와 프레임 수().
- av_read_frame()이있는 프레임을 얻을 때마다 해당 AVPacket을 순환 버퍼에 저장합니다.
- 내 응용 프로그램의 일부 지점에서이 순환 버퍼의 범위가 선택됩니다. 나는 시작하는 데 사용되는 키 프레임을 찾는다.
- 키 프레임에서 시작하는 AVPacket의 목록이 있으면 코드에서 설명한대로 헤더, 프레임 및 꼬리를 씁니다.
문제는 VLC, Windows Media Player 또는 다른 것을 사용하여 볼 때 생성되는 mp4 비디오에 인공물이 있다는 것입니다.
또한 패킷의 pts는 연속적이지 않고 dts는 연속적이라는 것을 깨달았습니다. 나는 B 프레임에 대해 알고 있지만 이것이 내 문제인가?
// Prepare the output
AVFormatContext* oc = avformat_alloc_context();
oc->oformat = av_guess_format(NULL, "video.mp4", NULL);
// Must write header, packets, and trailing
avio_open2(&oc->pb, "video.mp4", AVIO_FLAG_WRITE, NULL, NULL);
// Write header
AVStream* stream = avformat_new_stream(oc, (AVCodec*) context->streams[video_stream_index]->codec->codec);
avcodec_copy_context(stream->codec, context->streams[video_stream_index]->codec);
stream->sample_aspect_ratio = context->streams[video_stream_index]->codec->sample_aspect_ratio;
avformat_write_header(oc, NULL);
// FOR EACH FRAME...
... av_write_frame(oc, circular[k]); ...
// Write trailer and close the file
av_write_trailer(oc);
avcodec_close(stream->codec);
avio_close(oc->pb);
avformat_free_context(oc);
는
참고로 rtmpdump를 보거나 (심지어 librtmp를 직접 사용해도됩니다) - http://rtmpdump.mplayerhq.hu/ – benjymous