Skip to content

Commit

Permalink
fix(live_render): use ffmpeg output to get video meta info
Browse files Browse the repository at this point in the history
  • Loading branch information
windowsair committed May 14, 2023
1 parent 1baf627 commit 54c4deb
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
45 changes: 37 additions & 8 deletions src/live_render/ffmpeg_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,19 +255,48 @@ inline bool ffmpeg_get_stream_meta_info(const std::string stream_address,
}
};

/*
* Stream #0:1: Video: h264 (High), yuv420p(tv, bt709, progressive), 1920x1080, 10240 kb/s, 60 fps, 60 tbr, 1k tbn
*/
std::size_t pos;
char *substr;

while (!feof(fp)) {
if (fgets(buffer.data(), 10240 - 1, fp) != NULL) {
auto displayWidth_it = buffer.find("displayWidth");
auto displayHeight_it = buffer.find("displayHeight");
auto fps_it = buffer.find("fps");
if (buffer.find("Stream") == std::string::npos) {
continue;
}

get_item(displayWidth_it, displayWidth);
get_item(displayHeight_it, displayHeight);
get_item(fps_it, fps);
if ((pos = buffer.find("Video")) == std::string::npos) {
continue;
}

if (displayWidth != -1 && displayHeight != -1 && fps != -1) {
break;
// get displayWidth and displayHeight
pos = 0;
while (pos != std::string::npos) {
pos = buffer.find("x");
// , 1920x
pos = buffer.find_last_of(",", pos);
// 1920x1080
substr = buffer.data() + pos + 1;

ret = sscanf(substr, "%dx%d", &displayWidth, &displayHeight);
if (ret == 2) {
break;
}
}

assert(pos != std::string::npos);

// get fps
pos = buffer.find("fps", pos);
assert(pos != std::string::npos);
pos = buffer.find_last_of(",", pos);
substr = buffer.data() + pos + 1;

sscanf(substr, "%d", &fps);

break;
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/live_render/live_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,12 @@ live_danmaku::get_live_room_stream(uint64_t room_id, int qn, std::string proxy_a

std::vector<live_stream_info_t> ret;

ret = get_live_room_stream_v1(room_id, qn, proxy_address, user_cookie, retry_count);
if (!ret.empty()) {
return ret;
}
// gotcha address doesn't seem to work anymore

//ret = get_live_room_stream_v1(room_id, qn, proxy_address, user_cookie, retry_count);
//if (!ret.empty()) {
// return ret;
//}

live_detail_t live_detail;

Expand Down

1 comment on commit 54c4deb

@windowsair
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix #13

Please sign in to comment.