Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Reply
 
Thread Tools Search this Thread Display Modes
Old 28th March 2014, 00:39   #1  |  Link
lyinawake
Registered User
 
Join Date: Mar 2014
Posts: 14
FFMPEG - Adding splash image to front of video

I have tried many different ways to try to create a 10 second video file out of an image file and have used all the same switches and codecs as I used to encode my video file. However, when I concat the two using anything but complex_filter (which forces the video through another round of transcoding), the resulting video file is corrupt. I believe this is due to the inherent differences of the 10 second clip that ffmpeg created from the image, but there must be some way to get it to encode the exact same way as my video file.

Here is the command I am using to turn the image into a 10s video clip (I added a silent mp3 because I thought that an audio stream starting partway through the video was messing things up):

Code:
ffmpeg -loop 1 -i splash.jpg -i silence.mp3 -c:v libx264 -preset slow -g 60 -r 29.97 -crf 16 -c:a libfdk_aac -b:a 256k -cutoff 18000 -t 5 tmpoutput1.mp4
Here is the command I am using to encode my video:

Code:
ffmpeg -i input.f4v -c:v libx264 -preset slow -g 60 -r 29.97 -crf 16 -c:a libfdk_aac -b:a 256k -cutoff 18000 tmpoutput2.mp4
Here is the command I use to convert both of them to .ts to get ready for concat:

Code:
ffmpeg -i tmpoutput1.mp4 -c copy -bsf:v h264_mp4toannexb -f mpegts tmpoutput1.ts
And finally the concat (which is where I get crazy video corruption, everything along the way looks fine):

Code:
ffmpeg -i "concat:tmpoutput1.ts|tmpoutput2.ts" -c copy output.mp4
Again, the issue is that I'm already transcoding everything once and I should be able to get it to transcode in a similar enough structure so that it can be concatenated without another transcode tacked onto the end.

Has anyone successfully added a full-frame splash graphic to the front of a video with ffmpeg before? I am using a brand new cross-compile of ffmpeg as I thought that might be the issue, but alas, the issue persists after the update.

Thanks!
lyinawake is offline   Reply With Quote
Old 28th March 2014, 01:10   #2  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,340
1) It's recommended to use concat demuxer, which works at the stream level, instead of concat protocol which works at the container level
http://trac.ffmpeg.org/wiki/How%20to%20concatenate%20%28join,%20merge%29%20media%20files

2) When using x264, encoding with --stitchable may improve your chances of successfully appending segments. In ffmpeg libx264 it would be -x264-params stitchable

3) There is always a chance something may go wrong when appending segments for whatever reason. A foolproof way would be to join before with a script (eg. avisynth), and encode in 1 go with ffmpeg. ffmpeg can be compiled with avs support.

Last edited by poisondeathray; 28th March 2014 at 01:18.
poisondeathray is offline   Reply With Quote
Old 28th March 2014, 01:39   #3  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,556
Try it with:

Code:
ffmpeg .... <input and x264 options> -x264opts sps-id=X <other options>
Where the id is different for each segment (0-31, 0 is default). I certainly hope ffmpeg's concat will keep both SPS parameter sets, I haven't tested. Changing the ID resets the decoder.

Edit: Ah, yes, I forgot about stitchable. With identical settings you won't need different sps-ids in that case.
foxyshadis is offline   Reply With Quote
Old 28th March 2014, 19:02   #4  |  Link
oxyViz
Registered User
 
Join Date: Mar 2014
Posts: 5
Just tested what your advised. It works. Commands was:

Code:
ffmpeg -i seg01.mkv -c:v libx264 ... -x264opts sps-id=1 ... seg01-sps1.mkv 
ffmpeg -i seg02.mkv -c:v libx264 ... -x264opts sps-id=2 ... seg01-sps2.mkv
ffmpeg -i seg03.mkv -c:v libx264 ... -x264opts sps-id=3 ... seg01-sps3.mkv

for f in *.mkv; do ffmpeg -i "$f" -c copy -bsf:v h264_mp4toannexb -sn "$f".ts; done

for f in *.ts; do echo "file '$f'" >> flist.txt; done

ffmpeg -f concat -i flist.txt -c copy -sn concat.mkv
I also try concat on *.mkv without remuxing into TS - it doesn't work.

Have one question about SPS ID's - they must be different for all segments or may be reused for segments where encoders params are the same?
oxyViz is offline   Reply With Quote
Old 29th March 2014, 23:37   #5  |  Link
Guest
Guest
 
Join Date: Jan 2002
Posts: 21,901
[bump after post approved from mod queue]
Guest is offline   Reply With Quote
Old 31st March 2014, 19:48   #6  |  Link
lyinawake
Registered User
 
Join Date: Mar 2014
Posts: 14
Thanks so much for all of your helpful feedback! The answer was actually a very simple one. I did not explicitly set the profile (main), level (3.1), and pix_fmt (yuv420p) in my command line. This has never been a problem for me until trying to work with image files turned to video. For these image videos, ffmpeg autodetects the parameters as a 4:4:4 Predictive L3.1 instead of 4:2:0 Main L3.1. I only found out when I tried to upload my merged videos to be streamed and it only played audio, but trusty ol' VLC played it no problem while I was testing.

After adding those 3 parameters to the command to generate the image video file, I was able to merge the pieces using the basic concat method and did not have to transcode to get everything put together.
lyinawake is offline   Reply With Quote
Reply

Tags
ffmpeg concat

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:19.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.