3

I recently purchased a Synology Diskstation DS412+, and I have a number of .mkv movies which I would like to convert/transcode to mp4 files, so that I can stream them directly to my XBox 360. I use Handbrake on my laptop, but I would rather have this happen directly on my NAS.

I'm very rusty on Linux and new to transcoding, but the script I currently have is the following:

#!/bin/bash
for dir in *; do
  if test -d "$dir"; then
    #echo $dir
    for file in "$dir"/*.mkv; do
      noextension=${file%.*}.mp4
      ffmpeg -y -i "$file" -vcodec copy -acodec copy "$noextension"
    done
  fi
done

Which, as I understand it, simply copies the audio and video components within the mkv container, and inserts them into a new mp4 container. This has worked for several of my files, but there are a number for which this does not work.

The following is an example of the output for a failed run:

ffmpeg version UNKNOWN, Copyright (c) 2000-2011 the FFmpeg developers
  built on Sep 16 2013 00:45:02 with gcc 4.2.1
  configuration: --prefix=/usr/syno --arch=i686 --target-os=linux --cross-prefix=/usr/local/i686-linux-gnu/bin/i686-linux-gnu- --enable-cross-compile --enable-optimizations --disable-yasm --disable-altivec --enable-pic --enable-shared --disable-static --disable-swscale-alpha --disable-ffserver --disable-ffplay --enable-libmp3lame --enable-libfaac --enable-nonfree --enable-version3 --enable-libopencore-amrnb --enable-libopencore-amrwb --disable-decoder=amrnb --disable-indev=alsa --disable-outdev=alsa --disable-encoder=dca --disable-encoder=ac3 --disable-encoder=ac3_fixed --disable-encoder=ac3_float --disable-encoder=eac3 --disable-decoder=dca --disable-decoder=eac3 --disable-decoder=truehd --cc=/usr/local/i686-linux-gnu/bin/i686-linux-gnu-ccache-gcc
  libavutil    50. 40. 1 / 50. 40. 1
  libavcodec   52.120. 0 / 52.120. 0
  libavformat  52.108. 0 / 52.108. 0
  libavdevice  52.  4. 0 / 52.  4. 0
  libavfilter   1. 77. 0 /  1. 77. 0
  libswscale    0. 14. 0 /  0. 14. 0
[matroska,webm @ 0x80726c0] Estimating duration from bitrate, this may be inaccurate

Seems stream 1 codec frame rate differs from container frame rate: 47.95 (5994/125) -> 23.98 (24000/1001)

...and then a list of input chapter start and end times and then...

 Stream #0.0(eng): Audio: aac, 48000 Hz, stereo, s16 (default)
 Stream #0.1(eng): Video: h264 (High), yuv420p, 1280x692 [PAR 1:1 DAR 320:173], 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)

...and then a list of output chapter start and end times and then...

Stream #0.0(eng): Video: ![0][0][0] / 0x0021, yuv420p, 1280x692 [PAR 1:1 DAR 320:173], q=2-31, 2997 tbn, 23.98 tbc (default)
Stream #0.1(eng): Audio: libfaac, 48000 Hz, stereo (default)
Stream mapping:
  Stream #0.1 -> #0.0
  Stream #0.0 -> #0.1
Press [q] to stop encoding
[mp4 @ 0x808a020] pts < dts in stream 0
av_interleaved_write_frame(): Invalid data found when processing input

The XBox support website gives details on supported file types, with mp4 included in the H.264 standard: http://support.xbox.com/ar-SA/xbox-360/system/audio-video-playback

I'm at a bit of a loss. I've read through http://www.ffmpeg.org/ffmpeg.html but the error message from ffmpeg doesn't seem very helpful, and resources are sparse at best when it comes to running this stuff on a Synology Box.

I have tried a few permutations of my script, such as:

ffmpeg -i "$file" "$noextension"

and

ffmpeg -y -i "$file" -vcodec mpeg4 -acodec libfaac "$noextension"

But those both give me the following error:

Error while opening encoder for output stream #0.0 - maybe incorrect parameters such as bit_rate, rate, width or height

I assume that I'll need to specify input and output codecs specifically, along with things like bitrate, or aspect ratio but this is where I come unstuck.

Any help would be much appreciated!

Rob Gwynn-Jones
  • 677
  • 1
  • 4
  • 14
  • 3
    I wouldn't go further without updating your ffmpeg version first. Yours if from 2011 – that's now three years old. Please download or compile a newer one: http://ffmpeg.org/download.html — then try again and please include the full, uncut command line output, not just the parts you think are relevant. Thanks – slhck Feb 05 '14 at 12:15

1 Answers1

2

Okay now actually there needs to have a more detail of the video which fails while transcoding. But still looking at the errors, here are the tries you can do. I will warn you that there are hell lot of combinations possible for output(bitrate,framerate etc.), but all that you have to decide.

Option 1

ffmpeg -y -i ip.mkv -vcodec libx264 -acodec libvo_aacenc op.mp4

This is similar to ffmpeg -i ip.mkv op.mp4 but I added codecs explicitly.

Option 2

ffmpeg -y -i ip.mkv -vcodec libx264 -acodec libvo_aacenc -b:a 92k op.mp4

Added bitrate, which you can change as per your need.

Option 3

ffmpeg -y -i ip.mkv -vcodec libx264 -acodec libvo_aacenc -b:a 92k -r 30 op.mp4

Added fps of 30.

You can also give a try of mix of 2 and 3 option.

Hope this helps.Cheers.:)

PS: As @slhck told; please update ffmpeg first and then try these. Also all these are re-encoding commands, so if you are really going for them; use better audio encoder than I have illustrated.

BlueSword
  • 1,290
  • 12
  • 25
  • The OP does not want to re-encode the videos, which all of your options do. Of course that might work for codecs that cannot be placed in an MP4. – slhck Feb 05 '14 at 12:55
  • @slhck yes it does re-encode videos; but these are just possible solution so as to get output. – BlueSword Feb 05 '14 at 13:03
  • I actually have no problem with re-encoding; my preference would be simpler = better, but if the only solution involves re-encoding then that's fine. I'll try updating ffmpeg and seeing how I go later on. – Rob Gwynn-Jones Feb 05 '14 at 22:53
  • Wow, I completely forgot I'd asked this question, and just found it nearly 3 years later. The answer I went for in the end is to use Plex for playing videos in whatever format they come in, rather than wrestling them to mp4 for playing on an XBox 360. I've accepted this answer as a good deal of effort clearly went into it, and had I been brave enough to persist I'm sure it would have been very helpful. – Rob Gwynn-Jones Sep 15 '16 at 06:25