먼저 멀티미디어 파일 (예 : test.mp4 파일, 비디오 코덱 ID는 H264)을 디코딩 한 후 비디오 스트림과 오디오 마지막으로 비디오 스트림 (libx264 사용)과 오디오 스트림을 결과 파일 (result.mp4)로 인코딩합니다. 효율을 높이기 위해, 비디오 스트림의 디코드 및 인코딩을 생략하고 "av_read_frame"함수를 통해 비디오 패킷을 얻은 다음 함수 "av_write_frame"을 통해 결과 파일로 직접 출력합니다. 그러나 출력 파일에는 그림이 없으며 출력 파일의 크기는 매우 작습니다. 어떻게하면 libavformat을 통해 MP4 파일로 H264 스트림을 멀티플렉싱 할 수 있습니까?
난 등 (FFmpeg에 코드를 추적하는 기능 "av_write_frame-> mov_write_packet-> ff_mov_write_packet"은 함수 "ff_avc_parse_nal_units"를 호출에서 NAL 유닛의 크기를 구하는 것으로했지만 반환 값은 매우 작다 208 바이트).내가 MP4 파일의 H264 스트림이 부속서 B의 형식으로 저장되지 않는 것을 발견, 그래서 코드 (0x000001)를 시작 찾을 수없는, 지금 내 문제는 내가-B 부속서하기 위해 H264 스트림을 변경하는 방법입니다 ? 형식은, 내가 수동으로 모든 프레임의 시작 부분에 코드를 시작 추가 가 작동하게,하지만 여전히 작동하지
누군가가 나에게 어떤 힌트를 줄 수 있습니다 감사합니다 매우 을 내 유사한 코드이다 다음.?. :
// write the stream header, if any
av_write_header(pFormatCtxEnc);
.........
/**
* Init of Encoder and Decoder
*/
bool KeyFlag = false;
bool KeyFlagEx = false;
// Read frames and save frames to disk
int iPts = 1;
av_init_packet(&packet);
while(av_read_frame(pFormatCtxDec, &packet)>=0)
{
if (packet.flags == 1)
KeyFlag = true;
if (!KeyFlag)
continue;
if (m_bStop)
{
break;
}
// Is this a packet from the video stream?
if(packet.stream_index == videoStream)
{
currentframeNum ++;
if (progressCB != NULL && currentframeNum%20 == 0)
{
float fpercent = (float)currentframeNum/frameNum;
progressCB(fpercent,m_pUser);
}
if (currentframeNum >= beginFrame && currentframeNum <= endFrane)
{
if (packet.flags == 1)
KeyFlagEx = true;
if (!KeyFlagEx)
continue;
packet.dts = iPts ++;
av_write_frame(pFormatCtxEnc, &packet);
}
}
// Free the packet that was allocated by av_read_frame
}
// write the trailer, if any
av_write_trailer(pFormatCtxEnc);
/**
* Release of encoder and decoder
*/
return true;
'FFmpeg'의'MP4' 멀티플렉서는 시작 코드가 있거나없는 스트림 모두를 허용하도록 설정할 수 있습니다. 초기 NAL은 일반적으로 매개 변수 집합이며 작은 수는 가능합니다. 'av_write_frame'은 옳은 일입니다. 당신의 코드는 무엇입니까? 어쩌면 누군가가 문제를 느낄 것입니다. –
감사합니다. ffmpeg의 MP4 멀티플렉서를 시작 코드없이 스트림을 허용하도록 설정하는 방법은 무엇입니까? 몇 가지 특수 매개 변수를 설정해야합니까? 위 코드는 my와 비슷한 코드입니다. "ff_avc_parse_nal_units"함수의 반환 값은 모든 프레임에 대해 거의 0이며 대부분의 프레임은 아무 것도 출력하지 않습니다. – Brian