ireader / media-server

RTSP/RTP/RTMP/FLV/HLS/MPEG-TS/MPEG-PS/MPEG-DASH/MP4/fMP4/MKV/WebM
MIT License
3.12k stars 1.09k forks source link

h264+g711a封装为mpeg-ps #319

Closed Hyatt-Zhong closed 11 months ago

Hyatt-Zhong commented 11 months ago

大佬你好,我封装ps,g711音频无法被一些ffplay和分析工具检测 下面是代码 ` int main() { struct ps_muxer_func_t handler; handler.alloc = ps_alloc; handler.write = ps_write; handler.free = ps_free;

FILE* fp = fopen("avps.ps", "wb");
struct ps_muxer_t* ps = ps_muxer_create(&handler, fp);
int v_id=ps_muxer_add_stream(ps,PSI_STREAM_H264,0,0);
int a_id=ps_muxer_add_stream(ps,PSI_STREAM_AUDIO_G711A,0,0);
// int a_id=ps_muxer_add_stream(ps,PSI_STREAM_MPEG4_AAC,0,0);

FILE *vfp = fopen("VFrames.file", "rb"); // read binary
FILE *afp = fopen("AFrames.file", "rb"); // read binary

char *buf = (char *)malloc(500000);
char* frame=0;
unsigned long long pts=0;
char keyFrame=0;
while( 1 )
{
    //从原始文件中读取一帧视频帧
    int vsize = ReadAVFile(vfp,&frame, buf, 500000,0, &pts, &keyFrame);
    if (vsize < 0)
    {
        break;
    }
    // // print("vsize = %d pts = %lld",vsize,pts);
    //把一个vsize大小的视频帧放到264视频流里
    ps_muxer_input(ps,v_id,keyFrame,pts/10,pts/10,frame,vsize);

    //从原始音频文件中读取一帧音频帧
    int asize = ReadAVFile(afp,&frame, buf, 5000,1, &pts,&keyFrame);
    if (asize > 0)
    {
        // print("asize = %d pts = %lld",asize,pts);
        //把一个asize大小的音频帧放到音频流里
        ps_muxer_input(ps,a_id,0,pts/10,pts/10,frame,asize);
    }else{
        // break;
    }

}
free(buf);
fclose(vfp);
fclose(afp);

ps_muxer_destroy(ps);
return 0;

}`

是否 int a_id=ps_muxer_add_stream(ps,PSI_STREAM_AUDIO_G711A,0,0);这行代码我应该加 extrdata?

Hyatt-Zhong commented 11 months ago

ps