在ffmpeg中,如何使用scale2ref过滤器缩放dvdsub字幕以匹配视频大小? [英] In ffmpeg, how do I scale dvdsub subtitles to match video size, using scale2ref filter?

查看:245
本文介绍了在ffmpeg中,如何使用scale2ref过滤器缩放dvdsub字幕以匹配视频大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从直播电视录制的mpeg文件,其中包含视频以及多个音频和字幕流.我的最终目标是能够创建一个较小的视频文件,因为mpeg文件的大小为数GB.我在该路径上的第一步只是能够选择视频,音频和字幕流中的每个流,并将它们复制到mkv文件中,并丢弃我不感兴趣的流.(我选择了mkv,因为它将允许存储dvdsub字幕流,而其他容器格式则不会.)

I have an mpeg file, recorded from live TV, containing video and multiple audio and subtitles streams. My eventual goal is to be able to create a smaller video file as the mpeg file is multi-gigabytes in size. My first step on that path is just to be able to select one each of the video, audio and subtitle streams and copy them to an mkv file, discarding the streams I'm not interested in. (I chose mkv as it will allow storing a dvdsub subtitle stream where other container formats wont.)

我遇到的问题是,当播放输出视频时,dvdsub字幕显得很小,当我对此进行研究时,发现ffmpeg不会自动缩放字幕以匹配源视频:

The problem I'm having is that the dvdsub subtitles appear very small when I play the output video, when I researched this I found that ffmpeg doesn't automatically scale the subtitles to match the source video: https://trac.ffmpeg.org/ticket/4744

我尝试使用 scale2ref 过滤器,但我不理解文档,它们给我的示例对我来说毫无意义(请参见下面的示例).

I have tried using the scale2ref filter, but I don't understand the documentation, and the example they give makes no sense to me (see examples below).

我有一条命令选择三个流,并将1分钟复制到输出,如下所示:

I have a command that selects the three streams and copies 1 minute to the output, as follows:

ffmpeg -ss 00:28:00.200 -i Hillary-2016-08-21.mpg -t 00:01:00.000 -map 0:0 -c:v copy -map 0:3 -c:a copy -map 0:6 -c:s dvdsub cut.mkv

这是输出:

Input #0, mpegts, from 'Hillary-2016-08-21.mpg':
  Duration: 01:30:00.06, start: 20852.199389, bitrate: 6813 kb/s
  Program 1 
    Stream #0:0[0xfa]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x12c](eng): Audio: aac_latm (HE-AAC) ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp
    Stream #0:2[0x131](ita): Audio: aac_latm (HE-AAC) ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp (visual impaired)
    Stream #0:3[0x191](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:4[0x3ea]: Unknown: none ([11][0][0][0] / 0x000B)
    Stream #0:5[0x3ec]: Unknown: none ([11][0][0][0] / 0x000B)
    Stream #0:6[0x3fc](eng): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006) (hearing impaired)
    Stream #0:7[0x1f40]: Unknown: none ([5][0][0][0] / 0x0005)
File 'cut.mkv' already exists. Overwrite ? [y/N] y
Output #0, matroska, to 'cut.mkv':
  Metadata:
    encoder         : Lavf57.56.100
    Stream #0:0: Video: h264 (Main) (H264 / 0x34363248), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], q=2-31, 25 fps, 50 tbr, 1k tbn, 90k tbc
    Stream #0:1(eng): Audio: ac3 ([0] [0][0] / 0x2000), 48000 Hz, 5.1(side), 384 kb/s
    Stream #0:2(eng): Subtitle: dvd_subtitle (dvdsub) (hearing impaired)
    Metadata:
      encoder         : Lavc57.64.101 dvdsub
Stream mapping:
  Stream #0:0 -> #0:0 (copy)
  Stream #0:3 -> #0:1 (copy)
  Stream #0:6 -> #0:2 (dvb_subtitle (dvbsub) -> dvd_subtitle (dvdsub))
