obs-ffmpeg: Add speed percentage option

(Note: This commit also modifies the deps/media-playback module.)

Allows modifying the speed of local file playback.

Closes jp9000/obs-studio#1091
This commit is contained in:
Exeldro
2018-02-15 15:13:35 -08:00
committed by jp9000
parent dc0363d3e8
commit 277b664001
5 changed files with 31 additions and 1 deletions

View File

@@ -338,6 +338,15 @@ bool mp_decode_next(struct mp_decode *d)
d->stream->time_base,
(AVRational){1, 1000000000});
if (d->m->speed != 100) {
d->frame_pts = av_rescale_q(d->frame_pts,
(AVRational){1, d->m->speed},
(AVRational){1, 100});
duration = av_rescale_q(duration,
(AVRational){1, d->m->speed},
(AVRational){1, 100});
}
d->last_duration = duration;
d->next_pts = d->frame_pts + duration;
}

View File

@@ -271,7 +271,7 @@ static void mp_media_next_audio(mp_media_t *m)
for (size_t i = 0; i < MAX_AV_PLANES; i++)
audio.data[i] = f->data[i];
audio.samples_per_sec = f->sample_rate;
audio.samples_per_sec = f->sample_rate * m->speed / 100;
audio.speakers = convert_speaker_layout(f->channels);
audio.format = convert_sample_format(f->format);
audio.frames = f->nb_samples;
@@ -687,8 +687,12 @@ bool mp_media_init(mp_media_t *media, const struct mp_media_info *info)
media->v_preload_cb = info->v_preload_cb;
media->force_range = info->force_range;
media->buffering = info->buffering;
media->speed = info->speed;
media->is_local_file = info->is_local_file;
if (!info->is_local_file || media->speed < 1 || media->speed > 200)
media->speed = 100;
static bool initialized = false;
if (!initialized) {
av_register_all();

View File

@@ -54,6 +54,7 @@ struct mp_media {
char *path;
char *format_name;
int buffering;
int speed;
enum AVPixelFormat scale_format;
struct SwsContext *swscale;
@@ -107,6 +108,7 @@ struct mp_media_info {
const char *path;
const char *format;
int buffering;
int speed;
enum video_range_type force_range;
bool hardware_decoding;
bool is_local_file;