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}...

I know to convert from one format to other format using the commands like,

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

Now I m in need of doing conversions like M.avi to M.h264 and then from M.h264 to 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

While doing this everything worked fine, but M.mp4 is playing without audio.

As per the link,

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

I even tried with -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

while using the command ffmpeg -i M.mp4 -c:v h264_qsv -look_ahead 0 -strict -2 -preset:v fast -acodec copy n.h264, the outcome is

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%

Still no audio. Can someone help me with this?

  • Can you pastebin the complete command + full terminal output from one of your failed encodes? Bear in mind as well that saving audio to the output '*.h264' will not work... – andrew.46 Jul 27 '16 at 16:25
  • @andrew.46 updated the question. Then in which format can i store my intermediate file other than .h264? – Vanns Jul 28 '16 at 5:00
  • Why are you performing the unnecessary extra step of .h264 to .mp4? Why not encode directly to .mp4? – llogan Aug 3 '16 at 22:30
  • I have already tried encoding directly to .mp4. But anyways I am also interested in this extra step – Vanns Aug 4 '16 at 6:43
0

I'm not aware of a way to extract the Audio and Video in a single step, but you can easily extract both Audio and Video with a short script.

Assuming the audio is AAC as in your post:

#! /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

To recombine them in in an MP4 container, you can do:

#! /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

This is not an ideal solution, as it creates an additional step (as noted in the comments). But at least it would give you a starting point :)

Hope that helps! :)

0

.h264 is a raw video container format. It doesn't know about audio. ffmpeg behaves absolute correctly. If you want h264 - you get it. Without audio.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.