简体   繁体   English

如何使用ffmpeg改变mp4文件的h264属性、yuv、fps、tbr、tbn、tbc?

[英]How to use ffmpeg to change the h264 properties, yuv, fps, tbr, tbn, and tbc of an mp4 file?

Using ffmpeg, I would like to convert a video file such that its video stream changes like so:使用 ffmpeg,我想转换一个视频文件,使其视频 stream 变化如下:

  • Current video stream: Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 2560x1080 [SAR 4:3 DAR 256:81], 60 kb/s, 15 fps, 15 tbr, 15360 tbn, 30 tbc (default)当前视频stream: Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 2560x1080 [SAR 4:3 DAR 256:81], 60 kb/s, 15 fps, 15 tbr, 15360 tbn, 30 tbc (default)
  • Target video stream: Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 2560x1080, 272 kb/s, 20 fps, 20 tbr, 10240 tbn, 40 tbc (default)目标视频stream: Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 2560x1080, 272 kb/s, 20 fps, 20 tbr, 10240 tbn, 40 tbc (default)

(values that differ: h264 properties, yuv, fps, tbr, tbn, and tbc) (不同的值:h264 属性、yuv、fps、tbr、tbn 和 tbc)

... and its audio stream changes like so: ...及其音频 stream 变化如下:

  • Current audio stream: Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 191 kb/s (default)当前音频 stream: Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 191 kb/s (default)
  • Target audio stream: Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 69 kb/s (default) Target audio stream: Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 69 kb/s (default)

(values that differ: aac properties) (不同的值:aac 属性)

How can I do this?我怎样才能做到这一点?


Detailed version详细版

I would like to be able to concatenate, without re-encoding, main.mp4 , followed by outro.mp4 , using the following commands:我希望能够在不重新编码的情况下连接main.mp4 ,然后是outro.mp4 ,使用以下命令:

echo "file 'main.mp4'" > concat.txt
echo "file 'outro.mp4'" >> concat.txt
ffmpeg \
  -f concat \
  -safe 0 \
  -i concat.txt \
  -c copy \
  concat.mp4

What results is a file which plays till the end of main.mp4 , and then the video freezes, and I hear the audio of outro.mp4 .结果是一个文件播放到main.mp4结束,然后视频冻结,我听到outro.mp4的音频。 The same video frame then stays on, with no sound, for an extra ~30 minutes (end time shown in VLC).然后,相同的视频帧会在没有声音的情况下继续播放约 30 分钟(结束时间显示在 VLC 中)。

My assumption is that these files are incompatible with each other in some way that prevents them from being concatenated using -codec copy (without re-encoding).我的假设是这些文件在某种程度上彼此不兼容,这会阻止它们使用-codec copy连接(无需重新编码)。

Here is the ffprobe output for main.mp4 :这是ffprobe的 ffprobe main.mp4

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'main.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 01:13:00.65, start: 0.000000, bitrate: 348 kb/s
    Stream #0:0(und): Video: h264 (High 4:4:4 Predictive) (avc1 / 0x31637661), yuv444p, 2560x1080, 272 kb/s, 20 fps, 20 tbr, 10240 tbn, 40 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (mp4a / 0x6134706D), 48000 Hz, mono, fltp, 69 kb/s (default)
    Metadata:
      handler_name    : SoundHandler

Here is the ffprobe output for outro.mp4 :这是ffprobe的 ffprobe outro.mp4

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'outro.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf58.45.100
  Duration: 00:00:04.12, start: 0.000000, bitrate: 254 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 2560x1080 [SAR 4:3 DAR 256:81], 60 kb/s, 15 fps, 15 tbr, 15360 tbn, 30 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 191 kb/s (default)
    Metadata:
      handler_name    : Stereo

How can I convert outro.mp4 , such that I may concatenate the files without re-encoding?如何转换outro.mp4 ,这样我就可以在不重新编码的情况下连接文件?

Note that I am OK with re-encoding the outro.mp4 on its own, I simply want to avoid re-encoding during the concatenation step, and avoid re-encoding main.mp4 .请注意,我可以自行重新编码outro.mp4 ,我只是想避免在连接步骤中重新编码,并避免重新编码main.mp4


ffmpeg build ffmpeg 构建

$ ffmpeg -version
ffmpeg version 4.3-2~18.04.york0 Copyright (c) 2000-2020 the FFmpeg developers
built with gcc 7 (Ubuntu 7.5.0-3ubuntu1~18.04)
configuration: --prefix=/usr --extra-version='2~18.04.york0' --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librabbitmq --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libsrt --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-pocketsphinx --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared
libavutil      56. 51.100 / 56. 51.100
libavcodec     58. 91.100 / 58. 91.100
libavformat    58. 45.100 / 58. 45.100
libavdevice    58. 10.100 / 58. 10.100
libavfilter     7. 85.100 /  7. 85.100
libavresample   4.  0.  0 /  4.  0.  0
libswscale      5.  7.100 /  5.  7.100
libswresample   3.  7.100 /  3.  7.100
libpostproc    55.  7.100 / 55.  7.100

The conversion command for outro.mp4 is outro.mp4 的转换命令是

ffmpeg -i outro.mp4 -pix_fmt yuv444p -profile high444 -bf 0 -video_track_timescale 10240 -ac 1 out.mp4

Add -vf "setdar=dar=0,setsar=sar=0" , -r 20 , and -qscale:v 2 to the above command to get the exact intended output.在上述命令中添加-vf "setdar=dar=0,setsar=sar=0"-r 20-qscale:v 2以获得准确的预期 output。

ffmpeg \
  -i outro.mp4 \
  -vf "setdar=dar=0,setsar=sar=0" \
  -pix_fmt yuv444p \
  -profile:v high444 \
  -bf 0 \
  -video_track_timescale 10240 \
  -r 20 \
  -qscale:v 2 \
  -ac 1 \
  out.mp4

Side note: If the video contains audio as well, and using the copy codec, be sure to ensure that those are matching too.旁注:如果视频也包含音频,并且使用复制编解码器,请务必确保它们也匹配。 For example use -ar to set the audio rate.例如使用-ar设置音频速率。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM