Closed ferPrieto closed 3 years ago
What do you mean by one piece of video? As far as I can see you only have one input file in your reverse command. Do you have multiple input files when there are multiple pieces of video?
I've added a generic path as srcPath and destPath, but the actual path is something like: _-i, "src/video.mp4", -c:v, libx264, -crf, 22, -map, 0, -segment_time, 6, -g, 9, -sc_threshold, 0, -force_key_frames, expr:gte(t,nforced*6), -f, segment, "src/.SplitVideo/video0.mp4"
I get that. You've said that it works when there's one piece of video. I'm trying to understand what that is?
Yes, when the original video is about 2 seconds long, it does not need to get split in several segments, so there's just a unique piece to reverse. In that case, the reverse command goes through with no problems.
Hi @tanersener , can we follow up this problem? Because I guess it might happen to other people in the future. This is the class I use for the FFMpeg processing (Reverse Video feature). I follow the next flow:
And the step that fails with no logs is the reversing chunks, with the log I posted in the first message of this issue. This is the concrete class I use: https://github.com/ferPrieto/Twinpeaks/blob/master/data/src/main/java/fernando/prieto/data/ffmpeg/FfmpegCommandExecutor.kt
Thanks, Fernando
If videos shorter than 2 seconds are reversed successfully, for me this shows that your reverse command is correct. Therefore, I would concentrate on verifying that your splitting command is working as expected if I were you.
You say that videos shorter than 2 seconds don't need splitting, however your segment_size is 6 seconds in your splitting command. Do you have a 2 seconds check somewhere else?
You're forcing key frames every 6 seconds and but segment size is also 6 seconds. Do these options produce valid videos? Also did you try setting a smaller key frame interval.
You're using ffmpeg
and x264
specific options at the same time in your splitting command. Maybe they're not compatible with each other. Did you try to commenting out x264
options?
Hey @tanersener , I've tried to change the way I split the videos. As you said, I've avoided using x264 and it seems that the problem is in the reverse command, which potentially consumes too much CPU. For that reason Android OS closes the app all of a sudden. My new split command is: _-i sourceFilePath -c copy -map 0 -segmenttime 6 -f segment destinationPath The split 6 second videos seem to be ok, I can reproduce them all.
I've also tried to use a different reverse command, with no better solution: _-i fragmentSourcePath -filtercomplex "[0:v]reverse,fifo[r];[0:v][r] concat=n=2:v=1 [v]" -map [v] fragmentDestinationPath
There's no ffmpeg traces, simply a crash and the segments generated are 48 Bytes, which is wrong (they don't even play).
I found this trace at the bottom of my logs, referring to my app: Channel is unrecoverably broken and will be disposed!
I don't have the answers for some of my questions. So, where is that 2 second limit coming from? Additionally, are those 6 seconds segments playable, they should be all playable.
There was no second limit, I got the reverse command working only for short videos, such as 2 seconds. Any video longer than that crashed in the middle of the reverse process.
In regards to the 6s segments, they're playable as I indicated in the previous message. Hope that helps to spot the problem, although I reckon it's the CPU consumption.
Do you have the chance to test your reverse commands using desktop ffmpeg
? If not I'll ask you to provide me a sample application to reproduce this issue. I have to test it and see what's happening there.
I don't have ffmpeg running on Desktop. I can try to find the set up for that soon though.
The sample Android app I'm working on is this one: https://github.com/ferPrieto/Twinpeaks
Thanks for this follow up
Recorded a 8.7 second video in your app. This is the output https://ghostbin.co/paste/sork.
The following line is printed 37 times.
2020-10-14 21:51:57.641 25783-26679/prieto.fernando.twinpeaks D/FfmpegCommandExecutor: Started command : ffmpeg [-i, /storage/emulated/0/Android/data/prieto.fernando.twinpeaks/cache/VID_2020_10_14_21_51_19_529.mp4, -c:v, libx264, -crf, 22, -map, 0, -segment_time, 6, -g, 9, -sc_threshold, 0, -force_key_frames, expr:gte(t,n_forced*6), -f, segment, /storage/emulated/0/Android/media/prieto.fernando.twinpeaks/.VideoSplit/split_video%03d.mp4]
In the end, there are 2 split videos created. The first one is playable, the other one is not. The second one has wrong timestamp information. If you try to play it in a more advanced player it starts to play from 6th second until the 9th second.
221929 bytes - 6.14 seconds - split_video000.mp4
98006 bytes - 2.73 seconds - split_video001.mp4
If you look at the logs you can see the difference.
This is how video000.mp4 starts:
stream:0 start_pts_time:0 pts:1459 pts_time:0.128072 dts:691 dts_time:0.0606566
This is how video001.mp4 starts:
stream:0 start_pts_time:6.12807 pts:69811 pts_time:6.12807 dts:69043 dts_time:6.06066
After that, the following log line is printed 29 times. But it is only printed for video1 not for video0.
2020-10-14 21:52:16.668 25783-26679/prieto.fernando.twinpeaks D/FfmpegCommandExecutor: Started command : ffmpeg [-i, /storage/emulated/0/Android/media/prieto.fernando.twinpeaks/.VideoSplit/split_video001.mp4, -vf, reverse, -af, areverse, /storage/emulated/0/Android/media/prieto.fernando.twinpeaks/VideoPartsReverse/reverse_video1.mp4]
There are two reversed video outputs in the end. One of them is invalid, the other one is valid and playable.
48 bytes - 0 seconds - reverse_video0.mp4
97072 bytes - 2.73 seconds - reverse_video1.mp4
If you look at the reverse command outputs you can see the following errors for video000.mp4 and reverse_video0.mp4. I guess they show that there is something not supported in those videos. I'll suggest doing similar tests with longer videos or using shorter segment size to find the issue. Also try to set the correct timestamp for your videos.
Unknown dref type 0x206c7275 size 12
[h264 @ 0xd9853000] no picture
Thanks for sharing all of this @tanersener.
It's been really helpful to identify the time stamps issue of the split videos result. However, I've been trying to find the exact command to avoid that and I still keep looking for any.
It surprises me because, I've been trying with different segment times (longer and shorter), with numerous sizes source videos and I've never got the concatinating step at all. I always get the 48bytes reversed videos.
I'll keep you posted, let me know if there's anything I could try for the wrong timestamps. Thanks for the help
Hey @tanersener , after trying so many different commands I've not found any solution about the wrong time stamps. Do you know a generic way to do this and not screwing up the time stamps?
Thanks in advance
I'm using setpts=PTS-STARTPTS
to fix the timestamps. See the documentation about it.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Description I've split the video in several parts: _-i, srcPath, -c:v, libx264, -crf, 22, -map, 0, -segment_time, 6, -g, 9, -sc_threshold, 0, -force_key_frames, expr:gte(t,nforced*6), -f, segment, destPath Then I've tried to reverse those parts: -i, srcPath, -vf, reverse, -af, areverse, destPath
Expected behavior The video parts are reversed
Current behavior The process stops suddenly without showing any log. The last log it shows is: _cur_dts is invalid st:0 (0) [init:1 idone:0 finish:0] (this is harmless if it occurs once at the start per stream)
Environment
Other It seems to work when there's one piece of video only, which means the video is about 2 seconds. For longer video it crashes