Press [q] to stop, [?] for help
frame= 2956 fps=0.0 q=-1.0 Lsize=   39612kB time=00:00:59.99 bitrate=5408.7kbits/s speed= 216x    
video:36702kB audio:2896kB subtitle:23kB other streams:0kB global headers:0kB muxing overhead: unknown

scale2ref 的文档提供了一个带有覆盖的示例,我不想覆盖任何内容,我只想调整字幕流的大小.这是他们的示例:

The documentation for scale2ref gives an example with an overlay, and I don't want to overlay anything, I just want to resize the subtitles stream. Here's their example:

'scale2ref[b][a];[a][b]overlay'

我最近的是这样的:

ffmpeg -ss 00:28:00.200 -i Hillary-2016-08-21.mpg -t 00:01:00.000 -map 0:0 -c:v copy -map 0:3 -c:a copy -filter_complex "[0:6]scale2ref[b]" -map "[b]"   cut.mkv

输出为:

Input #0, mpegts, from 'Hillary-2016-08-21.mpg':
  Duration: 01:30:00.06, start: 20852.199389, bitrate: 6813 kb/s
  Program 1 
    Stream #0:0[0xfa]: Video: h264 (Main) ([27][0][0][0] / 0x001B), yuv420p(tv, bt709, top first), 1920x1080 [SAR 1:1 DAR 16:9], 25 fps, 50 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x12c](eng): Audio: aac_latm (HE-AAC) ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp
    Stream #0:2[0x131](ita): Audio: aac_latm (HE-AAC) ([17][0][0][0] / 0x0011), 48000 Hz, stereo, fltp (visual impaired)
    Stream #0:3[0x191](eng): Audio: ac3 ([129][0][0][0] / 0x0081), 48000 Hz, 5.1(side), fltp, 384 kb/s
    Stream #0:4[0x3ea]: Unknown: none ([11][0][0][0] / 0x000B)
    Stream #0:5[0x3ec]: Unknown: none ([11][0][0][0] / 0x000B)
    Stream #0:6[0x3fc](eng): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006) (hearing impaired)
    Stream #0:7[0x1f40]: Unknown: none ([5][0][0][0] / 0x0005)
Streamcopy requested for output stream 0:0, which is fed from a complex filtergraph. Filtering and streamcopy cannot be used together.

我不太了解如何使用过滤器并将调整大小的字幕流定向到输出文件中.

And I don't really understand how I can use a filter and direct my resized subtitle stream into the output file.

任何帮助表示赞赏!谢谢!

Any help appreciated! Thanks!

推荐答案

scale2ref 都将其输出标记为视频流,这几乎总是它们的输出.因此,ffmpeg将 c:v 的值应用于缩放后的子对象.

scale2ref tags both its output as video streams, which is what they almost always are. So ffmpeg is applying the value of c:v to the scaled subs.

相反,您应该尝试

ffmpeg -ss 28:00.2 -canvas_size 1920x1080 -i Hillary-2016-08-21.mpg -t 1:00 -map 0:0 -c:v copy -map 0:3 -c:a copy -map 0:6 -c:s dvdsub cut.mkv

使用

ffmpeg -ss 28:00.2 -i Hillary-2016-08-21.mpg -t 1:00 -filter_complex "[0:6][0:0]scale2ref[b][a]" -map 0:0 -c:v copy -map 0:3 -c:a copy -map "[b]" cut.mkv -map "[a]" -f null -

scale2ref 接受两个输入并吐出两个输出.两端的第二个元素是 ref erence视频.因此,必须告诉ffmpeg如何处理该引用的直通副本.在上面的命令中,分配了空混合器,该空混合器将其发送到遗忘区.

scale2ref takes two inputs and spits two outputs. The 2nd element at both ends is the reference video. So ffmpeg has to be told what to do with the passthrough copy of that reference. In the command above, the null muxer is assigned, which sends it to oblivion.

这篇关于在ffmpeg中,如何使用scale2ref过滤器缩放dvdsub字幕以匹配视频大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