bennetimo / shrinkwrap

Shrink audio and video from cameras and GoPros at high quality, preserving metadata and original file modification times
http://coderunner.io/shrink-videos-with-ffmpeg-and-preserve-metadata/
66 stars 13 forks source link

FFMPEG Error: missing picture in access unit with size 56 #8

Open 0kashi opened 3 years ago

0kashi commented 3 years ago

Firstly thank you for your post.

I am trying to use your tool to reduce the file sizes of some AVI files though I get the errors below. Admittedly I am a noob to ffmpeg so please forgive me if it is a simple solution.

# docker run --rm -v /path/to/files:/files bennetimo/shrinkwrap --input-extension avi /files/video1.avi                                                   
02:15:46.159 [main] DEBUG shrinkwrap - 
  ___ _        _      _
 / __| |_  _ _(_)_ _ | |____ __ ___ _ __ _ _ __
 \__ \ ' \| '_| | ' \| / /\ V  V / '_/ _` | '_ \
 |___/_||_|_| |_|_||_|_\_\ \_/\_/|_| \__,_| .__/
                                          |_|

02:15:46.168 [main] DEBUG shrinkwrap - 
Using config: 
Input Extension: avi
Output Extension: mp4
Transcode Audio: true
Transcode Video: true
Backup Metadata: false
Metadata Suffix: -metadata
Overwrite Existing Transcodes: false
Transcoded Files Suffix: -tc
Using Shrinkwrap Preset: standard
FFMpeg Additional Options: 
Input: /files/video1.avi

02:15:46.198 [main] DEBUG shrinkwrap - Shrinkwrapping file: /files/video1.avi (1/1)
02:15:46.238 [main] DEBUG shrinkwrap - Executing cmd: List(/bin/sh, -c, ffmpeg -y -noautorotate -i "/files/video1.avi" -copy_unknown  -map_metadata 0 -map 0 -codec copy -preset medium -codec:v libx264 -pix_fmt yuv420p -crf 23 -codec:a libfdk_aac -vbr 4 "/files/video1-tc.mp4")
ffmpeg version 4.0.4 Copyright (c) 2000-2019 the FFmpeg developers
  built with gcc 6.4.0 (Alpine 6.4.0)
  configuration: --disable-debug --disable-doc --disable-ffplay --enable-shared --enable-avresample --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-gpl --enable-libass --enable-libfreetype --enable-libvidstab --enable-libmp3lame --enable-libopenjpeg --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx265 --enable-libxvid --enable-libx264 --enable-nonfree --enable-openssl --enable-libfdk_aac --enable-libkvazaar --enable-libaom --extra-libs=-lpthread --enable-postproc --enable-small --enable-version3 --extra-cflags=-I/opt/ffmpeg/include --extra-ldflags=-L/opt/ffmpeg/lib --extra-libs=-ldl --prefix=/opt/ffmpeg
  libavutil      56. 14.100 / 56. 14.100
  libavcodec     58. 18.100 / 58. 18.100
  libavformat    58. 12.100 / 58. 12.100
  libavdevice    58.  3.100 / 58.  3.100
  libavfilter     7. 16.100 /  7. 16.100
  libavresample   4.  0.  0 /  4.  0.  0
  libswscale      5.  1.100 /  5.  1.100
  libswresample   3.  1.100 /  3.  1.100
  libpostproc    55.  1.100 / 55.  1.100
[avi @ 0x55c59148e780] sample size (2) != block align (4096)
[avi @ 0x55c59148e780] non-interleaved AVI
[h264 @ 0x55c5914a1ac0] missing picture in access unit with size 56
[h264 @ 0x55c5914a1ac0] No start code is found.
[h264 @ 0x55c5914a1ac0] Error splitting the input into NAL units.
[h264 @ 0x55c5914a1ac0] missing picture in access unit with size 56
[h264 @ 0x55c5914a1ac0] No start code is found.
[h264 @ 0x55c5914a1ac0] Error splitting the input into NAL units.
[h264 @ 0x55c5914a1ac0] missing picture in access unit with size 56
[h264 @ 0x55c5914a1ac0] No start code is found.
[h264 @ 0x55c5914a1ac0] Error splitting the input into NAL units.
[h264 @ 0x55c5914a1ac0] missing picture in access unit with size 56
[h264 @ 0x55c5914a1ac0] No start code is found.
[h264 @ 0x55c5914a1ac0] Error splitting the input into NAL units.
[h264 @ 0x55c5914a1ac0] missing picture in access unit with size 56
[h264 @ 0x55c5914a1ac0] No start code is found.
[h264 @ 0x55c5914a1ac0] Error splitting the input into NAL units.
[h264 @ 0x55c5914a1ac0] missing picture in access unit with size 56
[h264 @ 0x55c5914a1ac0] No start code is found.
[h264 @ 0x55c5914a1ac0] Error splitting the input into NAL units.
[h264 @ 0x55c5914a1ac0] missing picture in access unit with size 56
[h264 @ 0x55c5914a1ac0] No start code is found.
[h264 @ 0x55c5914a1ac0] Error splitting the input into NAL units.
[h264 @ 0x55c5914a1ac0] missing picture in access unit with size 56
    Last message repeated 68 times
[avi @ 0x55c59148e780] Could not find codec parameters for stream 1 (Audio: none ([172][10][0][0] / 0x0AAC), 16000 Hz, 1 channels, 256 kb/s): unknown codec
Consider increasing the value for the 'analyzeduration' and 'probesize' options
Guessed Channel Layout for Input Stream #0.1 : mono
Input #0, avi, from '/files/video1.avi':
  Metadata:
    VGN0            : Living Room
    VGT0            : ?q??w?
    VGT1            : ?
                    : ??w?
  Duration: 00:05:01.50, start: 0.000000, bitrate: 2188 kb/s
    Stream #0:0: Video: h264 (q264 / 0x34363271), yuv420p(progressive), 2048x1536, 2114 kb/s, 30 fps, 30 tbr, 30 tbn, 60 tbc
    Stream #0:1: Audio: none ([172][10][0][0] / 0x0AAC), 16000 Hz, mono, 256 kb/s
Stream mapping:
  Stream #0:0 -> #0:0 (h264 (native) -> h264 (libx264))
  Stream #0:1 -> #0:1 (? (?) -> aac (libfdk_aac))
Decoder (codec none) not found for input stream #0:1
02:15:50.412 [main] ERROR shrinkwrap - Encountered a problem. Exiting shrinkwrap for safety
bennetimo commented 3 years ago

Hi @0kashi, from the log it looks like it's having some problems with the audio stream inside your file:

Stream #0:1 -> #0:1 (? (?) -> aac (libfdk_aac))
Decoder (codec none) not found for input stream #0:1

Does it play correctly in other software, and does it have audio? And a couple of things you could try:

docker run --rm -v /path/to/files:/files bennetimo/shrinkwrap --ffmpeg-opts analyzeduration=2147483647,probesize=2147483647 --input-extension avi /files/video1.avi   

And if you have something like mediainfo installed, you could run that against your file to see what codecs are in use in the file, and then might need to tweak the parameters accordingly.

Hope that helps!

0kashi commented 3 years ago

Hi @bennetimo - Sorry to resurrect this after quite some time. I tried your suggestion with increasing the 'analyzeduration' and 'probesize' to no avail. But I figured out the issue with the audio stream. Below are the details about the file in case you are curious.

Basically I need to be able tried to insert -codec:a aac BEFORE the input file name (before the -i here: https://github.com/bennetimo/shrinkwrap/blob/master/src/main/scala/io/coderunner/shrinkwrap/Action.scala#L32). Though the --ffmpeg-opts is only for the output. Any ideas here?

General
Complete name                            : /Desktop/test-file.avi
Format                                   : AVI
Format/Info                              : Audio Video Interleave
File size                                : 78.1 MiB
Duration                                 : 4 min 59 s
Overall bit rate                         : 2 187 kb/s
VGN0                                     : Living Room
VGT0                                     : ‘|íz
VGT1                                     : Î"íz
Video
ID                                       : 0
Format                                   : q264
Codec ID                                 : q264
Duration                                 : 4 min 59 s
Bit rate                                 : 2 114 kb/s
Width                                    : 2 048 pixels
Height                                   : 1 536 pixels
Display aspect ratio                     : 4:3
Frame rate                               : 30.000 FPS
Bits/(Pixel*Frame)                       : 0.022
Stream size                              : 75.5 MiB (97%)

Audio
ID                                       : 1
Format                                   : AAC LC
Format/Info                              : Advanced Audio Codec Low Complexity
Format version                           : Version 4
Muxing mode                              : ADTS
Codec ID                                 : AAC-2
Duration                                 : 4 min 59 s
Bit rate                                 : 256 kb/s
Channel(s)                               : 1 channel
Channel layout                           : C
Sampling rate                            : 16.0 kHz
Frame rate                               : 15.625 FPS (1024 SPF)
Compression mode                         : Lossy
Stream size                              : 2.32 MiB (3%)
Alignment                                : Split across interleaves
Interleave, duration                     : 64  ms (1.92 video frames)

EDIT: I thought this fixed the issue, but after the first 30 or so seconds the audio got garbled and then cut out. Do you have any suggestions based upon the above output from mediainfo?

bennetimo commented 3 years ago

Hi, no problem :) Is it the same for all your files or just one bad one? Based on that mediainfo output it looks like possibly the files are from a QNAP and they have (weirdly) given the codec name of q264 instead of what it probably is, h264.

So some things you could try:

  1. Explicitly set the input file format using ffmpeg -f h264 -i yourfile.avi ... etc
  2. Try to track ahead to a later part of the file (sometime after the 30s or so where you found it break) using something likeffmpeg -i yourfile.avi -ss 00:40:00, and see if you can process the latter part of the file ok

About specifying modifiers to take effect before the input file, yeah that would be nice. It's not possible with how it is at the moment but is something I've thought about before as I've found myself wanting to do that a couple of times. So if you want to play around with it, you can exec into the container but not run shrinkwrap, and then play around with ffmpeg.

e.g. something like: docker run -v "$(pwd)":/test --entrypoint=/bin/bash -it bennetimo/shrinkwrap That will put you into the container with whatever directory you ran it from mounted at /test. So if your avi is in there, you can then experiment, ffmpeg -i /test/yourfile.avi...

HTH

0kashi commented 3 years ago

Thanks. Yeah that is a weird codec name and yes, it is from a qnap. The thing is the video portion works fine, it's the audio that doesn't get brought over. I get a scaled down video with no audio. I guess I will continue to play with it. If you ever do implement the ability to insert options for the input let me know.

Thanks again.