0

I am trying to convert an mp4 clip to h264 bytestream format using FFMPEG. I have successfully compiled FFMPEG from source with access to libx264.

Looking at the documentation for FFMPEG (version 3.2.2) under libx264 there is a bool flag -aud. In the online documentation it gives the example

ffmpeg -i input.flac -id3v2_version 3 out.mp3

Using this format, the following command works, but doesn't produce the desired AUDs in the output file:

ffmpeg -i input.mp4 -codec:v libx264 -aud 1 output.h264

I've also tried different variants with this including:

ffmpeg -i input.mp4 -vcodec libx264 -aud 1 output.h264
ffmpeg -i input.mp4 -aud 1 output.h264

etc.

I assume there is something I'm misunderstanding about performing this operation. I basically want to take a h264 movie in an mp4 container and dump it as an h264 stream with AUDs added to it. Any idea why this isn't working?

(I've also tried using x264 with the -aud flag, also ran fine but didn't produce the desired output).

syntheticgio
  • 588
  • 6
  • 25

2 Answers2

2

Since MPEG-TS muxer creates AUDs, this 2-step non-destructive process works:

ffmpeg -i in.mp4 -c copy -map v -vbsf h264_mp4toannexb in.ts

and then

ffmpeg -i in.ts -c copy -map v -f h264 in.h264
Gyan
  • 85,394
  • 9
  • 169
  • 201
  • I am getting an error with this method (I think because there is apparently a second stream in mjpeg format in addition to the h264 first stream) and it is complaining about mjpeg not being supported. I think I need to add the flag to only use the first stream (#0:0). I vaguely remember coming across how to do this in the documentation but I can't remember off hand. – syntheticgio Dec 30 '16 at 18:03
  • 1
    In that case, use `-map 0:v:0` instead of `-map v` – Gyan Dec 30 '16 at 18:04
1
ffmpeg -i input.mp4 -x264opts aud=1 output.h264
Zombo
  • 1
  • 62
  • 391
  • 407
  • Thanks for the links, I need to look at them further. Just quickly trying the command you provided though doesn't produce AUDs in the output (although it is much faster than what I was doing previously). I also tried adding the -aud 1 flag to no avail. From the second link I tried using exactly what they have just output.h264 instead of output.ts and it still didn't work. All of them have the first Access Unit Type as an SEI (6) and not an AUD (9) as I would expect if it was in Annex B format. In fact I can't find any expected AUD units (00 00 01 69) in the hex dump of the output file. – syntheticgio Dec 30 '16 at 17:35
  • 1
    Of course with `-c copy`, it won't have effect as libx264 isn't in play. – Gyan Dec 30 '16 at 17:39
  • @StevenPenny - Under "libx264 AVOptions" in the fullhelp output from ffmpeg there is an -aud option that sounds like it would do what I want. I got the full help by just running ffmpeg -h full – syntheticgio Dec 30 '16 at 17:40
  • Thanks @StevenPenny. Looks like this works for me. I had tried -x264opts previously but I think that was on an incorrectly compiled version of ffmpeg (it was just constantly complaining about the missing libx264 at the time). I see 00 00 01 09 (or 00 00 01 69) consistently which is in line with what I'd expect for AUDs. – syntheticgio Dec 30 '16 at 17:48
  • 1
    This command, though, re-encodes the video, so it's not simply the original video with the new format. See my answer for a non-destructive method that *may* work. – Gyan Dec 30 '16 at 17:51