¿Por qué ffmpeg genera un video de 600 fps desde una entrada de video de 120 fps?

Tengo un video muy corto de 120 fps .

ffprobe input.mp4muestra 118.99fps:

ffprobe version 3.0 Copyright (c) 2007-2016 the FFmpeg developers
  built with Apple LLVM version 7.3.0 (clang-703.0.29)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.0 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-opencl --enable-libx264 --enable-libmp3lame --enable-libxvid --enable-ffplay --enable-vda
  libavutil      55. 17.103 / 55. 17.103
  libavcodec     57. 24.102 / 57. 24.102
  libavformat    57. 25.100 / 57. 25.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 31.100 /  6. 31.100
  libavresample   3.  0.  0 /  3.  0.  0
  libswscale      4.  0.100 /  4.  0.100
  libswresample   2.  0.101 /  2.  0.101
  libpostproc    54.  0.100 / 54.  0.100
[h264 @ 0x7f8262009600] Increasing reorder buffer to 1
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp41mp42isom
    creation_time   : 2016-04-27 10:43:14
  Duration: 00:00:02.76, start: 0.000000, bitrate: 10318 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 720x1280, 10272 kb/s, 118.99 fps, 600 tbr, 600 tbn, 1200 tbc (default)
    Metadata:
      creation_time   : 2016-04-27 10:43:14
      handler_name    : Core Media Video

Estoy ejecutando una operación de recorte y cambio de tamaño cuadrado:

ffmpeg -i input.mp4 -vf "crop='if(gte(iw,ih),ih,iw):if(gte(ih,iw),iw,ih)', scale=640x640" -an -c:v libx264 -profile:v high -level 4.1 -preset veryslow -crf 20 output.mp4

Esto da:

....
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'input.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp41mp42isom
    creation_time   : 2016-04-27 10:43:14
  Duration: 00:00:02.76, start: 0.000000, bitrate: 10318 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 720x1280, 10272 kb/s, 118.99 fps, 600 tbr, 600 tbn, 1200 tbc (default)
....
Output #0, mp4, to 'output.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 1
    compatible_brands: mp41mp42isom
    encoder         : Lavf57.25.100
    Stream #0:0(und): Video: h264 (libx264) ([33][0][0][0] / 0x0021), yuv420p, 640x640, q=-1--1, 600 fps, 19200 tbn, 600 tbc (default)
....

Y efectivamente, ffprobe output.mp4confirma que output.mp4está a 600fps, al igual que VLC.

¿Cómo puedo asegurarme de que ffmpeg codificará mi video usando la misma velocidad de fotogramas que la entrada (ya sea 30, 60, 120 o 240 fps)?

Respuestas (1)

Actualización : las entradas PTS de entrada y salida para el siguiente comando son idénticas en la versión N-79630-g9ac154d. Parece que el archivo está marcado falsamente como VFR. Pero este comando de un solo paso a continuación funciona para el video de muestra.

Usar

ffmpeg -i input.mp4 -vf "crop='if(gte(iw,ih),ih,iw):if(gte(ih,iw),iw,ih)', scale=640x640" \
   -an -c:v libx264 -profile:v high -level 4.1 -preset veryslow -crf 20 -vsync 0 output.mp4

La velocidad de fotogramas almacenada en el contenedor ( tbr) es 600, mientras que los fps informados 118.99se obtienen contando el número de paquetes de video y dividiéndolos por la duración total. Si no se trata de una secuencia de velocidad de fotogramas variable, agréguela -r 118.99como opción de salida.


Para versiones anteriores, alternativamente, salida a MKV, es decir

ffmpeg -i input.mp4 -vf "crop='if(gte(iw,ih),ih,iw):if(gte(ih,iw),iw,ih)', scale=640x640" \
   -vsync 0 -an -c:v libx264 -profile:v high -level 4.1 -preset veryslow -crf 20 output.mkv

Si luego mux el MKV a MP4,

ffmpeg -i output.mkv -c copy output.mp4

El MP4 resultante mostrará (cerca de) la velocidad de fotogramas de origen.

Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'no-rc.mp4':
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.34.103
  Duration: 00:00:02.75, start: 0.000000, bitrate: 2462 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 640x640, 2444 kb/s, 119.88 fps, 600 tbr, 16k tbn (default)
Gracias, el problema con el uso -r 118.99es que la entrada puede tener diferentes velocidades de cuadro. ¿Hay alguna manera de hacerlo dinámico para que -r <value>coincida con la entrada fps?
Directamente no, pero sí, si pasas por el método MKV editado.
Solución genial: funciona. Voy a dejar la pregunta abierta durante un par de días para ver si a alguien se le ocurre un proceso de un solo paso; si no, lo aceptaré.
Si hay un error, presente uno en trac.ffmpeg.org...