正在显示
1 个修改的文件
包含
18 行增加
和
13 行删除
| @@ -82,20 +82,24 @@ int main(int argc, char** argv) | @@ -82,20 +82,24 @@ int main(int argc, char** argv) | ||
| 82 | printf("SRS(ossrs) client librtmp library.\n"); | 82 | printf("SRS(ossrs) client librtmp library.\n"); |
| 83 | printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision()); | 83 | printf("version: %d.%d.%d\n", srs_version_major(), srs_version_minor(), srs_version_revision()); |
| 84 | 84 | ||
| 85 | - if (argc <= 2) { | ||
| 86 | - printf("Usage: %s <h264_raw_file> <rtmp_publish_url>\n", argv[0]); | 85 | + if (argc <= 3) { |
| 86 | + printf("Usage: %s <h264_raw_file> <rtmp_publish_url> <fps>\n", argv[0]); | ||
| 87 | printf(" h264_raw_file: the h264 raw steam file.\n"); | 87 | printf(" h264_raw_file: the h264 raw steam file.\n"); |
| 88 | printf(" rtmp_publish_url: the rtmp publish url.\n"); | 88 | printf(" rtmp_publish_url: the rtmp publish url.\n"); |
| 89 | + printf(" fps: the video average fps, for example, 25.\n"); | ||
| 89 | printf("For example:\n"); | 90 | printf("For example:\n"); |
| 90 | - printf(" %s ./720p.h264.raw rtmp://127.0.0.1:1935/live/livestream\n", argv[0]); | 91 | + printf(" %s ./720p.h264.raw rtmp://127.0.0.1:1935/live/livestream 25\n", argv[0]); |
| 91 | printf("Where the file: http://winlinvip.github.io/srs.release/3rdparty/720p.h264.raw\n"); | 92 | printf("Where the file: http://winlinvip.github.io/srs.release/3rdparty/720p.h264.raw\n"); |
| 92 | - printf("See: https://github.com/ossrs/srs/issues/66\n"); | 93 | + printf(" See: https://github.com/ossrs/srs/issues/66\n"); |
| 93 | exit(-1); | 94 | exit(-1); |
| 94 | } | 95 | } |
| 95 | 96 | ||
| 96 | const char* raw_file = argv[1]; | 97 | const char* raw_file = argv[1]; |
| 97 | const char* rtmp_url = argv[2]; | 98 | const char* rtmp_url = argv[2]; |
| 98 | - srs_human_trace("raw_file=%s, rtmp_url=%s", raw_file, rtmp_url); | 99 | + // @remark, the dts and pts if read from device, for instance, the encode lib, |
| 100 | + // so we assume the fps is 25, and each h264 frame is 1000ms/25fps=40ms/f. | ||
| 101 | + double fps = atof(argv[3]); | ||
| 102 | + srs_human_trace("raw_file=%s, rtmp_url=%s, fps=%.2f", raw_file, rtmp_url, fps); | ||
| 99 | 103 | ||
| 100 | // open file | 104 | // open file |
| 101 | int raw_fd = open(raw_file, O_RDONLY); | 105 | int raw_fd = open(raw_file, O_RDONLY); |
| @@ -148,12 +152,9 @@ int main(int argc, char** argv) | @@ -148,12 +152,9 @@ int main(int argc, char** argv) | ||
| 148 | 152 | ||
| 149 | int dts = 0; | 153 | int dts = 0; |
| 150 | int pts = 0; | 154 | int pts = 0; |
| 151 | - // @remark, the dts and pts if read from device, for instance, the encode lib, | ||
| 152 | - // so we assume the fps is 25, and each h264 frame is 1000ms/25fps=40ms/f. | ||
| 153 | - int fps = 25; | ||
| 154 | // @remark, to decode the file. | 155 | // @remark, to decode the file. |
| 155 | char* p = h264_raw; | 156 | char* p = h264_raw; |
| 156 | - for (;p < h264_raw + file_size;) { | 157 | + for (int count = 0; p < h264_raw + file_size; count++) { |
| 157 | // @remark, read a frame from file buffer. | 158 | // @remark, read a frame from file buffer. |
| 158 | char* data = NULL; | 159 | char* data = NULL; |
| 159 | int size = 0; | 160 | int size = 0; |
| @@ -178,15 +179,19 @@ int main(int argc, char** argv) | @@ -178,15 +179,19 @@ int main(int argc, char** argv) | ||
| 178 | } | 179 | } |
| 179 | } | 180 | } |
| 180 | 181 | ||
| 181 | - // 5bits, 7.3.1 NAL unit syntax, | 182 | + // 5bits, 7.3.1 NAL unit syntax, |
| 182 | // H.264-AVC-ISO_IEC_14496-10.pdf, page 44. | 183 | // H.264-AVC-ISO_IEC_14496-10.pdf, page 44. |
| 184 | + // 7: SPS, 8: PPS, 5: I Frame, 1: P Frame, 9: AUD | ||
| 183 | u_int8_t nut = (char)data[nb_start_code] & 0x1f; | 185 | u_int8_t nut = (char)data[nb_start_code] & 0x1f; |
| 184 | - srs_human_trace("sent packet: type=%s, time=%d, size=%d, fps=%d, b[%d]=%#x(%s)", | 186 | + srs_human_trace("sent packet: type=%s, time=%d, size=%d, fps=%.2f, b[%d]=%#x(%s)", |
| 185 | srs_human_flv_tag_type2string(SRS_RTMP_TYPE_VIDEO), dts, size, fps, nb_start_code, (char)data[nb_start_code], | 187 | srs_human_flv_tag_type2string(SRS_RTMP_TYPE_VIDEO), dts, size, fps, nb_start_code, (char)data[nb_start_code], |
| 186 | - (nut == 7? "SPS":(nut == 8? "PPS":(nut == 5? "I":(nut == 1? "P":"Unknown"))))); | 188 | + (nut == 7? "SPS":(nut == 8? "PPS":(nut == 5? "I":(nut == 1? "P":(nut == 9? "AUD":"Unknown")))))); |
| 187 | 189 | ||
| 188 | // @remark, when use encode device, it not need to sleep. | 190 | // @remark, when use encode device, it not need to sleep. |
| 189 | - usleep(1000 / fps * 1000); | 191 | + if (count == 10) { |
| 192 | + usleep(1000 * 1000 * count / fps); | ||
| 193 | + count = 0; | ||
| 194 | + } | ||
| 190 | } | 195 | } |
| 191 | srs_human_trace("h264 raw data completed"); | 196 | srs_human_trace("h264 raw data completed"); |
| 192 | 197 |
-
请 注册 或 登录 后发表评论