Skip to content

Commit

Permalink
Transcript: Support set the video codec parameters. v5.14.11
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Mar 24, 2024
1 parent 62b2e5d commit 0c6baed
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
1 change: 1 addition & 0 deletions DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,7 @@ The following are the update records for the SRS Stack server.
* Dubbing: Refine download button with comments. v5.14.8
* Room: AI-Talk support post processing. v5.14.9
* Website: Support setting title for popout. v5.14.10
* Transcript: Support set the video codec parameters. [v5.14.11](https://github.com/ossrs/srs-stack/releases/tag/v5.14.11)
* v5.13:
* Fix bug for vlive and transcript. v5.13.1
* Support AWS Lightsail install script. v5.13.2
Expand Down
18 changes: 12 additions & 6 deletions platform/transcript.go
Original file line number Diff line number Diff line change
Expand Up @@ -1018,11 +1018,13 @@ type TranscriptConfig struct {
Language string `json:"lang"`
// The force_style for overlay subtitle.
ForceStyle string `json:"forceStyle"`
// The video codec parameters.
VideoCodecParams string `json:"videoCodecParams"`
}

func (v TranscriptConfig) String() string {
return fmt.Sprintf("all=%v, key=%vB, organization=%v, base=%v, lang=%v, forceStyle=%v",
v.All, len(v.SecretKey), v.Organization, v.BaseURL, v.Language, v.ForceStyle)
return fmt.Sprintf("all=%v, key=%vB, organization=%v, base=%v, lang=%v, forceStyle=%v, videoCodecParams=%v",
v.All, len(v.SecretKey), v.Organization, v.BaseURL, v.Language, v.ForceStyle, v.VideoCodecParams)
}

func (v *TranscriptConfig) Load(ctx context.Context) error {
Expand Down Expand Up @@ -1758,11 +1760,15 @@ func (v *TranscriptTask) DriveFixQueue(ctx context.Context) error {
}...)
}
}
// Generate the video parameters.
videoCodecParams := "-c:v libx264 -profile:v main -preset:v medium -tune zerolatency -bf 0"
if v.config.VideoCodecParams != "" {
videoCodecParams = v.config.VideoCodecParams
}
args = append(args, strings.Split(videoCodecParams, " ")...)
// Generate other parameters for FFmpeg.
args = append(args, []string{
"-vcodec", "libx264", "-profile:v", "main", "-preset:v", "medium",
"-tune", "zerolatency", // Low latency mode.
"-bf", "0", // Disable B frame for WebRTC.
"-acodec", "aac",
"-c:a", "aac",
"-copyts", // To keep the pts not changed.
"-y", overlayFile.File,
}...)
Expand Down
17 changes: 15 additions & 2 deletions ui/src/pages/ScenarioTranscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default
const [baseURL, setBaseURL] = React.useState(defaultConf.baseURL || (language === 'zh' ? '' : 'https://api.openai.com/v1'));
const [targetLanguage, setTargetLanguage] = React.useState(defaultConf.lang || language);
const [forceStyle, setForceStyle] = React.useState(defaultConf.forceStyle || 'Alignment=2,MarginV=20');
const [videoCodecParams, setVideoCodecParams] = React.useState(defaultConf.videoCodecParams || '-c:v libx264 -profile:v main -preset:v medium -tune zerolatency -bf 0');

const [liveQueue, setLiveQueue] = React.useState();
const [asrQueue, setAsrQueue] = React.useState();
Expand Down Expand Up @@ -89,15 +90,15 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default
if (!baseURL) return alert(`Invalid base url ${baseURL}`);

axios.post('/terraform/v1/ai/transcript/apply', {
uuid, all: !!enabled, secretKey, organization, baseURL, lang: targetLanguage, forceStyle,
uuid, all: !!enabled, secretKey, organization, baseURL, lang: targetLanguage, forceStyle, videoCodecParams,
}, {
headers: Token.loadBearerHeader(),
}).then(res => {
alert(t('helper.setOk'));
console.log(`Transcript: Apply config ok, uuid=${uuid}.`);
success && success();
}).catch(handleError);
}, [t, handleError, secretKey, baseURL, targetLanguage, forceStyle, uuid, organization]);
}, [t, handleError, secretKey, baseURL, targetLanguage, forceStyle, videoCodecParams, uuid, organization]);

const resetTask = React.useCallback(() => {
setOperating(true);
Expand Down Expand Up @@ -307,6 +308,9 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default
<Nav.Item>
<Nav.Link href="#overlay" onClick={(e) => changeConfigItem(e, 'overlay')}>{t('transcript.overlay2')}</Nav.Link>
</Nav.Item>
<Nav.Item>
<Nav.Link href="#transcode" onClick={(e) => changeConfigItem(e, 'transcode')}>{t('transcript.transcode')}</Nav.Link>
</Nav.Item>
</Nav>
</Card.Header>
{configItem === 'provider' && <Card.Body>
Expand Down Expand Up @@ -334,6 +338,15 @@ function ScenarioTranscriptImpl({activeKey, defaultEnabled, defaultConf, default
<Form.Control as="input" defaultValue={forceStyle} onChange={(e) => setForceStyle(e.target.value)} />
</Form.Group>
</Card.Body>}
{configItem === 'transcode' && <Card.Body>
<Form.Group className="mb-3">
<Form.Label>{t('transcript.trans0')}</Form.Label>
<Form.Text> * {t('transcript.trans1')}. &nbsp;
{t('helper.see')} <a href={t('transcript.trans2')} target='_blank' rel='noreferrer'>FFmpeg: video codec</a>.
</Form.Text>
<Form.Control as="input" defaultValue={videoCodecParams} onChange={(e) => setVideoCodecParams(e.target.value)} />
</Form.Group>
</Card.Body>}
</Card>
<p></p>
<Button ariant="primary" type="submit" onClick={(e) => {
Expand Down
8 changes: 8 additions & 0 deletions ui/src/resources/locale.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@
"res": "最后收到的响应"
},
"transcript": {
"trans2": "https://ossrs.net/lts/zh-cn/faq-srs-stack#how-to-setup-the-video-codec-parameters-for-ai-transcript",
"trans1": "自定义视频转码参数",
"trans0": "视频转码参数",
"transcode": "转码设置",
"fstyle3": "https://ossrs.net/lts/zh-cn/faq-srs-stack#how-to-setup-the-font-style-for-ai-transcript",
"fstyle2": "设置字幕的样式",
"fstyle": "字幕样式",
Expand Down Expand Up @@ -870,6 +874,10 @@
"setupOk": "Set record rule ok"
},
"transcript": {
"trans2": "https://ossrs.io/lts/en-us/faq-srs-stack#how-to-setup-the-video-codec-parameters-for-ai-transcript",
"trans1": "Customize video transcode parameters",
"trans0": "Video Transcode Parameters",
"transcode": "Transcode Settings",
"fstyle3": "https://ossrs.io/lts/en-us/faq-srs-stack#how-to-setup-the-font-style-for-ai-transcript",
"fstyle2": "Force the style of the subtitle",
"fstyle": "Force Style",
Expand Down

0 comments on commit 0c6baed

Please sign in to comment.