Como converter vídeo junto com áudio em h264 ffmpeg?

0

ffmpeg

ffmpeg version 3.1.1 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-4)
  configuration: --enable-libmfx --enable-nonfree
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 47.100 /  6. 47.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

Eu sei converter de um formato para outro formato usando os comandos like,

ffmpeg -i M.avi -c:v h264_qsv -look_ahead 0 -strict -2 -preset:v fast M.mp4

Agora eu estou precisando fazer conversões como M. avi para M.h264 e depois de M.h264 para M.mp4

ffmpeg -i M.avi -c:v h264_qsv -look_ahead 0 -strict -2 -preset:v fast M.h264

ffmpeg -i M.h264 -c:v h264_qsv -look_ahead 0 -strict -2 -preset:v fast M.mp4

Enquanto isso, tudo funcionou bem, mas a M.mp4 está tocando sem áudio.

De acordo com o link,

https://stackoverflow.com/questions/5725958/ffmpeg-conversion-skips-audio

Eu até tentei com -acodec copy as

ffmpeg -i M.avi -c:v h264_qsv -look_ahead 0 -strict -2 -preset:v fast -acodec copy M.h264

ffmpeg -i M.h264 -c:v h264_qsv -look_ahead 0 -strict -2 -preset:v fast -acodec copy M.mp4

enquanto usa o comando ffmpeg -i M.mp4 -c:v h264_qsv -look_ahead 0 -strict -2 -preset:v fast -acodec copy n.h264 , o resultado é

ffmpeg version 3.1.1 Copyright (c) 2000-2016 the FFmpeg developers
  built with gcc 4.8.5 (GCC) 20150623 (Red Hat 4.8.5-4)
  configuration: --enable-libmfx --enable-nonfree
  libavutil      55. 28.100 / 55. 28.100
  libavcodec     57. 48.101 / 57. 48.101
  libavformat    57. 41.100 / 57. 41.100
  libavdevice    57.  0.101 / 57.  0.101
  libavfilter     6. 47.100 /  6. 47.100
  libswscale      4.  1.100 /  4.  1.100
  libswresample   2.  1.100 /  2.  1.100
Input #0, mov,mp4,m4a,3gp,3g2,mj2, from 'M.mp4':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    creation_time   : 2016-01-31 09:44:22
  Duration: 00:03:28.38, start: 0.000000, bitrate: 2120 kb/s
    Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1280x720 [SAR 1:1 DAR 16:9], 1925 kb/s, 24 fps, 24 tbr, 24 tbn, 48 tbc (default)
    Metadata:
      handler_name    : VideoHandler
    Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 191 kb/s (default)
    Metadata:
      creation_time   : 2016-01-31 09:44:23
      handler_name    : IsoMedia File Produced by Google, 5-11-2011
File 'n.h264' already exists. Overwrite ? [y/N] y
libva info: VA-API version 0.35.0
libva info: va_getDriverName() returns 0
libva info: User requested driver 'iHD'
libva info: Trying to open /opt/intel/mediasdk/lib64/iHD_drv_video.so
libva info: Found init function __vaDriverInit_0_32
libva info: va_openDriver() returns 0
[h264 @ 0x2fd4940] Using AVStream.codec to pass codec parameters to muxers is deprecated, use AVStream.codecpar instead.
Output #0, h264, to 'n.h264':
  Metadata:
    major_brand     : mp42
    minor_version   : 0
    compatible_brands: isommp42
    encoder         : Lavf57.41.100
    Stream #0:0(und): Video: h264 (h264_qsv), nv12, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 1000 kb/s, 24 fps, 24 tbn, 24 tbc (default)
    Metadata:
      handler_name    : VideoHandler
      encoder         : Lavc57.48.101 h264_qsv
    Side data:
      cpb: bitrate max/min/avg: 0/0/1000000 buffer size: 0 vbv_delay: -1
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (h264_qsv))
Press [q] to stop, [?] for help
frame= 5001 fps=284 q=-0.0 Lsize=   23221kB time=00:03:28.33 bitrate= 913.1kbits/s speed=11.8x    
video:23221kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.000000%

Ainda sem áudio. Alguém pode me ajudar com isso?

    
por Vanns 27.07.2016 / 16:02

1 resposta

0

Não estou ciente de como extrair o áudio e o vídeo em uma única etapa, mas você pode extrair facilmente áudio e vídeo com um script curto.

Assumindo que o áudio seja AAC como em sua postagem:

#! /bin/bash
###################################################################
i="" # edit with the input avi file name including extension
###################################################################
  ffmpeg -i "$i" -c:v h264_qsv -look_ahead 0 -strict -2 -preset:v fast -an "${i%.*}.".h264
  ffmpeg -i "$i" -vn -acodec copy "${i%.*}.".aac
done

Para recombinar-los em um contêiner MP4, você pode fazer:

#! /bin/bash
###################################################################
i="" # edit with the input h264 file name including extension
###################################################################
  ffmpeg -i "$i" -i "${i%.*}.".aac -vcodec copy -acodec copy "${i%.*}.".mp4
done

Esta não é uma solução ideal, pois cria uma etapa adicional (conforme observado nos comentários). Mas pelo menos te daria um ponto de partida:)

Espero que ajude! :)

    
por ThatGuy 05.11.2016 / 05:01